Skip to content

Commit be0a00c

Browse files
authored
examples/http: update to v0.3.0
Fix build breakage. Fixes #383.
1 parent a617dce commit be0a00c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

examples/http/main.go

Lines changed: 7 additions & 10 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) {
@@ -145,17 +145,14 @@ func runClient(url string) {
145145
// Create the URL for the server.
146146
log.Printf("Connecting to MCP server at %s", url)
147147

148-
// Create a streamable client transport.
149-
transport := mcp.NewStreamableClientTransport(url, nil)
150-
151148
// Create an MCP client.
152149
client := mcp.NewClient(&mcp.Implementation{
153150
Name: "time-client",
154151
Version: "1.0.0",
155152
}, nil)
156153

157154
// Connect to the server.
158-
session, err := client.Connect(ctx, transport)
155+
session, err := client.Connect(ctx, &mcp.StreamableClientTransport{Endpoint: url}, nil)
159156
if err != nil {
160157
log.Fatalf("Failed to connect: %v", err)
161158
}

0 commit comments

Comments
 (0)