data_designer.engine.mcp.facade
data_designer.engine.mcp.facade
data_designer.engine.mcp.facade
Lightweight facade scoped to a specific ToolConfig.
MCPFacade provides a clean interface for MCP tool operations within the context of a specific tool configuration. It handles tool call extraction, validation, and execution using the mcp.io module for communication.
This mirrors the ModelFacade pattern where each facade is scoped to a specific configuration while sharing underlying resources through caching in the io module.
The alias for this tool configuration.
List of MCP provider names for this configuration.
Maximum number of tool-calling turns permitted in a single generation.
A turn is one iteration where the LLM requests tool calls. With parallel tool calling, a single turn may execute multiple tools simultaneously.
Optional allowlist of permitted tool names.
Timeout in seconds for MCP tool calls.
Count the number of tool calls in a completion response.
Returns True if tool calls are present in the completion response.
Get OpenAI-compatible tool schemas for this configuration.
Fetches tools from all providers in the configuration and applies allow_tools filtering if specified. Uses cached results from mcp_io.
Returns:
list[dict[str, typing.Any]]
List of tool schemas in OpenAI function calling format.
Raises:
If allowed tools are not found on any provider.
If the same tool name appears in multiple providers.
Process an LLM completion response and execute any tool calls.
This is the primary method for handling tool calls from an LLM response. It extracts the response content, reasoning content, and all tool calls from the completion response, executes each tool call (including parallel tool calls), and returns the messages for continuing the conversation.
Parameters:
The canonical ChatCompletionResponse from the model client.
Returns:
list[data_designer.engine.models.utils.ChatMessage]
A list of ChatMessages to append to the conversation history:
Raises:
If a requested tool is not in the allowed tools list.
If tool execution fails or times out.
If a requested tool is not found on any configured provider.
Refuse tool calls without executing them.
Used when the tool call turn budget is exhausted. Returns messages that include the assistant’s tool call request but with refusal responses instead of actual tool results.
Parameters:
The canonical ChatCompletionResponse containing tool calls.
Optional custom refusal message.
Returns:
list[data_designer.engine.models.utils.ChatMessage]
A list of ChatMessages to append to the conversation history.
Resolve secret references in an MCP provider’s api_key.
Build the assistant message containing tool call requests.
Execute canonical ToolCall objects and return tool response messages.
Find the provider that has the given tool and return it with resolved api_key.
Convert canonical ToolCall objects to the internal dict format for ChatMessage.