Connect to a Local MCP Server

The Python SDK can connect directly to an MCPServer object for tests, or launch a subprocess using stdio parameters for real local integrations.

In-process testing

from mcp.client import Client
from server import mcp

async with Client(mcp) as client:
    print(await client.list_tools())

Subprocess connection

For an actual local server, configure the executable, arguments, and only the environment variables that process needs. Avoid forwarding your entire shell environment automatically.

Operational checks