Prompt Toolkit
The MCP tools that a prompt offers the LLM.
MCPToolkit turns an LLMClient’s MCPClients into what an OpenAI-compatible chat
completion needs:
tools: one function tool per MCP server tool that the MCPClient allows, named
mcp<id>_<tool name>, with the server’s description and input schema. If the MCPClient allows resources, and the server has any, amcp<id>_read_resourcetool reads them.instructions: the servers’ instructions, for the system prompt.
tool calls:
MCPToolkit.call()runs a tool call on the right server, and returns the result as text for the LLM. Errors are returned to the LLM as text, so that it can recover, rather than failing the prompt.
An MCP server that cannot be reached is skipped, and reported in MCPToolkit.errors,
so that one unavailable server does not fail the prompt.
Note
Experimental. The MCPClient was designed and coded by Claude Code (Anthropic’s Claude Opus 5.5), with Lawrence McDaniel as co-author. It is experimental, and will be documented.
- class smarter.apps.mcpclient.toolkit.MCPFunction(name, mcpclient, kind, tool_name=None)[source]
Bases:
objectA function tool offered to the LLM, and what it calls.
- __init__(name, mcpclient, kind, tool_name=None)
- class smarter.apps.mcpclient.toolkit.MCPToolkit(mcpclients)[source]
Bases:
objectThe MCP tools, instructions and tool call dispatch of one prompt.
Example usage:
toolkit = MCPToolkit(LLMClientMCPClients.mcpclients_for(llmclient)).load() tools.extend(toolkit.tools) ... if toolkit.is_mcp_function(tool_call.function.name): content = toolkit.call(tool_call.function.name, arguments)
- add_function(function, description, parameters)[source]
Add a function tool, and remember what it calls.
- Return type:
- call(function_name, arguments=None)[source]
Run a tool call, and return its result as text for the LLM.
Errors, including an unreachable server and errors that the tool reports, are returned as text that begins with
Error:, so that the LLM can recover.
- function_name(mcpclient, name)[source]
Return a unique OpenAI function name for one of an MCPClient’s tools.
The name is
mcp<id>_<name>, with characters that OpenAI does not allow replaced by underscores, and at most 64 characters long. If two tools would have the same name, a short hash of the tool’s name is appended.
- functions: dict[str, MCPFunction]
- is_mcp_function(function_name)[source]
Return whether a function name is one of this toolkit’s tools.
- Return type:
- load()[source]
Fetch each MCPClient’s catalog, from the cache if possible, and build its tools.
- Return type:
- Returns:
This toolkit.