Skip to content

Commit 1fa18e0

Browse files
Expose tool response (#61)
1 parent 682b7ad commit 1fa18e0

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

client.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66

77
"github.com/metoro-io/mcp-golang/internal/protocol"
8-
"github.com/metoro-io/mcp-golang/internal/tools"
98
"github.com/metoro-io/mcp-golang/transport"
109
"github.com/pkg/errors"
1110
)
@@ -60,7 +59,7 @@ func (c *Client) Initialize(ctx context.Context) (*InitializeResponse, error) {
6059
}
6160

6261
// ListTools retrieves the list of available tools from the server
63-
func (c *Client) ListTools(ctx context.Context, cursor *string) (*tools.ToolsResponse, error) {
62+
func (c *Client) ListTools(ctx context.Context, cursor *string) (*ToolsResponse, error) {
6463
if !c.initialized {
6564
return nil, errors.New("client not initialized")
6665
}
@@ -79,7 +78,7 @@ func (c *Client) ListTools(ctx context.Context, cursor *string) (*tools.ToolsRes
7978
return nil, errors.New("invalid response type")
8079
}
8180

82-
var toolsResponse tools.ToolsResponse
81+
var toolsResponse ToolsResponse
8382
err = json.Unmarshal(responseBytes, &toolsResponse)
8483
if err != nil {
8584
return nil, errors.Wrap(err, "failed to unmarshal tools response")

server.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/invopop/jsonschema"
1313
"github.com/metoro-io/mcp-golang/internal/datastructures"
1414
"github.com/metoro-io/mcp-golang/internal/protocol"
15-
"github.com/metoro-io/mcp-golang/internal/tools"
1615
"github.com/metoro-io/mcp-golang/transport"
1716
"github.com/pkg/errors"
1817
)
@@ -630,17 +629,17 @@ func (s *Server) handleListTools(ctx context.Context, request *transport.BaseJSO
630629
}
631630
}
632631

633-
toolsToReturn := make([]tools.ToolRetType, 0)
632+
toolsToReturn := make([]ToolRetType, 0)
634633

635634
for i := startPosition; i < endPosition; i++ {
636-
toolsToReturn = append(toolsToReturn, tools.ToolRetType{
635+
toolsToReturn = append(toolsToReturn, ToolRetType{
637636
Name: orderedTools[i].Name,
638637
Description: &orderedTools[i].Description,
639638
InputSchema: orderedTools[i].ToolInputSchema,
640639
})
641640
}
642641

643-
return tools.ToolsResponse{
642+
return ToolsResponse{
644643
Tools: toolsToReturn,
645644
NextCursor: func() *string {
646645
if s.paginationLimit != nil && len(toolsToReturn) >= *s.paginationLimit {

server_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/metoro-io/mcp-golang/internal/protocol"
88
"github.com/metoro-io/mcp-golang/internal/testingutils"
9-
"github.com/metoro-io/mcp-golang/internal/tools"
109
"github.com/metoro-io/mcp-golang/transport"
1110
)
1211

@@ -191,7 +190,7 @@ func TestHandleListToolsPagination(t *testing.T) {
191190
t.Fatal(err)
192191
}
193192

194-
toolsResp, ok := resp.(tools.ToolsResponse)
193+
toolsResp, ok := resp.(ToolsResponse)
195194
if !ok {
196195
t.Fatal("Expected tools.ToolsResponse")
197196
}
@@ -215,7 +214,7 @@ func TestHandleListToolsPagination(t *testing.T) {
215214
t.Fatal(err)
216215
}
217216

218-
toolsResp, ok = resp.(tools.ToolsResponse)
217+
toolsResp, ok = resp.(ToolsResponse)
219218
if !ok {
220219
t.Fatal("Expected tools.ToolsResponse")
221220
}
@@ -239,7 +238,7 @@ func TestHandleListToolsPagination(t *testing.T) {
239238
t.Fatal(err)
240239
}
241240

242-
toolsResp, ok = resp.(tools.ToolsResponse)
241+
toolsResp, ok = resp.(ToolsResponse)
243242
if !ok {
244243
t.Fatal("Expected tools.ToolsResponse")
245244
}
@@ -272,7 +271,7 @@ func TestHandleListToolsPagination(t *testing.T) {
272271
t.Fatal(err)
273272
}
274273

275-
toolsResp, ok = resp.(tools.ToolsResponse)
274+
toolsResp, ok = resp.(ToolsResponse)
276275
if !ok {
277276
t.Fatal("Expected ToolsResponse")
278277
}

tool_response_types.go

+16
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,19 @@ type baseCallToolRequestParams struct {
144144
// Name corresponds to the JSON schema field "name".
145145
Name string `json:"name" yaml:"name" mapstructure:"name"`
146146
}
147+
148+
// Definition for a tool the client can call.
149+
type ToolRetType struct {
150+
// A human-readable description of the tool.
151+
Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`
152+
153+
// A JSON Schema object defining the expected parameters for the tool.
154+
InputSchema interface{} `json:"inputSchema" yaml:"inputSchema" mapstructure:"inputSchema"`
155+
156+
// The name of the tool.
157+
Name string `json:"name" yaml:"name" mapstructure:"name"`
158+
}
159+
type ToolsResponse struct {
160+
Tools []ToolRetType `json:"tools" yaml:"tools" mapstructure:"tools"`
161+
NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"`
162+
}

0 commit comments

Comments
 (0)