fix: connect remote mcp client immediately in the initialize middleware#114
Merged
fix: connect remote mcp client immediately in the initialize middleware#114
Conversation
3745d89 to
d4ccac1
Compare
We need this until PrefectHQ/fastmcp#2531 is accepted.
d4ccac1 to
fb9afeb
Compare
awsjjzhou
approved these changes
Dec 4, 2025
JacquesPotgieter
approved these changes
Dec 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Clients such ClaudeCode, Cursor, mcp inspector considers the connection as functional as long as the initialize request is successful, even if the following request to list tools, list template, list resources all fail due to the connection to remote cannot be established.
This PR connects to the client immediately in the fastmcp middleware on_initialize method so that the stdio initialize request fails early, instead of showing as a function but with no capabilities.
Changes
_connectfor kiro cli, because it does not handle initialize error well due to rust sdk fix: use the json rpc error from the initialize response and bubble up to the client modelcontextprotocol/rust-sdk#569User experience
ClaudeCode and Cursor experience is fixed. Currently for ClaudeCode and Cursor, the protocol initialization succeeds, but list-tools fail, which lead to the MCP server is shown as connected, but no capabilities.
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.