With Tool Prefix • AI Agent SDK

with_tool_prefix: Namespace this server's tool names with “prefix_“ to avoid

with_tool_prefix

Method

</div>

This is a method of the MCP class in the mcp module.

Namespace this server’s tool names with `&lt;prefix&gt;_` 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.

Diagram

uses

returns

Agent

Tool: with_tool_prefix

Result

Signature

python
def with_tool_prefix(prefix: str) -> 'MCP'

Parameters

ParamField str

The 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

  • ValueError
  • dict.fromkeys
  • callable

Source

View on GitHub

praisonaiagents/mcp/mcp.py at line 1247


Related Documentation