You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
excluded_tools=["delete_file"], # This tool will be filtered out
69
+
)
70
+
```
71
+
72
+
### Agent-level filtering
73
+
74
+
You can also filter tools at the Agent level using the `mcp_config` parameter. This allows you to control which tools are available across all MCP servers:
75
+
76
+
```python
77
+
agent = Agent(
78
+
name="Assistant",
79
+
instructions="Use the tools to achieve the task",
80
+
mcp_servers=[server1, server2, server3],
81
+
mcp_config={
82
+
"allowed_tools": {
83
+
"server1": ["read_file", "write_file"], # Only these tools from server1
84
+
"server2": ["search"], # Only search tool from server2
85
+
},
86
+
"excluded_tools": {
87
+
"server3": ["dangerous_tool"], # Exclude this tool from server3
88
+
}
89
+
}
90
+
)
91
+
```
92
+
93
+
**Filtering priority**: Server-level filtering is applied first, then Agent-level filtering. This allows for fine-grained control where servers can limit their exposed tools, and Agents can further restrict which tools they use.
94
+
44
95
## Caching
45
96
46
97
Every time an Agent runs, it calls `list_tools()` on the MCP server. This can be a latency hit, especially if the server is a remote server. To automatically cache the list of tools, you can pass `cache_tools_list=True` to [`MCPServerStdio`][agents.mcp.server.MCPServerStdio], [`MCPServerSse`][agents.mcp.server.MCPServerSse], and [`MCPServerStreamableHttp`][agents.mcp.server.MCPServerStreamableHttp]. You should only do this if you're certain the tool list will not change.
0 commit comments