mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 13:04:18 +02:00
Bumps the uv group with 1 update in the /examples/testing_demo directory: [authlib](https://github.com/authlib/authlib). Updates `authlib` from 1.6.6 to 1.6.7 - [Release notes](https://github.com/authlib/authlib/releases) - [Changelog](https://github.com/authlib/authlib/blob/main/docs/changelog.rst) - [Commits](https://github.com/authlib/authlib/compare/v1.6.6...v1.6.7) --- updated-dependencies: - dependency-name: authlib dependency-version: 1.6.7 dependency-type: indirect dependency-group: uv ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| tests | ||
| pyproject.toml | ||
| README.md | ||
| server.py | ||
| uv.lock | ||
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:
- Async fixture pattern: Proper client fixture using
async with - Tool testing: Calling tools and checking results via
.dataattribute - Resource testing: Reading static and templated resources
- Prompt testing: Getting prompts with different arguments
- Parametrized tests: Testing multiple scenarios efficiently
- Schema validation: Verifying tool schemas and structure
- 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.