Enhancing Agents with Multimodal Capabilities: ADK + MCP — Part 2 of 3
The Model Context Protocol (MCP) is an open standard that standardizes how LLMs interact with external tools and data sources. Think of it like a “USB-C for AI applications”, providing a universal way to connect AI models to different tools, services, and repositories. When combined with Google’s Agent Development Kit (ADK), it enables your agents to:
- Access pre-built tools and services
- Support multimedia content (images, files, etc.)
- Create interactive, multi-modal experiences
Prerequisites
Before getting started, ensure you have:
- Python 3.9+
- ADK installed (
pip install google-adk) - Node.js and npx (for some MCP servers)
- MCP package (
pip install model-context-protocol)
Integrating MCP with ADK
1. File System Example
Let’s enhance our weather agent with file system capabilities:
# weather_mcp_agent/agent.py
import os
import asyncio
from contextlib import ExitStack
from google.adk.agents import Agent
from google.adk.tools.mcp import MCPToolset, StdioServerParameters
async def setup_agent():
# Connect to MCP File System server
tools, exit_stack = await MCPToolset.from_server(
connection_params=StdioServerParameters(
command='npx',
args=['-y', '@modelcontextprotocol/server-filesystem']
)
)
# Our weather tool function
def get_weather(location: str) -> str:
"""Get the weather for a specific location"""
return f"The weather in {location} is sunny with a temperature of 70 degrees."
# Create agent with both our tool and MCP tools
return Agent(
name="weather_fs_agent",
description="An agent that can get weather and access files",
tools=[get_weather] + tools,
model="gemini-2.0-flash",
), exit_stack
# Set up the root_agent (required by ADK CLI)
root_agent, _ = asyncio.run(setup_agent())2. Directory Structure
weather_mcp_agent/
├── __init__.py
├── agent.py
└── .env3. Running the MCP-Enhanced Agent
# Run in interactive CLI mode
adk run weather_mcp_agent
# Run with web UI
adk web weather_mcp_agentExample Interaction
Here’s what interacting with the MCP-enhanced agent looks like:
user: What files are in my current directory?
[weather_fs_agent]: I can help you check that. Let me list the files in your current directory.
The files in your current directory are:
- agent.py
- __init__.py
- .env
user: What's the weather in Paris?
[weather_fs_agent]: The weather in Paris is sunny with a temperature of 70 degrees.
user: Create a report about today's weather
[weather_fs_agent]: I'll create a weather report file for you.
I've created a file called "weather_report.txt" with the following content:
Weather Report
Date: May 18, 2025
-----------------------
Today's weather is sunny with a temperature of 70 degrees.
Perfect weather for outdoor activities!Popular MCP Servers
ADK can connect to various MCP servers:
- File System (
@modelcontextprotocol/server-filesystem)|
Read, write, and manage files with configurable permissions - Google Maps (
@modelcontextprotocol/server-google-maps)
Geocoding, directions, place details, and location services - Browser/Brave Search (
@modelcontextprotocol/server-brave-search)
Web search, page reading, content extraction - Vector Database/Qdrant (
mcp-server-qdrant)
Document storage, semantic search, and memory management - GitHub (
@modelcontextprotocol/server-github)
Repository management, code access, pull requests - PostgreSQL (
@modelcontextprotocol/server-postgresql)
Database queries, schema inspection, and data retrieval
Advanced: Creating Custom MCP Servers
You can also expose your ADK tools as an MCP server:
from model_context_protocol.server import Server
from model_context_protocol.model import Tool, Parameter, ToolFunction, ParameterType
# Create MCP server
server = Server()
# Register tool
@server.register_tool
def my_tool() -> Tool:
return Tool(
name="my_custom_tool",
description="My custom tool description",
parameters=[
Parameter(name="param1", type=ParameterType.STRING)
],
function=ToolFunction(name="execute_my_tool")
)
# Add implementation
@server.register_tool_execution(tool_name="my_custom_tool")
async def execute_my_tool(param1: str):
# Implement your custom tool functionality here
result = f"Processed: {param1}"
return result
# Start server
server.start()Practical Tips
- Tool Discoverability: Allow your agent to “discover” MCP tools at runtime
- Error Handling: Implement robust error handling for MCP tool failures
- Server Management: Properly manage MCP server lifecycle with ExitStack
- Performance: Consider caching strategies for expensive MCP operations
- Security: Implement appropriate access controls and permissions
Coming Next
In Part 3, we’ll explore Agent-to-Agent (A2A) communication, allowing your ADK agents to collaborate with other agents through an open protocol. A2A is a key part of Google’s agent ecosystem, enabling collaboration between agents built with different frameworks and by different vendors.
Resources:
