# Useful but Little-Known Features of OpenAI Agent SDK
🌍 Are you exposing every single tool from your MCP server to the agent?
Tool filtering lets you control tool visibility statically or dynamically, improving agent accuracy and security.
📌 Title: Tool Filtering (Static / Dynamic)
🔗 URL:
🧩 Overview
When MCP servers expose many tools, showing them all to the agent can cause confusion or unintended tool calls. The `tool_filter` parameter lets you use a static filter (`create_static_tool_filter`) to specify allow/block lists, or a dynamic filter (a sync or async callable) to decide tool availability based on runtime context. When both `allowed_tool_names` and `blocked_tool_names` are supplied, the allow-list is applied first and blocked tools are then removed from the remaining set.
🛠 How to use it
```python
from agents.mcp import MCPServerStreamableHttp, create_static_tool_filter
# Static filter: explicitly allow specific tools
server = MCPServerStreamableHttp(
params={"url": ""},
tool_filter=create_static_tool_filter(
allowed_tool_names=["search", "summarize"]
),
)
# Dynamic filter: decide at runtime using context
async def my_filter(context, tool) -> bool:
# context.agent, context.server_name available
if == "admin":
return True # Admins get all tools
return in ["search", "read"]
server_dynamic = MCPServerStreamableHttp(
params={"url": ""},
tool_filter=my_filter,
)
```
🏗 Building it into production
・Dynamically switch available tools based on user permission levels
・Use static filters to exclude unnecessary tools and improve model tool selection accuracy
・Pass tenant information via ` to isolate tools in multi-tenant environments
・Log dynamic filter decisions for access control audit trails
💡 Use cases
🔒 Role-based tool access control
🎯 Narrowing tools for task-specific agents
🏢 Tool isolation in multi-tenant environments
🛡 Enforcing security policies on tool access
⚠️ Watch out
Dynamic filters are called every time the tool list is fetched, so heavy operations (like DB lookups) can impact latency. Keep filter logic simple and use caching when needed. Also verify that filtered-out tools aren't essential for the agent's core functionality.
✨ With tool filtering, give your agent exactly the tools it needs — nothing more, nothing less.
#
OpenAIAgentSDK# #
AIAgent#