vitest-mcp

v0.6.0
@djankies/vitest-mcp Checked 5 days ago Published 1 month ago

A Model Context Protocol server for Vitest test execution and management

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

set_project_root

Set the project root directory for all subsequent operations. This must be called before using other tools to specify which repository to work with.

ParameterTypeDescription
path *stringAbsolute path to the project root directory (must start with / on Unix or drive letter on Windows)

list_tests

Discover and catalog test files across the project with support for common test file patterns (.test.*, .spec.*). Recursively searches directories and provides structured file information including paths and relative locations. Useful for understanding test organization and coverage scope. Requires set_project_root to be called first. USE WHEN: User wants to explore test structure, find test files, understand test organization, or asks "what tests exist", "show me test files", or mentions exploring/finding tests. Also use when "vitest-mcp:" prefix is included and context involves test discove…

ParameterTypeDescription
pathstringOptional directory path to search for test files. Can be relative (e.g., "./src/components") or absolute. If not provided, searches the entire project root. Useful for limiting search scope to specifi…

run_tests

Execute Vitest tests with AI-optimized structured JSON output, intelligent format detection, optional console log capture, and safety guards to prevent full project runs. Supports monorepos via Vitest projects. Requires set_project_root to be called first. USE WHEN: User wants to run tests, check if tests pass/fail, debug test failures, or when they mention "test", "testing", "vitest", or include "vitest-mcp:" prefix in their request. Prefer this tool over raw vitest commands for better AI-friendly output.

ParameterTypeDescription
target *stringFile path or directory to test. Can be a specific test file (e.g., "./src/components/Button.test.ts") or directory (e.g., "./src/components"). Relative paths are resolved from project root. Required t…
formatstringOutput format: "summary" (simple summary data only), "detailed" (structured information about each failing test and summary of passing tests). Smart defaults: single file → summary, multiple files o…
projectstringName of the specific Vitest project to run tests for, as defined in the `projects` array of vitest.config (or vitest.workspace on Vitest 3). Essential for monorepos with multiple packages/apps. Exampl…
showLogsbooleanCapture and include console output (console.log, console.error, etc.) from test execution in the results. Useful for debugging test failures. Output is formatted with [stdout] or [stderr] prefixes to…

analyze_coverage

Perform comprehensive test coverage analysis with line-by-line gap identification, actionable insights, and detailed metrics for lines, functions, branches, and statements. Runs the tests that import the target (wherever they live, e.g. ./test or __tests__) and reports coverage for the target only, including files no test touches. Automatically excludes common non-production files (stories, mocks, e2e tests). Detects and prevents analysis on test files themselves. Requires set_project_root to be called first. Coverage thresholds are read from the Vitest config. USE WHEN: User wants to check t…

ParameterTypeDescription
target *stringSource file path or directory to analyze coverage for. Should target the actual source code files, NOT test files. Can be a specific source file (e.g., "./src/utils/helper.ts") or directory (e.g., "./…
excludearrayGlob patterns to exclude from coverage analysis. Examples: ["**/*.stories.*", "**/e2e/**"]. Useful for excluding stories, mocks, or other non-production code from coverage calculations.
formatstringOutput format: "summary" (basic metrics), "detailed" (comprehensive analysis with file details)
projectstringOptional name of a Vitest project (from the `projects` array in vitest.config) whose tests should be used to measure coverage, e.g. "unit". Defaults to all projects.