-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added MCP metadata and annotations to ToolDefinition.metadata
#2880
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
Added MCP metadata and annotations to ToolDefinition.metadata
#2880
Conversation
docs/mcp/client.md
Outdated
|
||
## Tool Metadata | ||
|
||
MCP tools often include metadata that provides additional information about the tool's characteristics, which can use useful in filtering and middleware. This metadata is available in the [`ToolDefinition.metadata`][pydantic_ai.tools.ToolDefinition.metadata] field. |
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.
Let's link to the FilteredToolset
docs
tests/test_mcp_metadata.py
Outdated
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.
I'd rather have this in test_mcp.py
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.
While moving this over, I noticed ya'll already have an tests/mcp_server.py
so decided I would just add some metadata to these tools to test with...
But it seems like it's running an older version of FastMCP that gets imported from the official MCP python SDK (I don't really understand what that's about)?
This version doesn't seem to have the meta
or tags
properties on the @tool
annotation.
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.
Looks like mcp.server.fastmcp
is the original version and fastMCP
2.0 has been moved to it's own project (I've been using FastMCP 2.0 but didn't realize this).
But also seems like mcp.server.fastmcp
is still getting updated?
For now, seems like the cleanest thing I can do is just test that the annotations and output_schema
get set on the metadata
since meta isn't available.
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.
@ChuckJonas Yeah the fact that there are now 2 FastMCPs is very confusing. Our test server uses the "official" one from mcp
, but we also have an open PR to add a FastMCPToolset
that uses the independent FastMCP's client library: #2784. (I've already commented there to suggest supporting ToolDefinition.metadata
well).
For now, seems like the cleanest thing I can do is just test that the annotations and output_schema get set on the metadata since meta isn't available.
Makes sense
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.
In the near future the FastMCP v1 that is in the sdk will be renamed, I think to MCPServer and FastMCP v2 will be the only FastMCP going forward
b918951
to
a337055
Compare
48cb232
to
3d95841
Compare
@DouweM I think I made the suggested changes There are a couple things I'm not 100% sure about.
But I think this would require making
|
2a6a074
to
9f1878c
Compare
Thinking this through now, we'll want to allow users to define tool metadata as well when registering their own tool functions. Can you add the |
Co-authored-by: Douwe Maan <[email protected]>
9f1878c
to
c4042b8
Compare
@DouweM Should be good to go! I think I completed all requested changes and CI seems to be passing. I also tested by running locally with my FastMCP2.0 server and the LMK if there's anything else. |
@ChuckJonas Any chance you can also do this final request from my comment?
Just to make this more generally useful as a feature. |
@DouweM sorry I somehow missed that... I'm not 100% sure I got everything. Also, I came across what I think was an unrelated bug (Added a comment to the line)... |
require_parameter_descriptions, | ||
schema_generator, | ||
strict, | ||
False, |
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.
@DouweM I think was this a bug? It seemed like we were 1 parameter off (requires_approval
was being passed into sequential
). I assume False
is the reasonable default.
Might be worth refactoring these to name parameters in the future to help prevent this type of miss!
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.
Hmm, I guess there are two issues here:
sequential
should've been added to these decorators as well- as you said, the no-kwargs style makes it way too easy to mess this up.
I'll submit a PR to fix both. Thanks for this feature!
require_parameter_descriptions, | ||
schema_generator, | ||
strict, | ||
False, |
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.
Hmm, I guess there are two issues here:
sequential
should've been added to these decorators as well- as you said, the no-kwargs style makes it way too easy to mess this up.
I'll submit a PR to fix both. Thanks for this feature!
ToolDefinition.metadata
Fixes #2875