Skip to main content
Glama
20251009-0009-test-fixtures.md2.27 kB
--- story_id: "0009" title: "Create pytest fixtures and mock MCP server" created: "2025-10-09" status: done dependencies: ["0001"] estimated_complexity: "medium" tags: ["testing", "infrastructure", "phase1"] - status: in-progress timestamp: 2025-10-09T21:53:54Z - status: ready-for-review timestamp: 2025-10-09T22:16:10Z - status: done timestamp: 2025-10-10T01:13:02Z --- # Story 0009: Create pytest fixtures and mock MCP server ## Description Create reusable pytest fixtures for testing, including a mock MCP server with sample tools, resources, and prompts. This provides a foundation for integration testing without requiring external dependencies. ## Acceptance Criteria - [x] `tests/conftest.py` created - [x] Mock MCP server fixture implemented using FastMCP - [x] Mock server includes sample tools (e.g., add, multiply, divide) - [x] Mock server includes sample resources (e.g., config://settings) - [x] Mock server includes sample prompts (e.g., greeting) - [x] ConnectionManager fixture for test isolation - [x] Async test configuration (pytest-asyncio) - [x] Fixtures properly clean up resources after tests - [x] Documentation of available fixtures - [x] Example integration test using fixtures ## Technical Notes **Mock MCP server example:** ```python @pytest.fixture async def mock_mcp_server(): """Create a mock MCP server for testing""" mcp = FastMCP(name="test-server") @mcp.tool() async def add(a: int, b: int) -> int: return a + b @mcp.resource("config://settings") async def get_settings(): return {"setting1": "value1"} # Start server, yield URL/connection, cleanup ``` **Pytest-asyncio configuration:** ```ini # pytest.ini or pyproject.toml [tool.pytest.ini_options] asyncio_mode = "auto" ``` ## AI Directives **IMPORTANT**: As you work through this story, please mark checklist items as complete `[x]` as you finish them. This ensures that if we need to pause and resume work, we have a clear record of progress. Update the `status` field in the frontmatter when moving between stages (in-progress, ready-for-review, done, blocked). Mock server should be realistic enough to test all tool functionality. Do not mock unnecessarily - use real FastMCP for the mock server.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rdwj/mcp-test-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server