This project demonstrates three approaches for integrating external API tools with Pydantic AI agents.
Uses Model Context Protocol (MCP) servers for tool integration. Tools are loaded from an external MCP server configured via .mcp.json.
Key Features:
- External tool server via MCP protocol
- Dynamic tool loading
- Configuration-driven approach
Directly initializes and registers connector tools within the agent code using closures.
Key Features:
- In-memory tool registration
- Direct connector initialization via closures
- Programmatic approach
Uses Pydantic-AI's built-in dependency injection framework for cleaner tool integration.
Key Features:
- Dependencies managed via
AgentDepsdataclass - Tools receive connectors via
RunContext[AgentDeps] - Centralized dependency creation with
create_deps()factory - Better testability and separation of concerns
- Python 3.12 or higher
- Environment variables configured (see below)
-
Clone or navigate to the project directory:
cd /path/to/example-api-tool-setup -
Run the setup script to create the shared virtual environment:
./setup.sh
This will:
- Create a shared
venv/directory at the project root - Install all required dependencies
- Set up the environment for l1-mcp, l2-tool, and l3-tool-di
- Create a shared
Both implementations share a single .env file at the project root. Copy the .env.example file as a starting point:
cp .env.example .env
# Edit .env and add your API keysRequired environment variables:
ANTHROPIC_API_KEY- Claude API keyGONG_ACCESS_KEY- Gong API access keyGONG_ACCESS_KEY_SECRET- Gong API secretLANGSMITH_*- (Optional) LangSmith tracing configurationAIRBYTE_*- Airbyte configuration for l2-tool direct integration
All implementations use the same Gradio chat interface and can be run independently.
cd l1-mcp
./run.shcd l2-tool
./run.shcd l3-tool-di
./run.shThe Gradio interface will be available at: http://localhost:8000