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, a mcp<id>_read_resource tool 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: object

A function tool offered to the LLM, and what it calls.

__init__(name, mcpclient, kind, tool_name=None)
kind: str
mcpclient: MCPClient
name: str
tool_name: str | None = None
class smarter.apps.mcpclient.toolkit.MCPToolkit(mcpclients)[source]

Bases: object

The MCP tools, instructions and tool call dispatch of one prompt.

Parameters:

mcpclients (list[MCPClient]) – The LLMClient’s active MCPClients, in order of priority.

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)
__init__(mcpclients)[source]
add_function(function, description, parameters)[source]

Add a function tool, and remember what it calls.

Return type:

None

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.

Parameters:
  • function_name (str) – The function name that the LLM called.

  • arguments (Optional[dict[str, Any]]) – The function’s arguments.

Return type:

str

Returns:

The result, or a description of the error.

connected: list[MCPClient]
errors: dict[str, str]
property formatted_class_name: str

The class name, for logging.

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.

Parameters:
  • mcpclient (MCPClient) – The MCPClient.

  • name (str) – The name of the tool, as the server reports it.

Return type:

str

Returns:

The function name.

functions: dict[str, MCPFunction]
instructions: dict[str, str]
is_mcp_function(function_name)[source]

Return whether a function name is one of this toolkit’s tools.

Return type:

bool

load()[source]

Fetch each MCPClient’s catalog, from the cache if possible, and build its tools.

Return type:

MCPToolkit

Returns:

This toolkit.

mcpclient_for(function_name)[source]

Return the MCPClient of one of this toolkit’s tools.

Return type:

Optional[MCPClient]

system_prompt()[source]

Return the MCP servers’ instructions, for the system prompt.

Return type:

Optional[str]

Returns:

The instructions, or None if no server has any.

tools: list[dict[str, Any]]