Test an MCP Server Locally

The current Python SDK supports in-process client testing, which is ideal for fast unit/integration tests because it requires no subprocess or network port.

import pytest
from mcp.client import Client
from server import mcp

@pytest.mark.anyio
async def test_add():
    async with Client(mcp) as client:
        result = await client.call_tool("add", {"a": 1, "b": 2})
        assert result.structured_content == {"result": 3}

What to test

Use Inspector for exploratory testing

mcp dev launches MCP Inspector, which is useful for manually exercising tools and inspecting schemas while developing.

Add transport tests later

Once business behavior passes in-process tests, add a smaller set of stdio or Streamable HTTP tests to verify deployment wiring, authentication, headers, and timeouts.

References