Skip to content

Commit ec64583

Browse files
authored
fix tool descriptions from config (#79)
1 parent 99c00e6 commit ec64583

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

mcpgenerator/server_tools.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func (s *MCPServer) SetTools(tools []model.Endpoint) {
2222
s.server.DeleteTools(names...)
2323
for _, endpoint := range tools {
2424
var opts []mcp.ToolOption
25+
if endpoint.Description != "" {
26+
opts = append(opts, mcp.WithDescription(endpoint.Description))
27+
} else if endpoint.Summary != "" {
28+
opts = append(opts, mcp.WithDescription(endpoint.Summary))
29+
}
2530
for _, col := range endpoint.Params {
2631
if col.Required {
2732
opts = append(opts, ArgumentOption(col, mcp.Required()))

mcpgenerator/server_tools_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package mcpgenerator
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/centralmind/gateway/mcp"
8+
"github.com/centralmind/gateway/model"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestSetToolsIncludesDescription(t *testing.T) {
13+
srv, err := New(nil)
14+
assert.NoError(t, err)
15+
ctx := context.Background()
16+
17+
// initialize server to enable tools capabilities
18+
_ = srv.Server().HandleMessage(ctx, []byte(`{"jsonrpc":"2.0","id":1,"method":"initialize"}`))
19+
20+
endpoint := model.Endpoint{
21+
MCPMethod: "test_method",
22+
Description: "sample description",
23+
Params: []model.EndpointParams{
24+
{Name: "id", Type: "string"},
25+
},
26+
}
27+
28+
srv.SetTools([]model.Endpoint{endpoint})
29+
30+
resp := srv.Server().HandleMessage(ctx, []byte(`{"jsonrpc":"2.0","id":2,"method":"tools/list"}`))
31+
listResp, ok := resp.(mcp.JSONRPCResponse)
32+
assert.True(t, ok)
33+
tools := listResp.Result.(mcp.ListToolsResult).Tools
34+
if assert.Len(t, tools, 1) {
35+
assert.Equal(t, "sample description", tools[0].Description)
36+
}
37+
}

0 commit comments

Comments
 (0)