Unit Test MCP
Intelligent test generation and execution for GitHub Copilot
A VS Code extension that enables GitHub Copilot to generate, run, and improve Jest, Vitest, Pytest, and .NET tests using the Model Context Protocol (MCP).
✨ Features
- 🚀 Zero Setup: Install and use immediately — MCP server registers automatically via the VS Code API
- 🧪 Multi-Framework Support: Jest/Vitest (JS/TS), Pytest (Python), and .NET (C#)
- 🤖 AI-Powered: Works seamlessly with GitHub Copilot Chat
- 📊 Coverage Reports: Get instant test coverage feedback with
inspect_coverage
- 📁 Batch Test Generation: Generate tests for entire folders at once with prioritization
- 🎯
@UnitTestEngineer Agent: Built-in custom agent for test generation, coverage improvement, and batch workflows
- 📝 Copilot Instructions: Auto-creates and syncs workspace instruction files that teach Copilot the test workflow
- 📖 Getting Started Walkthrough: Built-in tutorial accessible via
Unit Test MCP: Open Tutorial
📦 Installation
Install from the VS Code Marketplace or search for "Unit Test MCP" in the Extensions view (Ctrl+Shift+X).
🚀 Quick Start
1. Install the Extension
Install from the Marketplace link above. The extension auto-configures on first activation.
2. Start Using with Copilot
Open GitHub Copilot Chat and try:
Generate unit tests for this file
Generate tests for all files in src/
Run tests with coverage
What files have low coverage?
Or use the built-in @UnitTestEngineer agent for a guided workflow.
The extension will automatically activate and handle the requests.
📋 Requirements
| Requirement |
Version |
Notes |
| VS Code |
1.101.0+ |
Required (MCP server API) |
| GitHub Copilot |
Latest |
Must be active |
| Node.js |
N/A |
Bundled with VS Code |
| Python |
Any |
Only needed if running Pytest tests |
| .NET SDK |
6.0+ |
Only needed if running .NET tests |
🎯 What You Can Do
With Jest or Vitest (JavaScript/TypeScript)
- ✅ Generate JS/TS unit tests (including React component tests)
- ✅ Run tests with coverage
- ✅ Watch mode support
- ✅ Targeted test execution
- ✅ Update snapshots (Jest, via
--updateSnapshot, when applicable)
With Pytest (Python)
- ✅ Generate Python unit tests
- ✅ Run tests with coverage
- ✅ Parametrized test support
- ✅ Fixture-based testing
With .NET (C#)
- ✅ Generate xUnit/NUnit tests
- ✅ Run tests via
dotnet test
- ✅ Coverage reporting
- ✅ Solution-aware test generation
Coverage Reports
Ask Copilot "Run tests with coverage" or "What files have low coverage?" to get an interactive coverage report showing per-file line, branch, function, and statement coverage.

⚙️ Configuration
The extension works out-of-the-box, but you can customize it using the Unit Test MCP side panel.

- Open the Unit Test MCP view in the VS Code sidebar (look for the clipboard/gear icon in the Activity Bar).
- Use the UI to:
- Browse and select custom instruction files for Jest, Vitest, Pytest, or .NET.
- View currently loaded instructions.
- Set target code coverage percentage.
- Configure custom test commands.
Changes take effect immediately - no restart required!
📝 Custom Instructions
Customize test generation with your own instructions! See CUSTOM_INSTRUCTIONS.md for details.
📁 Generated Files & Git
The extension creates files in your workspace that Copilot reads at runtime:
.github/instructions/unittestMcp.instructions.md # Auto-synced on each activation
.github/prompts/UnitTestMcp.UnitTestEngineer.agent.md # Created once, never overwritten
These files work whether committed or gitignored — Copilot reads them from the filesystem. To keep your git history clean, add this to your .gitignore:
# Unit Test MCP (auto-managed by extension)
**/.github/instructions/unittestMcp.instructions.md
**/.github/prompts/UnitTestMcp.UnitTestEngineer.agent.md
Each developer's copy is managed independently by the extension — no commits needed.
💡 How It Works
┌─────────────────────────┐
│ GitHub Copilot Chat │
└───────────┬─────────────┘
│ MCP Protocol
┌───────────▼─────────────┐
│ TypeScript MCP Server │
│ (Bundled in Extension) │
└───────────┬─────────────┘
│
┌───────────▼─────────────┐
│ Jest / Vitest / Pytest │
│ / Dotnet │
└─────────────────────────┘
- You ask Copilot to generate/run tests
- Copilot calls the MCP server via standard protocol
- Server executes Jest/Vitest/Pytest/.NET and returns results
- Copilot shows you formatted output
🐛 Troubleshooting
Extension Not Working?
Check Status:
- Open the Unit Test MCP sidebar view.
- Verify that the server is connected and configuration is valid.
Still not working?
- Reload VS Code:
Ctrl+Shift+P → "Reload Window"
- Check Output panel: View → Output → Select "Log (Extension Host)" and search for "Unit Test MCP"
- Ensure GitHub Copilot extension is installed and active
- Run
MCP: List Servers from the Command Palette — "Unit Test MCP" should appear
- If not listed, reload VS Code:
Ctrl+Shift+P → "Reload Window"
- Try asking: "What MCP tools are available?"
Tests Not Running?
For Jest:
- Ensure
package.json exists in your project root
- Verify Jest is installed:
npm list jest
For Vitest:
- Ensure
package.json exists in your project root
- Verify Vitest is installed:
npm list vitest
For Pytest:
- Ensure Python is installed:
python --version
- Verify Pytest is installed:
pip list | grep pytest
For .NET:
- Ensure .NET SDK is installed:
dotnet --version
- Ensure your project is a valid .NET project
Structured Error Codes
When a tool call fails, the response carries isError: true with a human-readable message in content[0].text and a machine-readable envelope in structuredContent.error of the form:
{
"error": {
"code": "INVALID_ROOT_DIR",
"message": "root_dir is required and must be a non-empty string",
"details": { /* optional, code-specific */ }
}
}
Agents should branch on code rather than parsing message. Common recovery cases include:
| Code |
What to do |
INVALID_INPUT |
Correct the argument named in details.issues[].path. |
INVALID_ROOT_DIR |
Pass an absolute project directory containing files such as package.json, *.csproj, or pytest.ini. |
INVALID_SCOPE |
Add test_pattern when using scope='file', or use scope='auto' / 'repo'. |
NO_FRAMEWORK_DETECTED |
Pass an explicit framework such as jest, vitest, pytest, dotnet, or custom. |
TIMEOUT |
Retry with a larger timeout_ms, or investigate hanging tests. |
SPAWN_FAILED |
Verify node, python, or dotnet is installed and available on PATH. |
INTERNAL |
File an issue with the message and reproduction steps. |
The complete enum is exported as MCP_TOOL_ERROR_CODES from src/mcp/errors.ts for clients that need exhaustive handling.
Back-compat: consumers that only read content[0].text continue to work — structuredContent.error is additive.
📚 Examples
Example 1: Generate React Tests
You: Generate unit tests for src/components/Button.tsx
Copilot: [Uses generate_test tool]
Creates: src/components/__tests__/Button.test.tsx
Example 2: Run Tests with Coverage
You: Run tests with coverage for the Button component
Copilot: [Uses run_tests tool]
Shows: Test results + coverage report
Example 3: Batch Test Generation
You: Generate tests for all files in src/services/
Copilot: [Uses generate_tests_batch tool]
Scans folder, prioritizes by missing tests/low coverage
Creates tests for each file sequentially
Example 4: Inspect Coverage
You: What files have low test coverage?
Copilot: [Uses inspect_coverage tool]
Shows: Worst-covered files and branches from existing coverage artifacts
🖥️ Using with Copilot CLI
The VS Code extension automatically registers the MCP server for VS Code's built-in Copilot Chat. In newer VS Code builds, copilot chat terminal sessions may also see extension-provided MCP tools. For non-VS Code clients, background agents, or any CLI session where the tools are not listed, use the standalone server.
To add the standalone server:
- Open a Copilot CLI session (type
copilot in VS Code's integrated terminal)
- Run
/mcp add and fill in the form:
- Server Name:
unittest-mcp
- Server Type:
STDIO (or Local)
- Command:
npx -y unittest-mcp
- Environment Variables:
{} (leave empty)
- Tools:
*
- Press
Ctrl+S to save — the tools are available immediately
Alternatively, edit ~/.copilot/mcp-config.json directly:
{
"mcpServers": {
"unittest-mcp": {
"type": "local",
"command": "npx",
"args": ["-y", "unittest-mcp"],
"env": {},
"tools": ["*"]
}
}
}
Or add it to your workspace .vscode/mcp.json for VS Code-level access:
{
"servers": {
"unittest-mcp": {
"command": "npx",
"args": ["-y", "unittest-mcp"]
}
}
}
📄 License
MIT License - see LICENSE file for details
📮 Support
- Issues/Feedback: Use the "Unit Test MCP: Give Feedback" button in the Unit Test MCP sidebar panel
- Repository: GitHub (Internal Microsoft access only)
🏗️ For Developers
See DEVELOPMENT.md for local development setup, building from source, testing, and publishing.