An intelligent code optimization MCP server that analyzes and improves codebases across multiple dimensions
Optimist is a Model Context Protocol (MCP) server designed to work alongside other development tools to provide comprehensive codebase optimization. It analyzes code for performance bottlenecks, memory issues, code smells, and maintainability concerns, offering actionable suggestions for improvement.
- 🚀 Performance Analysis - Identify bottlenecks and hot paths
- 💾 Memory Optimization - Detect leaks and inefficient allocations
- 📊 Code Quality Metrics - Complexity analysis and maintainability scoring
- 🔍 Dead Code Detection - Find and eliminate unused code
- 📦 Dependency Management - Optimize and analyze dependency graphs
- 🎯 Smart Refactoring - AI-powered refactoring suggestions
- 🔗 MCP Integration - Seamless integration with other MCP tools
- ✅ Test-Driven - Built using TDD methodology
Optimist exposes a set of tools via the Model Context Protocol that can be invoked by MCP clients (like Claude Desktop, IDEs, or CI/CD pipelines).
| Tool | Purpose |
|---|---|
analyze_performance |
Profile code execution and identify performance bottlenecks |
optimize_memory |
Detect memory leaks and suggest memory-efficient patterns |
analyze_complexity |
Evaluate cyclomatic and cognitive complexity |
analyze_dependencies |
Map dependency graphs and find optimization opportunities |
detect_code_smells |
Identify anti-patterns and code quality issues |
find_dead_code |
Locate unused code, variables, and dependencies |
optimize_hot_paths |
Analyze and optimize frequently executed code paths |
suggest_refactoring |
Provide AI-powered refactoring recommendations |
# Clone the repository
git clone https://github.com/yourusername/mcp-optimist.git
cd mcp-optimist
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm testAdd to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"optimist": {
"command": "node",
"args": ["/path/to/mcp-optimist/dist/index.js"],
"env": {}
}
}
}import { OptimistServer } from 'mcp-optimist';
const server = new OptimistServer({
port: 3000,
analysisDepth: 'deep',
enabledTools: ['all']
});
await server.start();// Request via MCP
{
"tool": "analyze_performance",
"arguments": {
"path": "./src",
"includeTests": false,
"threshold": "medium"
}
}{
"tool": "optimize_memory",
"arguments": {
"path": "./src/services",
"detectLeaks": true,
"suggestFixes": true
}
}{
"tool": "analyze_complexity",
"arguments": {
"path": "./src",
"maxComplexity": 10,
"reportFormat": "summary"
}
}Create an optimist.config.json in your project root:
{
"analysis": {
"depth": "deep",
"ignorePatterns": ["**/node_modules/**", "**/dist/**"],
"fileExtensions": [".js", ".ts", ".jsx", ".tsx"]
},
"performance": {
"threshold": "medium",
"profileHotPaths": true
},
"memory": {
"detectLeaks": true,
"trackAllocations": true
},
"complexity": {
"maxCyclomatic": 10,
"maxCognitive": 15
},
"dependencies": {
"checkCircular": true,
"suggestUpdates": false
}
}mcp-optimist/
├── src/
│ ├── index.ts # Main entry point
│ ├── server.ts # MCP server implementation
│ ├── tools/ # Tool implementations
│ │ ├── performance.ts # Performance analysis
│ │ ├── memory.ts # Memory optimization
│ │ ├── complexity.ts # Complexity analysis
│ │ ├── dependencies.ts # Dependency management
│ │ ├── code-smells.ts # Code smell detection
│ │ ├── dead-code.ts # Dead code finder
│ │ ├── hot-paths.ts # Hot path optimization
│ │ └── refactoring.ts # Refactoring suggestions
│ ├── analyzers/ # Core analysis engines
│ ├── utils/ # Utility functions
│ └── types/ # TypeScript definitions
├── tests/ # Test suites
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── fixtures/ # Test fixtures
├── docs/ # Documentation
├── package.json
├── tsconfig.json
└── optimist.config.json # Default configuration
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test suite
npm test -- --grep "performance"
# Watch mode
npm run test:watch# Development build
npm run build
# Production build
npm run build:prod
# Watch mode
npm run build:watchThis project is built using Test-Driven Development:
- RED - Write failing tests first
- GREEN - Implement minimal code to pass tests
- REFACTOR - Improve code quality while maintaining tests
All features are developed following this cycle, ensuring high code quality and test coverage.
Optimist is designed to work alongside:
- Code Analysis Tools - Linters, formatters, type checkers
- Testing Frameworks - Jest, Vitest, Mocha
- Build Tools - Webpack, Vite, Rollup
- Documentation Generators - TypeDoc, JSDoc
- CI/CD Systems - GitHub Actions, GitLab CI, Jenkins
{
path: string; // Directory or file path
includeTests?: boolean; // Include test files (default: false)
threshold?: 'low' | 'medium' | 'high'; // Alert threshold
profileHotPaths?: boolean; // Analyze hot execution paths
}{
path: string; // Directory or file path
detectLeaks?: boolean; // Check for memory leaks
suggestFixes?: boolean; // Provide fix suggestions
trackAllocations?: boolean; // Track allocation patterns
}{
path: string; // Directory or file path
maxComplexity?: number; // Maximum allowed complexity
reportFormat?: 'summary' | 'detailed' | 'json';
}All tools return responses in this structure:
{
status: 'success' | 'error';
tool: string;
data: {
summary: string;
findings: Array<Finding>;
suggestions: Array<Suggestion>;
metrics: Record<string, any>;
};
metadata: {
timestamp: string;
duration: number;
filesAnalyzed: number;
};
}We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Write tests first (TDD approach)
- Implement your feature
- Ensure all tests pass (
npm test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TDD methodology
- Maintain >90% test coverage
- Use TypeScript strict mode
- Follow existing code style
- Update documentation
Optimist works seamlessly alongside other MCP servers:
- mcp-consult - AI consultation and reasoning for complex optimization decisions
- mcp-tdd - Test-driven development workflows during refactoring
- Code Analysis Tools - Linters, formatters, type checkers
- Testing Frameworks - Jest, Vitest, Mocha
- Build Tools - Webpack, Vite, Rollup
- CI/CD Systems - GitHub Actions, GitLab CI, Jenkins
- Project setup
- Core MCP server implementation
- Basic tool scaffolding
- Test infrastructure
- Performance analyzer ✅ COMPLETE
- Memory optimizer ✅ COMPLETE
- Complexity analyzer ✅ COMPLETE
- Code smell detector ✅ COMPLETE
Phase 2: 100% COMPLETE - All core optimization tools delivered!
- Dependency graph analysis
- Dead code elimination
- Hot path optimization
- AI-powered refactoring
- CI/CD integration
- IDE plugins
- Performance optimizations
- Documentation completion
Optimist is designed to be lightweight and fast:
- Async analysis for non-blocking operations
- Incremental analysis support
- Caching for repeated operations
- Parallel processing where applicable
- No code execution during analysis
- Read-only file access by default
- Sandboxed analysis environment
- Secure MCP protocol implementation
MIT License - see LICENSE file for details
- Built on the Model Context Protocol
- Inspired by tools like ESLint, SonarQube, and CodeClimate
- Developed with TDD using the mcp-tdd framework
- 📚 Documentation
- 🐛 Issue Tracker
- 💬 Discussions
- 📧 Email: support@optimist-mcp.dev
Built with ❤️ using Test-Driven Development and the Model Context Protocol