π¦ test-mcp
What's test-mcp? β’ Installation β’ Getting Started β’ Configuration & Test Format β’ How to Run β’ CLI Flags β’ Test Discovery β’ Interactive Mode β’ Programmatic API β’ Roadmap β’ Contributing β’ License
test-mcp is a headless MCP client for automated testing of MCP servers and agents.
If youβre building an MCP server or agent, test-mcp lets you run natural-language test scripts and assertions end-to-end, so you can validate behavior in a fast and repeatable way.
basic-demo.mov
π‘ What's `test-mcp`?
test-mcp gives you three core components:
- Configuration β define your MCP servers and LLM provider in a single JSON file.
- Test Files β write flows of natural-language prompts and assertions in YAML.
- Runner β run tests from the CLI, get clear pass/fail results.
Together, these let you automate and validate MCP server behavior with simple, repeatable tests.
Supported Transports & Providers:
- MCP Servers: STDIO (local) and HTTP (remote)
- LLM Providers: Anthropic Claude and OpenAI GPT models
- MCP Features: Tools (done), Resources/Prompts/Sampling (planned)
ποΈ Installation
# using npm npm install -g @loadmill/test-mcp # or with pnpm pnpm add -g @loadmill/test-mcp
Note
While test-mcp itself can run on Node.js 18 or higher, many popular MCP servers require Node.js 20.
For the smoothest experience, we recommend using Node.js 20.
When running from source:
git clone https://github.com/loadmill/test-mcp cd test-mcp npm install # For OpenAI (default example) echo "OPENAI_API_KEY=your_api_key_here" > .env # Or for Anthropic echo "ANTHROPIC_API_KEY=your_api_key_here" > .env npm run build
π Getting Started
To try test-mcp quickly with the included examples:
# from source
node build/index.jsThis will run a demonstration that shows both local STDIO and remote HTTP MCP servers working together. The test rolls a local dice server and queries a remote MCP server registry.
π Configuration & Test Format
1) Example config (mcp.config.json)
{
"mcpClient": {
"provider": "openai",
"model": "gpt-4o-mini",
"api_key": "${env:OPENAI_API_KEY}"
},
"mcpServers": {
"loadmill": {
"type": "stdio",
"command": "npx",
"args": ["@loadmill/mcp"],
"env": {
"LOADMILL_API_TOKEN": "${env:LOADMILL_API_TOKEN}"
}
}
}
}OpenAI is also supported - see configuration variations in the examples/ folder.
2) Example test (tests/bank-transaction.test.yaml)
description: "Maker Checker Bank - Transaction Creation and Rejection Flow" steps: - prompt: "Login with username alice and password alice123 and transfer $100 to Bob" - prompt: "Login with username bob and password bob456, reject transaction from Alice" - assert: "Validate the transaction was created and rejected successfully"
βΆοΈ How to run
By default, test-mcp looks for mcp.config.json in the project root and runs tests in the tests/ folder.
Globally installed:
From source:
Point to a specific config or tests directory:
test-mcp --config mcp.config.json --tests-dir ./tests
π» CLI Flags
Options:
-c, --config <file> Path to config file (default: mcp.config.json)
-t, --tests-dir <dir> Directory containing test files (default: tests)
-i, --interactive Run in interactive chat mode
--trace Enable detailed tracing output
-h, --help Show help
π Test Discovery
All files ending in .test.yaml under the tests/ directory are executed.
Recursive discovery and full glob patterns are planned for later.
π¬ Interactive Mode
Run the client without tests and chat with your MCP servers:
π§ Programmatic API
You can use test-mcp programmatically in your Node.js code:
import { TestMCPClient } from '@loadmill/test-mcp'; const client = new TestMCPClient({ llm: { provider: 'openai', model: 'gpt-4o-mini', apiKey: process.env.OPENAI_API_KEY }, servers: { myServer: { type: 'stdio', command: 'node', args: ['./server.js'] } } }); await client.connect(); const response = await client.prompt('Your question'); const assertion = await client.assert('Expected behavior'); await client.disconnect();
See examples/api-example.js for a complete example.
π£οΈ Roadmap
- Headless MCP client with Anthropic support
- Support for
stdiotransport - Support for MCP tools
- Evaluator for natural-language assertions
- OpenAI support
- Support for
httptransport - Test parameterization with
${} - CI-friendly reports
- Support for MCP resources
- Support for MCP prompts
- Support for MCP sampling
π€ Contributing
Contributions, ideas, and bug reports are welcome! See CONTRIBUTING.md.
π License
Apache License 2.0 Β© Loadmill