chore(mcp): evaluate minimal SDK v2 migration - #5180
Draft
chengyongru wants to merge 1 commit into
Draft
Conversation
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.
Purpose
This is an evaluation Draft for #5138. It implements the smallest viable MCP SDK v2 migration so we can judge the real code cost and runtime payoff before deciding whether to merge it.
It is intentionally a narrower alternative baseline to #5179: this branch keeps the supported low-level
ClientSessionintegration instead of also adopting the new high-levelClientand automatic 2026-07-28 protocol negotiation.What changed
mcpto>=2.0.0,<3.0.0and add the directly importedhttpx2dependencyinput_schema,is_error,mime_type,MCPError, and the two-stream HTTP transport result)Session not foundresponse as a stale session and reconnectFastMCPto v2MCPServerWhat the implementation tells us
Concrete benefit
A noisy stdio child was exercised against both SDK majors:
ExceptionGroupThe real v2 Streamable HTTP server also expires a session, returns
Session not found, and nanobot reconnects successfully.Important limitation
MCP v2 still raises:
when a stdio transport is closed from a task other than its owner.
_OwnedMCPConnectiontherefore remains necessary; upgrading alone does not eliminate the cancel-scope failure described in #5138.This branch also does not enable the 2026-07-28 protocol features.
ClientSession.initialize()deliberately uses the legacy handshake. Adopting discovery, caching, input-required flows, and other modern behavior would require a separate high-levelClientmigration such as #5179.Actual maintenance cost
The main unavoidable cost is maintaining HTTPX2 equivalents for the MCP HTTP path while the rest of nanobot continues to use HTTPX. The total patch is 8 files, 166 additions, and 85 deletions, with most production additions in the shared network-security layer.
Validation
181 passedacross the changed MCP, reconnect, and network-security suites2 passedbasedpyright:0 errors, 0 warnings, 0 notesruff check nanobot/and changed tests: passed5836 passed, 35 skipped; three system-proxy-sensitive web-fetch tests failed locally and reproduce unchanged onorigin/main; two similarly proxy-sensitive probe tests were deselected after baseline reproductiongit diff --check: passedDecision framing
Relates to #5138.