@@ -2,7 +2,6 @@ package mcp
22
33import (
44 "context"
5- "fmt"
65
76 "github.com/modelcontextprotocol/go-sdk/mcp"
87)
@@ -12,8 +11,13 @@ type GetMokapiTypeScriptApiInput struct {
1211}
1312
1413type GetMokapiTypeScriptApiOutput struct {
15- Package string `json:"package"`
16- Types string `json:"types"`
14+ Packages []Package `json:"packages"`
15+ }
16+
17+ type Package struct {
18+ Name string `json:"name"`
19+ Description string `json:"description"`
20+ Types string `json:"types"`
1721}
1822
1923func (s * Service ) registerGetMokapiTypeScriptApi (server * mcp.Server ) {
@@ -22,57 +26,158 @@ func (s *Service) registerGetMokapiTypeScriptApi(server *mcp.Server) {
2226 "properties" : map [string ]any {
2327 "package" : map [string ]any {
2428 "type" : "string" ,
25- "description" : "The name of the package to fetch TypeScript definitions for, e.g., 'mokapi/http'" ,
29+ "description" : "Filter package by name." ,
30+ "enum" : []string {"mokapi" , "mokapi/http" , "mokapi/kafka" , "mokapi/faker" , "mokapi/file" },
31+ "optional" : true ,
32+ },
33+ },
34+ }
35+
36+ outputSchema := map [string ]any {
37+ "type" : "object" ,
38+ "properties" : map [string ]any {
39+ "packages" : map [string ]any {
40+ "type" : "array" ,
41+ "description" : "The list of packages" ,
42+ "items" : map [string ]any {
43+ "type" : "object" ,
44+ "description" : "The package with the TypeScript types" ,
45+ "properties" : map [string ]any {
46+ "name" : map [string ]any {
47+ "type" : "string" ,
48+ "description" : "The name of the package" ,
49+ "enum" : []string {"mokapi" , "mokapi/http" , "mokapi/kafka" , "mokapi/faker" , "mokapi/file" },
50+ },
51+ "description" : map [string ]any {
52+ "type" : "string" ,
53+ "description" : "The description of the package" ,
54+ },
55+ "types" : map [string ]any {
56+ "type" : "string" ,
57+ "description" : "The types of the package" ,
58+ },
59+ },
60+ "required" : []any {"name" , "description" },
61+ },
2662 },
2763 },
28- "required" : []string {"package " },
64+ "required" : []string {"packages " },
2965 }
3066
3167 registerTool (server , & mcp.Tool {
3268 Name : "mokapi_get_typescript_api" ,
3369 Description : `Returns TypeScript definitions for a specific Mokapi package.
3470
35- Use this tool after selecting a package via "mokapi_get_typescript_api_list".
71+ - DISCOVERY: Call without 'package' to get an overview of all available APIs (names and descriptions).
72+ - DETAILS: Call with a specific 'name' to get the full type definitions.
3673
3774The returned types define:
3875- Event handler signatures
3976- Request and response structures
4077- Available properties
4178
42- Combine this with "get_scenario" to understand correct usage patterns.` ,
43- InputSchema : inputSchema ,
79+ Use the returned types to implement the mock script.
80+ Combine this with "mokapi_get_scenarios" to understand correct usage patterns.` ,
81+ InputSchema : inputSchema ,
82+ OutputSchema : outputSchema ,
4483 }, s .GetMokapiTypeScriptApi )
4584}
4685
4786func (s * Service ) GetMokapiTypeScriptApi (_ context.Context , in GetMokapiTypeScriptApiInput ) (GetMokapiTypeScriptApiOutput , error ) {
87+ if in .Package == "" {
88+ return GetMokapiTypeScriptApiOutput {
89+ Packages : []Package {
90+ {
91+ Name : "mokapi" ,
92+ Description : `Mokapi JavaScript API
93+ This module exposes the core scripting API for Mokapi.
94+ It allows you to intercept and manipulate protocol events (HTTP, Kafka, LDAP, SMTP),
95+ schedule jobs, generate mock data, and share state between scripts.` ,
96+ },
97+ {
98+ Name : "mokapi/http" ,
99+ Description : `Utilities for sending HTTP requests and handling HTTP interactions within Mokapi scripts.
100+ Use these functions to simulate client calls, test API integrations, or trigger endpoints from scripts.` ,
101+ },
102+ {
103+ Name : "mokapi/kafka" ,
104+ Description : `Utilities for producing and consuming messages on Kafka topics.
105+ This package allows you to mock message streams, inspect events, and simulate Kafka-based workflows.` ,
106+ },
107+ {
108+ Name : "mokapi/faker" ,
109+ Description : `Generates realistic random test data based on JSON schemas or attribute names.
110+ Use this to populate mock responses or generate dynamic content for API responses.` ,
111+ },
112+ {
113+ Name : "mokapi/file" ,
114+ Description : `File system utilities for reading, writing, and manipulating files within Mokapi scripts.
115+ Useful for mocking file-based APIs, loading fixtures, or storing script state.` ,
116+ },
117+ },
118+ }, nil
119+ }
120+
48121 switch in .Package {
49122 case "mokapi" :
50123 return GetMokapiTypeScriptApiOutput {
51- Package : "mokapi" ,
52- Types : pkgMokapi ,
124+ Packages : []Package {
125+ {
126+ Name : "mokapi" ,
127+ Description : `Mokapi JavaScript API
128+ This module exposes the core scripting API for Mokapi.
129+ It allows you to intercept and manipulate protocol events (HTTP, Kafka, LDAP, SMTP),
130+ schedule jobs, generate mock data, and share state between scripts.` ,
131+ Types : pkgMokapi ,
132+ },
133+ },
53134 }, nil
54135 case "mokapi/http" :
55136 return GetMokapiTypeScriptApiOutput {
56- Package : "mokapi/http" ,
57- Types : pkgHttp ,
137+ Packages : []Package {
138+ {
139+ Name : "mokapi/http" ,
140+ Description : `Utilities for sending HTTP requests and handling HTTP interactions within Mokapi scripts.
141+ Use these functions to simulate client calls, test API integrations, or trigger endpoints from scripts.` ,
142+ Types : pkgHttp ,
143+ },
144+ },
58145 }, nil
59146 case "mokapi/kafka" :
60147 return GetMokapiTypeScriptApiOutput {
61- Package : "mokapi/kafka" ,
62- Types : pkgKafka ,
148+ Packages : []Package {
149+ {
150+ Name : "mokapi/kafka" ,
151+ Description : `Utilities for producing and consuming messages on Kafka topics.
152+ This package allows you to mock message streams, inspect events, and simulate Kafka-based workflows.` ,
153+ Types : pkgKafka ,
154+ },
155+ },
63156 }, nil
64157 case "mokapi/faker" :
65158 return GetMokapiTypeScriptApiOutput {
66- Package : "mokapi/faker" ,
67- Types : pkgFaker ,
159+ Packages : []Package {
160+ {
161+ Name : "mokapi/faker" ,
162+ Description : `Generates realistic random test data based on JSON schemas or attribute names.
163+ Use this to populate mock responses or generate dynamic content for API responses.` ,
164+ Types : pkgFaker ,
165+ },
166+ },
68167 }, nil
69168 case "mokapi/file" :
70169 return GetMokapiTypeScriptApiOutput {
71- Package : "mokapi/file" ,
72- Types : pkgFile ,
170+ Packages : []Package {
171+ {
172+ Name : "mokapi/file" ,
173+ Description : `File system utilities for reading, writing, and manipulating files within Mokapi scripts.
174+ Useful for mocking file-based APIs, loading fixtures, or storing script state.` ,
175+ Types : pkgFile ,
176+ },
177+ },
73178 }, nil
74179 }
75- return GetMokapiTypeScriptApiOutput {}, fmt . Errorf ( "unknown Mokapi package: %s" , in . Package )
180+ return GetMokapiTypeScriptApiOutput {}, nil
76181}
77182
78183const (
0 commit comments