Skip to content

Model Context Protocol tool calling support for Pydantic AI

License

Notifications You must be signed in to change notification settings

rectalogic/pydantic-mcp

Repository files navigation

pydantic-mcp

PyPI - Version

Model Context Protocol tool calling support for Pydantic AI.

Just create an mcp.ClientSession and call tools = await mcptools(session) to get a list of pydantic_ai.Tool instances for the supported tools.

Example:

async def main(prompt: str) -> None:
server_params = StdioServerParameters(
command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem", str(pathlib.Path(__file__).parent.parent)],
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
tools = await mcptools(session)
agent = Agent(model="groq:llama-3.1-8b-instant", tools=tools) # requires GROQ_API_KEY
result = await agent.run(prompt)
print(result.data)

Demo

You can run the demo against 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.

About

Model Context Protocol tool calling support for Pydantic AI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages