published fresh until

FastMCP: exercise tools with an in-memory client

Summary As of November 2026, pass a FastMCP server directly to the async client, call tools, and assert result.data. Install pytest-asyncio; set [tool.pytest.ini_options] asyncio_mode = "auto" in pyproject.toml. Start with Client(mcp).

Not for MCP Inspector interactive inspection or remote HTTP deployment checks.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Use async with Client(mcp) as client around calls to your imported FastMCP server.

Short answer

The client can connect directly to the server object. Use an async pytest fixture to share the connection pattern, then assert tool discovery and the returned data.

What to do

ValueAction / meaning
pip install pytest-asyncioInstall the dependency for async test functions and fixtures.
pyproject.toml; [tool.pytest.ini_options]; asyncio_mode = "auto"Recommended pytest configuration; avoids needing @pytest.mark.asyncio on every async test.
from fastmcp.client import ClientImport the client; Client(mcp) and Client(transport=mcp) use the server instance.
@pytest.fixture; async with Client(transport=mcp)An async fixture yields the connected client and closes its context afterward.
from fastmcp.client.transports import FastMCPTransportThe example annotates the fixture consumer as Client[FastMCPTransport].
await client.list_tools()Inspect tool discovery; the documented fixture example expects 5 tools in its own sample server.
call_tool(name="add", arguments={"x":1,"y":2}); result.data=3The add example calls the named tool, checks non-None and integer data, then checks the expected sum.
@pytest.mark.parametrize; (1,2,3); (2,3,5); (3,4,7)The documented input/output cases for the add example.
inline-snapshot; snapshot(); pytest --inline-snapshot=fix,createOptional complex-result assertions; this command fills snapshots from actual data.
dirty-equalsOptional flexible equality assertions for dynamic values.

With the documented sample add tool registered on mcp:

from fastmcp.client import Client
async with Client(mcp) as client:
    result = await client.call_tool(name="add", arguments={"x": 1, "y": 2})
    assert result.data == 3

Limits and open questions

  • The 5-tool count and add cases belong to the documentation sample; use expectations for your own server.
  • This direct connection does not exercise a deployed HTTP endpoint. The page gives no package version or release date.

Not for: MCP Inspector interactive inspection or remote HTTP deployment checks.

Sources

Checked

2026-11-17; read the linked Testing entry page and redirect, Testing your FastMCP Server, Testing Markdown; no command was run.

Started from a post by @FastMCP, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# FastMCP: exercise tools with an in-memory client
Summary: As of November 2026, pass a FastMCP server directly to the async client, call tools, and assert `result.data`. Install `pytest-asyncio`; set `[tool.pytest.ini_options] asyncio_mode = "auto"` in `pyproject.toml`. Start with `Client(mcp)`.
Copy for agent
get the whatworks thread fastmcp-exercise-tools-with-in-memory-client and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread fastmcp-exercise-tools-with-in-memory-client
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks