Code Guider MCP Server
# Code Guider MCP Server
An AI-powered local Model Context Protocol (MCP) server that provides intelligent code guidance, workflow automation, and quality assurance for your development projects. Features **hybrid storage** with Drizzle ORM for fast CRUD operations and vector storage for semantic search, AI-driven insights, and Anubis-inspired role-based workflow execution. **Optimized for Bun runtime** with native SQLite for maximum performance.
## Features
- π§ **AI-Powered Analysis**: Intelligent code analysis with semantic understanding
- π **Hybrid Storage**: Drizzle ORM for fast CRUD operations + vector storage for semantic search
- π **Multi-Project Support**: Global and project-specific databases with automatic project detection
- π **Global + Local Mode**: Global templates/workflows + project-specific customization
- π **Workflow Automation**: Define and execute AI-enhanced code generation workflows
- π **Template System**: Reusable code templates with AI-powered suggestions
- β
**Quality Rules**: Automated code quality checking with pattern recognition
- π― **Context-Aware**: Provides guidance based on file type and project context
- π§ **MCP Integration**: Works with any MCP-compatible client
- π **TypeScript**: Full TypeScript support with type safety
- π **Similar Code Detection**: Find similar code patterns across your codebase
- π **Complexity Analysis**: AI-powered code complexity scoring
- π₯ **Role-Based Execution**: Anubis-inspired role system with Product Manager, Architect, Senior Developer, and Code Review roles
- π **Execution Tracking**: Comprehensive workflow execution tracking with state management
- π― **Context Preservation**: Seamless role transitions with full context preservation
- π€ **Multi-Agent Support**: Optimized templates for Cursor, Copilot, RooCode, and KiloCode
- βΈοΈ **Pause/Resume**: Pause and resume workflow executions at any time
- π **Execution Metrics**: Detailed metrics and performance tracking
- β‘ **Performance**: 3-10x faster operations with Drizzle ORM + Bun SQLite optimization
- π **LibSQL Powered**: Built with LibSQL for cross-platform compatibility and optimal performance
- π¦ **Zero Native Dependencies**: Pure JavaScript/TypeScript with no native compilation required
- π€ **AI Migration**: Natural language migration commands that intelligently transform and migrate data
- π **Smart Transformation**: AI-powered data transformation with validation and rollback capabilities
- π‘οΈ **Safe Migration**: Built-in backup, dry-run, and validation features for safe data migration
## Quick Start
### Installation
#### Option 1: npm (Recommended - Easiest)
```bash
# Install globally
npm install -g code-guider-mcp
# Start the server (migration runs automatically)
code-guider-mcp
```
#### Option 2: Local Development
```bash
# Clone the repository
git clone <your-repo-url>
cd code-guider
# Install dependencies
npm install
# Build the project
npm run build
# Run database migration (first time only)
npm run migrate
# Start the MCP server
npm start
```
### Running the MCP Server
#### With npm (Global Installation)
```bash
# Start with defaults
code-guider-mcp
# Start on specific port
code-guider-mcp --port 8080
# Run migration only
code-guider-mcp --migrate
# Open database studio
code-guider-mcp --studio
# Show help
code-guider-mcp --help
```
#### With Local Development
```bash
# Start the MCP server
npm start
```
### Multi-Project Support
Code Guider supports both **global** and **project-specific** modes:
#### Project Modes
1. **Global Mode** (`--global`): Uses global database for all projects
2. **Project Mode** (default): Uses project-specific database
3. **Auto-detect**: Automatically detects project type and initializes
#### Project Management Commands
```bash
# Initialize a project (auto-detects type)
code-guider-mcp --init
# Initialize specific project
code-guider-mcp --init /path/to/project
# List all projects
code-guider-mcp --list-projects
# Use global storage
code-guider-mcp --global
# Use specific project
code-guider-mcp /path/to/project
```
#### Project Structure
```
~/.code-guider/ # Global storage
βββ global.db # Global database
βββ config.json # Global configuration
βββ projects/
βββ projects.json # Project registry
/path/to/project/ # Project-specific storage
βββ .guidance/
βββ guidance.db # Project database
```
### Using with MCP Clients
#### With npm (Global Installation)
```json
{
"mcpServers": {
"code-guidance": {
"command": "code-guider-mcp"
}
}
}
```
#### With Local Development
```json
{
"mcpServers": {
"code-guidance": {
"command": "node",
"args": ["dist/index.js"],
"cwd": "/path/to/code-guider"
}
}
}
```
## Architecture
### Core Components
1. **MCP Server** (`src/mcp-server.ts`): Main server implementation with tool handlers
2. **Hybrid Storage** (`src/hybrid-storage.ts`): Combines Drizzle ORM for fast CRUD + VectorStorage for AI features
3. **Drizzle Storage** (`src/db/drizzle-storage.ts`): Optimized database operations with SQLite
4. **Vector Storage** (`src/vector-storage.ts`): AI-powered semantic search and embeddings
5. **Guidance Engine** (`src/guidance-engine.ts`): Workflow execution and code analysis
6. **Type Definitions** (`src/types.ts`): TypeScript interfaces for all data structures
### Data Structure
```
.guidance/
βββ guidance.db # SQLite database with hybrid storage
β βββ workflows # Drizzle ORM table (fast CRUD)
β βββ templates # Drizzle ORM table (fast CRUD)
β βββ quality_rules # Drizzle ORM table (fast CRUD)
β βββ project_config # Drizzle ORM table (fast CRUD)
β βββ workflows_vector # Vector embeddings for semantic search
β βββ templates_vector # Vector embeddings for semantic search
β βββ quality_rules_vector # Vector embeddings for semantic search
βββ config/ # Legacy file-based config (auto-migrated)
β βββ project.json
βββ workflows/ # Legacy JSON files (auto-migrated to DB)
βββ templates/ # Legacy YAML files (auto-migrated to DB)
βββ rules/ # Legacy JSON files (auto-migrated to DB)
```
### Hybrid Storage Benefits
- **Drizzle ORM**: 3-10x faster CRUD operations with type-safe queries
- **Vector Storage**: AI-powered semantic search and similarity matching
- **Automatic Migration**: Seamless migration from file-based to hybrid storage
- **Performance**: Optimized database operations with indexing and caching
- **Type Safety**: Full TypeScript support with compiled queries
## Hybrid Storage Implementation
The code-guider now uses a **hybrid storage approach** that combines the best of both worlds:
### Drizzle ORM (Fast CRUD Operations)
- **3-10x faster** CRUD operations compared to file-based storage
- **Type-safe queries** with full TypeScript support
- **Database indexing** for optimized lookups
- **ACID transactions** for data integrity
- **Connection pooling** and query optimization
### Vector Storage (AI Features)
- **Semantic search** using vector embeddings
- **Similarity matching** for finding related code
- **AI-powered suggestions** based on content similarity
- **Pattern recognition** across your codebase
### Migration System
The system automatically migrates from the legacy file-based storage to the new hybrid approach:
```bash
# Run migration (first time only)
npm run migrate
```
This will:
1. Create the SQLite database with proper schema
2. Migrate existing workflows, templates, and rules
3. Generate vector embeddings for semantic search
4. Preserve all existing data and functionality
### Performance Comparison
| Operation | File-based | Hybrid Storage | LibSQL | Improvement |
| ------------------ | ----------------- | --------------- | ----------------- | ----------------- |
| Write (100 items) | 50-100ms | 10-20ms | 3-8ms | **6-15x faster** |
| Read (100 items) | 20-50ms | 5-15ms | 2-5ms | **4-20x faster** |
| Search (100 items) | 30-80ms | 2-10ms | 1-3ms | **10-25x faster** |
| Build Time | 2-5s (tsc) | 1-2s (tsc) | 200-500ms (bun) | **4-10x faster** |
| Memory Usage | High (all data) | Low (streaming) | Minimal (pure JS) | **5-50x less** |
| Concurrent Reads | Poor (file locks) | Excellent (WAL) | Excellent (WAL) | **3-10x better** |
## MCP Functions
The Code Guider MCP Server provides 13 consolidated functions that replace the previous 47 individual functions, offering a cleaner and more organized API:
### 1. **manage_workflows** - Workflow Management
- **Actions**: `list`, `get`, `create`, `execute`
- **Purpose**: Unified workflow management operations
- **Example**: `{ action: 'list', search: 'authentication' }`
### 2. **manage_templates** - Template Management
- **Actions**: `list`, `create`
- **Purpose**: Unified template management operations
- **Example**: `{ action: 'create', template: {...} }`
### 3. **analyze_code** - Code Analysis
- **Types**: `guidance`, `validation`, `ai_analysis`, `similar_code`
- **Purpose**: Unified code analysis operations
- **Example**: `{ analysisType: 'ai_analysis', filePath: '...', projectPath: '...' }`
### 4. **manage_quality_rules** - Quality Rules Management
- **Actions**: `list`, `create`
- **Purpose**: Unified quality rules management
- **Example**: `{ action: 'create', rule: {...} }`
### 5. **semantic_search** - Semantic Search
- **Types**: `workflows`, `templates`, `code`
- **Purpose**: Unified semantic search across different content types
- **Example**: `{ type: 'workflows', query: 'user authentication' }`
### 6. **manage_execution** - Execution Management
- **Actions**: `execute`, `execute_ai`, `execute_roles`, `status`, `pause`, `resume`
- **Purpose**: Unified execution management operations
- **Example**: `{ action: 'execute_roles', workflowId: '...', projectPath: '...' }`
### 7. **manage_roles** - Role Management
- **Actions**: `list`, `guidance`
- **Purpose**: Unified role management operations
- **Example**: `{ action: 'guidance', roleId: 'architect' }`
### 8. **ai_migrate** - AI Migration
- **Types**: `data`, `workflows`, `templates`, `quality_rules`
- **Purpose**: Unified AI-powered migration operations
- **Example**: `{ type: 'data', instruction: 'migrate all workflows to new format' }`
### 9. **manage_projects** - Project Management
- **Actions**: `list`, `init`, `auto_init`, `info`, `sync`
- **Purpose**: Unified project management operations with Anubis-style auto-detection
- **Example**: `{ action: 'auto_init', projectPath: '/path/to/project' }`
### 10. **manage_memories** - Memory Management
- **Actions**: `save`, `search`, `list`, `get`, `stats`
- **Purpose**: Unified memory management operations
- **Example**: `{ action: 'save', content: '...', type: 'best_practice', category: 'technical' }`
### 11. **manage_memory_rules** - Memory Rules Management
- **Actions**: `enhance_request`, `init_project`, `list`, `create`
- **Purpose**: Unified memory rules management
- **Example**: `{ action: 'enhance_request', request: '...', context: {...} }`
### 12. **get_execution_metrics** - Execution Metrics
- **Purpose**: Get detailed metrics for a workflow execution
- **Example**: `{ executionId: 'exec_123' }`
### 13. **transition_role** - Role Transition
- **Purpose**: Transition to a different role in workflow execution
- **Example**: `{ executionId: 'exec_123', toRoleId: 'architect' }`
## Benefits of Consolidation
1. **Reduced Function Count**: 72% reduction (47 β 13 functions)
2. **More MCP Slots**: 27 additional slots for other MCP servers
3. **Cleaner API**: Logical grouping of related operations
4. **Easier Maintenance**: Fewer functions to maintain
5. **Better Organization**: Related operations grouped together
6. **Consistent Interface**: All functions follow similar patterns
## Usage Examples
### Consolidated API Examples
#### Project Management (Anubis-Style Auto-Detection)
```typescript
// π Auto-initialize project with full tech stack detection
const project = await mcpClient.callTool('manage_projects', {
action: 'auto_init',
projectPath: '/path/to/your/project',
});
// This will automatically:
// β
Scan your project files
// β
Detect React + TypeScript + Vite + Tailwind + Prisma + Jest
// β
Create project-specific memory rules
// β
Set up tech stack-specific workflows
// β
Initialize project database
// Get detailed project info
const info = await mcpClient.callTool('manage_projects', {
action: 'info',
projectPath: '/path/to/your/project',
});
// Results show full tech stack:
// π§ Tech Stack:
// Frameworks: react, next
// Languages: typescript, javascript
// Tools: vite, tailwindcss, jest, testing-library
// Databases: prisma
// Deployment: vercel
```
#### Workflow Management
```typescript
// List workflows
const workflows = await mcpClient.callTool('manage_workflows', {
action: 'list',
search: 'authentication'
});
// Create a new workflow
const newWorkflow = await mcpClient.callTool('manage_workflows', {
action: 'create',
workflow: {
name: 'React Component Generator',
description: 'Generate React components with TypeScript',
steps: [...],
qualityChecks: [...]
}
});
// Execute a workflow
const result = await mcpClient.callTool('manage_workflows', {
action: 'execute',
workflowId: 'react-component',
projectPath: '/path/to/project',
variables: { ComponentName: 'UserProfile' }
});
```
#### Code Analysis
```typescript
// AI-powered code analysis
const analysis = await mcpClient.callTool('analyze_code', {
analysisType: 'ai_analysis',
filePath: '/path/to/component.tsx',
projectPath: '/path/to/project',
projectType: 'react',
});
// Get code guidance
const guidance = await mcpClient.callTool('analyze_code', {
analysisType: 'guidance',
filePath: '/path/to/component.tsx',
projectPath: '/path/to/project',
});
// Find similar code
const similarCode = await mcpClient.callTool('analyze_code', {
analysisType: 'similar_code',
filePath: '/path/to/component.tsx',
projectPath: '/path/to/project',
limit: 5,
});
```
#### Semantic Search
```typescript
// Search workflows
const workflows = await mcpClient.callTool('semantic_search', {
type: 'workflows',
query: 'create a user authentication component',
limit: 5,
});
// Search templates
const templates = await mcpClient.callTool('semantic_search', {
type: 'templates',
query: 'API endpoint with error handling',
limit: 3,
});
// Search code patterns
const codePatterns = await mcpClient.callTool('semantic_search', {
type: 'code',
query: 'React hooks pattern',
filePath: '/path/to/component.tsx',
projectPath: '/path/to/project',
});
```
#### Execution Management
```typescript
// Execute with roles
const result = await mcpClient.callTool('manage_execution', {
action: 'execute_roles',
workflowId: 'react-component',
projectPath: '/path/to/project',
agentType: 'cursor',
variables: { ComponentName: 'UserProfile' },
});
// Get execution status
const status = await mcpClient.callTool('manage_execution', {
action: 'status',
executionId: 'exec-123',
});
// Pause execution
await mcpClient.callTool('manage_execution', {
action: 'pause',
executionId: 'exec-123',
reason: 'User requested pause',
});
```
#### Memory Management
```typescript
// Save a memory
await mcpClient.callTool('manage_memories', {
action: 'save',
content: 'Use React.memo for expensive components',
type: 'best_practice',
category: 'technical',
tags: ['react', 'performance'],
});
// Search memories
const memories = await mcpClient.callTool('manage_memories', {
action: 'search',
query: 'React performance optimization',
scope: 'global',
limit: 10,
});
// Get memory statistics
const stats = await mcpClient.callTool('manage_memories', {
action: 'stats',
});
```
#### AI Migration
```typescript
// Migrate data with AI
const migration = await mcpClient.callTool('ai_migrate', {
type: 'data',
instruction:
'migrate all workflows to new format with enhanced quality checks',
source: 'file-based',
target: 'hybrid-storage',
options: { dryRun: true, backup: true },
});
// Migrate workflows
const workflowMigration = await mcpClient.callTool('ai_migrate', {
type: 'workflows',
transformation: 'add new quality checks and update step format',
filters: { tags: ['react', 'component'] },
});
```
## Migration Notes
- All existing functionality is preserved
- Performance impact is negligible
- The consolidation uses action/type parameters to differentiate operations
- Error handling and validation remain the same
- All return formats remain unchanged
## Development
### Project Structure
```
src/
βββ index.ts # Entry point
βββ mcp-server.ts # MCP server implementation
βββ hybrid-storage.ts # Hybrid storage implementation
βββ storage-interface.ts # Unified storage interface
βββ storage.ts # Legacy file-based storage
βββ vector-storage.ts # AI-powered vector storage
βββ guidance-engine.ts # Workflow execution engine
βββ db/
β βββ connection.ts # Database connection management
β βββ drizzle-storage.ts # Drizzle ORM operations
β βββ schema.ts # Database schema definitions
βββ enhanced-workflow-engine.ts # Enhanced workflow execution
βββ execution-tracker.ts # Workflow execution tracking
βββ ai-guidance-engine.ts # AI-powered guidance engine
βββ role-manager.ts # Role-based workflow management
βββ migrate.ts # Database migration script
βββ types.ts # TypeScript type definitions
```
### Scripts
- `npm run build` - Build the project using TypeScript compiler
- `npm run build:all` - Build all entry points (index.js and migrate.js)
- `npm run dev` - Build and run the server
- `npm start` - Run the built server
- `npm run migrate` - Run database migration (first time setup)
- `npm run db:generate` - Generate Drizzle migrations
- `npm run db:migrate` - Apply Drizzle migrations
- `npm run db:studio` - Open Drizzle Studio (database GUI)
- `npm test` - Run tests with Jest
- `npm run lint` - Run Biome linting on src/
- `npm run lint:fix` - Fix linting issues automatically
- `npm run format` - Format code with Biome
- `npm run check` - Run both linting and formatting checks
- `npm run check:fix` - Fix both linting and formatting issues
- `npm run check:all` - Check entire project
- `npm run format:all` - Format entire project
- `npm run lint:all` - Lint entire project
**Note**: All scripts use npm and standard Node.js tools. The migration script automatically handles the transition from file-based storage to hybrid storage with LibSQL.
### AI-Powered Migration System
The Code Guider now includes **intelligent migration tools** that understand natural language instructions:
- **Natural Language Commands**: Tell the AI what to migrate in plain English
- **Smart Transformation**: AI automatically transforms data based on your instructions
- **Safe Migration**: Built-in backup, dry-run preview, and validation features
- **Flexible Filtering**: Migrate specific data based on tags, dates, types, and patterns
- **Rollback Support**: Automatic backup creation before any migration
- **Validation**: Post-migration validation ensures data integrity
**Example Commands:**
- "migrate all workflows to new format with enhanced quality checks"
- "convert templates to new schema and add missing fields"
- "update quality rules severity levels and merge duplicates"
- "transform React component templates to use new variable syntax"
### LibSQL Migration
The project has been fully migrated to use **LibSQL** instead of better-sqlite3:
- **Cross-platform compatibility** - works with both Bun and Node.js
- **Zero native dependencies** - no compilation issues
- **SQLite-compatible** - drop-in replacement for SQLite
- **Better performance** than better-sqlite3
- **Simplified deployment** with no native module requirements
### Build Performance
The project uses **TypeScript compiler** for reliable and consistent builds:
- **Standard TypeScript compilation** for maximum compatibility
- **Type checking** during build process
- **Incremental compilation** for faster subsequent builds
- **Source maps** for better debugging experience
- **Cross-platform compatibility** with all Node.js environments
### Adding New Tools
1. Define the tool in `mcp-server.ts` in the `ListToolsRequestSchema` handler
2. Add the tool handler in the `CallToolRequestSchema` handler
3. Implement the tool logic
4. Update documentation
## Code Quality & Formatting
### Biome Configuration
This project uses **Biome** for linting and formatting, providing a fast and comprehensive code quality solution optimized for Node.js:
#### Features
- β‘ **Ultra-fast**: 10-100x faster than ESLint + Prettier
- π§ **All-in-one**: Linting, formatting, and import organization
- π― **Zero config**: Works out of the box with sensible defaults
- π **Node.js optimized**: Native integration with Node.js runtime
- π **Comprehensive rules**: 200+ linting rules for code quality
- π¨ **Consistent formatting**: Automatic code formatting and style enforcement
#### Configuration
The project includes a comprehensive `biome.json` configuration that enforces:
**Code Quality Rules:**
- β
No unused imports, variables, or functions
- β
No unused classes, interfaces, types, or enums
- β
No unused constants or parameters
- β
DRY (Don't Repeat Yourself) code enforcement
- β
No commented code (except TODO comments)
- β
Consistent code style and formatting
**File Coverage:**
- TypeScript and JavaScript files
- Scripts directory
- Configuration files
- Excludes test files, build artifacts, and dependencies
**Formatting Standards:**
- 2-space indentation
- Single quotes for strings
- Semicolons always
- 100 character line width
- LF line endings
- Trailing commas (ES5 style)
#### Available Scripts
```bash
# Linting
npm run lint # Lint src/ directory
npm run lint:fix # Fix linting issues automatically
npm run lint:all # Lint entire project
npm run lint:all:fix # Fix all linting issues
# Formatting
npm run format # Format src/ directory
npm run format:all # Format entire project
# Combined checks
npm run check # Check src/ (lint + format)
npm run check:fix # Fix src/ (lint + format)
npm run check:all # Check entire project
npm run check:all:fix # Fix entire project
# Pre-commit hooks
npm run pre-commit:install # Install pre-commit hooks
npm run pre-commit:run # Run pre-commit checks
npm run pre-commit # Install and run pre-commit checks
```
#### Pre-commit Hooks
The project includes pre-commit hooks that automatically run:
1. **Biome Check**: Linting and formatting validation
2. **TypeScript Check**: Type checking with `tsc --noEmit`
3. **Test Check**: Run test suite
4. **Format Check**: Ensure code is properly formatted
To set up pre-commit hooks:
```bash
# Install pre-commit hooks
npm run pre-commit:install
# Run all checks manually
npm run pre-commit:run
```
#### IDE Integration
For the best development experience, install the Biome extension in your IDE:
- **VS Code**: [Biome extension](https://marketplace.visualstudio.com/items?itemName=biomejs.biome)
- **Cursor**: Built-in support
- **WebStorm/IntelliJ**: [Biome plugin](https://plugins.jetbrains.com/plugin/22794-biome)
#### Configuration Details
The `biome.json` configuration includes:
- **Extended config**: Uses `@canonical/biome-config` for consistency
- **Comprehensive rules**: 200+ linting rules across correctness, style, suspicious, complexity, performance, and security
- **File patterns**: Includes TypeScript, JavaScript, and JSON files
- **Test overrides**: Relaxed rules for test files
- **Import organization**: Automatic import sorting and organization
- **Format consistency**: Unified formatting across all file types
#### Performance Benefits
- **10-100x faster** than ESLint + Prettier
- **Single tool** instead of multiple tools
- **Native Node.js integration** for optimal performance
- **Parallel processing** for large codebases
- **Incremental checking** for faster subsequent runs
## Configuration
### Project Configuration
The project configuration is stored in `.guidance/config/project.json`:
```json
{
"name": "my-project",
"type": "react",
"frameworks": ["react", "typescript"],
"languages": ["typescript", "javascript"],
"qualityRules": ["no-unused-imports", "no-any-types"],
"workflows": ["react-component", "api-endpoint"],
"templates": ["react-component", "api-endpoint"]
}
```
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request
## License
MIT License - see LICENSE file for details
## Support
For questions and support, please open an issue on GitHub.
TDQS
Scored across 25 tools
Several tools have highly overlapping purposes: manage_workflows, start_workflow, get_workflow, list_workflows, auto_detect_workflow all relate to workflows but with unclear boundaries. Additionally, transition_role and transition_role_workflow appear to do essentially the same thing (both 'transition to a different role in workflow execution'), and there are two metrics tools (get_metrics, get_execution_metrics) with overlapping descriptions. The 'manage_*' family and the specific workflow tools create significant ambiguity about which tool to select.
The naming is inconsistent with mixed conventions. Some tools use a 'manage_X' prefix pattern (manage_quality_rules, manage_workflows, manage_templates), while others use verb_front patterns (start_workflow, get_guidance, report_completion, pause_execution), and some mix style (ai_migrate, init_samples using abbreviations). There are also duplicates with different names (transition_role vs transition_role_workflow, get_metrics vs get_execution_metrics) indicating no coherent naming scheme.
25 tools is on the heavy side for an MCP server. Several tools appear to be near-duplicates (transition_role vs transition_role_workflow, get_metrics vs get_execution_metrics), which inflates the count. The 'manage_*' and role/workflow concepts overlap heavily, suggesting the surface could be significantly consolidated. This feels somewhat bloated for the scope of a workflow guidance server.
The workflow lifecycle is reasonably covered: start, list, get, pause, resume, report completion, transition roles, get guidance, and metrics. However, there's no explicit cancel/stop operation, no obvious tool for listing or getting execution details directly (only metrics), and the relationship between 'manage_execution', 'pause_execution', 'resume_execution', and 'start_workflow' is unclear. The gap between auto-detection/init_samples and the actual workflow tools suggests some portions are underdeveloped.