Skip to content
Closed
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
16 changes: 8 additions & 8 deletions examples/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ type GetTimeParams struct {
}

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

city := params.Arguments.City
city := params.City
if city == "" {
city = "nyc" // Default to NYC
}

// Get the timezone.
tzName, ok := locations[city]
if !ok {
return nil, fmt.Errorf("unknown city: %s", city)
return nil, nil, fmt.Errorf("unknown city: %s", city)
}

// Load the location.
loc, err := time.LoadLocation(tzName)
if err != nil {
return nil, fmt.Errorf("failed to load timezone: %w", err)
return nil, nil, fmt.Errorf("failed to load timezone: %w", err)
}

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

return &mcp.CallToolResultFor[any]{
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: response},
},
}, nil
}, nil, nil
}

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

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

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

// Connect to the server.
session, err := client.Connect(ctx, transport)
session, err := client.Connect(ctx, transport, nil)
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
Expand Down