Skip to main content
Glama

Vitest MCP Server

by djankies

Vitest MCP Server

AI-optimized Vitest interface with structured output, visual debugging, and intelligent coverage analysis.

Problem & Solution

The Problem

When AI assistants help with testing, they typically run raw Vitest commands that produce:

  • Verbose terminal output that's hard for AI to parse
  • Missing failure context - no code snippets or visual indicators
  • Accidental full test runs when no target is specified
  • Basic coverage metrics without actionable insights

The Solution

This MCP server provides AI-optimized testing tools that deliver:

  • Structured JSON output designed for AI consumption
  • Visual debugging context with code snippets and failure markers
  • Intelligent targeting prevents accidental full test suite runs
  • Coverage gap analysis with line-by-line insights and recommendations

Features

  • 🎯 Smart Test Execution - Run specific files/folders with structured output
  • 📊 Coverage Analysis - Line-by-line gap analysis with actionable insights
  • 📁 Test Discovery - Find and organize test files across your project
  • 🔗 Claude Code Hooks - Automatic interception of Vitest commands
  • 🛡️ Safety Guards - Prevents accidental full project test runs

Quick Start

1. Add to Claude Desktop

Add this to your Claude Desktop configuration:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json
{ "mcpServers": { "vitest": { "command": "npx", "args": ["-y", "@djankies/vitest-mcp"] } } }

2. Restart Claude Desktop

3. Start Using

Ask Claude to:

  • "Run tests in the components folder"
  • "Check coverage for the auth module"
  • "List all test files"

Requirements

Minimum Versions

  • Node.js: 18+
  • Vitest: 0.34.0+ (3.0.0+ recommended)
  • Coverage Provider: @vitest/coverage-v8 (for coverage analysis)
npm install --save-dev vitest@latest @vitest/coverage-v8@latest

Project Setup

Ensure your vitest.config.ts includes:

export default defineConfig({ test: { coverage: { provider: 'v8', reporter: ['text', 'json', 'html'] } } })

Tools

list_tests

List test files in your project.

list_tests({ directory: "./src" })

run_tests

Execute tests with AI-optimized output.

run_tests({ target: "./src/components", format: "detailed" // or "summary" })

analyze_coverage

Analyze test coverage with gap insights.

analyze_coverage({ target: "./src/api", threshold: 80, format: "detailed" })

Automatically intercept Vitest commands and suggest MCP tools.

Copy hook script

curl -o .claude/vitest-hook.sh https://raw.githubusercontent.com/djankies/vitest-mcp/main/hooks/vitest-hook.sh chmod +x .claude/vitest-hook.sh

Update .claude/settings.local.json

{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": ".claude/vitest-hook.sh" } ] } ] } }

Configuration Options

MCP Server Options

{ "mcpServers": { "vitest": { "command": "npx", "args": [ "-y", "@djankies/vitest-mcp", "--format", "detailed", "--timeout", "60000" ] } } }

Available CLI Options

  • --format <summary|detailed> - Default output format
  • --timeout <ms> - Test timeout (default: 30000)
  • --verbose - Debug information

Troubleshooting

Version Issues

# Check compatibility npx -y @djankies/vitest-mcp --version-check

Common Issues

"Vitest not found"

npm install --save-dev vitest@latest

"Coverage provider not found"

npm install --save-dev @vitest/coverage-v8@latest

Hook not working

# Test hook directly ./.claude/vitest-hook.sh vitest run src/ # Bypass hook npx vitest run src/ --bypass-hook

License

MIT

Related MCP Servers

  • -
    security
    A
    license
    -
    quality
    A server that helps AI models better understand Vite/Nuxt applications, providing enhanced context awareness for development support.
    Last updated -
    728
    TypeScript
    MIT License
  • A
    security
    F
    license
    A
    quality
    Integrates 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 -
    11
    749
    15
    TypeScript
  • A
    security
    A
    license
    A
    quality
    Provides tools for frontend testing including code analysis, test generation, test execution, and React component testing for Jest and Cypress frameworks.
    Last updated -
    4
    16
    TypeScript
    MIT License
  • A
    security
    A
    license
    A
    quality
    A server that integrates Locust load testing capabilities with AI-powered development environments, allowing users to run performance tests through natural language commands.
    Last updated -
    1
    5
    Python
    MIT License

View all related MCP servers

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/djankies/vitest-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server