The Vitest MCP Server provides an AI-optimized interface for Vitest that enhances test management, debugging, and coverage analysis through structured tools and safety features.
Core Capabilities:
Run Tests: Execute Vitest commands on specific files or directories with structured JSON output (summary or detailed) optimized for AI consumption
Analyze Coverage: Conduct comprehensive coverage analysis with configurable thresholds, line-by-line insights, and detailed metrics for line, function, and branch coverage
List Test Files: Discover and list test files within projects or specified directories
Multi-Repository Support: Manage project context and switch between multiple repositories in a single session
AI Integration & Safety:
Smart Targeting: Prevents accidental full test suite runs by requiring target files or directories
Console Log Capture: Captures console output for debugging test failures and troubleshooting
Safety Guards: Includes mechanisms to prevent resource exhaustion and unintended operations
Debug Mode: Provides enhanced debugging tools with detailed logging for development purposes
Customization:
Configurable Behavior: Customize default settings, coverage thresholds, and Vitest configurations through multiple priority sources (config files, command-line flags, environment variables)
Flexible Output: Generate structured JSON reports tailored for AI systems with coverage gap analysis and threshold validation
Runs within a Node.js environment (requiring Node.js 18+) to provide test execution capabilities and coverage analysis tools for JavaScript/TypeScript projects.
Provides AI-optimized testing tools for Vitest including structured output, visual debugging context, and intelligent coverage analysis with tools for test discovery, execution, and gap analysis.
🧪 Vitest MCP Server
MCP Vitest runner with LLM-optimized test output, log capturing, and line-by-line coverage analysis.
Table of Contents
- 😢 The Problem with LLMs and Testing
- ✨ Key Features
- 🚀 Quick Start
- 📋 Requirements
- 🧰 Tools
- 🔄 Multi-Repository Support
- 🪝 Claude Code Hook
- 🤖 LLM instructions
- ⚙️ Configuration
- 🔍 Development Mode & Debugging
- 🔧 Troubleshooting
- 📜 License
😢 The Problem with LLMs and Testing 😢
- Noisy test output - Raw Vitest output can be extremely verbose eating up tokens/context with useless information.
- Full test suite runs - LLMs sometimes forget to limit the scope of the test run, causing full test suite runs to be executed.
- Buried console logs - Console logs can be hidden in test output, making it inefficient for LLMs to debug test failures.
- Raw coverage files - Raw coverage files are too large for AI to parse.
- Watch mode - LLMs get stuck when vitest runs in watch mode.
✨ Key Features ✨
- Smart Test Results with adaptive, structured output to limit noise.
- Console Log Capture to prevent logs from getting lost in test output.
- Coverage Analysis with line-by-line gap insights.
- Multi-Repository Support in a single session with context switching.
- Safety Guards prevent full project runs, watch mode, invalid vitest commands, and context hogging.
🚀 Quick Start 🚀
The Vitest MCP server can be used with any MCP-compatible IDE or tool and works with all Javascript or Typescript Vitests. The basic configuration is:
⚠️ Note: The above example may not be valid for all MCP clients. Verify your client's specific setup instructions.
🛠️ Client-Specific Setup
Select your preferred IDE or tool from the setup guides below:
Configuration Methods
Claude Code supports multiple configuration approaches:
Method 1: CLI Wizard (Interactive)
Method 2: Direct Configuration File
Create or edit .mcp.json
in your project root:
Configuration Scopes
- Local (default): Personal, project-specific - stored in user settings
- Project: Team-shared - stored in
.mcp.json
in project root - User: Available across all projects - global configuration
Setup Steps
- Navigate to your project directory
- Choose either CLI or file-based configuration
- For CLI: Run
claude mcp add vitest npx -y @djankies/vitest-mcp
- For file: Create
.mcp.json
with the configuration above - Verify with
/mcp
command in Claude Code to see connection status
Usage
Once configured, use the MCP server naturally in your conversations:
- "Set the project root to this directory"
- "Run the auth component tests"
- "Show me the test coverage gaps"
Configuration Location
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
Example Configuration
Setup Steps
- Open Claude Desktop
- Navigate to File → Settings → Developer
- Click Edit Config
- Add the configuration above
- Save and restart Claude Desktop
- Look for the MCP indicator (🔌) in the conversation input
Configuration Methods
- Workspace:
.vscode/mcp.json
in your project - Global: Run command
MCP: Open User Configuration
Example Configuration
Setup Steps
- Install VS Code 1.86+ with GitHub Copilot
- Open Command Palette (
Cmd/Ctrl + Shift + P
) - Run
MCP: Add Server
- Select Workspace Settings or Global
- Add the configuration and save
- Access via Copilot Chat: Add Context → MCP Resources
Configuration Location
- Project:
.cursor/mcp.json
in your project directory - Global:
~/.cursor/mcp.json
for all workspaces
Example Configuration
Setup Steps
- Create the configuration file in your preferred location
- Add the server configuration
- Restart Cursor
- The MCP server will be available in Cursor's AI chat
- Use natural language to run tests: "Run the auth component tests"
Configuration Location
Similar to Cursor, but use serverUrl
instead of url
for remote servers
Example Configuration
Setup Steps
- Open Windsurf Settings (
Cmd/Ctrl + ,
) - Navigate to Cascade settings
- Add MCP server configuration
- Reload MCP servers to activate
Configuration via Cline UI
Example Configuration
Setup Steps
- Open VS Code with Cline extension installed
- Click the Cline icon in the sidebar
- Click MCP Servers → Configure MCP Servers
- Add the vitest-mcp configuration
- Save and reload VS Code
- Access through Cline's chat interface
3. Use It 🎮
Once configured, you can use natural language to interact with your tests:
- "Run the tests for this component"
- "Debug this test file"
- "Analyze the coverage for this file"
Or prepend your message with vitest-mcp:
to ensure the tools are used:
- "vitest-mcp: run tests for this component"
- "vitest-mcp: debug this test file"
- "vitest-mcp: analyze coverage for this file"
📋 Requirements
- Node.js: 18+ 🟢
- Vitest: 0.34.0+ 🧪
- Coverage:
@vitest/coverage-v8
(for coverage analysis) 📊
🧰 Tools
set_project_root
🚨 Required first - Set the project root for all operations.
Parameter | Type | Required | Description |
---|---|---|---|
path | string | Yes | Project root path |
list_tests
List test files in your project. Helps keep LLMs from slipping back to using command line tools while working with tests.
Parameter | Type | Required | Description |
---|---|---|---|
directory | string | Yes | Directory to search for test files |
run_tests
Execute tests with structured output.
Parameters:
Parameter | Type | Required | Description |
---|---|---|---|
target | string | Yes | File or directory to test |
format | string | No | Output format: "summary" or "detailed" (auto-detects based on results) |
showLogs | boolean | No | Include console output with [stdout] or [stderr] prefixes |
project | string | No | Vitest project name for monorepos |
analyze_coverage
Analyze test coverage with gap insights.
Parameter | Type | Required | Description |
---|---|---|---|
target | string | Yes | File or directory to analyze coverage for |
format | string | No | Output format: "summary" (overview only) or "detailed" (includes line-by-line coverage) |
exclude | string[] | No | Patterns to exclude from coverage (e.g., ["**/.stories."]) |
Note: Coverage thresholds should be configured in your
vitest.config.ts
file, not via MCP parameters.
Automatically excludes test utilities, mocks, stories, and e2e files.
🔄 Multi-Repository Support
🪝 Claude Code Hook
Automatically redirect Vitest commands to MCP tools:
Then add to your project's .claude/settings.local.json
:
The hook can be bypassed with the BYPASS_VITEST_HOOK
environment variable:
Or export for entire session:
🤖 LLM instructions
Encourage claude or your ide to use the tools correctly: CLAUDE.example.md
⚙️ Configuration
Vitest Configuration Priority
The MCP server automatically detects and uses Vitest configuration files in the following priority order:
vitest.mcp.config.ts
- MCP-specific configuration (highest priority) 🔝vitest.config.ts
vitest.config.js
vitest.config.mjs
vite.config.ts
(if it contains test configuration)vite.config.js
(if it contains test configuration)vite.config.mjs
(if it contains test configuration)
This allows you to have a dedicated MCP-specific configuration that won't interfere with your regular development workflow:
Coverage Thresholds
To enable coverage threshold reporting in the analyze_coverage
tool, just configure in your Vitest configuration file:
💡 Note: Coverage analysis is always available regardless of threshold settings. Threshold reporting just helps keep your LLM on target.
Vitest-MCP Configuration File
Optional .vitest-mcp.json
in home or project directory:
Priority Order
Configuration is merged in the following order (highest priority first):
- Command-line flags
- Environment variables
- Configuration file
- Built-in defaults
🧑🏻💻 Development Mode & Debugging
Enable Debug Mode
Set the debug environment variable for detailed logging:
Or in your MCP config file:
Development Mode
Enable to test the server on its own codebase:
🔧 Troubleshooting
"Vitest not found" - Install: npm install --save-dev vitest@latest
"Coverage provider not found" - Install: npm install --save-dev @vitest/coverage-v8@latest
📊
Hook issues - Bypass with: VITEST_HOOK_BYPASS=1 npm test
Found a bug? Submit a bug report, please, and thank you.
📜 License
MIT — See LICENSE.
AI-optimized Vitest interface that provides structured test output, visual debugging context, and intelligent coverage analysis for more effective AI assistance with testing.
- Table of Contents
- 😢 The Problem with LLMs and Testing 😢
- ✨ Key Features ✨
- 🚀 Quick Start 🚀
- 🛠️ Client-Specific Setup
- Configuration Methods
- Configuration Scopes
- Setup Steps
- Usage
- Configuration Location
- Example Configuration
- Setup Steps
- Configuration Methods
- Example Configuration
- Setup Steps
- Configuration Location
- Example Configuration
- Setup Steps
- Configuration Location
- Example Configuration
- Setup Steps
- Configuration via Cline UI
- Example Configuration
- Setup Steps
- 3. Use It 🎮
- 📋 Requirements
- 🧰 Tools
- 🔄 Multi-Repository Support
- 🪝 Claude Code Hook
- 🤖 LLM instructions
- ⚙️ Configuration
- 🧑🏻💻 Development Mode & Debugging
- 🔧 Troubleshooting
- 📜 License
Related MCP Servers
- -securityAlicense-qualityA server that helps AI models better understand Vite/Nuxt applications, providing enhanced context awareness for development support.Last updated -760MIT License
- AsecurityFlicenseAqualityIntegrates Cursor AI with Vite Dev server, allowing AI agents to modify code and observe live updates through the Hot Module Replacement system in real-time.Last updated -114620
- AsecurityAlicenseAqualityProvides tools for frontend testing including code analysis, test generation, test execution, and React component testing for Jest and Cypress frameworks.Last updated -420MIT License
- -securityAlicense-qualityAI-powered agent that integrates with coding assistants via MCP to automate web testing workflows, allowing developers to record tests, execute regression testing, and discover test flows using natural language prompts.Last updated -57Apache 2.0