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

@reaatech/tool-use-firewall-core

v0.2.0

Published

Core types, errors, and utilities for tool-use-firewall

Readme

@reaatech/tool-use-firewall-core

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Core types, error classes, structured logger, sensitive data redactor, and ReDoS-safe regex utilities for tool-use-firewall. This is the foundational package used by every other @reaatech/tool-use-firewall-* package.

Installation

npm install @reaatech/tool-use-firewall-core
# or
pnpm add @reaatech/tool-use-firewall-core

Feature Overview

  • Request context typesRequestContext, Middleware, MiddlewareResult, InterceptorResponse for building the interceptor pipeline
  • Typed error hierarchyFirewallError, RateLimitError, ValidationError, PolicyViolationError, BudgetExceededError, ApprovalRequiredError — all with error codes
  • Structured logger — JSON logging to stderr (never stdout) to avoid corrupting MCP JSON-RPC streams
  • Sensitive data redactor — Pattern-based redaction of API keys, bearer tokens, emails, and custom patterns
  • ReDoS-safe regexsafeRegExp() and isSafeRegex() with nested quantifier detection, depth limits, and length caps
  • Glob-to-regex conversionglobToRegex() for tool name pattern matching
  • Zero runtime dependencies — lightweight and tree-shakeable

Quick Start

import { FirewallError, Logger, redact, safeRegExp } from "@reaatech/tool-use-firewall-core";

// Throw typed errors
throw new FirewallError({ code: "POLICY_VIOLATION", message: "Blocked by policy" });

// Structured logging (writes to stderr)
const log = new Logger("MyService");
log.info("Request processed", { toolName: "db_query", latency: 42 });

// Redact sensitive data
const safe = redact({ api_key: "sk-1234", query: "SELECT 1" });
// → { api_key: "[REDACTED]", query: "SELECT 1" }

// Safe regex compilation
const re = safeRegExp("^SELECT\\s+.*$", "i");

Exports

Types

| Export | Description | |--------|-------------| | RequestContext | Immutable request metadata flowing through the pipeline: requestId, sessionId, method, toolName, arguments, metadata | | createRequestContext | Factory for constructing a RequestContext with receivedAt timestamp and empty metadata map | | Middleware | Interface: execute(context: RequestContext): Promise<MiddlewareResult> | | MiddlewareAction | Union: 'CONTINUE' | 'BLOCK' | 'APPROVAL_REQUIRED' | | MiddlewareResult | { action, reason?, metadata? } | | InterceptorResponse | { allowed, action, reason?, metadata? } |

Error Classes

| Class | Code | Description | |-------|------|-------------| | FirewallError | (custom) | Base error with code, message, requestId, details, toJSON() | | PolicyViolationError | POLICY_VIOLATION | Blocked by a policy rule | | RateLimitError | RATE_LIMIT_EXCEEDED | Rate limit hit, includes retryAfterMs | | ValidationError | VALIDATION_ERROR | Argument validation failed | | BudgetExceededError | BUDGET_EXCEEDED | Session cost budget exceeded | | ApprovalRequiredError | APPROVAL_REQUIRED | Human approval required, includes approvalId |

Utilities

| Export | Description | |--------|-------------| | Logger | JSON structured logger, writes to stderr (never stdout) | | redact | Deep-redact values using pattern matching | | DEFAULT_REDACTION_PATTERNS | Built-in patterns: API keys, bearer tokens, emails | | safeRegExp(pattern, flags?) | Compile a regex safely, throws UnsafeRegexError on ReDoS patterns | | isSafeRegex(pattern) | Boolean check for ReDoS safety | | globToRegex(pattern) | Convert *-wildcard glob to anchored regex | | UnsafeRegexError | Thrown by safeRegExp when a pattern is rejected as unsafe |

Related Packages

License

MIT