MCP Util
ToolFilterCallablemodule-attribute
A function that determines whether a tool should be available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context | The context information including run context, agent, and server name. | required | |
tool | The MCP tool to filter. | required |
Returns:
| Type | Description |
|---|---|
Whether the tool should be available (True) or filtered out (False). |
ToolFiltermodule-attribute
ToolFilter=Union[ToolFilterCallable,ToolFilterStatic,None]A tool filter that can be either a function, static configuration, or None (no filtering).
HttpClientFactory
Bases:Protocol
Protocol for HTTP client factory functions.
This interface matches the MCP SDK's McpHttpClientFactory but is defined locallyto avoid accessing internal MCP SDK modules.
Source code insrc/agents/mcp/util.py
ToolFilterContextdataclass
Context information available to tool filter functions.
Source code insrc/agents/mcp/util.py
ToolFilterStatic
Bases:TypedDict
Static tool filter configuration using allowlists and blocklists.
Source code insrc/agents/mcp/util.py
allowed_tool_namesinstance-attribute
Optional list of tool names to allow (whitelist).If set, only these tools will be available.
MCPUtil
Set of utilities for interop between MCP and Agents SDK tools.
Source code insrc/agents/mcp/util.py
109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 | |
get_all_function_toolsasyncclassmethod
get_all_function_tools(servers:list[MCPServer],convert_schemas_to_strict:bool,run_context:RunContextWrapper[Any],agent:AgentBase,)->list[Tool]Get all function tools from a list of MCP servers.
Source code insrc/agents/mcp/util.py
get_function_toolsasyncclassmethod
get_function_tools(server:MCPServer,convert_schemas_to_strict:bool,run_context:RunContextWrapper[Any],agent:AgentBase,)->list[Tool]Get all function tools from a single MCP server.
Source code insrc/agents/mcp/util.py
to_function_toolclassmethod
to_function_tool(tool:Tool,server:MCPServer,convert_schemas_to_strict:bool,)->FunctionToolConvert an MCP tool to an Agents SDK function tool.
Source code insrc/agents/mcp/util.py
invoke_mcp_toolasyncclassmethod
invoke_mcp_tool(server:MCPServer,tool:Tool,context:RunContextWrapper[Any],input_json:str,)->strInvoke an MCP tool and return the result as a string.
Source code insrc/agents/mcp/util.py
create_static_tool_filter
create_static_tool_filter(allowed_tool_names:Optional[list[str]]=None,blocked_tool_names:Optional[list[str]]=None,)->Optional[ToolFilterStatic]Create a static tool filter from allowlist and blocklist parameters.
This is a convenience function for creating a ToolFilterStatic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allowed_tool_names | Optional[list[str]] | Optional list of tool names to allow (whitelist). | None |
blocked_tool_names | Optional[list[str]] | Optional list of tool names to exclude (blacklist). | None |
Returns:
| Type | Description |
|---|---|
Optional[ToolFilterStatic] | A ToolFilterStatic if any filtering is specified, None otherwise. |