-
Notifications
You must be signed in to change notification settings - Fork 3.3k
docs: fill migration guide gaps surfaced by automated upgrade eval #2412
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
Merged
+235
−5
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
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 migration guide shows
Context[ServerSession, None]→ bareContext, but this silently changesLifespanContextTfromNonetodict[str, Any]for type-checker users. The type-accurate v2 equivalent ofContext[ServerSession, None]isContext[None], not bareContext.Extended reasoning...
What the bug is: In the migration guide's "Context generic params" section (lines 600–626), the before example is
Context[ServerSession, None]where the second type param isLifespanContextT=None. The after example shows bareContext, which in v2 resolves toContext[dict[str, Any], Any]becauseLifespanContextThas a default ofdict[str, Any].The specific code path: In
src/mcp/server/context.py,LifespanContextTis defined asTypeVar('LifespanContextT', default=dict[str, Any]). So bareContextexpands toContext[dict[str, Any], Any]under a type checker, notContext[None, Any].Why existing doc text doesn't prevent it: The guide says bare
Contextis "usually sufficient", which partially mitigates the concern, but the direct before/after pairing ofContext[ServerSession, None]→Contextimplies they are type-equivalent when they are not. Users following this one-to-one mapping will silently changeLifespanContextTfromNonetodict[str, Any].Impact: Runtime behavior is completely unaffected — TypeVar defaults only matter to static type checkers. However, users who had
Context[ServerSession, None]specifically to signal "no lifespan" and follow this guide will end up withContext(i.e.,Context[dict[str, Any], Any]), which could cause false type-checker positives or negatives if they try to accessctx.request_context.lifespan_contextand expect it to beNone.How to fix: Change the after example to show
Context[None]as the direct type-preserving equivalent, and note bareContextseparately as a convenience when lifespan type precision is not required:Step-by-step proof:
async def my_tool(ctx: Context[ServerSession, None]) -> str: ...— hereLifespanContextT = Noneasync def my_tool(ctx: Context) -> str: ...Contextwithout type params uses TypeVar defaults:LifespanContextT = TypeVar('LifespanContextT', default=dict[str, Any])Context=Context[dict[str, Any], Any], notContext[None, Any]Context[None](keepingLifespanContextT=None), which the guide does not show as an option