With Tool Prefix • AI Agent SDK
with_tool_prefix: Namespace this server's tool names with “prefix_“ to avoid
with_tool_prefix
Method
</div>
Namespace this server’s tool names with `<prefix>_` to avoid collisions when multiple MCP servers are loaded together.
Both the callable tool names (`__name__) and the OpenAI schema names produced by :meth:to_openai_tool` are prefixed, while calls are still dispatched to the original server-side tool names.
Signature
def with_tool_prefix(prefix: str) -> 'MCP'Parameters
ParamField
strThe server name to derive the prefix from. It is sanitized to contain only `[0-9A-Za-z_]` characters.
Returns
ResponseField
'MCP'self, to allow fluent chaining.
Exceptions
ValueError
If `prefix` sanitizes to an empty string, since an
Uses
ValueErrordict.fromkeyscallable
Source
View on GitHubpraisonaiagents/mcp/mcp.py at line 1247