Skip to content

Expose tool response #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"

"github.com/metoro-io/mcp-golang/internal/protocol"
"github.com/metoro-io/mcp-golang/internal/tools"
"github.com/metoro-io/mcp-golang/transport"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -60,7 +59,7 @@ func (c *Client) Initialize(ctx context.Context) (*InitializeResponse, error) {
}

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

var toolsResponse tools.ToolsResponse
var toolsResponse ToolsResponse
err = json.Unmarshal(responseBytes, &toolsResponse)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal tools response")
Expand Down
7 changes: 3 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/invopop/jsonschema"
"github.com/metoro-io/mcp-golang/internal/datastructures"
"github.com/metoro-io/mcp-golang/internal/protocol"
"github.com/metoro-io/mcp-golang/internal/tools"
"github.com/metoro-io/mcp-golang/transport"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -630,17 +629,17 @@ func (s *Server) handleListTools(ctx context.Context, request *transport.BaseJSO
}
}

toolsToReturn := make([]tools.ToolRetType, 0)
toolsToReturn := make([]ToolRetType, 0)

for i := startPosition; i < endPosition; i++ {
toolsToReturn = append(toolsToReturn, tools.ToolRetType{
toolsToReturn = append(toolsToReturn, ToolRetType{
Name: orderedTools[i].Name,
Description: &orderedTools[i].Description,
InputSchema: orderedTools[i].ToolInputSchema,
})
}

return tools.ToolsResponse{
return ToolsResponse{
Tools: toolsToReturn,
NextCursor: func() *string {
if s.paginationLimit != nil && len(toolsToReturn) >= *s.paginationLimit {
Expand Down
9 changes: 4 additions & 5 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/metoro-io/mcp-golang/internal/protocol"
"github.com/metoro-io/mcp-golang/internal/testingutils"
"github.com/metoro-io/mcp-golang/internal/tools"
"github.com/metoro-io/mcp-golang/transport"
)

Expand Down Expand Up @@ -191,7 +190,7 @@ func TestHandleListToolsPagination(t *testing.T) {
t.Fatal(err)
}

toolsResp, ok := resp.(tools.ToolsResponse)
toolsResp, ok := resp.(ToolsResponse)
if !ok {
t.Fatal("Expected tools.ToolsResponse")
}
Expand All @@ -215,7 +214,7 @@ func TestHandleListToolsPagination(t *testing.T) {
t.Fatal(err)
}

toolsResp, ok = resp.(tools.ToolsResponse)
toolsResp, ok = resp.(ToolsResponse)
if !ok {
t.Fatal("Expected tools.ToolsResponse")
}
Expand All @@ -239,7 +238,7 @@ func TestHandleListToolsPagination(t *testing.T) {
t.Fatal(err)
}

toolsResp, ok = resp.(tools.ToolsResponse)
toolsResp, ok = resp.(ToolsResponse)
if !ok {
t.Fatal("Expected tools.ToolsResponse")
}
Expand Down Expand Up @@ -272,7 +271,7 @@ func TestHandleListToolsPagination(t *testing.T) {
t.Fatal(err)
}

toolsResp, ok = resp.(tools.ToolsResponse)
toolsResp, ok = resp.(ToolsResponse)
if !ok {
t.Fatal("Expected ToolsResponse")
}
Expand Down
16 changes: 16 additions & 0 deletions tool_response_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,19 @@ type baseCallToolRequestParams struct {
// Name corresponds to the JSON schema field "name".
Name string `json:"name" yaml:"name" mapstructure:"name"`
}

// Definition for a tool the client can call.
type ToolRetType struct {
// A human-readable description of the tool.
Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`

// A JSON Schema object defining the expected parameters for the tool.
InputSchema interface{} `json:"inputSchema" yaml:"inputSchema" mapstructure:"inputSchema"`

// The name of the tool.
Name string `json:"name" yaml:"name" mapstructure:"name"`
}
type ToolsResponse struct {
Tools []ToolRetType `json:"tools" yaml:"tools" mapstructure:"tools"`
NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"`
}
Loading