npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@purplesquirrel/guardrails-mcp-server

v1.0.3

Published

AI Agent Guardrails MCP Server - Security layer for Claude Code and AI agents

Readme

License: MIT

npm version npm downloads License: MIT

MCP Security CI OpenSSF Scorecard

AI Guardrails MCP Server

MCP server providing security guardrails for Claude Code and AI agents. Implements input validation, output filtering, policy enforcement, and audit logging.

Features

  • Input Validation - Sanitize and validate all inputs before processing
  • Output Filtering - Redact sensitive data from responses
  • Policy Enforcement - Enforce custom security policies
  • Audit Logging - Complete audit trail of all requests
  • Rate Limiting - Protect against abuse and overuse

Architecture

User Request
     │
     ▼
┌─────────────────────────────────────┐
│       Guardrails Engine             │
├─────────────────────────────────────┤
│  ┌─────────┐  ┌──────────────────┐  │
│  │  Rate   │  │     Input        │  │
│  │ Limiter │──▶   Validator      │  │
│  └─────────┘  └────────┬─────────┘  │
│                        │            │
│               ┌────────▼─────────┐  │
│               │     Policy       │  │
│               │     Engine       │  │
│               └────────┬─────────┘  │
│                        │            │
│               ┌────────▼─────────┐  │
│               │     Output       │  │
│               │     Filter       │  │
│               └────────┬─────────┘  │
│                        │            │
│  ┌─────────────────────▼─────────┐  │
│  │        Audit Logger           │  │
│  └───────────────────────────────┘  │
└─────────────────────────────────────┘
     │
     ▼
  Response

Components

GuardrailsEngine (src/engine/GuardrailsEngine.js)

Core orchestration engine that coordinates all security components:

import { GuardrailsEngine } from './src/engine/GuardrailsEngine.js';

const engine = new GuardrailsEngine({
  enableInputValidation: true,
  enableOutputFiltering: true,
  enablePolicyEnforcement: true,
  enableAuditLogging: true,
  enableRateLimiting: true,
  maxRequestsPerMinute: 60,
});

// Process incoming request
const result = await engine.processInput(request, { userId: 'user123' });

// Filter outgoing response
const filtered = await engine.processOutput(response, context);

InputValidator (src/validators/InputValidator.js)

Validates and sanitizes incoming requests:

  • Pattern matching for blocked content
  • Size and token limits
  • Character encoding validation
  • SQL injection detection
  • XSS prevention

OutputFilter (src/filters/OutputFilter.js)

Filters and redacts sensitive information from outputs:

  • PII detection and redaction (SSN, credit cards, emails)
  • API key/secret detection
  • Custom pattern redaction
  • Configurable replacement text

PolicyEngine (src/policies/PolicyEngine.js)

Enforces custom security policies:

  • Allow/deny lists for operations
  • Domain restrictions
  • Resource access controls
  • Custom policy rules

AuditLogger (src/audit/AuditLogger.js)

Comprehensive audit logging:

  • Request/response logging
  • Policy violation tracking
  • Rate limit events
  • Searchable log queries

Configuration

const config = {
  // Feature toggles
  enableInputValidation: true,
  enableOutputFiltering: true,
  enablePolicyEnforcement: true,
  enableAuditLogging: true,
  enableRateLimiting: true,

  // Rate limiting
  maxRequestsPerMinute: 60,
  maxTokensPerRequest: 100000,

  // Security patterns
  blockedPatterns: [
    /password\s*[:=]/i,
    /api[_-]?key/i,
  ],

  // Domain restrictions
  allowedDomains: ['api.example.com'],

  // Sensitive data patterns for redaction
  sensitiveDataPatterns: [
    { pattern: /\b\d{3}-\d{2}-\d{4}\b/, replacement: '[SSN REDACTED]' },
    { pattern: /\b\d{16}\b/, replacement: '[CARD REDACTED]' },
  ],
};

Installation

cd ~/guardrails-mcp-server
npm install

Usage with Claude Code

Add to ~/.claude.json:

{
  "mcpServers": {
    "guardrails": {
      "type": "stdio",
      "command": "node",
      "args": ["/path/to/guardrails-mcp-server/index.js"]
    }
  }
}

Use Cases

Enterprise AI Deployments

  • Ensure all AI interactions comply with security policies
  • Prevent data leakage through output filtering
  • Maintain audit trails for compliance

Multi-Tenant Systems

  • Rate limiting per user/tenant
  • Policy isolation between tenants
  • Usage tracking and billing

Regulated Industries

  • Healthcare: HIPAA compliance with PHI detection
  • Finance: PCI-DSS with card number redaction
  • Government: Data classification enforcement

API

processInput(request, context)

Process and validate an incoming request.

Returns:

{
  allowed: boolean,
  requestId: string,
  request: object,  // Sanitized request
  processingTime: number,
  // If blocked:
  reason: string,
  code: 'RATE_LIMIT' | 'VALIDATION_ERROR' | 'POLICY_VIOLATION',
  violations: array,
}

processOutput(response, context)

Filter and redact sensitive data from a response.

Returns:

{
  filtered: boolean,
  response: object,  // Filtered response
  redactions: array, // List of redactions applied
  processingTime: number,
}

getStats()

Get current engine statistics.

getAuditLogs(filter)

Query audit logs with optional filtering.

Files

guardrails-mcp-server/
├── package.json
├── README.md
├── src/
│   ├── engine/
│   │   └── GuardrailsEngine.js    # Core engine
│   ├── validators/
│   │   └── InputValidator.js      # Input validation
│   ├── filters/
│   │   └── OutputFilter.js        # Output filtering
│   ├── policies/
│   │   └── PolicyEngine.js        # Policy enforcement
│   └── audit/
│       └── AuditLogger.js         # Audit logging
├── tests/
└── docs/

Author

Matthew Karsten - Purple Squirrel Media

License

MIT

💜 Support This Project

If this MCP server is useful to you, consider supporting its development:

GitHub Sponsors Buy Me a Coffee

Enterprise support available - Contact us for SLAs, custom development, and priority support.