-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix unknown-method error code and add a protocol version registry #2836
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
maxisbey
merged 9 commits into
main
from
maxisbey/method-not-found-and-version-registry
Jun 11, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
89722dd
Compare protocol versions through a known-version registry
maxisbey 3230c3f
Return METHOD_NOT_FOUND for requests with unknown methods
maxisbey 4468a7f
Answer unknown methods with METHOD_NOT_FOUND before the initialize gate
maxisbey 3789d00
Expose the negotiated protocol version on ServerSession
maxisbey 2374c99
docs: extra fields on MCP types are ignored, not rejected
maxisbey 22176ef
Limit the version registry to released protocol versions
maxisbey b978383
docs: record the unknown-method error-code change in the migration guide
maxisbey e1bf53f
Clarify protocol-version docstrings and tighten new tests
maxisbey 5dd7e4a
Answer any unserved method with METHOD_NOT_FOUND before the initializ…
maxisbey 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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,37 @@ | ||
| """Protocol-version registry and comparison helpers. | ||
|
|
||
| Date-string protocol revisions happen to sort lexicographically, but versions | ||
| are an enumerated set, not an ordered scalar: future identifiers are not | ||
| guaranteed to be date-shaped, and unrecognized peer strings must compare | ||
| conservatively instead of accidentally (e.g. "zzz" > "2025-11-25"). All | ||
| ordering questions go through KNOWN_PROTOCOL_VERSIONS. | ||
| """ | ||
|
|
||
| from typing import Final | ||
|
|
||
| from mcp.types import LATEST_PROTOCOL_VERSION | ||
|
|
||
| KNOWN_PROTOCOL_VERSIONS: Final[tuple[str, ...]] = ( | ||
| "2024-11-05", | ||
| "2025-03-26", | ||
| "2025-06-18", | ||
| "2025-11-25", | ||
| ) | ||
| """Every released protocol revision, oldest to newest.""" | ||
|
|
||
| SUPPORTED_PROTOCOL_VERSIONS: list[str] = ["2024-11-05", "2025-03-26", "2025-06-18", LATEST_PROTOCOL_VERSION] | ||
| """Protocol revisions this SDK can negotiate.""" | ||
|
|
||
|
|
||
| def is_version_at_least(version: str, minimum: str) -> bool: | ||
| """Return True if `version` is a known revision at least as new as `minimum`. | ||
|
|
||
| Unknown `version` strings return False (treat unrecognized peers | ||
| conservatively). `minimum` must be a member of KNOWN_PROTOCOL_VERSIONS; | ||
| passing anything else is programmer error and raises ValueError. | ||
| """ | ||
| if minimum not in KNOWN_PROTOCOL_VERSIONS: | ||
| raise ValueError(f"minimum must be a known protocol version, got {minimum!r}") | ||
| if version not in KNOWN_PROTOCOL_VERSIONS: | ||
| return False | ||
| return KNOWN_PROTOCOL_VERSIONS.index(version) >= KNOWN_PROTOCOL_VERSIONS.index(minimum) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks correct but feels brittle to tie the logic specifically to a random array constant being in the right order, but seems fine 🤷♂️ we won't change this that often I guess. |
||
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
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
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
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
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.
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.
not adding 2026-07-28 as part of this yet?
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.
yep not yet