MCP Util
ToolFilterCallable
module-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). |
ToolFilter
module-attribute
ToolFilter = Union[
ToolFilterCallable, ToolFilterStatic, None
]
A tool filter that can be either a function, static configuration, or None (no filtering).
ToolFilterContext
dataclass
Context information available to tool filter functions.
Source code in src/agents/mcp/util.py
ToolFilterStatic
Bases: TypedDict
Static tool filter configuration using allowlists and blocklists.
Source code in src/agents/mcp/util.py
allowed_tool_names
instance-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 in src/agents/mcp/util.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
get_all_function_tools
async
classmethod
get_all_function_tools(
servers: list[MCPServer],
convert_schemas_to_strict: bool,
run_context: RunContextWrapper[Any],
agent: Agent[Any],
) -> list[Tool]
Get all function tools from a list of MCP servers.
Source code in src/agents/mcp/util.py
get_function_tools
async
classmethod
get_function_tools(
server: MCPServer,
convert_schemas_to_strict: bool,
run_context: RunContextWrapper[Any],
agent: Agent[Any],
) -> list[Tool]
Get all function tools from a single MCP server.
Source code in src/agents/mcp/util.py
to_function_tool
classmethod
to_function_tool(
tool: Tool,
server: MCPServer,
convert_schemas_to_strict: bool,
) -> FunctionTool
Convert an MCP tool to an Agents SDK function tool.
Source code in src/agents/mcp/util.py
invoke_mcp_tool
async
classmethod
invoke_mcp_tool(
server: MCPServer,
tool: Tool,
context: RunContextWrapper[Any],
input_json: str,
) -> str
Invoke an MCP tool and return the result as a string.
Source code in src/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. |