New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

correctover-mcp-gateway

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

correctover-mcp-gateway

MCP security gateway for any MCP client — Claude Code, Cursor, Cline, Windsurf and more. CCS runtime verification at the tool-call boundary: tools/list baseline, schema consistency, declaration drift, response-stamp, field-order hash. Zero runtime depende

latest
npmnpm
Version
1.1.7
Version published
Weekly downloads
45
-19.64%
Maintainers
1
Weekly downloads
 
Created
Source

correctover-mcp-gateway

Production-grade MCP Security Gateway — CCS runtime verification, bidirectional request/response scanning, Ed25519-signed receipts, policy engine, rate limiting, circuit breaker, protocol-metadata verification, Prometheus metrics, structured logging, zero runtime dependencies.

  • License: Apache-2.0 OR LicenseRef-Commercial (dual: community core + commercial premium features)
  • Node.js: >= 18.0.0
  • Runtime dependencies: 0

Why

Model Context Protocol (MCP) lets AI agents call external tools. Every tools/call is a potential injection, exfiltration, or policy violation vector. Most MCP security proxies only inspect inbound requests — they don't scan what the tool returns to the model.

This gateway enforces security on both sides:

  • Inbound scanning — blocks shell injection, SSRF, credential exfiltration, path traversal, SQLi, command execution, and prompt injection before the request reaches the upstream MCP server.
  • Outbound scanning — blocks secrets, PII, and sensitive filesystem content in tool responses before they reach the model.
  • Protocol-metadata verification — verifies that a server's declared tools/list schema matches its actual behavior (the "lying MCP server" defense).

Every verdict produces a tamper-evident CCS receipt (Ed25519-signed), aligned with draft-correctover-ccs-04.

Quick Start

Install

npm install correctover-mcp-gateway

Run as a standalone gateway (HTTP proxy mode)

npx mcp-gateway \
  --http --target http://your-mcp-server:8000/sse \
  --port 3000 \
  --api-key your-secret-key \
  --policy ./policy.json \
  --sign-receipts \
  --enable-metrics

Point your MCP client at the gateway's /mcp endpoint. All traffic is scanned, policy-enforced, and receipt-logged.

Run as stdio sidecar

npx mcp-gateway --stdio -- python server.py --sign-receipts

Use as an in-process SDK

import { MCPGateway } from 'correctover-mcp-gateway';

const gateway = new MCPGateway({
  mode: 'http',
  target: { url: 'http://your-mcp-server:8000/sse' },
  policy: {
    default_tool_action: 'allow',
    tools: {},
    callers: {},
    scan_output: true,
    sign_receipts: true,
  },
  api_keys: { 'sk-live-xxx': 'app-prod' },
  enable_metrics: true,
});

await gateway.start();

🇨🇳 免费网关之外 · 支付宝 SkillPay

社区版网关可免费部署使用。如果你需要人工深度审计或正式合规凭证,可以在支付宝 SkillPay 货架获取:

  • 货架首页:https://skillpay.alipay.com/public/correctover
  • 也可以在支持「支付宝 AI 付」的智能体对话里直接输入对应服务名唤起购买:
    • MCP配置安全体检:请通过 SkillPay 购买并安装 Skill「MCP配置安全体检」
    • CCS收据批量审计:请通过 SkillPay 购买并安装 Skill「CCS收据批量审计」
    • CCS收据验签:请通过 SkillPay 购买并安装 Skill「CCS收据验签」

Beyond the free gateway: human-led deep audits and compliance evidence are available on the Alipay SkillPay shelf — open the link above, or type the service name (e.g. MCP配置安全体检) in an agent with Alipay AI Pay enabled.

Architecture

Client ──▶ Gateway ──▶ Upstream MCP Server

Gateway pipeline:
  1. Auth (API key / Bearer token)
  2. Rate limit (token bucket)
  3. Circuit breaker (upstream health)
  4. Policy engine (ACL + arg rules)
  5. Input verification (8 rules)
  6. Protocol pre-check (baseline/schema)
  7. Proxy to upstream
  8. Output scan + protocol post-check
  9. Ed25519 receipt signing
  10. Metrics + structured logging

Side outputs: /metrics, /admin/*, receipts/*.jsonl

Security Rules (16 total)

Input Rules (8 — request direction)

IDRuleSeverityBlocks
SEC-001Shell InjectionblockShell metacharacter chains and command substitution
SEC-002SSRF / Internal IPblockLink-local, loopback, and private ranges
SEC-003Cloud Credential ExfiltrationblockCloud secret values in arguments
SEC-004Path TraversalblockParent-directory traversal sequences
SEC-005SQL InjectioncriticalCommon SQLi patterns in inputs
SEC-006Command ExecutionblockEval/exec/system/spawn patterns
SEC-007Prompt Injection — Role OverridecriticalAttempts to override system/developer instructions
SEC-008Prompt Injection — JailbreakcriticalDAN-style jailbreak patterns

Output Rules (8 — response direction)

IDRuleSeverityBlocks
OUT-001AWS Key LeakcriticalAWS access key ID patterns in tool output
OUT-002Private Key LeakblockRSA/OpenSSH private key material in output
OUT-003GitHub Token LeakcriticalGitHub token patterns
OUT-004Generic API Key LeakcriticalHigh-entropy API key patterns
OUT-005PII — Email AddresswarningEmail addresses in response content
OUT-006PII — SSN / ID CardcriticalUS SSN and China Resident ID patterns
OUT-007PII — Credit CardcriticalMajor credit card numbers (Luhn-validated)
OUT-008Password File ContentblockSystem password file content pattern

Protocol-Metadata Verification Layer

The gateway also verifies the declared contract of the upstream server:

CheckBehavior
tools/list baselineCaptures a trust baseline of declared tools and schemas
Undeclared tool invocationBlocked before upstream execution
Input schema mismatchBlocked before upstream execution
Missing baselineBlocked when require_input_schema is enabled (default)
Output schema mismatchBlocked after response is received
Declaration driftWarns on first changes, blocks after repeated unverified drift
Response stampRequires a valid server-signed response stamp when enabled
Field-order hashWarns or blocks when output field order changes

Fail-Closed Design

术语说明:MRTR 是 Multi Round-Trip Requests(多轮交互请求),不是 stamp/receipt。本包统一使用 “response stamp” 表示服务端签名的响应戳。

When verification fails, the gateway returns a structured JSON-RPC error and never proxies the request. When output scanning fails, the response is blocked and the model receives an error instead of leaked data.

Empty or absent carrier fields return INDETERMINATE disposition (aligned with the CCS absence principle) rather than a false ALLOW.

Configuration

CLI Options

FlagEnvDefaultDescription
--http—falseUse Streamable HTTP transport
--stdio—falseUse stdio transport
--target <url>MCP_GATEWAY_UPSTREAM—Upstream MCP server URL (HTTP mode)
--port <n>MCP_GATEWAY_PORT3100HTTP listen port
--host <addr>MCP_GATEWAY_HOSTloopback interfaceListen address
--api-key <key>MCP_GATEWAY_API_KEY—Client API key (Bearer or X-API-Key)
--admin-key <key>MCP_GATEWAY_ADMIN_KEY—Admin API key
--policy <path>MCP_GATEWAY_POLICY—Policy JSON file path
--sign-receiptsMCP_GATEWAY_SIGNfalseEnable Ed25519 receipt signing
--receipt-dir <dir>MCP_GATEWAY_RECEIPTS_DIR./receiptsReceipt storage directory
--enable-metricsMCP_GATEWAY_METRICSfalseEnable Prometheus metrics endpoint
--log-level <level>MCP_GATEWAY_LOG_LEVELinfodebug/info/warn/error
--log-format <fmt>MCP_GATEWAY_LOG_FORMATtextjson or text
--rate-limit <n>MCP_GATEWAY_RATE_LIMIT—Global requests per minute
--max-concurrency <n>MCP_GATEWAY_MAX_CONCURRENCY—Max simultaneous upstream calls
--max-body <bytes>MCP_GATEWAY_MAX_PAYLOAD1048576Max request body size
--timeout <ms>—120000Upstream timeout
--circuit-threshold <n>—5Failures before opening circuit
--circuit-reset <ms>—30000Ms before half-open probe
--retention <days>—90Receipt retention in days
--no-verify——Disable CCS verification
--no-output-scan——Disable output scanning
--no-protocol-verify——Disable protocol-metadata verification
--require-response-stampMCP_GATEWAY_REQUIRE_RESPONSE_STAMPfalseRequire signed server response stamps
--server-public-key <file>——Server public key PEM for response stamps
--response-key-id <id>MCP_GATEWAY_RESPONSE_KEY_ID—Expected response stamp keyId
--field-order <mode>—warnwarn or block for field-order changes

Policy File

The policy file uses the same schema as PolicyConfig:

{
  "default_tool_action": "allow",
  "tools": {
    "search": {
      "action": "allow",
      "rate_limit_rpm": 60,
      "allowed_args": ["query"],
      "denied_args": ["password"]
    },
    "execute_command": {
      "action": "deny"
    }
  },
  "callers": {
    "trusted-agent": {
      "id": "trusted-agent",
      "allowed_tools": ["search", "read_file"],
      "rate_limit_rpm": 120,
      "max_concurrency": 10
    }
  },
  "global_rate_limit_rpm": 1000,
  "global_max_concurrency": 50,
  "max_body_size_bytes": 1048576,
  "scan_output": true,
  "sign_receipts": false,
  "receipt_retention_days": 90
}

Policy changes are hot-reloaded via fs.watch — no restart required.

API Key Authentication

When --api-key is set, all /mcp endpoints require either:

Authorization: Bearer your-secret-key
# or
X-API-Key: your-secret-key

Admin endpoints (/admin/*) require the separate --admin-key.

Commercial License Gate

Protocol-metadata verification can be sold as a premium capability while keeping the base CCS gateway usable in community mode.

mcp-gateway --http --target http://your-mcp-server:8000 \
  --require-license \
  --license-key "v1.<payload>.<signature>" \
  --license-public-key ./license-public.pem
  • When --require-license is enabled and the license is valid, protocol-metadata verification stays on.
  • When the license is missing/expired/invalid, the gateway logs the reason and runs in community mode (scanner-only); base CCS scanning remains available.
  • License format: v1.<base64url(payload)>.<base64url(RSA-SHA256 signature)>.

The license issuance side is available for Correctover's own license server via issueLicense() / generateLicenseKeyPair() (exported from the SDK).

HTTP Endpoints

MethodPathAuthDescription
POST/mcpAPI keyMCP JSON-RPC endpoint (Streamable HTTP)
GET/mcpAPI keySSE stream for server-initiated messages
GET/healthNoneHealth check
GET/metricsAdmin keyPrometheus text exposition format
GET/admin/statsAdmin keyGateway statistics snapshot
GET/admin/policyAdmin keyCurrent policy configuration
POST/admin/policy/reloadAdmin keyForce policy reload from disk
POST/admin/circuit/resetAdmin keyManually reset circuit breaker
GET/admin/receiptsAdmin keyList recent receipts

JSON-RPC Error Codes

CodeConstantMeaning
-32001CCS_BLOCKEDInput verification failed — request blocked
-32002CCS_INDETERMINATEVerification inconclusive (carrier absence)
-32003CCS_OUTPUT_BLOCKEDResponse output scan blocked
-32004RATE_LIMITEDRate limit exceeded
-32005CIRCUIT_OPENCircuit breaker is open
-32006AUTH_REQUIREDMissing or invalid API key
-32007TOOL_DENIEDTool denied by policy
-32008PAYLOAD_TOO_LARGERequest body exceeds limit

Receipts

Every verified call produces a CCS receipt in JSONL format under --receipt-dir. The signature covers canonicalized JSON (sorted keys, no whitespace) using Ed25519. The public key is stored under the receipt key directory.

Performance

Measured on Node.js v22.23.2, 10,000 samples, built-in verifier (gateway mode):

ConfigurationP50P95P99Throughput
No signing2.8 μs5.7 μs14.4 μs~159K calls/sec
Ed25519 signing2.3 μs—9.2 μs~340K calls/sec

Microsecond overhead means the gateway adds negligible latency to MCP call chains.

Docker

docker build -f examples/Dockerfile -t mcp-gateway .

docker run -p 3000:3000 \
  -e MCP_GATEWAY_API_KEY=your-key \
  -e MCP_GATEWAY_UPSTREAM=http://your-mcp-server:8000/sse \
  -v $(pwd)/policy.json:/app/policy.json:ro \
  mcp-gateway

Or use docker-compose:

docker compose -f examples/docker-compose.yml up -d

Framework Integration

Programmatic API

import {
  MCPGateway,
  BuiltinVerifier,
  RateLimiter,
  CircuitBreaker,
  Metrics,
  Logger,
  loadPolicy,
  generateKeyPair,
  signReceipt,
  verifyReceiptSignature,
  ProtocolMetadataVerifier,
  LicenseGate,
  verifyLicense,
  VERSION,
} from 'correctover-mcp-gateway';

Testing

# Build
npm run build

# Run all 103 unit tests
npm test

# Run E2E tests (starts real HTTP server on port 3199)
npm run e2e

# Performance benchmark (10,000 samples)
npm run bench

Test coverage:

  • 77 gateway / core unit tests
  • 19 protocol-metadata verifier tests
  • 7 license gate tests
  • 20 E2E checks

See QUALITY_GATE.md for the 3+9 release gate and VC due-diligence checklist.

Standards Alignment

  • CCS 7 dimensions: Structure / Schema / Latency / Cost / Identity / Integrity / Security
  • Receipt format: Aligned with draft-correctover-ccs-04
  • Transport: MCP Streamable HTTP (2025-03-26 spec)
  • Signature: Ed25519 (RFC 8032)
  • Metrics: Prometheus text exposition format

Zero Runtime Dependencies

Every feature — Ed25519 signing, rate limiting, circuit breaker, Prometheus metrics, JSON logging, policy engine, license verification — is implemented using only Node.js built-in modules. No third-party runtime dependencies means zero supply-chain attack surface from the gateway itself.

License

Dual-licensed:

  • Community core: Apache License 2.0
  • Premium protocol-metadata verification / License Gate: commercial license required

See QUALITY_GATE.md for commercial gate details.

Keywords

mcp

FAQs

Package last updated on 29 Sep 2026

Related posts