Skip to content

Commit d14d18e

Browse files
committed
feat(mcp): improve tools collection
reduced number of tools
1 parent 613ab98 commit d14d18e

8 files changed

Lines changed: 131 additions & 92 deletions

mcp/get_http_mock_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ You can:
4545
4646
Typical pattern:
4747
1. Apply your business logic (e.g., find a resource)
48-
2. Call generate_http_mock_response with the correct status code
48+
2. Call mokapi_generate_http_mock_response with the correct status code
4949
3. Override result.data if needed
5050
4. Assign result to response
5151
`,

mcp/get_mokapi_typescript_api.go

Lines changed: 124 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package mcp
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/modelcontextprotocol/go-sdk/mcp"
87
)
@@ -12,8 +11,13 @@ type GetMokapiTypeScriptApiInput struct {
1211
}
1312

1413
type 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

1923
func (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
3774
The 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

4786
func (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

78183
const (

mcp/get_mokapi_typescript_list.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

mcp/get_scenarios.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func (s *Service) registerGetScenarios(server *mcp.Server) {
1111
Name: "mokapi_get_scenarios",
1212
Description: `Lists available scenarios for generating Mokapi scripts.
1313
14-
Use this tool BEFORE calling template tools (e.g., "get_http_mock_template")
14+
Use this tool BEFORE calling template tools (e.g., "mokapi_get_http_mock_template")
1515
to discover supported scenarios.
1616
1717
Typical workflow:

mcp/produce_kafka_message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (s *Service) registerProduceKafkaMessage(server *mcp.Server) {
7373
Name: "mokapi_produce_kafka_message",
7474
Description: `Produce a message to a Kafka topic.
7575
76-
Use this tool after retrieving the API specification with 'get_api_spec' to understand available topics and message formats.
76+
Use this tool after retrieving the API specification with 'mokapi_get_api_spec' to understand available topics and message formats.
7777
7878
Allows sending messages with optional key and headers.`,
7979
InputSchema: inputSchema,

mcp/send_http_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (s *Service) registerSendHttpRequest(server *mcp.Server) {
9191
Name: "mokapi_send_http_request",
9292
Description: `Send an HTTP request to a mocked API.
9393
94-
Use this tool AFTER retrieving the API specification with 'get_api_spec' to understand available endpoints.
94+
Use this tool AFTER retrieving the API specification with 'mokapi_get_api_spec' to understand available endpoints.
9595
9696
Supports GET, POST, PUT, PATCH, and DELETE requests.
9797
Returns the full response including status code, headers, and body.`,

mcp/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func NewServer(app *runtime.App) http.Handler {
3535

3636
svc.registerGetEvents(server)
3737

38-
svc.registerGetMokapiTypeScriptList(server)
3938
svc.registerGetMokapiTypeScriptApi(server)
4039
svc.registerGetScenarios(server)
4140
svc.registerGetHttpMockTemplate(server)

mcp/server_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ func TestServer(t *testing.T) {
3131

3232
list, err := session.ListTools(ctx, &gomcp.ListToolsParams{})
3333
require.NoError(t, err)
34-
require.Len(t, list.Tools, 9)
34+
require.Len(t, list.Tools, 8)
3535
// alphabetical order
3636
require.Equal(t, "mokapi_generate_http_mock_response", list.Tools[0].Name)
3737
require.Equal(t, "mokapi_get_api_spec", list.Tools[1].Name)
3838
require.Equal(t, "mokapi_get_events", list.Tools[2].Name)
3939
require.Equal(t, "mokapi_get_http_mock_template", list.Tools[3].Name)
4040
require.Equal(t, "mokapi_get_scenarios", list.Tools[4].Name)
4141
require.Equal(t, "mokapi_get_typescript_api", list.Tools[5].Name)
42-
require.Equal(t, "mokapi_get_typescript_list", list.Tools[6].Name)
43-
require.Equal(t, "mokapi_produce_kafka_message", list.Tools[7].Name)
44-
require.Equal(t, "mokapi_send_http_request", list.Tools[8].Name)
42+
require.Equal(t, "mokapi_produce_kafka_message", list.Tools[6].Name)
43+
require.Equal(t, "mokapi_send_http_request", list.Tools[7].Name)
4544
}

0 commit comments

Comments
 (0)