Shentia/MCP-Generate-Unit-Testing-Server
If you are the rightful owner of MCP-Generate-Unit-Testing-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
An intelligent MCP server that generates unit tests for Angular, React, and Next.js projects.
MCP Generate Unit Testing Server
An intelligent Model Context Protocol (MCP) server that automatically generates comprehensive unit tests for Angular, React, and Next.js projects using Jest, Karma/Jasmine, or other testing frameworks.
Features
- 🔍 Automatic Project Detection - Detects Angular, React, or Next.js projects and their versions
- 📦 Framework Management - Checks for testing frameworks and offers automated installation
- 📚 Live Documentation Fetching - Retrieves latest Jest and Jasmine documentation before generating tests
- 🤖 LLM-Powered Generation - Uses Claude Sonnet 4.5+ for intelligent test generation
- 🎯 High Coverage Target - Generates tests targeting >85% code coverage
- ✅ All Public Methods - Creates tests for all exported functions and public class methods
- 🔄 Side-by-Side Validation - Displays source and test code for easy review
- 🛠️ Multiple Frameworks - Supports Jest, Karma/Jasmine, and Vitest
Installation
npm install
npm run build
Usage
As MCP Server
Add to your MCP client configuration (e.g., Claude Desktop, VS Code with MCP):
{
"mcpServers": {
"generate-unit-testing": {
"command": "node",
"args": ["/path/to/GenerateUnitTesting/build/index.js"]
}
}
}
Available Tools
1. detect_project
Detects the project type and testing framework.
{
"filePath": "/path/to/your/project/src/component.ts"
}
2. install_test_framework
Installs missing testing framework with user permission.
{
"projectPath": "/path/to/your/project",
"framework": "jest",
"autoInstall": false
}
3. generate_unit_test
Generates comprehensive unit tests for a source file.
{
"filePath": "/path/to/your/project/src/component.ts",
"framework": "jest",
"coverageTarget": 85,
"generateForAllPublicMethods": true,
"includeEdgeCases": true
}
4. validate_test
Runs generated tests and calculates coverage.
{
"testFilePath": "/path/to/your/project/src/component.test.ts",
"framework": "jest"
}
5. display_side_by_side
Creates side-by-side comparison of source and test code.
{
"sourceFilePath": "/path/to/your/project/src/component.ts",
"testFilePath": "/path/to/your/project/src/component.test.ts"
}
Available Resources
docs://jest/latest- Latest Jest documentationdocs://jasmine/latest- Latest Jasmine documentation
Available Prompts
generate-unit-test- Comprehensive unit test generation promptgenerate-edge-cases- Edge case test generation promptgenerate-mocks- Mock generation prompt
Architecture
src/
├── index.ts # Main MCP server entry point
├── types.ts # TypeScript type definitions
├── tools/
│ ├── detectProject.ts # Project and framework detection
│ └── testGenerator.ts # Test generation logic
├── resources/
│ └── documentationFetcher.ts # Live doc fetching from Jest/Jasmine
├── templates/
│ └── testTemplates.ts # Framework-specific test templates
├── prompts/
│ └── testPrompts.ts # LLM prompts for test generation
└── utils/
├── fileUtils.ts # File system utilities
└── codeAnalyzer.ts # AST-based code analysis
Workflow
- Project Detection - Analyzes
package.jsonto identify project type and existing test setup - Framework Check - Verifies testing framework installation, prompts for installation if missing
- Documentation Fetch - Retrieves latest framework documentation from official sources
- Code Analysis - Parses source code using Babel to extract functions, classes, and methods
- Test Generation - Uses LLM with context (code + docs + templates) to generate comprehensive tests
- Validation - Runs tests and calculates coverage
- Display - Shows side-by-side comparison for developer review
Supported Frameworks
Jest
- React and Next.js projects
- TypeScript/JavaScript
- Modern async/await patterns
- Mock functions and spies
Karma/Jasmine
- Angular projects
- Component testing with TestBed
- Service and pipe testing
- Traditional describe/it syntax
Coverage Goals
The server targets >85% code coverage by generating:
- Tests for all public functions
- Tests for all public class methods
- Edge case scenarios
- Error handling tests
- Async operation tests
- Mock implementations for dependencies
Example Output
For a React component:
// Original: Button.tsx
export const Button = ({ onClick, label }) => {
return <button onClick={onClick}>{label}</button>;
};
Generated test:
// Generated: Button.test.tsx
import { render, fireEvent } from '@testing-library/react';
import { Button } from './Button';
describe('Button', () => {
it('should render with label', () => {
const { getByText } = render(<Button label="Click me" onClick={() => {}} />);
expect(getByText('Click me')).toBeInTheDocument();
});
it('should call onClick when clicked', () => {
const handleClick = jest.fn();
const { getByText } = render(<Button label="Click me" onClick={handleClick} />);
fireEvent.click(getByText('Click me'));
expect(handleClick).toHaveBeenCalledTimes(1);
});
// ... more tests for edge cases;
Requirements
- Node.js 18+
- TypeScript 5+
- MCP client (Claude Desktop, VS Code with MCP extension, etc.)
Development
# Install dependencies
npm install
# Build
npm run build
# Watch mode
npm run watch
# Start server
npm start
Configuration
The server automatically detects:
- Package manager (npm, yarn, pnpm)
- Project type (Angular, React, Next.js)
- Existing test framework
- TypeScript/JavaScript
No manual configuration required!
License
MIT
Contributing
Contributions welcome! Please ensure:
- Code follows existing patterns
- Tests are included for new features
- Documentation is updated
Support
- For issues or questions, please open an issue on the repository.
- Author: Ahmadreza Shamimi (https://github.com/shentia)