Enhancement Request
The MCP server template doesn't include test examples for MCP tools. Adding comprehensive test examples would help users write reliable MCP servers.
Proposed Test Structure
1. Basic Tool Testing
# tests/test_hello.py
import pytest
from app.tools.hello import hello
@pytest.mark.asyncio
async def test_hello_valid_input():
result = await hello("World")
assert result == "Hello, World!"
@pytest.mark.asyncio
async def test_hello_empty_input():
with pytest.raises(ValueError):
await hello("")
@pytest.mark.asyncio
async def test_hello_special_characters():
result = await hello("Claude 3.5!")
assert result == "Hello, Claude 3.5!!"
2. MCP Server Testing
# tests/test_mcp_server.py
import pytest
from fastmcp.testing import MCPTestClient
from app.main import mcp
@pytest.fixture
def mcp_client():
return MCPTestClient(mcp)
@pytest.mark.asyncio
async def test_tool_registration(mcp_client):
tools = await mcp_client.list_tools()
assert "hello" in [tool.name for tool in tools]
@pytest.mark.asyncio
async def test_tool_execution(mcp_client):
result = await mcp_client.call_tool("hello", {"name": "Test"})
assert result == "Hello, Test!"
3. Integration Testing
# tests/test_integration.py
@pytest.mark.asyncio
async def test_multiple_tool_calls(mcp_client):
# Test calling multiple tools in sequence
pass
@pytest.mark.asyncio
async def test_error_propagation(mcp_client):
# Test that errors are properly propagated
pass
4. Mock and Fixture Examples
# tests/conftest.py
import pytest
from unittest.mock import AsyncMock
@pytest.fixture
def mock_database():
"""Mock database for testing."""
db = AsyncMock()
db.query.return_value = [{"id": 1, "name": "Test"}]
return db
@pytest.fixture
def mock_api_client():
"""Mock API client for testing."""
client = AsyncMock()
client.get.return_value = {"status": "success"}
return client
5. Test Configuration
# pytest.ini or pyproject.toml
[tool.pytest.ini_options]
testpaths = ["tests"]
asyncio_mode = "auto"
python_files = "test_*.py"
python_functions = "test_*"
Test Categories to Include
- Unit Tests: Individual tool functions
- Integration Tests: Multiple tools working together
- Error Handling Tests: Edge cases and error scenarios
- Performance Tests: Response time and resource usage
- Security Tests: Input validation and sanitization
Benefits
- Ensures code reliability
- Prevents regressions
- Documents expected behavior
- Facilitates refactoring
- Improves code quality
Implementation
- Add
tests/ directory to template
- Include example test files
- Add testing dependencies to
pyproject.toml
- Include GitHub Actions workflow for CI/CD
- Add test coverage reporting
Dependencies to Add
[project.optional-dependencies]
test = [
"pytest>=7.0.0",
"pytest-asyncio>=0.21.0",
"pytest-cov>=4.0.0",
"pytest-mock>=3.10.0",
]
Enhancement Request
The MCP server template doesn't include test examples for MCP tools. Adding comprehensive test examples would help users write reliable MCP servers.
Proposed Test Structure
1. Basic Tool Testing
2. MCP Server Testing
3. Integration Testing
4. Mock and Fixture Examples
5. Test Configuration
Test Categories to Include
Benefits
Implementation
tests/directory to templatepyproject.tomlDependencies to Add