Skip to main content
Glama
MCP Policy Gatekeeper

MCP Policy Gatekeeper

by GILSMON

MCP Server as Policy Gatekeeper

Real-time policy enforcement for AI coding agents using Model Context Protocol

Prevent AI agents from violating organizational standards by intercepting and validating their actions before execution.

🎯 Problem

AI coding assistants can bypass:

  • Naming conventions (camelCase vs snake_case)

  • Security policies (secrets in code, destructive commands)

  • Compliance rules (file access, API usage)

Traditional solutions (CI/CD, code review) catch violations after the damage is done.

Related MCP server: Hivelore

✨ Solution

MCP server that acts as a policy gatekeeper - validates every agent action in real-time:

Agent: "Create myFirst--File.txt"
   ↓
MCP Server: ❌ Violates snake_case policy
   ↓
Agent: "Creating my_first_file.txt instead"

πŸš€ Quick Start

# Clone & setup
git clone https://github.com/yourusername/mcpServer_as_gatekeeper.git
cd mcpServer_as_gatekeeper

# Install with uv
uv init
uv add mcp

# Run server
uv run server.py

πŸ”§ Windsurf Integration

Add to ~/.windsurf/mcp_config.json:

{
  "mcpServers": {
    "policy-gatekeeper": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/mcpServer_as_gatekeeper",
        "run",
        "server.py"
      ]
    }
  }
}

Restart Windsurf. Done.

πŸ“‹ Built-in Policies

1. Command Validation

  • ❌ Blocks: rm -rf /, curl | bash, chmod 777

  • βœ… Allows: git, npm, docker, safe operations

2. File Naming

  • Enforces: snake_case for files

  • Rejects: camelCase, kebab-case, special characters

3. Sensitive Paths

  • Blocks: /etc/shadow, .ssh/id_rsa, .env files

4. Network Security

  • Prevents: Command injection, data exfiltration

πŸ§ͺ Test It

Prompt your agent:

Create a file called myTest--File.txt

Expected: Agent auto-corrects to my_test_file.txt

Validate this command: rm -rf /

Expected: Blocked with policy violation ORG-SEC-001

πŸ“Š Features

Feature

Status

Command validation

βœ…

File naming enforcement

βœ…

Audit logging

βœ…

Statistics dashboard

βœ…

OPA integration

πŸ”„ Roadmap

Secret scanning

πŸ”„ Roadmap

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  AI Agent       β”‚
β”‚  (Windsurf)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ MCP Protocol
         ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Policy Gatekeeper      β”‚
β”‚  - Validate command     β”‚
β”‚  - Check naming rules   β”‚
β”‚  - Scan for secrets     β”‚
β”‚  - Audit log            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         ↓
    ALLOW / DENY

πŸŽ›οΈ Customize Policies

Edit server.py:

POLICY_RULES = {
    "your_rule": {
        "patterns": [r"your_regex"],
        "message": "Your policy message"
    }
}

Restart MCP server. Policies update immediately.

πŸ“ˆ Scale Impact

For a 50-developer team:

  • 5,000 daily policy checks (100 per dev)

  • ~100 hours/week saved on manual enforcement

  • 80% of violations prevented before code review

  • Zero failed CI builds from policy violations

πŸ” Enterprise Use Cases

  • Security: Block secrets, malicious commands

  • Compliance: Enforce SOC2/HIPAA file access rules

  • Quality: Consistent naming, code structure

  • Cost: Prevent expensive CI/CD failures

πŸ›£οΈ Roadmap

  • OPA/Rego integration for complex policies

  • Secret detection (TruffleHog integration)

  • RBAC (role-based validation)

  • Multi-team policy federation

  • VS Code / Cursor support

  • Dashboard UI for policy management

🀝 Contributing

Have a policy pattern to share? PRs welcome!

  1. Fork the repo

  2. Add your policy to POLICY_RULES

  3. Add test cases

  4. Submit PR

πŸ“„ License

MIT

Available Tools

5 tools
create_fileB

Create a new file (automatically applies snake_case naming convention)

Inputs: path (required), content.

delete_fileC

Delete a file

Inputs: path (required).

list_filesC

List all files in directory

Inputs: path.

read_fileC

Read contents of a file

Inputs: path (required).

write_fileB

Write to an existing file (naming convention enforced on creation only)

Inputs: path (required), content (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose targeting specific file operations: create, delete, list, read, and write. There is no overlap or ambiguity between these functions, making tool selection straightforward for an agent.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern (e.g., create_file, delete_file) using snake_case throughout. The naming is predictable and aligns perfectly with the operations performed.

    Tool Count5/5

    With 5 tools, the server is well-scoped for file management, covering essential CRUD operations (create, read, update via write, delete) and listing. Each tool earns its place without being excessive or insufficient.

    Completeness5/5

    The tool set provides complete coverage for basic file operations in the domain, including create, read, update (write), delete, and list. There are no obvious gaps, and agents can perform full file lifecycle management without dead ends.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Runtime policy enforcement for AI agents. Evaluate every agent action against your organization's policies before execution, with observe and enforce modes.
      1
      1
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Policy and quality engine for AI coding agents that enforces team coding standards and provides validation gates for agent-assisted software delivery.
      7
      56 npm
      5
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to self-govern by scanning code for hardcoded secrets, structural violations, and AI drift in real-time, providing fix packets for automatic remediation.
      29
      MIT