Skip to main content

Module 27: Introduction to MCP & Stateful Tools

Theoryโ€‹

Model Context Protocol Architecture (Light) Model Context Protocol Architecture (Dark) Figure: The Model Context Protocol (MCP) bridging autonomous agents with external stateful tools and servers.

The Limits of Stateless Toolsโ€‹

Welcome to Part 5: Advanced Integrations & UI. Your agents from Part 4 are production-ready -- they remember, they're evaluated, they're observed, they're guarded by callbacks. Now it's time to give them richer capabilities and connect them to the outside world, starting with how they talk to tools.

The custom function tools you've built so far are powerful, but they have a fundamental limitation: they are stateless. Every time your agent calls a tool like add(a, b), the tool executes from scratch, performs its calculation, returns a result, and then forgets everything.

This is perfect for many tasks, but it falls short for more complex, ongoing interactions where a tool needs to maintain its own memory or state across multiple turns of a conversation (e.g., managing a database connection, a multi-step booking process, or an interactive data analysis session).

MCP: A Protocol for Stateful, Multi-turn Toolsโ€‹

To solve this problem, the ADK integrates with the Model Context Protocol (MCP). MCP is an open standard designed to allow AI agents to have rich, stateful conversations with external tools. Instead of writing custom integrations for every service, you can connect to pre-built MCP servers from the community.

Benefits:

  • ๐Ÿ”Œ Plug-and-Play: Instantly connect to existing MCP servers for filesystems, databases, and popular APIs.
  • ๐ŸŒ Community Ecosystem: Leverage a growing library of community-built tools.
  • ๐Ÿงฉ Standardized Interface: Interact with all external tools through a consistent API.
  • ๐Ÿš€ Extensible: Build your own custom servers to expose proprietary systems to your agents.

The MCP Architecture: Client and Serverโ€‹

MCP works on a client-server model:

  1. The MCP Server: A standalone application that exposes a set of stateful tools (e.g., a server that manages a filesystem).
  2. The MCP Client: The application that wants to use the tools. In our case, the ADK agent acts as the MCP client.

MCP 3-Tier Client-Server Architecture (Light) MCP 3-Tier Client-Server Architecture (Dark) Figure: 3-Tier MCP Integration topology showing Agent Node, McpToolset adapter, and external MCP servers.

The McpToolset is the bridge. It connects to an MCP server, discovers the tools it offers, and makes them available to your agent node. When your agent decides to use one of these tools, the McpToolset proxies the call to the server, which executes the logic and maintains the state.

MCP Connection Typesโ€‹

The ADK exposes McpToolset and its transport parameter classes under google.adk.tools.mcp_tool (installed via uv add "google-adk[mcp]"):

  • StdioConnectionParams (paired with StdioServerParameters from mcp): Runs an MCP server as a local subprocess and communicates over standard input/output. This is the most common method for local development.
  • SseConnectionParams: Connects to a remote MCP server that uses Server-Sent Events (SSE) for streaming communication.
  • StreamableHTTPConnectionParams: Connects to a remote MCP server over modern streamable HTTP (ideal for hosted APIs like GitHub's MCP endpoint).
from google.adk.tools.mcp_tool import (
McpToolset,
StdioConnectionParams,
StreamableHTTPConnectionParams,
)
from mcp import StdioServerParameters

In the lab, you will configure StdioConnectionParams to launch a sandboxed local filesystem server and give your agent the ability to inspect files, plus an optional remote HTTP integration.

๐ŸŽฏ Knowledge CheckSelect Best Answer

What role does McpToolset play when connecting an ADK Agent to an external MCP server over StdioConnectionParams?

Key Takeawaysโ€‹

  • Standard function tools are stateless, which limits their ability to handle ongoing, multi-turn interactions.
  • The Model Context Protocol (MCP) is an open standard that enables agents to connect to stateful external tools.
  • The ADK acts as an MCP client, using McpToolset (google.adk.tools.mcp_tool) to connect to and consume tools from an MCP server.
  • Workflow Integration: In ADK 2.0, an Agent node equipped with an McpToolset becomes a powerful interface to external systems within your graph.
  • Security and Sandboxing: Launching an MCP server as a subprocess (e.g., via StdioConnectionParams) grants the external code operational freedom. Always sandbox the server to a specific directory and restrict exposed tools with tool_filter to minimize risk.
๐Ÿ“–

27: Intro to Model Context Protocol(Theory & Overview)

Part 5: Advanced Integrations & UI โ€ข Module 27

Overall Course Progress:
0%(0/98)
Next Step: Challenge Lab ๐Ÿงช โ†’