mcp-testclient
pytest-native TestClient for the MCP Python SDK Server class.
Using FastMCP? You already have
Client(server)built in. mcp-testclient targets the officialmcp.server.lowlevel.Serverclass 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
Metadata
Release files for mcp-testclient 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mcp_testclient-0.1.0.tar.gz | 57.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_testclient-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.9 kB
Release files / mcp_testclient-0.1.0.tar.gz
| Download URL | mcp_testclient-0.1.0.tar.gz |
|---|---|
| Size | 57.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10426f97e1e5ae23231a9ad01d5f820e26f577d2eadd20fa1da404d4fbe96b3e
|
|
BLAKE2b-256 checksum How to use checksums |
194ecee23fe97f8bf45c111af3769845b3724472801896d13903ce77cf51d9bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / mcp_testclient-0.1.0-py3-none-any.whl
| Download URL | mcp_testclient-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
274799da8517453b5df35f99221c42fb4a2cce14c2ee4b946365e2ea948d9cc0
|
|
BLAKE2b-256 checksum How to use checksums |
73468bfda07d2ddf636a166148c62f00ab4d1aa495a489c69ac4d9ff33b3fc31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|