Welcome to the Model Context Protocol (MCP) integration guide! This example demonstrates how to connect your ADK agents with external data sources and tools through the standardized MCP protocol.
Sign in to save downloads to your library and vote.
Preview
๐ MCP Tools Integration
Welcome to the Model Context Protocol (MCP) integration guide! This example demonstrates how to connect your ADK agents with external data sources and tools through the standardized MCP protocol.
๐ฏ What You'll Learn
- MCP Fundamentals: Understanding the Model Context Protocol
- ADK โ MCP Integration: Using
MCPToolsetto connect to MCP servers - External Tool Access: Leveraging tools from MCP servers
- Server Communication: Working with both local and remote MCP servers
- Real-world Applications: Practical examples with filesystem and Wikipedia
๐ง Core Concept: Model Context Protocol
The Model Context Protocol (MCP) is an open standard that enables AI agents to:
- Access external data sources consistently
- Use tools from remote servers
- Communicate with various applications
- Maintain context across interactions
How MCP Works with ADK
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ ADK Agent โโโโโบโ MCPToolset โโโโโบโ MCP Server โ
โ โ โ โ โ โ
โ Gemini โ โ Bridge โ โ Tools โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
MCPToolset acts as a bridge that:
- Connects to MCP servers (local or remote)
- Discovers available tools automatically
- Translates MCP tools into ADK-compatible format
- Manages connection lifecycle
๐ง Integration Patterns
1. Using External MCP Servers
Connect to existing MCP servers:
- Filesystem Server: File operations
- Wikipedia Server: Knowledge retrieval
- Database Server: Data access
- API Server: External service integration
2. Communication Protocols
- Server-Sent Events (SSE): Real-time communication for remote servers
- Standard I/O: Local process communication for MCP servers
๐ Examples in This Tutorial
๐ Example 1: Filesystem Agent
Location: ./filesystem_agent/
- Connect to filesystem MCP server
- Perform file operations (read, write, list)
- Handle local file system interactions
- Use Standard I/O communication
๐ฅ Example 2: Firecrawl Agent
Location: ./firecrawl_agent/
- Connect to Firecrawl MCP server for advanced web scraping
- Perform single page scraping, batch processing, and website crawling
- Extract structured data with AI-powered analysis
- Conduct deep web research with multi-source synthesis
- Use Standard I/O communication with cloud API integration
๐ Project Structure
4_4_mcp_tools/
โโโ README.md # This file - MCP integration guide
โโโ requirements.txt # MCP dependencies
โโโ filesystem_agent/ # Filesystem MCP integration
โ โโโ __init__.py # Package initialization
โ โโโ agent.py # Main agent implementation
โ โโโ README.md # Filesystem agent guide
โโโ firecrawl_agent/ # Firecrawl web scraping integration
โ โโโ __init__.py # Package initialization
โ โโโ agent.py # Main agent implementation
โ โโโ README.md # Firecrawl agent guide
๐ฏ Key Features
- Seamless Integration:
MCPToolsethandles all MCP protocol details - Automatic Discovery: Tools are discovered and made available automatically
- Multiple Protocols: Supports both stdio and SSE communication
- Error Handling: Robust error management for network and server issues
- Resource Management: Proper cleanup of connections and resources
๐ Prerequisites
Before running these examples:
-
Install Dependencies:
pip install -r requirements.txt -
Set up Environment:
# From the root tutorials directory cp env.example .env # Edit .env and add your Google AI API key -
Node.js for MCP Servers (for community servers):
# Install Node.js if not already installed # Required for npm/npx based MCP servers
๐ How It Works
Connection Flow
- Initialize MCPToolset with connection parameters
- Establish Connection to MCP server
- Discover Tools via MCP protocol
- Adapt Tools to ADK format
- Use Tools in agent conversations
- Cleanup connections on completion
Code Example
from google.adk.agents import LlmAgent
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StdioServerParameters
# Create MCP toolset for external server
toolset = MCPToolset(
connection_params=StdioServerParameters(
command='npx',
args=['-y', '@modelcontextprotocol/server-filesystem', '/path/to/folder']
)
)
# Create agent with MCP tools
agent = LlmAgent(
model='gemini-3-flash-preview',
name='mcp_agent',
instruction='Use MCP tools to help users',
tools=[toolset]
)
๐ Getting Started
Quick Start
-
Choose an example to explore:
- Filesystem Agent: For file operations
- Firecrawl Agent: For advanced web scraping and research
-
Follow the guide in each example directory
-
Run with ADK Web:
# From the root tutorials directory adk web
๐ Example Walkthrough
Filesystem Agent Example
# Connect to filesystem MCP server
toolset = MCPToolset(
connection_params=StdioServerParameters(
command='npx',
args=['-y', '@modelcontextprotocol/server-filesystem', '/path/to/folder']
)
)
# Ask agent to use filesystem tools
# "List files in the current directory"
# "Read the contents of sample.txt"
Firecrawl Agent Example
# Connect to Firecrawl MCP server
toolset = MCPToolset(
connection_params=StdioServerParameters(
command='npx',
args=['-y', 'firecrawl-mcp'],
env={'FIRECRAWL_API_KEY': 'your_api_key'}
)
)
# Ask agent to use web scraping tools
# "Scrape the homepage of https://example.com"
# "Find all blog post URLs on https://blog.example.com"
# "Search for recent AI research papers and extract summaries"
# "Extract product details from this e-commerce page: [URL]"
๐ก Best Practices
- Connection Management: Always handle connection lifecycle properly
- Error Handling: Implement robust error handling for network issues
- Resource Cleanup: Use proper cleanup patterns for connections
- Security: Validate inputs and handle authentication appropriately
- Performance: Consider connection pooling for high-throughput scenarios
๐ Troubleshooting
Common Issues
- Connection Errors: Check server URL and network connectivity
- Tool Not Found: Verify server is running and tools are exposed
- Authentication: Ensure proper API keys and credentials
- Version Compatibility: Check MCP protocol version compatibility
Debug Commands
# Test MCP server connection
npx @modelcontextprotocol/inspector
# Check ADK agent logs
adk web --debug
๐ Next Steps
After completing this tutorial:
- Tutorial 4: Memory Agent - Add memory capabilities
- Tutorial 5: Workflow Agent - Multi-step processes
- Tutorial 6: Multi-agent System - Agent collaboration
๐ Additional Resources
- MCP Specification - Protocol details
- ADK MCP Documentation - Integration guide
- Community MCP Servers - Ready-to-use servers
๐ฏ Real-World Applications
MCP tools enable:
- Knowledge Retrieval: Access Wikipedia, databases, documents
- File Operations: Read, write, manage files and directories
- API Integration: Connect to external services and APIs
- Data Processing: Transform and analyze data from various sources
- Custom Tools: Create and share specialized tools across agents
Ingestion metadata
- Source catalog
- awesome-llm-apps
- Repository
- Shubhamsaboo/awesome-llm-apps ยท main
- File path
- ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/README.md
- Last refreshed
- 7/24/2026, 3:00:13 AM (51m ago)
- Refresh schedule
- Daily ยท 03:00 UTC
- Dedupe status
- Unique ยท deduped by (source, url)