Skip to content

About

Sandboxed FastMCP v2 developer server exposing 17 AST and filesystem tools with path traversal guards. Bridges internal AI assistants to engineering codebases for compliant AI-assisted coding under strict enterprise policies.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– FastMCP Code Copilot

Enterprise Sandboxed Model Context Protocol (MCP) Server for AI-Assisted Engineering

Python 3.10+ FastMCP v2 Starlette Uvicorn License: MIT Version: 3.0.0 Author


FastMCP Security Sandbox Architecture
Filesystem isolation firewall confining agent operations to designated workspace while blocking directory traversal attacks (../, /etc, .env).


πŸ“Œ Executive Summary & Enterprise Origin

In strictly regulated enterprise R&D environments (such as Tier-1 automotive and industrial engineering), commercial cloud-based AI code assistants (like commercial GitHub Copilot) are frequently restricted due to proprietary IP leakage, strict network proxy constraints, and compliance mandates.

FastMCP Code Copilot was architected to bridge internal enterprise AI chatbots and desktop assistants (such as Claude Desktop, Cursor, or custom LLM gateways) directly to local codebases with institutional-grade cybersecurity rigor:

  • Zero Data Egress: Operates entirely over local network transports (HTTP/SSE or standard I/O) without transmitting repository contents to unverified third parties.
  • Hardware-Level Containment: Enforces strict directory containment, symlink escape checks, and path normalization.
  • High-Throughput Engineering Context: Delivers 6 consolidated poly-tools cutting token overhead by 83%, multi-file atomic transactions with automatic rollback, line-scoped reading, and AST symbol extraction.
  • Enterprise Web Interoperability: Starlette ASGI dual-transport (/mcp and /sse) with CORS Private Network Access (allow_private_network=True) and FastMCP OriginGuard bypass for corporate HTTPS chatbots.
  • Zero-Clutter Reverse-Patch Undo: Centralized SQLite reverse-patch undo in .copilot/history.db with zero .bak files created on disk.

πŸ“Έ Architectural Showcase

Security Sandbox & Path Containment Developer Copilot & AST Codebase Tools
Security Sandbox Copilot Tools
Hardened containment firewall: eliminates directory escaping and path injection. 17 specialized code analysis tools: AST parsing, symbol extraction, and ripgrep.

πŸ—οΈ System Architecture & Security Model

The server operates as an asynchronous Starlette application exposing the standard Model Context Protocol (MCP) specification:

flowchart TD
    Client["AI Assistant (Claude Desktop / Cursor / Internal Chatbot)"] -->|JSON-RPC via MCP| Server["Starlette ASGI Application (Uvicorn)"]
    
    subgraph "Security Containment Middleware"
        Server --> CORS["CORS & Request Logging Middleware"]
        CORS --> PathValidator{"Path Sandbox Validator (security.py)"}
        
        PathValidator -->|Absolute Path| Reject1["REJECT: Absolute paths forbidden"]
        PathValidator -->|Traversal Attempt '../'| Reject2["REJECT: Directory traversal detected"]
        PathValidator -->|Symlink Escape| Reject3["REJECT: Target outside PROJECT_ROOT"]
        PathValidator -->|Normalized Safe Relative Path| ToolDispatcher["MCP Tool Dispatcher"]
    end
    
    subgraph "Consolidated Poly-Tools"
        ToolDispatcher --> T1["file_ops (read, write, patch, delete, batch, atomic transactions)"]
        ToolDispatcher --> T2["code_search (grep, symbol, fulltext, file-tree glob)"]
        ToolDispatcher --> T3["run_command (sandboxed execution, pytest, git, npm)"]
        ToolDispatcher --> T4["git_ops (status, compacted diff, shadow checkpoint, rollback)"]
        ToolDispatcher --> T5["inspect_ast (structural symbol outlines, ~60 tokens)"]
        ToolDispatcher --> T6["diagnostics (telemetry summary, token quota tracker)"]
    end
    
    ToolDispatcher --> SandboxWorkspace[("Designated Project Sandbox Root")]
Loading

Institutional Security Invariants:

  1. Root Boundary Enclosure: Every operation is strictly relative to the designated PROJECT_ROOT. Attempting to access parent paths (../../) raises an immediate validation exception.
  2. Symlink Traversal Protection: Evaluates Path.resolve() against the physical filesystem. If a symlink resolves to an inode outside the project root, access is terminated immediately.
  3. Internal State Concealment: Persistent search indexes (.mcp_index) and telemetry databases (.copilot/) are excluded from file listings and search queries.
  4. Controlled Execution Whitelist: Command execution is restricted to safe, verified developer toolchains (pytest, git, python, npm, cargo, go) with Windows .cmd resolution and process-tree termination.

πŸ› οΈ Consolidated Poly-Tools Architecture (83% Token Savings)

Instead of 25+ fine-grained schemas that bloat system prompts, operations are consolidated into 6 high-performance poly-tools:

1. file_ops

  • Actions: read, write, patch, delete, info, batch_read, and transaction.
  • Features: Sliced line reading, Windows CRLF line-ending preservation without double-newlines, atomic temp-file replacement, and multi-file atomic transactions with automatic rollback on error.

2. code_search

  • Modes: grep (regex with context lines), symbol (functions/classes across languages), fulltext (SQLite FTS5 indexing with <<<match>>> snippets), and files (glob file tree).
  • Features: Native Ripgrep integration with Python fallback and guaranteed .git, .venv, and node_modules ignore pruning.

3. run_command

  • Features: Sandboxed execution of whitelisted CLIs, environment credential scrubbing (hiding API keys), hard timeouts, and process-tree cleanup via psutil.

4. git_ops

  • Actions: status, diff (compacted), checkpoint (Git shadow commit), and rollback (safe revert without deleting untracked files).

5. inspect_ast

  • Features: Multi-language structural outlines (Python AST and Tree-sitter for JS/TS) returning classes, methods, and line spans in under 60 tokens.

6. diagnostics

  • Features: System health checks, structured error telemetry (.copilot/logs/trace.jsonl), and token quota tracker (session://token-usage).

πŸ“ Repository Structure

MCP-Code-Copilot/
β”œβ”€β”€ assets/                         # Architectural diagrams and figures
β”œβ”€β”€ copilot/                        # Core modular engine
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ security.py             # Strict path jail & credential sanitization
β”‚   β”‚   β”œβ”€β”€ sandbox.py              # Process execution sandbox & timeouts
β”‚   β”‚   └── history.py              # SQLite reverse-patch undo engine (.copilot/history.db)
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ ast_service.py          # Structural AST symbol extraction (~60 tokens)
β”‚   β”‚   β”œβ”€β”€ search_service.py       # SQLite FTS5 & Ripgrep code search
β”‚   β”‚   └── telemetry.py            # Structured JSONL tracing & 1M token budget tracker
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   β”œβ”€β”€ __init__.py             # FastMCP tool registry
β”‚   β”‚   β”œβ”€β”€ file_ops.py             # Atomic file operations & transactions
β”‚   β”‚   β”œβ”€β”€ code_search.py          # Unified code search
β”‚   β”‚   β”œβ”€β”€ run_command.py          # Sandboxed command execution
β”‚   β”‚   β”œβ”€β”€ git_ops.py              # Git status, shadow stash & rollback
β”‚   β”‚   β”œβ”€β”€ inspect_ast.py          # Structural outline inspection
β”‚   β”‚   └── diagnostics.py          # Health, error classification & diagnostics
β”‚   └── prompts/
β”‚       β”œβ”€β”€ __init__.py             # Standard MCP Prompts (@mcp.prompt)
β”‚       └── resources.py            # Dynamic MCP Resources (@mcp.resource)
β”œβ”€β”€ tests/                          # 25 test suites (431 passing tests)
β”œβ”€β”€ config.py                       # Centralized configuration & thresholds
β”œβ”€β”€ pyproject.toml                  # Explicit package discovery specification
β”œβ”€β”€ server.py                       # Starlette ASGI dual-transport server (/mcp & /sse)
└── README.md                       # Master documentation

πŸš€ Quick Start & Integration Guide

1. Installation

Install the package directly into your Python environment:

# Clone the repository
git clone https://github.com/Vignesh-Manivasakam/MCP-Code-Copilot.git
cd MCP-Code-Copilot

# Install with pip (editable CLI mode)
pip install -e .

2. Launch the Server

Start the server and specify your project workspace:

# Using the installed CLI wrapper:
mcp-code-copilot /path/to/your/project --port 8000

# Or via Python directly:
python server.py /path/to/your/project --port 8000

Console Output:

============================================================
πŸš€ FastMCP Code Copilot Server  v3.0.0
============================================================
  Project : my-project-workspace
  MCP     : http://127.0.0.1:8000/mcp
  Health  : http://127.0.0.1:8000/health
  Sandbox : ENFORCED (/path/to/your/project)
============================================================

3. Register with Claude Desktop

Add the server definition to your claude_desktop_config.json:

{
  "mcpServers": {
    "fastmcp-code-copilot": {
      "command": "python",
      "args": [
        "-m", "server",
        "D:\\path\\to\\your\\workspace",
        "--port", "8000"
      ]
    }
  }
}

πŸ§ͺ Verification & Security Testing

Run the automated test suite to verify sandbox boundary enforcement:

# Run security and path traversal penetration tests
python -m pytest tests/test_security.py tests/test_fts5.py -v

πŸ›‘οΈ License & Enterprise Compliance Notice

  • License: Released under the open-source MIT License.
  • Compliance: Engineered to conform with enterprise corporate IT governance guidelines. Eliminates commercial per-seat licensing fees while providing transparent, auditable code interaction logs.
  • Author: Vignesh Manivasakam (LinkedIn Β· GitHub)

About

Sandboxed FastMCP v2 developer server exposing 17 AST and filesystem tools with path traversal guards. Bridges internal AI assistants to engineering codebases for compliant AI-assisted coding under strict enterprise policies.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages