Tool Call Execution

The execution of an MCP tool call, from its resolved MCPToolCall.

MCPToolkit resolves each call in the app, into an MCPToolCall, and hands it to the tool runner (smarter.apps.llmtool.runner), which executes it with execute_mcp_call(). The call carries the MCPClient’s MCPEndpoint, so nothing here reads the database, and the same call can run in the app’s process today, or in a worker without credentials (ADR-038).

The executor checks allowed_tools and allowed_resources again, from the endpoint, so a worker doesn’t trust its caller to have checked them.

class smarter.apps.mcpclient.execution.MCPToolCall(**data)[source]

Bases: ToolCall

An MCP tool call, resolved for execution.

Variables:
  • endpoint – The MCPClient’s resolved endpoint, credential included.

  • operation – tool to call a tool, or read_resource to read a resource.

  • tool_name – The tool’s name, as the server reports it, for tool.

  • uri – The resource’s URI, for read_resource.

  • arguments – The tool’s arguments, from the LLM.

arguments: dict[str, JsonValue]
endpoint: MCPEndpoint
kind: Literal['mcp']
model_config = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

operation: Literal['tool', 'read_resource']
tool_name: str
uri: str
smarter.apps.mcpclient.execution.MCP_TOOL_CALL_KIND: Final = 'mcp'

The kind of an MCP tool call, which selects execute_mcp_call().

smarter.apps.mcpclient.execution.READ_RESOURCE: Final = 'read_resource'

The operation that reads one of the server’s resources.

It matches MCPFunction.kind.

smarter.apps.mcpclient.execution.TOOL: Final = 'tool'

The operation that calls one of the server’s tools.

It matches MCPFunction.kind.

smarter.apps.mcpclient.execution.execute_mcp_call(call)[source]

Execute a resolved MCP tool call: connect, perform the handshake, call the tool or read the resource, and disconnect.

Parameters:

call (ToolCall) – The call, an MCPToolCall.

Return type:

ToolCallResult

Returns:

The tool’s text, with is_error when the tool reports an error, or a result with a failure when the call couldn’t be made: refused, unreachable, timed out, or not allowed.

Raises:

TypeError – If the call isn’t an MCPToolCall.