Skip to content

yashranaway/CodeSyncReview_MCP

Repository files navigation

TypeScript MCP Worker

🚧 Development Status: In Active Development 🚧

A Model Context Protocol (MCP) worker that provides comprehensive TypeScript/JavaScript code analysis capabilities. This worker integrates with AI assistants and development tools to provide intelligent code review, static analysis, and automated patch generation.

What is MCP?

The Model Context Protocol (MCP) is an open standard that enables AI assistants to securely connect to external data sources and tools. This worker implements the MCP specification to provide TypeScript code analysis services to AI models and development environments.

Features

🔍 Code Analysis

  • ESLint Integration: Full ESLint rule support with custom rule loading
  • TypeScript Compiler: Type checking, compilation errors, and project analysis
  • TSQuery Pattern Matching: Custom AST pattern detection for code smells
  • Multi-file Analysis: Project-wide code review capabilities

🤖 AI-Ready Tools

  • MCP Protocol: Standardized interface for AI model integration
  • Structured Output: JSON responses optimized for AI consumption
  • Error Handling: Graceful degradation with detailed error reporting
  • Health Monitoring: Built-in health checks and status reporting

🛠️ Developer Experience

  • Automated Patches: AI-generated code fixes and improvements
  • Confidence Scoring: ML-based confidence ratings for findings
  • Custom Rules: Extensible rule system for team-specific standards
  • Real-time Analysis: Fast, incremental analysis for large codebases

Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

# Clone the repository
git clone https://github.com/yashranaway/typescript-mcp-worker.git
cd typescript-mcp-worker

# Install dependencies
npm install

# Build the project
npm run build

Basic Usage

import { TypeScriptWorker } from './src';

// Initialize the worker
const worker = new TypeScriptWorker();

// Analyze a single file
const result = await worker.analyzeCode('example.ts', sourceCode, {
  enableESLint: true,
  enableTypeScript: true,
  enableTsQuery: true,
  generatePatches: true
});

console.log('Findings:', result.findings);
console.log('Patches:', result.patches);

MCP Integration

# Start the MCP server
npm run mcp:serve

# Or build and run
npm run build
node dist/mcp-server.js

MCP Tools

This worker exposes the following tools through the MCP protocol:

analyze_code

Analyzes a single TypeScript/JavaScript file.

Parameters:

  • filePath: Path to the file
  • sourceCode: Source code content
  • options: Analysis configuration

Returns: Analysis results with findings and patches

analyze_project

Analyzes an entire TypeScript project.

Parameters:

  • projectRoot: Project root directory
  • projectOptions: Project analysis options

Returns: Array of analysis results for all files

health_check

Performs health check on all analysis tools.

Returns: Health status and tool details

update_eslint_config

Updates ESLint configuration.

Parameters:

  • configPath: Path to ESLint config file

update_typescript_config

Updates TypeScript configuration.

Parameters:

  • tsConfigPath: Path to TypeScript config file

load_custom_rules

Loads custom ESLint rules.

Parameters:

  • rulesPath: Path to custom rules directory

Configuration

MCP Configuration

{
  "mcpServers": {
    "typescript-worker": {
      "command": "node",
      "args": ["dist/mcp-server.js"],
      "env": {
        "NODE_ENV": "production"
      }
    }
  }
}

Worker Configuration

const config = {
  eslintConfigPath: './eslint.config.js',     // Custom ESLint config
  typescriptConfigPath: './tsconfig.json',   // TypeScript config
  maxFileSize: 1024 * 1024                   // Max file size (1MB)
};

const worker = new TypeScriptWorker(config);

Development

Project Structure

typescript-mcp-worker/
├── src/
│   ├── index.ts                 # Main worker class
│   ├── mcp-server.ts           # MCP protocol server
│   ├── eslint-analyzer.ts      # ESLint integration
│   ├── typescript-analyzer.ts  # TypeScript compiler
│   ├── tsquery-analyzer.ts     # TSQuery pattern matching
│   ├── patch-generator.ts      # Automated patch generation
│   ├── confidence-scorer.ts    # ML-based confidence scoring
│   ├── logger.ts               # Logging utilities
│   └── types.ts                # Type definitions
├── mcp-config.json             # MCP configuration
├── example.ts                  # Usage examples
└── package.json                # Project configuration

Available Scripts

# Development
npm run dev              # Start in watch mode
npm run build            # Build the project
npm run start            # Start production server

# MCP
npm run mcp:serve        # Start MCP server

# Testing
npm run test             # Run tests
npm run test:watch       # Run tests in watch mode
npm run test:coverage    # Run tests with coverage

# Utilities
npm run example          # Run example code
npm run lint             # Lint the codebase
npm run clean            # Clean build artifacts

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

Example Output

Analysis Result

{
  "filePath": "example.ts",
  "findings": [
    {
      "id": "eslint-console-log",
      "type": "CODE_QUALITY",
      "severity": "WARNING",
      "message": "Console.log statements should be removed in production",
      "location": {
        "file": "example.ts",
        "line": 2,
        "column": 10
      },
      "rule": "no-console",
      "confidence": 0.9
    }
  ],
  "patches": [
    {
      "id": "patch-console-log",
      "description": "Remove console.log statement",
      "changes": [
        {
          "type": "delete",
          "start": 0,
          "end": 20,
          "description": "Remove console.log line"
        }
      ],
      "confidence": 0.8
    }
  ],
  "metadata": {
    "analysisTime": 150,
    "tools": {
      "eslint": true,
      "typescript": true,
      "tsquery": true
    }
  }
}

Contributing

This project is in active development! We welcome contributions:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Add tests for new functionality
  • Ensure all tests pass before submitting
  • Update documentation for new features
  • Follow the existing code style

Roadmap

Phase 1: Core MCP Integration ✅

  • Basic MCP server implementation
  • Tool registration and handling
  • Error handling and logging

Phase 2: Enhanced Analysis (In Progress)

  • Advanced TypeScript analysis
  • Custom rule engine
  • Performance optimizations

Phase 3: AI Integration

  • LLM-based patch generation
  • Intelligent rule suggestions
  • Learning from user feedback

Phase 4: Enterprise Features

  • Multi-tenant support
  • Advanced security scanning
  • Integration APIs

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Acknowledgments


🚧 Note: This project is in active development. APIs and features may change. 🚧

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published