Skip to main content

pytest-native TestClient for the MCP Python SDK Server class

Project description

mcp-testclient

CI PyPI Python 3.10+

pytest-native TestClient for the MCP Python SDK Server class.

Using FastMCP? You already have Client(server) built in. mcp-testclient targets the official mcp.server.lowlevel.Server class only.

Why

The MCP Python SDK ships a Server class with no built-in test transport. Testing requires spawning a subprocess or standing up a real HTTP server — until now.

mcp-testclient wires your Server directly to a ClientSession using anyio memory streams. No subprocess. No network. No stdio. In-process, in a single pytest function.

from mcp.server.lowlevel import Server
import mcp.types as types
from mcp_testclient import TestClient

server = Server("my-server")

@server.list_tools()
async def list_tools():
    return [types.Tool(name="add", description="Add two numbers",
                       inputSchema={"type": "object", "properties":
                           {"a": {"type": "number"}, "b": {"type": "number"}}})]

@server.call_tool()
async def call_tool(name, arguments):
    return [types.TextContent(type="text", text=str(arguments["a"] + arguments["b"]))]

def test_add():
    with TestClient(server) as client:
        tools = client.list_tools()
        assert tools[0].name == "add"

        result = client.call_tool("add", {"a": 1, "b": 2})
        assert result[0].text == "3"

Install

pip install mcp-testclient

API

with TestClient(server) as client:
    client.list_tools()                            # → list[types.Tool]
    client.call_tool("name", {"arg": "value"})    # → list[TextContent | ...]
    client.list_resources()                        # → list[types.Resource]
    client.read_resource("resource://uri")         # → list[TextResourceContents | ...]
    client.list_prompts()                          # → list[types.Prompt]
    client.get_prompt("name", {"arg": "value"})   # → GetPromptResult

call_tool raises RuntimeError if the server returns isError=True.

Compatibility

  • Python 3.10, 3.11, 3.12
  • mcp >= 1.0.0 (tested on 1.26.0)

Known Issues

MCP SDK v1.9.1+: default host changed to 127.0.0.1

Docker containers will be unreachable externally. Explicitly set host='0.0.0.0' in your FastMCP or server config if deploying in a container.

MCP SDK v1.9.4+: Streamable HTTP incompatible with Cloud Run

If you're hitting connection errors on Cloud Run after upgrading, downgrade the SDK or use SSE transport temporarily until a fix ships upstream.

SSE transport deprecated as of April 1, 2026 (grace period through June 30, 2026)

All SSE-based MCP servers need to migrate to Streamable HTTP by end of June. See the MCP spec migration guide for details.

MCP Registry

mcp-name: io.github.peytongreen-dev/mcp-testclient

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_testclient-0.1.0.tar.gz (57.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_testclient-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file mcp_testclient-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_testclient-0.1.0.tar.gz
  • Upload date:
  • Size: 57.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mcp_testclient-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10426f97e1e5ae23231a9ad01d5f820e26f577d2eadd20fa1da404d4fbe96b3e
MD5 3a85c2ecc9fcba9d074e3ed9f9eaf6a6
BLAKE2b-256 194ecee23fe97f8bf45c111af3769845b3724472801896d13903ce77cf51d9bb

See more details on using hashes here.

File details

Details for the file mcp_testclient-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_testclient-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mcp_testclient-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 274799da8517453b5df35f99221c42fb4a2cce14c2ee4b946365e2ea948d9cc0
MD5 e8dcc0f44f88cf762e064c9d31546638
BLAKE2b-256 73468bfda07d2ddf636a166148c62f00ab4d1aa495a489c69ac4d9ff33b3fc31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page