Advanced MCP Usage
Agno’s MCP integration also supports handling connections to multiple servers, specifying server parameters and using your own MCP servers:
Connecting to Multiple MCP Servers
You can use multiple MCP servers in a single agent by using the MultiMCPTools
class.
Understanding Server Parameters
The recommended way to configure MCPTools
or MultiMCPTools
is to use the command
or url
parameters.
Alternatively, you can use the server_params
parameter with MCPTools
to configure the connection to the MCP server in more detail.
When using the stdio transport, the server_params
parameter should be an instance of StdioServerParameters
. 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.
When using the SSE transport, the server_params
parameter should be an instance of SSEClientParams
. It contains the following fields:
url
: The URL of the MCP server.headers
: Headers to pass to the MCP server (optional).timeout
: Timeout for the connection to the MCP server (optional).sse_read_timeout
: Timeout for the SSE connection itself (optional).
When using the Streamable HTTP transport, the server_params
parameter should be an instance of StreamableHTTPClientParams
. It contains the following fields:
url
: The URL of the MCP server.headers
: Headers to pass to the MCP server (optional).timeout
: Timeout for the connection to the MCP server (optional).sse_read_timeout
: how long (in seconds) the client will wait for a new event before disconnecting. All other HTTP operations are controlled bytimeout
(optional).terminate_on_close
: Whether to terminate the connection when the client is closed (optional).
More Flexibility
You can also create the MCP server yourself and pass it to the MCPTools
constructor.