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. The results of read-only tools and resource reads are cached for the MCPClient’scacheTtl.
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, read_only=False, cacheable=False)[source]
Bases:
objectA function tool offered to the LLM, and what it calls.
- __init__(name, mcpclient, kind, tool_name=None, read_only=False, cacheable=False)
- cacheable: bool = False
Whether the call’s results may be cached.
It may if it only reads, and its server is not the staff-only endpoint of this platform’s MCPServer, whose results depend on who is chatting, and whose every call must reach its audit trail. See
is_staff_endpoint_url().
- 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.
- 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.A cacheable call (see
MCPFunction.cacheable) is cached for the MCPClient’scache_ttlseconds, bycached_tool_call(). Errors are never cached. A cached result sendsmcpclient_tool_responded, ormcpclient_resource_read, withcached=True.
- 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.
- 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.