run_tests
Execute targeted Vitest tests and return AI-friendly structured JSON results, with optional console logs and safeguards to prevent accidental full project runs.
Instructions
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.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Output 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 or failures → detailed | summary |
| target | Yes | File 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 to prevent accidental full project test runs. | |
| project | No | Name 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. Example: "client", "api", "shared". | |
| showLogs | No | Capture 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 distinguish message types. |