data_designer.engine.mcp.io
data_designer.engine.mcp.io
data_designer.engine.mcp.io
Low-level MCP I/O operations with caching and session pooling.
This module provides stateless functions for MCP communication using an actor-style service that owns all async state within a single background event loop. Public APIs are synchronous wrappers that submit coroutines to the loop and wait for results.
Architecture: All MCP I/O is funneled through a single dedicated asyncio event loop running in a background daemon thread. This avoids the complexity of managing multiple event loops and allows sessions to be reused across calls from any thread.
Worker Thread 1 ──┐ Worker Thread 2 ──┼──► MCP Event Loop Thread ──► MCP Servers Worker Thread N ──┘ (all sessions live here)
Request Coalescing: When multiple threads request tools from the same provider simultaneously, only one request is made to the MCP server. Other callers wait for the in-flight request to complete and share the result. This prevents N concurrent workers from making N separate ListToolsRequest calls.
The caller (MCPFacade) is responsible for resolving any secret references in provider api_key fields before passing providers to these functions.
Create a stable cache key for a provider.
Actor-style MCP I/O service owning all async state.
List tools from an MCP provider (cached with request coalescing).
Call multiple tools in parallel.
Clear caches and session pool entries for specific providers.
Clear the list_tools cache (best effort).
Get cache statistics for list_tools.
Clear all pooled MCP sessions (best effort).
Get information about the session pool.
Shutdown the MCP event loop and close all sessions.
List tools from an MCP provider (cached with request coalescing).
Return the names of all tools available on an MCP provider.
Call multiple tools in parallel.
Clear all caches for specific MCP providers.
Clear the list_tools cache.
Get cache statistics for list_tools.
Clear all pooled MCP sessions.
Get information about the session pool.
Build authentication headers for remote MCP clients.
Coerce a tool from various formats into MCPToolDefinition.
Serialize tool result content to a string.