MCP Hub
Back to servers

CodeGuard MCP Server

CodeGuard MCP Server provides centralized, context-aware security instructions for AI assistants, ensuring generated code adheres to best practices for cryptography, authentication, and input validation without duplicating rule files across repositories.

Tools
2
Updated
Jan 19, 2026

CodeGuard MCP Server

Centralized security instruction server for AI-assisted code generation

๐ŸŽฏ Overview

Problem: Every repository needs .github/instructions/ files to enforce security rules with GitHub Copilot and AI assistants. This leads to:

  • Duplicated instruction files across repositories
  • Inconsistent rule versions
  • Difficult to update security policies organization-wide
  • Manual maintenance overhead

Solution: CodeGuard MCP Server provides centralized security instructions via the Model Context Protocol (MCP), eliminating per-repo instruction files while ensuring all AI-generated code follows security best practices.


๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+

Installation

# Install dependencies
npm install

# Build the project
npm run build

# Test the server
npm start

Setup with Claude Desktop

  1. Build first: npm run build

  2. Configure Claude Desktop (%APPDATA%\Claude\claude_desktop_config.json):

    {
      "mcpServers": {
        "codeguard": {
          "command": "node",
          "args": ["C:\\repo\\contextpilot-server\\dist\\index.js"]
        }
      }
    }
    
  3. Restart Claude Desktop

  4. Test: Ask Claude to generate Python code with password hashing!

Setup with GitHub Copilot (VS Code)

Add to your project's .github/.mcp.json:

{
  "mcp": {
    "servers": {
      "codeguard": {
        "command": "node",
        "args": ["C:\\repo\\contextpilot-server\\dist\\index.js"]
      }
    }
  }
}

Note: GitHub Copilot MCP support is pending. Currently works best with Claude Desktop.


๐Ÿ—๏ธ How It Works

Current Approach (Per-Repository)

my-app/
  .github/
    instructions/
      codeguard-1-crypto.instructions.md          โŒ Duplicated
      codeguard-1-credentials.instructions.md     โŒ Duplicated
      codeguard-0-input-validation.instructions.md โŒ Duplicated
      ... (copy to every repo)

CodeGuard MCP Approach (Centralized)

User: "Generate Python code to hash passwords"
         โ†“
AI Assistant (Copilot/Claude):
  - Connects to CodeGuard MCP Server
  - Requests: "Get security instructions for Python + crypto"
         โ†“
CodeGuard MCP Server:
  - Matches request to rules (applyTo: **/*.py)
  - Returns applicable instructions:
    โ€ข codeguard-1-crypto-algorithms
    โ€ข codeguard-0-authentication-mfa
    โ€ข codeguard-1-hardcoded-credentials
         โ†“
AI generates code following all rules:
  โœ… Uses bcrypt/Argon2 (not MD5)
  โœ… No hardcoded secrets
  โœ… Proper salt generation
  โœ… Secure configuration

NO .github/instructions needed in the repo!

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  AI Assistants (GitHub Copilot, Claude, etc.)      โ”‚
โ”‚  Working in any repository/workspace                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚ MCP Protocol
                     โ”‚ stdio/HTTP
                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           CodeGuard MCP Server                      โ”‚
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  MCP Protocol Layer                       โ”‚    โ”‚
โ”‚  โ”‚  โ€ข Resources (instruction delivery)       โ”‚    โ”‚
โ”‚  โ”‚  โ€ข Prompts (dynamic injection)            โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚                    โ”‚                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  Rule Engine                              โ”‚    โ”‚
โ”‚  โ”‚  โ€ข Load instruction files                 โ”‚    โ”‚
โ”‚  โ”‚  โ€ข Parse frontmatter (applyTo, version)   โ”‚    โ”‚
โ”‚  โ”‚  โ€ข Match language/file patterns           โ”‚    โ”‚
โ”‚  โ”‚  โ€ข Context-aware rule selection           โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚                    โ”‚                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  Centralized Rule Repository              โ”‚    โ”‚
โ”‚  โ”‚  /rules/codeguard-1-*.instructions.md     โ”‚    โ”‚
โ”‚  โ”‚  /rules/codeguard-0-*.instructions.md     โ”‚    โ”‚
โ”‚  โ”‚  /rules/custom-*.instructions.md          โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‹ Core Components

1. MCP Resources

AI assistants can query instructions as resources:

// Resource: All instructions
codeguard://instructions/all

// Resource: By language
codeguard://instructions/python
codeguard://instructions/javascript
codeguard://instructions/typescript

// Resource: By file pattern
codeguard://instructions/file?path=src/auth/handler.ts

2. MCP Prompts

Dynamic instruction injection based on context:

Prompt: get_security_instructions
Arguments:
  - language: "python" | "javascript" | "c" | ...
  - context: "auth" | "crypto" | "database" | ...
  - filepath: Optional file path for pattern matching

Returns: Concatenated instruction text for matched rules

3. Rule Matching Engine

Smart rule selection based on:

  • Language Detection: **/*.py โ†’ Python rules
  • File Patterns: **/*.test.js โ†’ Testing rules
  • Context Keywords: "authentication" โ†’ Auth/MFA rules
  • Critical Rules: Always include hardcoded credentials, weak crypto
  • Frontmatter Parsing: applyTo, version, description

๐ŸŽจ Rule Structure

Each instruction file follows this format:

---
applyTo: '**/*.js,**/*.ts,**/*.jsx,**/*.tsx'
description: No Hardcoded Credentials
version: 1.0.1
---

rule_id: codeguard-1-hardcoded-credentials

# No Hardcoded Credentials

NEVER store secrets, passwords, API keys, tokens or any other 
credentials directly in source code.

[... detailed rules and examples ...]

Current Rules (21+ instruction files):

  • codeguard-1-hardcoded-credentials โš ๏ธ Critical
  • codeguard-1-crypto-algorithms โš ๏ธ Critical
  • codeguard-1-digital-certificates โš ๏ธ Critical
  • codeguard-0-authentication-mfa
  • codeguard-0-authorization-access-control
  • codeguard-0-input-validation-injection
  • codeguard-0-api-web-services
  • codeguard-0-client-side-web-security
  • codeguard-0-session-management-and-cookies
  • ... (and 12+ more)

๐Ÿ’ก Usage Examples

Example 1: Python Password Hashing

User Prompt:

"Generate Python code to hash user passwords"

What Happens:

  1. AI detects: language=python, context=crypto password
  2. MCP Server returns instructions:
    • codeguard-1-crypto-algorithms (no MD5/SHA-1)
    • codeguard-0-authentication-mfa
    • codeguard-1-hardcoded-credentials

Generated Code:

import bcrypt

def hash_password(password: str) -> bytes:
    """Hash password using bcrypt with secure defaults."""
    # โœ… Uses bcrypt (not MD5)
    # โœ… Automatic salt generation
    # โœ… Secure work factor
    salt = bcrypt.gensalt(rounds=12)
    return bcrypt.hashpw(password.encode('utf-8'), salt)

def verify_password(password: str, hashed: bytes) -> bool:
    """Verify password against hash."""
    return bcrypt.checkpw(password.encode('utf-8'), hashed)

Example 2: Node.js Database Query

User Prompt:

"Create a function to get user by email in TypeScript"

What Happens:

  1. AI detects: language=typescript, context=database
  2. MCP Server returns instructions:
    • codeguard-0-input-validation-injection
    • codeguard-0-data-storage
    • codeguard-0-authorization-access-control

Generated Code:

import { Pool } from 'pg';

async function getUserByEmail(email: string): Promise<User | null> {
  // โœ… Input validation
  if (!email || typeof email !== 'string') {
    throw new Error('Invalid email parameter');
  }
  
  // โœ… Parameterized query (no SQL injection)
  const query = 'SELECT * FROM users WHERE email = $1';
  const result = await pool.query(query, [email]);
  
  return result.rows[0] || null;
}

Example 3: React Authentication Component

User Prompt:

"Create a login form component in React"

What Happens:

  1. AI detects: language=typescript, context=auth, filepath=*.tsx
  2. MCP Server returns instructions:
    • codeguard-0-client-side-web-security (XSS, CSRF)
    • codeguard-0-authentication-mfa
    • codeguard-0-session-management-and-cookies

Generated Code:

// โœ… No credentials in code
// โœ… CSRF protection
// โœ… Secure cookie handling
// โœ… XSS prevention via React defaults

export function LoginForm() {
  const handleSubmit = async (e: FormEvent) => {
    e.preventDefault();
    
    const formData = new FormData(e.target as HTMLFormElement);
    const response = await fetch('/api/auth/login', {
      method: 'POST',
      credentials: 'same-origin', // โœ… Secure cookies
      headers: {
        'Content-Type': 'application/json',
        'X-CSRF-Token': getCsrfToken(), // โœ… CSRF protection
      },
      body: JSON.stringify({
        email: formData.get('email'),
        password: formData.get('password'),
      }),
    });
    // ... handle response
  };
  
  return <form onSubmit={handleSubmit}>...</form>;
}

๐Ÿ› ๏ธ Technology Stack

  • Runtime: Node.js 18+ / TypeScript
  • Protocol: MCP SDK (@modelcontextprotocol/sdk)
  • Transport: stdio (standard MCP)
  • Parser: Gray-matter (frontmatter), micromatch (glob patterns)
  • Testing: Jest / Vitest

๐Ÿšฆ Roadmap

See ROADMAP.md for detailed implementation plan.

Phase 1: Core MCP Server โœ… COMPLETED (January 16, 2026)

  • MCP server setup with stdio transport
  • Rule loader with frontmatter parsing
  • Pattern matching engine (glob patterns, language detection)
  • Basic resource handlers
  • Prompt handlers for dynamic instruction injection
  • 22 instruction files loaded and working
  • TypeScript build system configured
  • Basic tests implemented

Current Status:

  • โœ… Server built and functional (dist/index.js)
  • โœ… Works with Claude Desktop (MCP supported)
  • โณ Waiting for GitHub Copilot MCP support

Phase 2: Smart Matching ๐Ÿ”„ (Week 2) - In Progress

  • Language detection from prompts
  • Context keyword matching
  • File pattern glob matching
  • Rule deduplication and prioritization
  • Performance benchmarking
  • Cache optimization

Phase 3: Enhanced Features (Week 3)

  • Custom organization rules support
  • Rule versioning and updates
  • Advanced performance optimization
  • Comprehensive test coverage

Phase 4: Production Ready (Week 4+)

  • Docker containerization
  • HTTP transport option
  • Configuration management
  • Monitoring and logging
  • GitHub Copilot integration (when available)

๐ŸŽฏ Success Metrics

  • โœ… Zero duplication: No .github/instructions in any repo
  • โœ… Centralized updates: Update once, apply everywhere
  • โœ… Automatic enforcement: AI follows rules without developer intervention
  • โœ… Fast response: < 100ms to serve instructions
  • โœ… High accuracy: 95%+ correct rule matching
  • โœ… Developer experience: Transparent, no workflow changes

๐Ÿค Benefits

For Developers

  • No manual rule maintenance per repo
  • Consistent security standards across projects
  • AI generates secure code automatically
  • Clear, actionable security guidance

For Organizations

  • Centralized security policy management
  • Easy to update and enforce rules organization-wide
  • Audit trail of instruction versions
  • Reduced security vulnerabilities in AI-generated code

For Security Teams

  • Single source of truth for security rules
  • Version control for policy changes
  • Measurable compliance across all projects
  • Proactive security guidance at code generation time

๐Ÿ—๏ธ Architecture

Component Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  AI Assistants (Copilot, Claude, etc.)             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚ MCP Protocol (stdio)
                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           CodeGuard MCP Server                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  MCP Layer (Resources, Prompts, Tools)    โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  Rule Engine (Match & Prioritize)         โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  Rules Repository (22+ instructions)      โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

MCP Endpoints

Resources:

  • codeguard://instructions/all - All instructions
  • codeguard://instructions/{language} - Language-specific
  • codeguard://instructions/file?path={file} - File-specific

Prompts:

  • get_security_instructions - Context-aware instruction retrieval
    • Args: language, context, filepath

Tools:

  • get_security_instructions - Get rules for code generation
  • validate_code_security - Validate code against rules

Pattern Matching

The server intelligently matches rules based on:

  • File patterns: **/*.py, src/auth/**
  • Language: Detected from extensions or prompts
  • Context: Keywords like "auth", "crypto", "database"
  • Critical rules: Always included (credentials, crypto, certificates)

๐Ÿ“ฆ Project Structure

contextpilot-server/
โ”œโ”€โ”€ rules/                      # 22+ security instruction files
โ”‚   โ”œโ”€โ”€ codeguard-1-*.md       # Critical rules
โ”‚   โ””โ”€โ”€ codeguard-0-*.md       # Best practices
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts               # MCP server entry
โ”‚   โ”œโ”€โ”€ handlers/              # Resource/Prompt/Tool handlers
โ”‚   โ””โ”€โ”€ rules/                 # Loader & Matcher
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ dist/                      # Compiled output
โ””โ”€โ”€ package.json

๐Ÿงช Development

# Development mode (hot reload)
npm run dev

# Run tests
npm test

# Build
npm run build

๐Ÿšฆ Current Status

โœ… Completed (Phase 1)

  • Core MCP server with stdio transport
  • Rule loader with frontmatter parsing
  • Pattern matching (glob, language, context)
  • Resource & Prompt handlers
  • 22 instruction files loaded
  • Works with Claude Desktop

โณ Pending

  • GitHub Copilot MCP support (waiting on Microsoft)
  • Advanced caching & optimization
  • Custom organization rules

๐Ÿค Benefits

For Developers:

  • No manual rule maintenance per repo
  • Consistent security across projects
  • AI generates secure code automatically

For Organizations:

  • Centralized security policy management
  • Easy organization-wide updates
  • Reduced security vulnerabilities

For Security Teams:

  • Single source of truth
  • Version control for policies
  • Proactive security at code generation time

๐Ÿ“ License

MIT


๐Ÿ”— Resources


Built with โค๏ธ for secure AI-assisted development

Reviews

No reviews yet

Sign in to write a review

CodeGuard MCP Server โ€” MCP Server | MCP Hub