一键导入
mcp-testing
Generate and manage comprehensive test suites for MCP tools with coverage reporting
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Generate and manage comprehensive test suites for MCP tools with coverage reporting
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | mcp-testing |
| description | Generate and manage comprehensive test suites for MCP tools with coverage reporting |
The MCP Testing Skill automates test generation for Model Context Protocol tools. It creates comprehensive test suites with happy path, error cases, edge cases, and parameter validation tests, ensuring robust coverage.
Request: "Generate tests for the get_current_weather tool"
[Provide tool code]
Skill: Analyzes tool and generates comprehensive test suite
Output: Test file with 5-8 test cases covering all scenarios
Request: "Create integration tests for all weather tools"
[Provide multiple tool definitions]
Skill: Generates combined tool tests plus integration scenarios
Output: test_tools_integration.py with cross-tool tests
✓ test_get_current_weather_valid_coordinates
✓ test_get_current_weather_different_units
✓ test_get_current_weather_expected_fields_present
✓ test_get_current_weather_latitude_too_high
✓ test_get_current_weather_latitude_too_low
✓ test_get_current_weather_invalid_units
✓ test_get_current_weather_api_timeout
✓ test_get_current_weather_api_error
✓ test_get_current_weather_network_error
✓ test_get_current_weather_boundary_values
✓ test_get_current_weather_special_characters
import pytest
from unittest.mock import AsyncMock, patch
@pytest.mark.asyncio
async def test_<tool_name>_<scenario>():
"""
Test [tool_name] for [scenario].
This test verifies:
- [What is being tested]
- [Why it matters]
"""
# Arrange: Setup test data and mocks
mock_response = {...}
expected_result = {...}
with patch("httpx.AsyncClient.get") as mock_get:
mock_get.return_value.json.return_value = mock_response
mock_get.return_value.raise_for_status = AsyncMock()
# Act: Call the tool
result = await get_current_weather(lat=51.5, lon=-0.1)
# Assert: Verify results
assert result == expected_result
assert "error" not in result
mock_get.assert_called_once()
tests/
├── conftest.py # Shared fixtures, mocks
├── test_tools_weather.py # Weather tool tests
├── test_tools_location.py # Location tool tests
├── test_tools_integration.py # Combined tool tests
├── test_tools_performance.py # Performance tests
└── fixtures/
├── weather_responses.json
├── location_responses.json
└── error_responses.json
| Category | Target | Why |
|---|---|---|
| Overall | 80%+ | Catch most issues |
| Tool Logic | 90%+ | All paths covered |
| Error Paths | 85%+ | Error handling verified |
| Integration | 70%+ | Combined scenarios work |
pytest tests/ -v --cov=src --cov-report=html
pytest tests/test_tools_weather.py::test_get_current_weather_valid_coordinates -v
pytest tests/ --cov=src --cov-report=term-missing
with patch("httpx.AsyncClient.get") as mock_get:
mock_get.return_value.json.return_value = {"temp": 20}
result = await get_current_weather(51.5, -0.1)
with patch.dict(os.environ, {"OPENWEATHERMAP_API_KEY": "test-key"}):
result = await get_current_weather(51.5, -0.1)
@pytest.fixture
def mock_weather_response():
return {
"main": {"temp": 20},
"weather": [{"main": "Cloudy"}]
}
❌ Bad Test
def test_weather(): # Vague name
result = get_current_weather(0, 0)
assert result # Generic assertion
✓ Good Test
@pytest.mark.asyncio
async def test_get_current_weather_valid_coordinates_success():
"""Get weather succeeds with valid lat/lon coordinates."""
result = await get_current_weather(lat=51.5, lon=-0.1)
assert "error" not in result, "Valid coordinates should not produce errors"
assert result["temperature"] > -100, "Temperature should be reasonable"
assert result["humidity"] >= 0 and result["humidity"] <= 100
@pytest.mark.asyncio
async def test_get_current_weather_performance():
"""Tool should respond within 5 seconds."""
import time
start = time.time()
result = await get_current_weather(51.5, -0.1)
elapsed = time.time() - start
assert elapsed < 5.0, f"Tool took {elapsed}s, expected <5s"
assert "error" not in result
@pytest.mark.asyncio
async def test_weather_for_location_integration():
"""Test search + weather combination."""
# This combines two tools
result = await weather_for_location("London")
assert "error" not in result
assert "location" in result
assert "temperature" in result
test_<tool_name>_<scenario>_<expectation>
Examples:
test_get_current_weather_valid_coordinates_success
test_get_current_weather_latitude_out_of_range_error
test_search_location_empty_query_returns_error
test_weather_for_location_integration_combines_results
# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.11"
- run: pip install -r requirements.txt
- run: pytest tests/ --cov=src --cov-report=xml
- uses: codecov/codecov-action@v2
name stmts miss cover
────────────────────────────────────────
src/server/index.py 120 5 96%
src/tools/weather.py 45 2 95%
src/tools/location.py 38 3 92%
────────────────────────────────────────
TOTAL 203 10 95%
Cause: Timing issues or incomplete mocks Fix: Ensure all async operations are awaited; mock all external calls
Cause: Test data doesn't match real API responses Fix: Capture real API responses and use as fixtures
Cause: Actually calling external APIs or slow assertions Fix: Mock all I/O; use fixtures; check for N+1 queries
Cause: Not testing error paths or edge cases Fix: Systematically add tests for each error condition
.github/instructions/testing.instructions.md - Testing standards.github/copilot/exemplars.md - Example implementationsPerform comprehensive code review of MCP tools focusing on security, reliability, and best practices
Plan and execute MCP server deployment to production environments
Generate professional documentation for MCP tools including docstrings, examples, and API reference