|
|
ADK Agent Connecting to an MCP Server
Author: Venkata Sudhakar
The Model Context Protocol (MCP) defines a standard interface for exposing tools to AI agents. Google ADK supports MCP natively through MCPToolset, which connects to any MCP server and automatically discovers the tools it exposes. This means you can build a tool server once and use it from any ADK agent without writing custom integration code for each agent.
MCPToolset launches the MCP server as a subprocess using StdioServerParameters, communicates over stdin/stdout, and returns the server tools as ADK-compatible FunctionTools. The agent then calls these tools exactly like any other ADK tool. The MCP server handles all execution logic and returns structured results.
The below example shows a ShopMax India ADK agent connecting to a local MCP server that exposes product search and inventory tools.
Now connect an ADK agent to this MCP server,
It gives the following output,
ShopMax India currently has 42 laptops in stock, priced at Rs 45,000 each,
available from the Mumbai warehouse. Would you like to place an order?
MCPToolset handles the full lifecycle of the MCP server subprocess - it starts it, maintains the stdio communication channel, and cleans up when exit_stack.aclose() is called. In production, run the MCP server as a persistent process or Docker container and connect via HTTP/SSE transport instead of stdio, which is better suited for multi-agent environments where several ADK agents need to share the same MCP server simultaneously.
|
|