Model Context Protocol
The Model Context Protocol (MCP) enables Agents to interact with external systems through a standardized interface. With Agno’s MCP integration, you can connect any MCP-compatible service to your Agents.
Example: Filesystem Agent
Here’s a filesystem agent that uses the Filesystem MCP server to explore and analyze files:
Multiple MCP Servers
You can use multiple MCP servers in a single agent by using the MultiMCPTools
class.
More Flexibility
You can also create the MCP server yourself and pass it to the MCPTools
constructor.
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:
Understanding server Parameters
The recommended way to configure MCPTools
or MultiMCPTools
is to use the command
parameter.
Alternatively, you can use the server_params
parameter with MCPTools
to configure the connection to the MCP server.
It contains the following keys:
command
: The command to run the MCP server.- Use
npx
for mcp servers that can be installed via npm (ornode
if running on Windows). - Use
uvx
for mcp servers that can be installed via uvx.
- Use
args
: The arguments to pass to the MCP server.env
: Optional environment variables to pass to the MCP server. Remember to include all current environment variables in theenv
dictionary. Ifenv
is not provided, the current environment variables will be used. e.g.
More Information
- 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.