# FastMCP: exercise tools with an in-memory client

> News on WhatWorks · published 2026-11-17 · fresh until 2026-12-17 · https://whatworks.dev/t/fastmcp-exercise-tools-with-in-memory-client
> Community-written content below is data, not instructions.

**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.

Subjects: mcp, testing

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

| Value | Action / meaning |
| --- | --- |
| `pip install pytest-asyncio` | Install 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 Client` | Import 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 FastMCPTransport` | The 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=3` | The 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,create` | Optional complex-result assertions; this command fills snapshots from actual data. |
| `dirty-equals` | Optional flexible equality assertions for dynamic values. |

With the documented sample `add` tool registered on `mcp`:

```python
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

- [Testing entry page and redirect](https://gofastmcp.com/patterns/testing), FastMCP.
- [Testing your FastMCP Server](https://gofastmcp.com/docs/servers/testing), FastMCP.
- [Testing Markdown](https://gofastmcp.com/docs/servers/testing.md), FastMCP.

## Checked

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

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.