Skip to content

Commit 495c0ac

Browse files
committed
Update MCP docs
1 parent c9a4f4e commit 495c0ac

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

tools/mcp.mdx

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,10 @@ from mcp import StdioServerParameters
2323
async def run_agent(message: str) -> None:
2424
"""Run the filesystem agent with the given message."""
2525

26-
# MCP parameters for the Filesystem server accessed via `npx`
27-
server_params = StdioServerParameters(
28-
command="npx",
29-
args=[
30-
"-y",
31-
"@modelcontextprotocol/server-filesystem",
32-
str(Path(__file__).parent.parent.parent.parent), # Set this to the root of the project you want to explore
33-
],
34-
)
26+
file_path = str(Path(__file__).parent.parent.parent.parent)
3527

36-
37-
# Create a client session to connect to the MCP server
38-
async with MCPTools(server_params=server_params) as mcp_tools:
28+
# MCP server to access the filesystem (via `npx`)
29+
async with MCPTools(f"npx -y @modelcontextprotocol/server-filesystem {file_path}") as mcp_tools:
3930
agent = Agent(
4031
model=OpenAIChat(id="gpt-4o"),
4132
tools=[mcp_tools],
@@ -64,39 +55,33 @@ if __name__ == "__main__":
6455

6556
## Multiple MCP Servers
6657

67-
You can use multiple MCP servers in a single agent by passing multiple `MCPTools` instances to the `tools` parameter of the `Agent` constructor.
58+
You can use multiple MCP servers in a single agent by using the `MultiMCPTools` class.
6859

6960
```python multiple_mcp_servers.py
7061
import asyncio
7162
import os
7263

7364
from agno.agent import Agent
74-
from agno.tools.mcp import MCPTools
75-
from mcp import StdioServerParameters
65+
from agno.tools.mcp import MultiMCPTools
7666

7767

7868
async def run_agent(message: str) -> None:
79-
"""Run the GitHub agent with the given message."""
69+
"""Run the Airbnb and Google Maps agent with the given message."""
8070

8171
env = {
8272
**os.environ,
8373
"GOOGLE_MAPS_API_KEY": os.getenv("GOOGLE_MAPS_API_KEY"),
8474
}
8575

86-
# Time-zone MCP server accessed via `uvx`
87-
time_server_params = StdioServerParameters(
88-
command="uvx",
89-
args=["mcp-server-time", "--local-timezone=Europe/London"],
90-
)
91-
92-
# Maps MCP server accessed via `npx`
93-
maps_server_params = StdioServerParameters(
94-
command="npx", args=["-y", "@modelcontextprotocol/server-google-maps"], env=env
95-
)
96-
97-
async with MCPTools(server_params=time_server_params) as time_mcp_tools, MCPTools(server_params=maps_server_params) as maps_mcp_tools:
76+
async with MultiMCPTools(
77+
[
78+
"npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt",
79+
"npx -y @modelcontextprotocol/server-google-maps",
80+
],
81+
env=env,
82+
) as mcp_tools:
9883
agent = Agent(
99-
tools=[time_mcp_tools, maps_mcp_tools],
84+
tools=[mcp_tools],
10085
markdown=True,
10186
show_tool_calls=True,
10287
)
@@ -109,7 +94,7 @@ if __name__ == "__main__":
10994
# Pull request example
11095
asyncio.run(
11196
run_agent(
112-
"What is the current time in Cape Town? What restaurants are open right now?"
97+
"What listings are available in Cape Town for 2 people for 3 nights from 1 to 4 August 2025?"
11398
)
11499
)
115100
```
@@ -188,9 +173,9 @@ if __name__ == "__main__":
188173

189174
1. **Error Handling**: Always include proper error handling for MCP server connections and operations.
190175

191-
2. **Resource Cleanup**: Use `MCPTools` as an async context manager to ensure proper cleanup of resources:
176+
2. **Resource Cleanup**: Use `MCPTools` or `MultiMCPTools` as an async context manager to ensure proper cleanup of resources:
192177
```python
193-
async with MCPTools(server_params) as mcp_tools:
178+
async with MCPTools(command) as mcp_tools:
194179
# Your agent code here
195180
```
196181

@@ -208,12 +193,15 @@ You are a filesystem assistant. Help users explore files and directories.
208193

209194
## Understanding server Parameters
210195

211-
The `server_params` parameter to `MCPTools` is used to configure the connection to the MCP server. It contains the following keys:
196+
The recommended way to configure `MCPTools` or `MultiMCPTools` is to use the `command` parameter.
197+
198+
Alternatively, you can use the `server_params` parameter with `MCPTools` to configure the connection to the MCP server.
199+
It contains the following keys:
212200
- `command`: The command to run the MCP server.
213201
- Use `npx` for mcp servers that can be installed via npm (or `node` if running on Windows).
214202
- Use `uvx` for mcp servers that can be installed via uvx.
215203
- `args`: The arguments to pass to the MCP server.
216-
- `env`: Optional environment variables to pass to the MCP server. Remember to include all current environment variables in the `env` dictionary.
204+
- `env`: Optional environment variables to pass to the MCP server. Remember to include all current environment variables in the `env` dictionary. If `env` is not provided, the current environment variables will be used.
217205
e.g.
218206
```python
219207
{

0 commit comments

Comments
 (0)