-
Notifications
You must be signed in to change notification settings - Fork 22
fix: use factory to refresh session once it is finished #97
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
fix: use factory to refresh session once it is finished #97
Conversation
| args.endpoint, service, region, metadata, timeout, profile | ||
| ) | ||
|
|
||
| async with _initialize_client(transport) as client: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The client should be a ProxyClient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? We are doing the same as FastMCP.as_proxy https://github.com/jlowin/fastmcp/blob/ba69fba3055db6938ba368dc17275a85ca626ae3/src/fastmcp/server/server.py#L2612-L2634
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we probably want a mix of the if-else branches
- connect the session to be reused
- use ProxyClient to support features like elicitation and sampling; the regular client does not support
| nonlocal client | ||
| if not client.is_connected(): | ||
| logger.debug('Reinitialize client') | ||
| client = ProxyClient(transport) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if you do client.new() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns Client and not ProxyClient
| if not client.is_connected(): | ||
| logger.debug('Reinitialize client') | ||
| client = ProxyClient(transport) | ||
| await client._connect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this method throws, the client also hangs, the _initialize_client context manager writes the jsonrpc error to stdout.
Can this be done here too? I think it is a bit tricky to get the new json rpc message id.
Summary
Changes
Timeouts stop the background session task in FastMCP, this makes follow-up tool calls fail with
With this PR, we are explicitly refreshing the session when the client is no longer connected.
User experience
config for testing:
Cline
Before:
There is an error after a timeout
After:
Session refreshes under the hood and the next call succeeds
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change? (Y/N)
Please add details about how this change was tested.
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.