loading…
Search for a command to run...
loading…
Enables AI assistants to run Vitest tests and analyze code coverage, supporting test-driven development workflows with tools for test execution and coverage ana
Enables AI assistants to run Vitest tests and analyze code coverage, supporting test-driven development workflows with tools for test execution and coverage analysis.

A production-ready Model Context Protocol (MCP) server for running Vitest tests and analyzing coverage. This server provides AI assistants with intelligent tools for test-driven development workflows.
If your project uses Vitest, you can ask your AI agent in Cursor, Claude Desktop, or any other MCP-compatible editor these kinds of questions:
Configure your AI assistant (like Claude Desktop, Cursor, etc.) to use this MCP server in the usual way. On top of that the server needs to know the path to your project root in order to be able to find your Vitest config file.
Unlike many other MCP servers, this one executes Vitest commands that must run in your specific project directory. Here's why:
vitest run and vitest --coverage commandsvitest.config.ts/jspackage.jsonVITEST_PROJECT_DIR, Vitest can't find your config and failsFor best performance and reliability, use only the environment variable (the cwd is redundant):
{
"mcpServers": {
"vitest-runner": {
"command": "npx",
"args": [
"-y",
"@madrus/vitest-mcp-server@latest"
],
"env": {
"VITEST_PROJECT_DIR": "/Users/<your-username>/path/to/your/project/root"
}
}
}
}
Cursor (macOS/Linux):
~/.cursor/mcp.json/Users/<your-username>/.cursor/mcp.jsonClaude Desktop (macOS):
~/Library/Application Support/Claude/claude_desktop_config.jsonClaude Desktop (Windows):
%APPDATA%\Claude\claude_desktop_config.jsonHere's a complete example for Cursor with multiple MCP servers:
{
"mcpServers": {
"vitest-runner": {
"command": "npx",
"args": [
"-y",
"@madrus/vitest-mcp-server@latest"
],
"env": {
"VITEST_PROJECT_DIR": "/Users/<your-username>/path/to/your/project/root"
}
}
}
}
/Users/<your-username>/path/to/your/project/root to your actual project pathpackage.json and Vitest config files are located)ping tool to verify the server is working correctlyTesting with MCP Inspector:
You can use the MCP Inspector to visually test the server's tools and resources before integrating with your AI assistant:
npx @modelcontextprotocol/inspector npx -y @madrus/vitest-mcp-server@latest
This opens a web interface where you can test the ping, run-vitest, and run-vitest-coverage tools interactively and view the available resources.
Common Issues and Solutions:
Server fails to start or times out:
VITEST_PROJECT_DIR is correct and absolutepackage.jsonnpx vitest run manually in your project directory"Cannot find vitest config" errors:
vitest.config.ts/js or vite.config.ts/js filenpm list vitestVITEST_PROJECT_DIRpingSimple health check that returns "pong". Useful for verifying server connectivity.
Returns: "pong"
run-vitestExecutes Vitest tests and returns structured results.
Parameters:
projectDir (optional): Override auto-detected project directoryFeatures:
vitest.config.tsReturns: Complete test execution results including:
run-vitest-coverageExecutes Vitest tests with comprehensive coverage analysis.
Parameters:
projectDir (optional): Override auto-detected project directoryFeatures:
Returns: Test results + detailed coverage data including:
After running tests, the following resources become available:
vitest://test-resultsComplete test execution results in JSON format.
vitest://coverage-reportDetailed coverage analysis with file-by-file metrics.
vitest://test-summaryHuman-readable test summary with success percentages.
{
"numTotalTests": 167,
"numPassedTests": 167,
"numFailedTests": 0,
"coverage": {
"app/components/AppBar.tsx": {
"summary": {
"lines": {"pct": 95.78, "total": 166, "covered": 159},
"functions": {"pct": 33.33, "total": 3, "covered": 1},
"statements": {"pct": 95.78, "total": 166, "covered": 159},
"branches": {"pct": 84.21, "total": 19, "covered": 16}
},
"status": "⚠️ 7 lines uncovered",
"uncoveredLines": "43-44, 49-50, 52, 63-64",
"totalUncoveredLines": 7
},
"app/components/AuthErrorBoundary.tsx": {
"summary": {
"lines": {"pct": 100, "total": 64, "covered": 64},
"functions": {"pct": 100, "total": 3, "covered": 3},
"statements": {"pct": 100, "total": 64, "covered": 64},
"branches": {"pct": 100, "total": 17, "covered": 17}
},
"status": "✅ Perfect coverage",
"uncoveredLines": "none",
"totalUncoveredLines": 0
}
}
}
The server automatically detects your Vitest configuration by looking for:
vitest.config.tsvitest.config.jsvitest.config.mjsvite.config.tsvite.config.jsvite.config.mjsYou can override the project directory using:
projectDirVITEST_PROJECT_DIR (recommended)| Variable | Description | Required | Default |
|---|---|---|---|
VITEST_PROJECT_DIR |
HIGHLY RECOMMENDED: Specifies your project directory since MCP servers run in isolated processes. Unlike other MCPs that just analyze files, this one executes Vitest commands that need to run in your project root. | No | Auto-detected |
NODE_ENV |
Set automatically to test during execution. You don't need to set this manually. |
No | test |
npx usageMIT
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues, please report them on the GitHub Issues page.
Built with the Model Context Protocol SDK and designed for seamless integration with AI-powered development workflows.
Выполни в терминале:
claude mcp add vitest-mcp-server -- npx Не уверен что выбрать?
Найди свой стек за 60 секунд
Автор?
Embed-бейдж для README
Похожее
Все в категории development