Mcp_proxy_pydantic_agent

by p2c2e

18 stars
188 downloads
Not rated
GitHub

About

Example for exposing MCP servers to Pydantic Agents

Details

Author
p2c2e
GitHub stars
18
Downloads
188
Categories
AI

- Integrates MCP servers with Pydantic.AI agents
- Uses two different LLMs (gpt‑4o and sonnet) for demonstration
- Pure PydanticAI option via client2.py (no Anthropic library dependency)
- Works with any function‑calling LLM in the pure Pydantic variant

Clone the repo, run uv sync, change into mcp-client, then run either client.py (requires OpenAI and Anthropic API keys and uses Anthropic libraries directly) or client2.py (uses only PydanticAI and works with any function‑calling LLM). Export OPENAI_API_KEY and ANTHROPIC_API_KEY before running.

Sample to show to integrate MCP (Model Context Protocol) servers with Pydantic.AI

Parts of this example uses content from : https://github.com/modelcontextprotocol/quickstart-resources.git - Esp. the weather 'server' code

Code uses two different LLMs just for demonstration. The Proxy Agent uses gpt-4o and the tool uses sonnet.
So, export OPENAI_API_KEY as well as ANTHROPIC_API_KEY - OR - modify the code to suit your models

The pyproject.toml assumes you are using 'uv' package manager

Steps to run

1. Clone this repo 1. uv sync 3. cd mcp-client 2. uv run client.py (this requires openai and anthropic keys and uses anthropic libs directly) 2. uv run client2.py (for pure pydantic and works with any fn calling LLM)

(Alternatively try client2.py - this uses only PydanticAI - no direct dep on Anthropic libs)

Now, try interacting with some questions like:

> What is the time in NY when it is 7:30pm in Bangalore?

> What is the Weather currently in Chicago?

(and quit when done)

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.