Utils
This module contains internal utilities and helpers.
STDIO Proxy
Shared STDIO↔HTTP MCP proxy utilities.
Provides a small MCP server over STDIO that forwards initialize/initialized and tools/* JSON-RPC calls to an HTTP MCP server (e.g., http://127.0.0.1:8123/mcp).
Used by both Claude Desktop and Codex launchers to avoid code duplication.
This module uses FastMCP’s built-in proxy pattern (FastMCP.as_proxy) to automatically mirror tools, resources, and prompts from the backend server. This ensures that: 1. Tool descriptions are automatically forwarded to MCP clients 2. New tools added to the backend are automatically available 3. No manual synchronization of tool definitions is required
- async instrmcp.utils.stdio_proxy.check_http_mcp_server(host='127.0.0.1', port=8123)[source]
Check if the HTTP MCP server is running and responding.
- instrmcp.utils.stdio_proxy.create_stdio_proxy_server(base_url, server_name='InstrMCP Proxy')[source]
Create an MCP proxy server that forwards requests to an HTTP backend.
This uses FastMCP’s built-in proxy pattern which automatically: - Mirrors all tools with their descriptions and schemas - Mirrors all resources - Handles session management and request forwarding
- Parameters:
base_url (
str) – URL of the HTTP MCP backend (e.g., “http://127.0.0.1:8123”)server_name (
str) – Name for this proxy server
- Return type:
FastMCP- Returns:
FastMCP server instance configured as a proxy
Note
Connection to the backend is lazy - errors will surface on first tool call, not at proxy creation time.
- class instrmcp.utils.stdio_proxy.StdioMCPClient(launcher_path=None, mcp_url='http://127.0.0.1:8123')[source]
Bases:
objectMCP client that communicates with a proxy subprocess via STDIO.
This client spawns the claude_launcher.py subprocess and sends JSON-RPC commands via STDIN, receiving responses via STDOUT.
Used by instrmcp metadata validate to test the full communication path: CLI → STDIO → stdio_proxy → HTTP → MCP Server
- Usage:
client = StdioMCPClient() try:
client.start() tools = client.list_tools() resources = client.list_resources()
- finally:
client.stop()
- __init__(launcher_path=None, mcp_url='http://127.0.0.1:8123')[source]
Initialize the STDIO MCP client.
- start(timeout=10.0)[source]
Start the proxy subprocess and initialize the MCP session.
- Parameters:
timeout (
float) – Timeout in seconds for initialization.- Raises:
RuntimeError – If subprocess fails to start or initialize.
FileNotFoundError – If launcher script not found.
- Return type:
Key Functions
check_http_mcp_server
create_stdio_proxy_server
- instrmcp.utils.stdio_proxy.create_stdio_proxy_server(base_url, server_name='InstrMCP Proxy')[source]
Create an MCP proxy server that forwards requests to an HTTP backend.
This uses FastMCP’s built-in proxy pattern which automatically: - Mirrors all tools with their descriptions and schemas - Mirrors all resources - Handles session management and request forwarding
- Parameters:
base_url (
str) – URL of the HTTP MCP backend (e.g., “http://127.0.0.1:8123”)server_name (
str) – Name for this proxy server
- Return type:
FastMCP- Returns:
FastMCP server instance configured as a proxy
Note
Connection to the backend is lazy - errors will surface on first tool call, not at proxy creation time.
Creates a FastMCP proxy server that forwards STDIO to an HTTP backend. Uses FastMCP’s built-in
as_proxy()pattern for automatic tool and resource mirroring with full description forwarding.Example usage:
mcp = create_stdio_proxy_server( base_url="http://127.0.0.1:8123", server_name="InstrMCP Proxy" ) mcp.run()