when tools/call request is complete, but notifications/progress is still sent, will get a error "rejected by transport" #669
Replies: 2 comments
|
this error refer to https://github.com/modelcontextprotocol/go-sdk/blob/main/mcp/streamable.go#L1156 if s == nil { |
|
With Streamable HTTP, the SDK also enforces this at the transport layer. The handler context carries the related request, and the response removes that request-to-stream association. Reusing the context afterward therefore produces Keep the handler open until the work and its final progress notification finish, and check each notification error: mcp.AddTool(server, tool, func(
ctx context.Context,
req *mcp.CallToolRequest,
args Input,
) (*mcp.CallToolResult, Output, error) {
token := req.Params.GetProgressToken()
for i := range steps {
// Perform this step synchronously, or wait for its worker here.
if err := runStep(ctx, steps[i]); err != nil {
return nil, Output{}, err
}
if token != nil {
if err := req.Session.NotifyProgress(ctx, &mcp.ProgressNotificationParams{
ProgressToken: token,
Progress: float64(i + 1),
Total: float64(len(steps)),
}); err != nil {
return nil, Output{}, err
}
}
}
return &mcp.CallToolResult{}, Output{/* ... */}, nil
})Do not launch a goroutine that keeps using the handler's The SDK's current progress example sends all notifications before returning, and the closed-stream check documents that related messages are rejected after the response. |
Uh oh!
There was an error while loading. Please reload this page.
Pre-submission Checklist
Question Category
Your Question
How can I solve this : after the server-side tools/call returns results, ensuring the notification request can still be sent out?
All reactions