MCP Util
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.
MCPToolMetaContextdataclass
Context information available to MCP tool meta resolver functions.
Source code insrc/agents/mcp/util.py
MCPUtil
Set of utilities for interop between MCP and Agents SDK tools.
Source code insrc/agents/mcp/util.py
170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 | |
get_all_function_toolsasyncclassmethod
get_all_function_tools(servers:list[MCPServer],convert_schemas_to_strict:bool,run_context:RunContextWrapper[Any],agent:AgentBase,failure_error_function:ToolErrorFunction|None=default_tool_error_function,)->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,failure_error_function:ToolErrorFunction|None=default_tool_error_function,)->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,agent:AgentBase|None=None,failure_error_function:ToolErrorFunction|None=default_tool_error_function,)->FunctionToolConvert an MCP tool to an Agents SDK function tool.
Theagent parameter is optional for backward compatibility with oldercall sites that usedMCPUtil.to_function_tool(tool, server, strict).When omitted, this helper preserves the historical behavior and leavesneeds_approval disabled.
Source code insrc/agents/mcp/util.py
invoke_mcp_toolasyncclassmethod
invoke_mcp_tool(server:MCPServer,tool:Tool,context:RunContextWrapper[Any],input_json:str,*,meta:dict[str,Any]|None=None,)->ToolOutputInvoke an MCP tool and return the result as ToolOutput.
Source code insrc/agents/mcp/util.py
create_static_tool_filter
create_static_tool_filter(allowed_tool_names:list[str]|None=None,blocked_tool_names:list[str]|None=None,)->ToolFilterStatic|NoneCreate 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 | list[str] | None | Optional list of tool names to allow (whitelist). | None |
blocked_tool_names | list[str] | None | Optional list of tool names to exclude (blacklist). | None |
Returns:
| Type | Description |
|---|---|
ToolFilterStatic | None | A ToolFilterStatic if any filtering is specified, None otherwise. |