Skip to content

Commit 34bdc1c

Browse files
committed
examples/http: fix broken tool function signatures
The HTTP example was using incorrect CallToolParamsFor and CallToolResultFor types that don't exist in the current API. Updated to use standard MCP tool pattern with CallToolRequest, CallToolResult, and proper return values. Also fixed client.Connect call to include missing ClientSessionOptions parameter. Fixes the build errors introduced in the previous commit.
1 parent a617dce commit 34bdc1c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

examples/http/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,29 @@ type GetTimeParams struct {
6464
}
6565

6666
// getTime implements the tool that returns the current time for a given city.
67-
func getTime(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[GetTimeParams]) (*mcp.CallToolResultFor[any], error) {
67+
func getTime(ctx context.Context, req *mcp.CallToolRequest, params GetTimeParams) (*mcp.CallToolResult, any, error) {
6868
// Define time zones for each city
6969
locations := map[string]string{
7070
"nyc": "America/New_York",
7171
"sf": "America/Los_Angeles",
7272
"boston": "America/New_York",
7373
}
7474

75-
city := params.Arguments.City
75+
city := params.City
7676
if city == "" {
7777
city = "nyc" // Default to NYC
7878
}
7979

8080
// Get the timezone.
8181
tzName, ok := locations[city]
8282
if !ok {
83-
return nil, fmt.Errorf("unknown city: %s", city)
83+
return nil, nil, fmt.Errorf("unknown city: %s", city)
8484
}
8585

8686
// Load the location.
8787
loc, err := time.LoadLocation(tzName)
8888
if err != nil {
89-
return nil, fmt.Errorf("failed to load timezone: %w", err)
89+
return nil, nil, fmt.Errorf("failed to load timezone: %w", err)
9090
}
9191

9292
// Get current time in that location.
@@ -103,11 +103,11 @@ func getTime(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolPar
103103
cityNames[city],
104104
now.Format(time.RFC3339))
105105

106-
return &mcp.CallToolResultFor[any]{
106+
return &mcp.CallToolResult{
107107
Content: []mcp.Content{
108108
&mcp.TextContent{Text: response},
109109
},
110-
}, nil
110+
}, nil, nil
111111
}
112112

113113
func runServer(url string) {
@@ -146,7 +146,7 @@ func runClient(url string) {
146146
log.Printf("Connecting to MCP server at %s", url)
147147

148148
// Create a streamable client transport.
149-
transport := mcp.NewStreamableClientTransport(url, nil)
149+
transport := &mcp.StreamableClientTransport{Endpoint: url}
150150

151151
// Create an MCP client.
152152
client := mcp.NewClient(&mcp.Implementation{
@@ -155,7 +155,7 @@ func runClient(url string) {
155155
}, nil)
156156

157157
// Connect to the server.
158-
session, err := client.Connect(ctx, transport)
158+
session, err := client.Connect(ctx, transport, nil)
159159
if err != nil {
160160
log.Fatalf("Failed to connect: %v", err)
161161
}

0 commit comments

Comments
 (0)