-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add FastMCPToolset #2784
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
base: main
Are you sure you want to change the base?
Add FastMCPToolset #2784
Conversation
f68660d
to
54367c8
Compare
54367c8
to
27592c7
Compare
@DouweM this is ready for review when you have a chance |
if isinstance(part, ImageContent | AudioContent): | ||
return messages.BinaryContent(data=base64.b64decode(part.data), media_type=part.mimeType) | ||
|
||
msg = f'Unsupported/Unknown content block type: {type(part)}' # pragma: no cover |
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.
What are the other types?
In mcp.py
, we have to specifically account for embedded resources or resource links (which we're possibly doing incorrectly: #2288)
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.
Probably just those two, will take a look
Basically I had implemented the content handling here, gotten annoyed at how weird it was, and then went and fixed it in FastMCP -- Once the next version of FastMCP comes out I was going to simplify the content handling here and return structured content if it's available and only return content if it's not (which I'm sure is what the MCP code was doing). Will incorporate the feedback tomorrow and work on simpler examples |
This PR is stale, and will be closed in 3 days if no reply is received. |
Ok sorry for the delay, will pick this back up today/tomorrow |
This PR is stale, and will be closed in 3 days if no reply is received. |
b5cc6d3
to
6ea1dd3
Compare
PR is updated for most of the feedback, I still need to take a look at resources -- I think if it's a dataclass i lose the nice behavior of being able to provide transports or a client. Let me know if you have any thoughts right now in the pr its a data class with an init which kinda defeats the purpose alternatively, I could split it into two toolsets one for transport and one for Client |
"coverage[toml]>=7.10.3", | ||
"dirty-equals>=0.9.0", | ||
"duckduckgo-search>=7.0.0", | ||
"fastmcp>=2.12.0", |
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 don't think we need it here if it's already coming in through pydantic-ai-slim[...,fastmcp,...]
above
if client: | ||
self.client = client | ||
else: | ||
self.client = Client[Any](transport=transport) |
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'm guessing this will raise an error if the dict[str,Any]
or str
doesn't look like it should?
*, | ||
client: Client[Any] | None = None, | ||
max_retries: int = 2, | ||
tool_error_behavior: Literal['model_retry', 'error'] = 'error', |
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 prefer for the default to be model_retry
for consistency with MCPServer
.
|
||
See the [MCP Client](./mcp/client.md) documentation for how to use MCP servers with Pydantic AI. | ||
|
||
### FastMCP Tools {#fastmcp-tools} |
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.
Note to self: before merging this, see if it makes sense to move this to a separate doc that can be listed in the "MCP" section in the sidebar.
Fixes: #2406
Introduces a FastMCPToolset which can take a FastMCP Client, a FastMCP Server, a config for an MCP Server, or an MCP JSON config.
This enables running FastMCP Servers in-memory, running Stdio servers via FastMCP, connecting to remote MCP Servers, transforming tools, etc.
Todo: