Skip to main content
Glama

Constraint Monitor

Real-time constraint enforcement system for Claude Code that prevents policy violations before they happen.

Overview

The four MCP tools are retired. Their schemas cost ~1.5 KB in every context window for actions only ever taken deliberately. The agent-facing entry point is the constraints CLI (bin/constraints + the /constraints skill), which runs in-process against the same ConstraintEngine — so it keeps working when the container is down. Enforcement was never MCP anyway: it is the PreToolUse / UserPromptSubmit hooks, which are unchanged. src/server.js and src/sse-server.js still work for any external MCP client.

The Constraint Monitor provides:

  • Real-time validation: Checks constraints before tool execution

  • Flexible rules: Regex patterns with optional semantic validation

  • Low latency: 1-5ms for regex checks, 50-200ms with semantic validation

  • Dashboard: Web UI for monitoring violations and compliance

  • File path vs content checking: Control whether constraints check paths or content

Related MCP server: cco-mcp

Quick Start

Installation

cd integrations/constraint-monitor
npm install
./install.sh

Basic Usage

  1. Define constraints in .constraint-monitor.yaml:

constraints:
  - id: my-constraint
    pattern: "forbidden-pattern"
    message: "This pattern is not allowed"
    severity: error
    enabled: true
  1. Start the monitor:

node scripts/global-service-coordinator.js --daemon
  1. View dashboard: http://localhost:3030

Docker Deployment (HTTP/SSE Mode)

For containerized deployments, the MCP server supports HTTP/SSE transport:

# Start as SSE server (Docker mode)
npm run sse-server

# Or directly:
node src/sse-server.js

HTTP/SSE Endpoints:

  • GET /health - Health check endpoint

  • GET /sse - Server-Sent Events connection

  • POST /messages - JSON-RPC message endpoint

Port Configuration:

  • MCP SSE Server: 3849 (configurable via CONSTRAINT_MONITOR_SSE_PORT)

  • Dashboard UI: 3030 (via CONSTRAINT_DASHBOARD_PORT)

  • API Backend: 3031 (via CONSTRAINT_API_PORT)

Health Check:

curl http://localhost:3849/health

Claude Code Integration (Docker Mode):

In Docker mode, Claude connects via a lightweight stdio proxy:

{
  "constraint-monitor": {
    "command": "node",
    "args": ["path/to/src/stdio-proxy.js"],
    "env": {
      "CONSTRAINT_MONITOR_SSE_URL": "http://localhost:3849"
    }
  }
}

See the parent Docker Deployment Guide for full containerization setup.

Documentation

Core Documentation

  • Constraint Configuration Guide ⭐ START HERE

    • Basic constraint structure

    • All constraint properties (applies_to, severity, flags, etc.)

    • Pattern matching tips

    • Real-world examples

    • Best practices and troubleshooting

Advanced Features

Integration

Key Features

File Path vs Content Checking

NEW: Use applies_to: file_path to check file paths instead of content:

- id: knowledge-base-protection
  pattern: "\\.data/knowledge-export/"
  applies_to: file_path  # Only blocks files IN this path
  message: "Use bin/ukb CLI to modify knowledge base"

This prevents false positives when file content mentions protected paths.

Semantic Validation

Reduce false positives with AI-powered validation:

- id: smart-constraint
  pattern: "console\\.log"
  semantic_validation: true  # LLM verifies if it's a real violation

Exceptions and Whitelists

Exclude specific files from constraint checking:

- id: my-constraint
  pattern: "strict-rule"
  exceptions:
    - path: "**/*.test.js"
      reason: "Tests are exempt"

Architecture

Claude Code Tool Call
        ↓
Pre-Tool Hook (Node.js)
        ↓
Constraint Engine
        ↓
[Regex Check] → [Semantic Validation (optional)]
        ↓
Block or Allow

Configuration Files

  • .constraint-monitor.yaml: Project-specific constraints (primary)

  • constraints.yaml: Global constraints (repository-wide)

  • config/enforcement.json: Enforcement settings

  • .env.ports: Port configuration

Dashboard

Access the web dashboard at http://localhost:3030 to:

  • View real-time constraint violations

  • Monitor compliance scores

  • Analyze violation trends

  • Test constraint patterns

  • Manage enforcement settings

Development

Running Tests

npm test

Debugging

Enable debug logging:

export LOG_LEVEL=debug
node src/dashboard-server.js

Adding New Constraints

  1. Edit .constraint-monitor.yaml

  2. Restart the monitor: pkill -f global-service-coordinator && node scripts/global-service-coordinator.js --daemon

  3. Test with actual file operations

  4. Monitor dashboard for violations

Troubleshooting

Constraint not firing

  1. Check enabled: true in configuration

  2. Verify pattern regex is correct

  3. For applies_to: file_path, ensure pattern matches paths not content

  4. Restart the constraint monitor

False positives

  1. Add applies_to: file_path if checking paths

  2. Enable semantic_validation: true

  3. Add exceptions for specific files

  4. Refine regex pattern

See the Constraint Configuration Guide for detailed troubleshooting.

Performance

  • Regex checking: 1-5ms per constraint

  • Semantic validation: 50-200ms with caching

  • Dashboard: Real-time updates via WebSocket

  • Memory: ~50MB base + caching overhead

Contributing

When adding features:

  1. Update relevant documentation

  2. Add tests for new functionality

  3. Update configuration examples

  4. Test with real-world scenarios

License

Part of the coding infrastructure project.

Support

  • Documentation: See docs/ directory

  • Issues: Create an issue in the main repository

  • Dashboard: http://localhost:3030 for monitoring

Available Tools

4 tools
check_constraintsC

Check code or actions against defined constraints

Inputs: type (required), content (required), filePath.

get_constraint_statusC

Get current constraint monitoring status and compliance metrics

Inputs: sessionId.

get_violation_historyC

Get history of constraint violations and their resolutions

Inputs: limit, sessionId.

update_constraintsC

Update or add constraint rules

Inputs: constraints (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3.1/5.0

    Scored across 4 tools

    Disambiguation4/5

    Each tool maps to a distinct action: history retrieval, rule mutation, status/metrics, and validation checks. The only mild overlap is between get_violation_history and get_constraint_status, since compliance metrics and violation history are related, but their descriptions make the boundary reasonably clear.

    Naming Consistency5/5

    All four tools use consistent snake_case verb_noun naming (get_*, update_*, check_*). The verbs differ appropriately by action while the pattern stays predictable.

    Tool Count4/5

    Four tools is a tight but sensible scope for a focused constraint monitor, and each earns its place. It sits near the thin end, but not problematically so.

    Completeness3/5

    Core operations are covered (check, status, history, update/add), but there is no way to delete or list constraints explicitly, and although violation resolutions are mentioned, no tool lets an agent resolve a violation. These are notable gaps for full lifecycle coverage.

    Maintenance

    ActivityActive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Policy-enforcing MCP proxy that blocks dangerous tool calls before they execute. Protects credentials, filesystem, shell, and databases across Claude Desktop, Cursor, Windsurf, and OpenClaw.
      17 npm
      41
      Apache 2.0
    • A
      license
      Not graded
      quality
      D
      maintenance
      Real-time audit and approval system for Claude Code tool calls, enabling monitoring and control of AI agent actions with a web dashboard.
      19
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      MartinLoop is the independent governance and financial control layer for AI coding agents. Set hard spend limits, prevent runaway loops, enforce verification, trigger rollback on failure, and generate auditable receipts showing what changed, what it cost, and whether the work passed.
      24
      224 npm
      263
      Apache 2.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Deterministic policy enforcement for AI agent tool calls. It evaluates every tool call against user-defined rules before execution, with no LLM in the authorization path.
      4
      MIT