-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Prevent MCP ClientSession hang #580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Per https://modelcontextprotocol.io/specification/draft/basic/lifecycle#timeouts "Implementations SHOULD establish timeouts for all sent requests, to prevent hung connections and resource exhaustion. When the request has not received a success or error response within the timeout period, the sender SHOULD issue a cancellation notification for that request and stop waiting for a response. SDKs and other middleware SHOULD allow these timeouts to be configured on a per-request basis."
@njbrake - thanks. Couple of quick questions:
|
Thanks for the quick response @rm-openai.
Based on my understanding of the MCP python sdk, yep this is different because this ClientSession applies to both SSE and Stdio sessions. The current The parameter that I'm adding to mcp.ClientSession is passed to https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/shared/session.py#L246-L263
Sounds good to me 👍 |
@rm-openai Ok gave a shot at implementing the timeout as you suggested, let me know what you think 🙏 |
@rm-openai ah sorry, I see some linting etc failing, one sec I'll fix it up |
Per https://modelcontextprotocol.io/specification/draft/basic/lifecycle#timeouts
"Implementations SHOULD establish timeouts for all sent requests, to prevent hung connections and resource exhaustion. When the request has not received a success or error response within the timeout period, the sender SHOULD issue a cancellation notification for that request and stop waiting for a response.
SDKs and other middleware SHOULD allow these timeouts to be configured on a per-request basis."
I picked 5 seconds since that's the default for SSE