MCP is all you need — Samuel Colvin, Pydantic MCP: All You Need? A Deep Dive into its Capabilities This blog post summarizes a presentation on using the Message-Passing Component Protocol (MCP) for building autonomous agents. The speaker emphasizes MCP's versatility and argues that it simplifies many complex agent-to-agent communication scenarios. Introduction and Speaker Background The speaker is known for creating Pydantic, a popular Python data validation library. Pydantic is widely used, including in various GenAI SDKs and agent frameworks. Pydantic has expanded into a company, developing Pydantic AI (an agent framework) and Pydantic Logfire (an observability platform). The speaker is also a co-maintainer of the MCP Python SDK. MCP: A Single Tool for Agent Communication The presentation title is inspired by Jason Lou's talks ("Pydantic is all you need"). While acknowledging that MCP isn't a universal solution, the speaker highlights its capabilities in simplifying agent-to-agent communication. The focus is on autonomous agents and code, not cursor-based coding agents. MCP's original design primarily targeted the latter. Two MCP primitives—prompts and resources—are less relevant in the context of autonomous agents. Tool calling , however, is crucial. The Complexity of Tool Calling Tool calling in MCP is more complex than it initially appears. It addresses several challenges not solved by simple Open API approaches: Dynamic tools: Tools that appear and disappear during agent execution. Logging: Returning data to the user during tool execution. Sampling: A mechanism for tools to access LLMs (explained later). Tracing and observability: Monitoring and debugging agent interactions. Subprocess operation: MCP's ability to function as a subprocess via standard input/output. MCP's Architectural Design The typical MCP architecture involves an agent interacting with multiple tools. The agent and tools are designed independently, promoting modularity and flexibility. This is analogous to how web browsers interact with websites. The system can be nested, with tools themselves being agents that can access LLMs and other tools. The Challenge of LLM Access and the Solution: Sampling A limitation of nested agent systems is that every agent needs LLM access, increasing cost and complexity. Sampling solves this by allowing tools to indirectly access the LLM used by the main agent. The client (main agent) proxies LLM requests from the tool, reducing redundancy and cost. Sampling in Action: A Research Agent Example A simplified example demonstrates a research agent querying BigQuery for package download statistics. The example uses Pydantic AI and showcases several features: Retry mechanism: Handles LLM errors by retrying with more context. Type-safe logging: Uses MCP context.log for progress updates during tool execution. This enables real-time feedback to the user. Output validation and formatting: Ensures the tool's output is in a format easily processed by the LLM (XML-like). Implementing the BigQuery Tool with MCP The example uses fastapi-mcp to create an MCP server. The tool's description (used by the LLM) is derived from the function's docstring. SQL query generation is done within the tool itself, preventing context window bloat in the main agent. This improves efficiency. Running the Agent and Observability The main application defines the agent and registers the BigQuery tool. The agent's execution is demonstrated, retrieving download statistics. Logfire (Pydantic's observability platform) is used to visualize the agent's interactions, showcasing the flow of requests and responses between the agent, LLM, and tools. Key Takeaways and Conclusion MCP simplifies complex agent-to-agent communication by enabling modularity and independent tool design. Sampling significantly improves efficiency by allowing tools to share the main agent's LLM access. Features like logging and output validation enhance the user experience and robustness of the system. The use of Pydantic AI ensures type safety and structured data handling.