关于 pydantic-mcp
pydantic-mcp 将 MCP 服务的工具适配为 Pydantic AI 工具实例,供使用 Pydantic AI 的应用调用。README 指出 PydanticAI 现已内置 MCP 服务支持,并建议改用该功能。
主要功能
- 01将 MCP 工具载入 Pydantic AI
- 02通过 MCP ClientSession 使用工具
适用场景
- 01让 Pydantic AI 使用 MCP 服务工具
- 02运行随附的文件读取演示
MCP 相关
它通过 MCP ClientSession 连接,获取服务支持的工具,并将其提供为 pydantic_ai.Tool 实例。
详细介绍
pydantic-mcp
PydanticAI 现已支持 MCP 服务,请改用该方案
Model Context Protocol 为 Pydantic AI 提供的工具调用支持。
只需创建一个 mcp.ClientSession,然后调用 tools = await mcptools(session) 即可获取支持的工具对应的 pydantic_ai.Tool 实例列表。
示例:
演示
您可以针对 Groq 的 llama-3.1-8b-instant 运行演示:
$ export GROQ_API_KEY=xxx
$ uv run tests/demo.py "Read and summarize the file ./LICENSE"
Secure MCP Filesystem Server running on stdio
Allowed directories: [ '/users/aw/projects/rectalogic/pydantic-mcp' ]
The file ./LICENSE is a MIT License agreement. It states that the software is provided "as is" without warranty and that the authors and copyright holders are not liable for any claims, damages, or other liability arising from the software or its use.
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。