MCP + Agent Development Kit (ADK): Crash Course

aiwithbrandonAbout 5 min readMay 30, 2025Watch original
THE SUMMARYAI-generated

Key Concepts

  • Model Context Protocol (MCP): A standardized way for AI agents to connect to external tools.
  • Agent Development Kit (ADK): A framework for building AI agents.
  • Tool Calling: The process of an AI agent using external tools to perform tasks.
  • MCP Server: A server that provides a standardized interface for accessing tools.
  • Standard Input/Output (STDIO): A method of communication between processes using text streams.

Phase 1: Understanding MCP

What is MCP?

MCP (Model Context Protocol) is a standardized way for AI agents to connect to external tools. It acts as a server that provides a unified interface for accessing various real-world AI tools. Instead of directly connecting an agent to multiple tools, the agent connects to a single MCP server, which then manages the connections to the individual tools.

Traditional Tool Calling vs. MCP

Traditional Tool Calling:

  • Each tool is directly integrated into the agent's code.
  • Adding a new tool requires writing custom code to wrap the tool's API.
  • Sharing tools between projects involves copying the tool's code, violating the DRY (Don't Repeat Yourself) principle.
  • Example: Connecting an ADK agent to Notion without MCP requires writing custom tools for each Notion API endpoint (e.g., creating a page, querying a database).

MCP Tool Calling:

  • The agent connects to an MCP server, which provides access to a collection of tools.
  • Tools are standardized and can be easily accessed through the MCP server's interface.
  • Sharing tools between projects is simplified, as multiple agents can connect to the same MCP server.
  • Example: Connecting an ADK agent to Notion via MCP allows the agent to access all Notion API endpoints through the Notion MCP server.

Benefits of MCP

  • Standardization: Provides a consistent interface for accessing tools, simplifying agent development.
  • Reusability: Tools can be easily shared and reused across multiple projects.
  • Reduced Redundancy: Developers don't have to rewrite code for common tools.
  • Simplified Integration: Adding new tools is as simple as connecting to the appropriate MCP server.

Drawbacks of MCP

  • Additional Setup: Requires setting up and managing an MCP server.
  • Complexity: Can be more complex than traditional tool calling for simple, custom tools.

When to Use MCP

  • Use MCP: For common, widely used APIs (e.g., Notion, Slack, databases).
  • Avoid MCP: For rapidly experimenting with custom tools locally.

Phase 2: Connecting to a Remote MCP Server

Finding MCP Servers

  • Model Context Protocol GitHub Repository: Contains links to various MCP servers for common tools.
  • Smithery: Another resource for finding MCP servers.

Running an MCP Server

  • Docker: Use Docker to create a container that runs the MCP server.
  • NPX (Node Package Executable): Use NPX to run a Node.js package that implements the MCP server.
  • Python: Run a Python script that implements the MCP server.

Notion MCP Server Example

  1. Setup: Follow the instructions in the Notion MCP server's GitHub repository to set up the server.
  2. Credentials: Create a Notion API key and grant the necessary permissions to the application.
  3. Connection: Connect the ADK agent to the Notion MCP server using the MCP tool set command.
  4. Interaction: Use the agent to list available tools, describe tools, and call tools to interact with Notion.

Example Code

agent.add_tool_set(
    MCP_tool set(
        connection_parameters="npx @modelcontextprotocol/notion-agent",
        environment_variables={"NOTION_API_KEY": "your_notion_api_key"},
    )
)

Demonstration

The video demonstrates connecting an ADK agent to a Notion MCP server and using it to:

  • List available tools.
  • Describe the search page tool.
  • Query databases.
  • Add a comment to a Notion page.

Phase 3: Creating a Local MCP Server

Overview

This phase demonstrates how to create a custom MCP server that runs locally on your computer and connects to an ADK agent. The example focuses on creating tools to interact with a SQLite database containing user and to-do information.

Steps

  1. Create a Local MCP Server (server.py):

    • Import necessary libraries from ADK and MCP.
    • Define tools to interact with the SQLite database (e.g., list_database_tables, get_table_schema, query_database_table, insert_data, delete_data).
    • Create an instance of the MCP server with a name, version, and instructions.
    • Implement the list_tools function to return a list of available tools.
    • Implement the call_tool function to execute a specific tool based on its name and arguments.
    • Use run_MCP_STDIO_server to start the server and listen for requests from the agent.
  2. Add Tools to the MCP Server:

    • Create a dictionary of ADK database tools.
    • Use the ADK helper function to convert raw tools to MCP-compatible tools.
  3. Create an ADK Agent (agent.py):

    • Create an ADK agent and connect it to the local MCP server using the MCP tool set command.
    • Specify the command to run the Python server (e.g., python3 server.py).
    • Provide the absolute path to the server.py file.
  4. Run the Agent and Interact with the MCP Server:

    • Start the ADK agent using the ADK web command.
    • Use the agent to list available tools, query the database, add data, and delete data.

Example Code (agent.py)

agent.add_tool_set(
    MCP_tool set(
        connection_parameters=f"python3 {absolute_path_to_server_py}",
        instructions="You are an efficient database agent. You can talk to databases. Be smart about it.",
    )
)

Demonstration

The video demonstrates connecting an ADK agent to a local MCP server and using it to:

  • List available tools.
  • Query the database for users.
  • Query the database for to-dos.
  • Add a new to-do item.

Synthesis/Conclusion

MCP provides a standardized and reusable way to connect AI agents to external tools. While it may require additional setup compared to traditional tool calling, it offers significant benefits in terms of code reusability, simplified integration, and reduced redundancy, especially when working with common APIs. The video provides a comprehensive guide to understanding MCP, connecting to remote MCP servers, and creating custom local MCP servers, empowering developers to build more powerful and versatile AI agents.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.