MCP server for testing REST API with built-in assertions
Project description
api-test-mcp
MCP server for REST API testing with assertions. Provides a test_api tool that accepts either a cURL command or structured request fields, runs the request, and validates against expected status codes and response fields
Prerequisites
- Python >= 3.10
- pip or uv for package installation
Install
From PyPI
pip install mcp-api-test
From source
git clone git@gitlab.com:ryaneatfood/mcp-api-testing.git
# change the directory
cd api-test-mcp
# install from source
pip install -e .
This registers the api-test-mcp CLI command on your PATH. Verify with:
which api-test-mcp
Testing with MCP Inspector
The MCP Inspector provides a browser-based UI to verify your server connects and responds correctly before wiring it into a client.
Make sure api-test-mcp is installed on your PATH (see Install), then run:
npx @modelcontextprotocol/inspector
This launches the inspector and opens http://localhost:5173 in your browser. From the UI:
- Set Transport Type to
STDIO - Set Command to
api-test-mcp - Leave Arguments empty (your server needs none)
- Click Connect
When the connection succeeds, the status badge changes to Connected and the inspector lists the test_api tool under the Tools tab. You can click the tool to open a form and run test calls interactively. This is useful for rapid iteration without restarting your MCP client.
If the status shows "Failed to connect" double-check that which api-test-mcp resolves and that pip install -e . completed without errors
Running Tests
Install test dependencies and run the suite:
# install test dependencies
pip install pytest pytest-asyncio respx
# run the whole test suite
pytest -v
All integration tests use respx to mock HTTP responses. No real network calls are made, so the suite runs fast and offline. The test suite also consisted of unit test and integration test
OpenCode Setup
Edit opencode.json (already configured at project root):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"api-test-mcp": {
"type": "local",
"command": ["api-test-mcp"],
"enabled": true
}
}
}
Claude Desktop Setup
Edit claude_desktop_config.json (usually at ~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"api-test-mcp": {
"command": "api-test-mcp"
}
}
}
Restart Claude Desktop after saving.
Usage
The test_api tool supports two modes:
cURL mode
Pass a raw cURL command, and then the server parses method, URL, headers, and payload automatically into restructured data. Example prompt that you might be used:
"Please test this API using this cURL:
curl -X POST https://api.example.com/v1/users -H 'Authorization: Bearer xxx' -d '{"name":"test"}', ensure status code is 201 and response contains 'id'"
Structured mode
Provide individual fields rather than used a cURL command. Example prompt:
"Please test this API at https://api.example.com/v1/users with method GET, and the request header is {"Content-Type":"application/json"}, ensure status code is 200 and response body contains 'data'" attribute
Assertions
At the moment, this library provides built-in assertions that proved useful for testing the API, such as:
| Parameter | Type | Description |
|---|---|---|
required_status_code |
int |
Assert exact status code |
required_status_code_range |
str |
Assert status code is within a range (e.g. "2xx", "200-299") |
required_response_fields |
list[str] |
Assert fields exist in JSON response |
required_response_contains |
str |
Assert response body contains a substring |
Response
The tool returns a formatted console string with box-drawing, pass/fail symbols, and a summary:
Passing (with assertions)
┌──────────────────────────────────────────────┐
│ Api Test Result │
└──────────────────────────────────────────────┘
API Name : create-user
Method : POST
URL : https://api.example.com/v1/users
Status Code : 201
Response Time : 142.35 ms
Overall Result : Passed
Assertions
--------------------------------------------------
✓ status_code
✓ response_field_exist
Summary
--------------------------------------------------
Total Assertions : 2
Passed : 2
Failed : 0
Failing (assertion mismatch)
┌──────────────────────────────────────────────┐
│ Api Test Result │
└──────────────────────────────────────────────┘
API Name : create-user
Method : POST
URL : https://api.example.com/v1/users
Status Code : 500
Response Time : 89.12 ms
Overall Result : Failed
Assertions
--------------------------------------------------
✗ status_code
Summary
--------------------------------------------------
Total Assertions : 1
Passed : 0
Failed : 1
Network / runtime error
┌──────────────────────────────────────────────┐
│ Api Test Result │
└──────────────────────────────────────────────┘
API Name : check-service
Method : GET
URL : https://api.internal.example.com/v1/status
Overall Result : Failed
Error
--------------------------------------------------
ConnectError: [Errno 8] nodename nor servname provided, or not known
Logging
The server writes logs to log/mcp-api-test.log at the project root. Useful for debugging failed requests or tracing tool calls.
Environment Variables
The server loads a .env file via python-dotenv on startup. Useful for storing API keys, base URLs, etc. without hardcoding them in prompts.
Development
# Re-install after pulling changes
pip install -e .
# Run the MCP server directly
api-test-mcp
To run the test suite:
pip install -e ".[dev]"
pytest -v
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_api_test-0.1.0.tar.gz.
File metadata
- Download URL: mcp_api_test-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17c561be505114e8554fb5453e7b93bf5a439f5826ab83bb54c7e9a245e2b32e
|
|
| MD5 |
fa706a046dd8c56cd8ab28315a48eab7
|
|
| BLAKE2b-256 |
5be5500df57ae68eb4b8efb18b294322ebab815b449f17fe552a5ce6e283d018
|
File details
Details for the file mcp_api_test-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_api_test-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84243ae6ac6c9367a8093e1b8e037e3ff05b416700d5773d7b81221bce01f410
|
|
| MD5 |
8d19ecceb577730875ce4136d45ac871
|
|
| BLAKE2b-256 |
04150806910e341f8515e952f5f773c6936743920ae0956aac5cb009774f78c9
|