fastmcp/examples/testing_demo
dependabot[bot] 139d058fc5
chore(deps): bump the uv group across 2 directories with 3 updates (#5171)
Bumps the uv group with 2 updates in the / directory: [httpcore2](https://github.com/pydantic/httpx2) and [httpx2](https://github.com/pydantic/httpx2).
Bumps the uv group with 1 update in the /examples/testing_demo directory: [anyio](https://github.com/agronholm/anyio).


Updates `httpcore2` from 2.7.0 to 2.10.0
- [Release notes](https://github.com/pydantic/httpx2/releases)
- [Commits](https://github.com/pydantic/httpx2/compare/v2.7.0...v2.10.0)

Updates `httpx2` from 2.7.0 to 2.10.0
- [Release notes](https://github.com/pydantic/httpx2/releases)
- [Changelog](https://github.com/pydantic/httpx2/blob/main/src/httpx2/CHANGELOG.md)
- [Commits](https://github.com/pydantic/httpx2/compare/v2.7.0...v2.10.0)

Updates `anyio` from 4.12.1 to 4.14.2
- [Release notes](https://github.com/agronholm/anyio/releases)
- [Commits](https://github.com/agronholm/anyio/compare/4.12.1...4.14.2)

Updates `anyio` from 4.12.1 to 4.14.2
- [Release notes](https://github.com/agronholm/anyio/releases)
- [Commits](https://github.com/agronholm/anyio/compare/4.12.1...4.14.2)

---
updated-dependencies:
- dependency-name: anyio
  dependency-version: 4.14.2
  dependency-type: indirect
- dependency-name: httpcore2
  dependency-version: 2.10.0
  dependency-type: indirect
- dependency-name: httpx2
  dependency-version: 2.10.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-09-22 13:48:38 -05:00
..
tests docs: clarify pytest-asyncio dependency and asyncio mode configuration (#2399) 2025-11-15 10:34:29 -05:00
pyproject.toml chore(deps): bump the uv group across 2 directories with 1 update (#3913) 2026-04-13 20:12:30 -04:00
README.md Align CLI, deployment, and config docs (#4259) 2026-07-19 14:24:07 -04:00
server.py docs: clarify pytest-asyncio dependency and asyncio mode configuration (#2399) 2025-11-15 10:34:29 -05:00
uv.lock chore(deps): bump the uv group across 2 directories with 3 updates (#5171) 2026-09-22 13:48:38 -05:00

FastMCP Testing Demo

A comprehensive example demonstrating FastMCP testing patterns with pytest-asyncio.

Overview

This example shows how to:

  • Set up pytest-asyncio configuration in pyproject.toml
  • Write async test fixtures for MCP clients
  • Test tools, resources, and prompts
  • Use parametrized tests for multiple scenarios
  • Leverage inline-snapshot and dirty-equals for assertions

Project Structure

testing_demo/
├── pyproject.toml          # Project config with pytest-asyncio setup
├── server.py               # Simple MCP server with tools/resources/prompts
├── tests/
│   └── test_server.py      # Comprehensive test suite
└── README.md               # This file

Key Features

pyproject.toml Configuration

The pyproject.toml includes the critical pytest-asyncio configuration:

[tool.pytest.ini_options]
asyncio_mode = "auto"

This eliminates the need for @pytest.mark.asyncio decorators on every async test.

Server Components

The demo server (server.py) includes:

  • Tools: add, greet, async_multiply
  • Resources: demo://info, demo://greeting/{name}
  • Prompts: hello, explain

Test Patterns

The test suite demonstrates:

  1. Async fixture pattern: Proper client fixture using async with
  2. Tool testing: Calling tools and checking results via .data attribute
  3. Resource testing: Reading static and templated resources
  4. Prompt testing: Getting prompts with different arguments
  5. Parametrized tests: Testing multiple scenarios efficiently
  6. Schema validation: Verifying tool schemas and structure
  7. Pattern matching: Using dirty-equals for flexible assertions

Running the Tests

# Install dependencies
uv sync

# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run a specific test
uv run pytest tests/test_server.py::test_add_tool

Running the Server

# Run the server
uv run fastmcp run server.py

# Inspect the server
uv run fastmcp inspect server.py

Learning More

For detailed information about testing FastMCP servers, see the Testing Documentation.