Repository navigation
Replies: 1 comment
|
The server-side code is close. The main things to verify are:
For example, the server handler can be written as: func downloadHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
var progressToken mcp.ProgressToken
if request.Params.Meta != nil {
progressToken = request.Params.Meta.ProgressToken
}
srv := server.ServerFromContext(ctx)
total := 100.0
for i := 1; i <= 100; i++ {
if progressToken != nil {
if err := srv.SendNotificationToClient(ctx, "notifications/progress", map[string]any{
"progressToken": progressToken,
"progress": float64(i),
"total": total,
"message": fmt.Sprintf("Download progress: %d%%", i),
}); err != nil {
return nil, fmt.Errorf("send progress notification: %w", err)
}
}
time.Sleep(300 * time.Millisecond)
}
return mcp.NewToolResultText("download completed"), nil
}With the mcp-go client, install the handler before Start/Initialize, and send a token: client.OnNotification(func(n mcp.JSONRPCNotification) {
if n.Method == "notifications/progress" {
log.Printf("progress: %+v", n.Params)
}
})
if err := client.Start(ctx); err != nil { /* handle */ }
if _, err := client.Initialize(ctx, initRequest); err != nil { /* handle */ }
_, err := client.CallTool(ctx, mcp.CallToolRequest{
Params: mcp.CallToolParams{
Name: "download",
Meta: &mcp.Meta{ProgressToken: "download-1"},
},
})If this still does not arrive, do not ignore the error from SendNotificationToClient; also inspect the POST response Content-Type. A non-streaming ResponseWriter or a proxy that buffers SSE can prevent notifications from being delivered while the tool is running. This is also covered by the current mcp-go implementation and HTTP client tests: |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Refer to the example: examples/sampling_http_server/main.go, create an MCP service, add the following processing, but it doesn't seem to work, the client is not receiving progress notifications.
Using the code below is sent
All reactions