🎉 ai-infra v1.0 is here — Production-ready AI/LLM infrastructure
What's new
nfrax logonfrax

Infrastructure that just works. Ship products, not boilerplate.

Frameworks

  • svc-infra
  • ai-infra
  • fin-infra
  • robo-infra

Resources

  • Getting Started
  • What's New
  • Contributing

Community

  • GitHub

© 2026 nfrax. All rights reserved.

nfrax logonfrax
Start HereWhat's New
GitHub
ai-infra / API Reference

MCPClient

from ai_infra.mcp import MCPClient
View source
ai_infra.mcp

MCP Client for connecting to one or more MCP servers. Production-ready features: - Multi-server support with automatic discovery - All transports: stdio, sse, streamable_http - Auto-reconnect with configurable retry - Health checks - Timeout handling - Graceful shutdown via async context manager

python
# Simple usage
    mcp = MCPClient([
        {"command": "npx", "args": ["-y", "@anthropic/mcp-server-filesystem", "/tmp"]},
    ])
    await mcp.discover()
    tools = await mcp.list_tools()

    # With async context manager
    async with MCPClient(configs) as mcp:
        tools = await mcp.list_tools()
    # Automatic cleanup on exit
Constructor
MCPClient(config: list[dict] | list[McpServerConfig], callbacks: Callbacks | CallbackManager | None = None, interceptors: list[ToolCallInterceptor] | None = None, auto_reconnect: bool = False, reconnect_delay: float = 1.0, max_reconnect_attempts: int = 5, tool_timeout: float | None = 60.0, discover_timeout: float | None = 30.0, pool_size: int = 10)
ParameterTypeDefaultDescription
configrequiredlist[dict] |list[McpServerConfig]—List of MCP server configurations.
callbacksCallbacks | CallbackManager |NoneNoneCallback handler(s) for MCP events (progress, logging). Receives MCPProgressEvent and MCPLoggingEvent during tool execution. Can be a single Callbacks instance or a CallbackManager.
interceptorslist[ToolCallInterceptor] |NoneNoneList of tool call interceptors for request/response modification.
auto_reconnectboolFalseWhether to auto-reconnect on connection failure.
reconnect_delayfloat1.0Delay between reconnect attempts in seconds.
max_reconnect_attemptsint5Maximum number of reconnect attempts.
tool_timeoutfloat|None60.0Timeout for tool calls in seconds (default: 60.0). Set to None to disable timeout (not recommended).
discover_timeoutfloat|None30.0Timeout for server discovery in seconds (default: 30.0). Set to None to disable timeout (not recommended).
pool_sizeint10HTTP connection pool size (for future use).

Methods

On This Page

Constructorcall_toolasynccloseasyncdiscoverasyncget_clientget_openmcpasyncget_promptasyncget_resourcesasynchealth_checkasynclast_errorslist_clientsasynclist_openmcpasynclist_promptsasynclist_resourcesasynclist_toolsasyncserver_names