Model Context Protocol (MCP) Introduction
The Model Context Protocol (MCP) enables Agents to interact with external systems through a standardized interface. You can connect your Agents to any MCP server, using Agno’s MCP integration.
Usage
Find the MCP server you want to use
You can use any working MCP server. To see some examples, you can check this GitHub repository, by the maintainers of the MCP themselves.
Initialize the MCP integration
Intialize the MCPTools
class as a context manager. The recommended way to define the MCP server, is to use the command
or url
parameters. With command
, you can pass the command used to run the MCP server you want. With url
, you can pass the URL of the running MCP server you want to use.
For example, to use the “mcp-server-git” server, you can do the following:
Provide the MCPTools to the Agent
When initializing the Agent, pass the MCPTools
class in the tools
parameter.
The agent will now be ready to use the MCP server:
Basic example: Filesystem Agent
Here’s a filesystem agent that uses the Filesystem MCP server to explore and analyze files:
Using MCP in Agno Playground
You can also run MCP servers in the Agno Playground, which provides a web interface for interacting with your agents. Here’s an example of a GitHub agent running in the Playground:
Best Practices
-
Error Handling: Always include proper error handling for MCP server connections and operations.
-
Resource Cleanup: Use
MCPTools
orMultiMCPTools
as an async context manager to ensure proper cleanup of resources:
- Clear Instructions: Provide clear and specific instructions to your agent:
More Information
- Find examples of Agents that use MCP here.
- Find a collection of MCP servers here.
- Read the MCP documentation to learn more about the Model Context Protocol.
- Checkout the Agno Cookbook for more examples of Agents that use MCP.