-
Notifications
You must be signed in to change notification settings - Fork 2k
Add version discovery and calling a certain version for components #2897
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b4baa85
Add version discovery and selection for components
jlowin d07dbc5
Fix version selection to use request-level meta, not arguments
jlowin d69d053
Fix docs: use meta (not _meta) in Python, clarify request params
jlowin 565fed1
Include version in read_resource error messages for consistency
jlowin 6745eb1
Add versioning examples
jlowin 27a109b
Add noqa for intentional redefinitions in versioning examples
jlowin 871764e
Update run-tests.yml
jlowin 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,7 @@ async with client: | |
| **Parameters:** | ||
| - `name`: The tool name (string) | ||
| - `arguments`: Dictionary of arguments to pass to the tool (optional) | ||
| - `version`: Specific tool version to call (optional, see [Version Selection](#version-selection) below) | ||
| - `timeout`: Maximum execution time in seconds (optional, overrides client-level timeout) | ||
| - `progress_handler`: Progress callback function (optional, overrides client-level handler) | ||
| - `meta`: Dictionary of metadata to send with the request (optional, see below) | ||
|
|
@@ -292,4 +293,48 @@ async with client: | |
|
|
||
| <Tip> | ||
| For multi-server clients, tool names are automatically prefixed with the server name (e.g., `weather_get_forecast` for a tool named `get_forecast` on the `weather` server). | ||
| </Tip> | ||
| </Tip> | ||
|
|
||
| ## Version Selection | ||
|
|
||
| <VersionBadge version="3.0.0" /> | ||
|
|
||
| FastMCP servers can expose multiple versions of the same tool. By default, clients receive and call the highest version, but you can request a specific version when needed. | ||
|
|
||
| ### Discovering Versions | ||
|
|
||
| When a server registers multiple versions of a tool, the `list_tools()` response includes version information in the metadata. The `meta.fastmcp.version` field shows which version is being returned, while `meta.fastmcp.versions` lists all available versions sorted from highest to lowest. | ||
|
|
||
| ```python | ||
| async with client: | ||
| tools = await client.list_tools() | ||
|
|
||
| for tool in tools: | ||
| if tool.meta: | ||
| fastmcp_meta = tool.meta.get("fastmcp", {}) | ||
| version = fastmcp_meta.get("version") | ||
| all_versions = fastmcp_meta.get("versions") | ||
| if all_versions: | ||
| print(f"{tool.name}: v{version} (available: {all_versions})") | ||
| ``` | ||
|
|
||
| Unversioned tools omit these metadata fields entirely. | ||
|
|
||
| ### Calling Specific Versions | ||
|
|
||
| Pass the `version` parameter to `call_tool()` to execute a specific version instead of the highest. | ||
|
|
||
| ```python | ||
| async with client: | ||
| # Call the highest version (default) | ||
| result = await client.call_tool("calculate", {"x": 1, "y": 2}) | ||
|
|
||
| # Call version 1.0 specifically | ||
| result_v1 = await client.call_tool("calculate", {"x": 1, "y": 2}, version="1.0") | ||
| ``` | ||
|
Comment on lines
+325
to
+334
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. Add error handling for version-specific tool calls. Line 325-334 uses 💡 Suggested update async with client:
# Call the highest version (default)
result = await client.call_tool("calculate", {"x": 1, "y": 2})
# Call version 1.0 specifically
- result_v1 = await client.call_tool("calculate", {"x": 1, "y": 2}, version="1.0")
+ from fastmcp.exceptions import NotFoundError
+ try:
+ result_v1 = await client.call_tool("calculate", {"x": 1, "y": 2}, version="1.0")
+ print(result_v1.data) # Expected: 3
+ except NotFoundError:
+ print("Version 1.0 not available") |
||
|
|
||
| If the requested version doesn't exist, the server raises a `NotFoundError`. This ensures you get exactly what you asked for rather than silently falling back to a different version. | ||
|
|
||
| <Note> | ||
| Version selection is a FastMCP extension to the MCP protocol. See [Versioning](/servers/versioning#requesting-specific-versions) for details on how this works at the protocol level for non-FastMCP clients. | ||
| </Note> | ||
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.
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.
Add error handling and expected output to the versioned read example.
Line 106-111 shows a direct versioned read but omits the NotFoundError path and any verification output. Adding a try/except with a minimal success print makes the snippet runnable and self-checking. As per coding guidelines.
💡 Suggested update