Redacts sensitive credentials and prunes framework noise from error logs to optimize context for AI coding agents.
Also known as daffa2555/Tokenectomy, tokenectomy
- Stars
- 6
- Tools
- 5
- Downloads, 30 days
- โ
- Latest version
- 1.1.1
- Last commit
- Nov 13, 2026
- License
- MIT
What is Tokenectomy Razor MCP?
Tokenectomy Razor redacts sensitive credentials and prunes framework noise from error logs to optimize context for AI coding agents. It exposes 5 tools, such as get_error_context, analyze_code, apply_code_patch.
Summary generated from the project's README
About Tokenectomy Razor MCP server
Developers using AI coding agents like Claude Code, Cursor, or Cline can use Tokenectomy Razor to reduce token consumption and protect sensitive data. This tool acts as a local AI gateway and MCP server that intercepts outbound prompts to prune unnecessary framework noise from error logs. By stripping out massive stack traces from directories like node_modules or site-packages, it prevents agents from getting lost in third-party library internals.
Users set up the server locally on 127.0.0.1:8080, which can then be connected to various agents via environment variables or specific MCP configuration files. The system provides sub-millisecond redaction of database URIs, JWTs, and API keys before they reach upstream providers like Anthropic, OpenAI, or local models via Ollama. It also features a built-in prompt cache and a real-time dashboard to monitor token savings and security redactions.
What you can do with it
- 1Reduce AI token costsAn AI agent can process much smaller error logs by removing thousands of lines of third-party library code.
- 2Prevent credential leakageThe server automatically scrubs database passwords and API keys from error traces before they are sent to an LLM.
- 3Cross-provider model compatibilityYou can use Claude Code with models from other providers by having the gateway transpile the request formats.
Written from the project's README. Every use case is checked against a quote from it.
Tokenectomy Razor MCP tools 5
Detected from the READMEget_error_contextanalyze_codeapply_code_patchsearch_stack_overflowaudit_context_health
Automated checks
Ran Nov 13, 2026Full report โPassed our automated checks. That is not a security audit: read the code and give the server the narrowest access it needs. How checks work
- Source repository linked and reachablePass
- Open source license (OSI)Pass
- Commit or release in the last yearPass
- Package name not close to a popular packageNot checked
- Remote endpoint uses HTTPSNot checked
- Destructive tools are labelledPass
- No hidden instructions to the modelPass
- No critical advisory in the package or its dependenciesNot checked
README
View on GitHub โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Autonomous Agents โ
โ Claude Code โข Cursor โข Antigravity โข Cline โข Windsurf โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ (HTTP / SSE Outbound Prompts)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โก TOKENECTOMY AI GATEWAY (127.0.0.1:8080) โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Zero-Cost Prompt โ โ Zero-Leak Credential โ โ Polyglot Trace Surgery โ โ
โ โ Cache โ โ Redaction โ โ (9 Languages) โ โ
โ โ <1ms Hit โข 100% Free โ โ API Keys โข JWTs โข DB URIsโ โ node_modules โข site-packages โข .cargo โ โ
โ โโโโโโโโโโโโโฌโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โผ โ
โ Smart Upstream Auto-Router โ
โ (Anthropic โข OpenAI โข Groq โข Ollama Local) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ โผ โผ
api.anthropic.com api.openai.com localhost:11434
(Claude 3.5 / 3.7 Sonnet) (GPT-4o / o1 / o3-mini) (DeepSeek / Llama)
โก Quick Start (10s)
0. Zero-Config One-Liner Wrapper (wrap)
Run any coding agent or test suite directly behind Tokenectomy's privacy & caching gateway with zero manual environment variable setup:
# Wrap Claude Code CLI
razor wrap -- claude
# Wrap Aider with DeepSeek or Ollama (Auto-Transpiled on the fly!)
razor wrap -- aider --model deepseek/deepseek-chat
# Wrap test runs to scrub logs and prevent accidental credential leakage
razor wrap npm test
1. Launch the Standalone AI Gateway (Manual Mode)
npx -y tokenectomy-razor --proxy
๐ก Smart Multi-Provider Auto-Routing & Universal LLM Transpiler ON by default! Tokenectomy automatically analyzes request paths and headers. Need to run Claude Code against DeepSeek or Ollama? Tokenectomy transparently transpiles Anthropic
/v1/messagesformat into OpenAI/v1/chat/completionson-the-fly and vice-versa.
2. Connect Your Favorite Agent
Point your coding agent or CLI to the local gateway on 127.0.0.1:8080:
| Agent / Environment | Setup Command or Configuration | Auto-Routed Upstream |
|---|---|---|
| Claude Code | export ANTHROPIC_BASE_URL="http://127.0.0.1:8080" |
https://api.anthropic.com |
| Cursor | Models > OpenAI Base URL: http://127.0.0.1:8080/v1 |
https://api.openai.com |
| Google Antigravity / Gemini | export OPENAI_BASE_URL="http://127.0.0.1:8080/v1" |
https://api.openai.com |
| Cline / Roo Code | Provider: OpenAI Compatible โข Base URL: http://127.0.0.1:8080/v1 |
https://api.openai.com |
| Ollama / Local LLMs | Base URL: http://127.0.0.1:8080 |
http://localhost:11434 |
3. Real-Time FinOps & Security Dashboard
Open http://127.0.0.1:8080/dashboard in your browser to observe live token reductions, prompt cache hits, dollar savings, and redacted credentials in real time.
4. Companion MCP Server Setup (Sub-Cortex)
For agents calling deep diagnostic tools (get_error_context, analyze_code, apply_code_patch):
Claude Code CLI
claude mcp add tokenectomy npx -y tokenectomy-razor --mcp
Google Antigravity / Gemini CLI
agy mcp add tokenectomy-razor -- npx -y tokenectomy-razor --mcp
Cursor Composer (.cursor/mcp.json)
{
"mcpServers": {
"tokenectomy": {
"command": "npx",
"args": ["-y", "tokenectomy-razor", "--mcp"]
}
}
}
Claude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"tokenectomy": {
"command": "npx",
"args": ["-y", "tokenectomy-razor", "--mcp"]
}
}
}
5. Terminal Piping & CLI Scrubbing
npm test 2>&1 | npx tokenectomy-razor
๐ The Problem: Why Your AI Hits Rate Limits & Hallucinates
When your app crashes during development (Next.js, Express, FastAPI, Tokio), the runtime dumps hundreds of lines of third-party plumbing from node_modules or site-packages.
When you paste that raw crash dump into Cursor or Claude:
- Eats Your 5-Hour Rate Limit: A single Express/Prisma error can dump 5,000 to 45,000 tokens of third-party library code you never wrote. A few crash loops easily burn your session limit.
- Triggers AI Hallucinations: Claude gets lost in framework internals (
node_modules/express/lib/router/layer.jsorstarlette/routing.py) and tries to edit library files instead of your actual application code. - Leaks Secrets & Credentials: Connection strings with raw database passwords, JWT bearer tokens, and cloud keys embedded in error traces get forwarded to external model servers.
Raw Terminal Crash (45,820 tokens + Leaked Secrets)
โ
โผ <0.2ms Local Rust DFA Engine
[Redact Passwords & Keys] โโโบ [Strip Third-Party Framework Frames] โโโบ [Isolate Root Cause]
โ
โผ
Clean Context (118 tokens โข Zero Secrets โข Sub-millisecond)
๐ Before & After Comparison
โ Without Tokenectomy: AI Hallucinates & Burns Context
TypeError: Cannot read properties of undefined (reading 'token')
at loadComponents (/app/node_modules/next/dist/server/load-components.js:14:2)
at renderToHTML (/app/node_modules/next/dist/server/render.js:50:5)
at nextServer (/app/node_modules/next/dist/server/next-server.js:80:12)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runMicrotasks (node:internal/process/task_queues:120:3)
at checkoutHandler (/app/pages/api/checkout.ts:42:15)
Database connection failed: postgresql://admin:super_secret_password@db.prod.internal:5432/primary
API key leaked: sk-ant-api03-abcdef1234567890abcdef1234567890
What Claude does: Analyzes
load-components.jsandnext-server.js, speculates on Webpack / Next.js internals, and leaks connection credentials to remote inference logs.
โ With Tokenectomy: Clean Context & Instant Fix
// [Tokenectomy Surgery: 5 internal framework frames pruned (83.3%)]
// Source: /app/pages/api/checkout.ts:42:15
42 | const sessionToken = req.headers.authorization.token;
| ^ TypeError: Cannot read properties of undefined (reading 'token')
๐ก๏ธ [CONNECTION_STRING_REDACTED]
๐ก๏ธ [ANTHROPIC_KEY_REDACTED]
What Claude does: Instantly identifies that line 42 in
checkout.tsattempted to access.tokenon undefined headers. Suggests optional chainingreq.headers.authorization?.tokenimmediately. Credentials redacted before transmission.
๐ฌ Verifiable Benchmarks
All performance claims are hardware-grounded and independently reproducible on physical hardware (measured on 10-Core Intel Core i5-1235U @ 15W running Arch Linux, Kernel 6.13):
Hardware Dependency Notice: Performance is hardware-dependent; reported throughput represents measured results on the specified test hardware (10-Core Intel Core i5-1235U @ 15W TDP). Throughput scales with higher TDP desktop/server CPUs and faster memory buses. Developers are encouraged to independently audit performance using the reproduction command below.
$ cargo test --release --test stress_benchmark -- --nocapture
=====================================================================================
๐งช TOKENECTOMY OSS VERIFIABLE HEAVY STRESS BENCHMARK (100% REPRODUCIBLE IN OSS)
Hardware: 10-Core / 12-Thread Intel Core i5-1235U | OS: Arch Linux | Kernel Telemetry Active
Initial Baseline Process Memory (VmRSS): 3.45 MB
=====================================================================================
๐ฅ [TEST 1/3] QUARTER-MILLION LINES LOG REDACTION TORTURE (250,000 LINES / 25MB+ BUFFER)
โโโ Buffer Size: 24.44 MB (250000 lines)
โโโ Redaction Latency: 471.05ms (51.9 MB/sec)
โโโ Line Throughput: 530,735 lines/sec
โโโ Peak Memory (VmRSS): 76.05 MB (Delta: +72.60 MB)
โโโ Status: โ
PASSED (100% of 250,000 lines sanitized, zero memory balloon)
๐ฅ [TEST 2/3] REDOS CATASTROPHIC BACKTRACKING TORTURE (50,000 CHARS PAYLOAD)
โโโ Attack Payload Size: 50,082 characters
โโโ Execution Latency: 1.165 ms
โโโ Status: โ
PASSED (Linear O(N) evaluation, ReDoS-resistant on tested payloads)
๐ฅ [TEST 3/3] HIGH-CONCURRENCY TORTURE (100 PARALLEL OS THREADS)
โโโ Thread Concurrency: 100 concurrent OS threads
โโโ Successful Operations: 100/100 (100.0%)
โโโ Total Elapsed: 11.31ms
โโโ Concurrency Throughput: 17,688 ops/sec
โโโ Final VmRSS: 78.99 MB
โโโ Status: โ
PASSED (Zero race condition, zero deadlock)
=====================================================================================
๐ TOKENECTOMY OSS STRESS BENCHMARK: 3/3 PASSED (100% GREEN)
Total Suite Duration: 580.83ms
Bounded Final VmRSS: 78.99 MB
=====================================================================================
test test_oss_heavy_stress_benchmark ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.58s
| Benchmark Target | Workload Under Test | Verified Measurement | Result |
|---|---|---|---|
| Log Redaction Throughput | 250,000 lines (24.44 MB) enterprise dump with API keys & connection URIs | 530,735 lines/sec (471.0 ms, 51.9 MB/s) | Pass |
| ReDoS Resilience | 50,000-character pathological backtracking regex payload | 1.16 ms (Deterministic Linear $O(N)$ DFA Evaluation) | Pass |
| Thread Concurrency | 100 concurrent OS threads executing simultaneous redaction | 17,688 ops/sec (100/100 completed in 11.31 ms) | Pass |
| Memory Footprint | Peak Resident Memory during 250k-line continuous stress test | 76.05 MB VmRSS via /proc/self/status (~3ร input buffer size) |
Pass |
| Release Test Suite | Full integration test matrix across extractors, filters, and analyzers | 90 / 90 Verified Green (Zero panics, zero leaks) | Pass |
๐ก๏ธ Automated Redaction & Secret Sanitization Benchmark
Evaluated across an internal benchmark test fixture (tests/fixtures/) of 12 polyglot crash traces (Rust, Python, TypeScript, Go, YAML) containing 22 ground-truth credentials and clean negative controls. Evaluated head-to-head against Gitleaks v8.30.1 (default ruleset).
Architectural Note: Gitleaks is designed primarily as a repository commit/diff scanner, not an in-memory runtime trace redactor. Tokenectomy Razor is engineered specifically for runtime stream sanitization and stack trace surgery.
1. Per-Category Precision, Recall & F1-Score
| Secret Category | Ground Truth | Razor Recall | Razor F1 | Gitleaks Recall | Gitleaks F1 | Sanitization Advantage |
|---|---|---|---|---|---|---|
Anthropic Claude API Key (sk-ant-...) |
1 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
AWS Access Key ID (AKIA...) |
1 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
| AWS Secret Access Key | 1 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
| Database URI (PostgreSQL, MySQL, Redis, Mongo) | 4 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
| Generic Passwords / Auth Secrets (YAML/JSON) | 3 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
GitHub Personal Access Token (ghp_...) |
1 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
GitLab Personal Access Token (glpat-...) |
1 | 100.0% | 100.0% | 100.0% | 100.0% | Parity (100% caught) |
HuggingFace API Token (hf_...) |
1 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
| JSON Web Token (RFC 7519 / Truncated) | 2 | 100.0% | 100.0% | 100.0% | 100.0% | Parity (100% caught) |
npm Registry Access Token (npm_...) |
1 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
OpenAI API Key (sk-..., sk-proj-...) |
1 | 100.0% | 100.0% | 100.0% | 100.0% | Parity (100% caught) |
| PEM Private RSA Key Block | 1 | 100.0% | 100.0% | 100.0% | 100.0% | Parity (100% caught) |
PyPI Package Upload Token (pypi-AgEI...) |
1 | 100.0% | 100.0% | 100.0% | 100.0% | Parity (100% caught) |
SendGrid API Key (SG...) |
1 | 100.0% | 100.0% | 0.0% | 0.0% | +100% Recall (M2M zero-leak) |
Slack Bot/User Token (xoxb-...) |
1 | 100.0% | 100.0% | 100.0% | 100.0% | Parity (100% caught) |
Stripe Live/Test Secret Key (sk_live_...) |
1 | 100.0% | 100.0% | 100.0% | 100.0% | Parity (100% caught) |
2. Head-to-Head Performance & Architectural Summary
| Dimension | Tokenectomy Razor (--scrub) |
Gitleaks v8.30.1 | Architectural Rationale |
|---|---|---|---|
| Overall Secret Recall | 100.0% (22/22) | 36.4% (8/22) | Razor captures unquoted URIs, DB ports & AI keys missed by diff rules |
| Overall Precision | 100.0% (0 False Positives) | 88.9% | Zero false triggers on compiler errors & minified traces |
| Overall F1-Score | 100.0% (internal fixture) | 51.6% | Comprehensive coverage engineered specifically for crash context |
| Execution Engine | High-throughput Rust DFA ($O(N)$) | Go regex scanner + Git tree crawler | Sub-millisecond latency for agent streaming backtraces |
| ReDoS Resilience | Deterministic Linear Time ($O(N)$) | Engine dependent | Non-backtracking DFA regex prevents catastrophic backtracking on tested dumps |
| Sanitization Action | Inline token redaction ([KEY_REDACTED]) |
Warning log only (No scrub) | Directly sanitizes text before ingestion by LLM cortex |
3. Token Reduction & LLM Context Savings (tiktoken cl100k_base)
| Metric | Measured Value | Operational Impact for AI Coding Agents |
|---|---|---|
| Mean Token Reduction | 41.67% | Consistently shrinks raw crash trace token footprint |
| Median Reduction (P50) | 42.95% | Typical credential and connection dump reduction |
| 90th Percentile (P90) | 61.42% | Eliminates long multi-line keys and credentials |
| Min / Max Spread | 0.00% โ 81.36% | 0% on clean negative controls (zero distortion), up to 81.4% on leaks |
| Total Tokens Preserved / Saved | 920 tokens (44.02% net) | Prevents context window saturation and reduces LLM billing |
๐ Advanced Agent & Gateway Configuration
1. Multi-Provider AI Gateway Options (--proxy)
Tokenectomy's gateway runs locally on 127.0.0.1:8080 with zero manual configuration. In complex development environments or containerized agent topologies, you can customize binding and routing:
# Default Smart Auto-Routing (routes Anthropic, OpenAI, and Ollama requests dynamically):
razor --proxy
# Safety Circuit Breaker: Prevent runaway agent loops from burning your hourly budget or 5-hour window:
razor --proxy --max-hourly-tokens 200000
# Resilient 429 Auto-Retry: Automatically pause and retry when hitting upstream rate limits (default: on):
razor --proxy --max-retries 5
# Explicit upstream override (e.g. Groq, vLLM, or OpenRouter):
razor --proxy --upstream-url https://api.groq.com/openai/v1
# Secure remote container binding with mandatory bearer token:
razor --proxy --proxy-bind 0.0.0.0:8080 --allow-remote --proxy-token "$MY_GATEWAY_TOKEN"
Real-Time Metrics & Prometheus Export
Tokenectomy exposes live FinOps and token economics data via JSON:
curl http://127.0.0.1:8080/v1/metrics
Returns instant telemetry for rate_limits_mitigated, circuit_breaker_trips, last_latency_ms, current_hourly_tokens, cache_hits, cache_tokens_saved, and estimated_cost_saved_usd.
2. Standalone CLI & Terminal Scrubbing
When debugging or piping terminal test output directly:
# Pipe terminal test failures through the surgical redactor:
npm test 2>&1 | razor --scrub
# Sanitize a specific raw log file:
razor --scrub --file /var/log/app/error.log > sanitized.log
# Offline local air-gapped mode (zero external network calls):
cat failure.log | razor --scrub --local-only
๐ ๏ธ Exposed MCP Tools
Tokenectomy Razor complies with Glama Grade A Tool Definition Quality Score (TDQS) with explicit parameter boundaries:
| Tool Name | Capability Description |
|---|---|
get_error_context |
Performs trace surgery on error dumps, removes framework noise, redacts credentials, and extracts relevant local source context bounded to the workspace. |
analyze_code |
Performs static AST code analysis to detect resource leaks, unclosed handles, and syntax vulnerabilities with bounded execution limits and precise LSP UTF-16 coordinates. |
apply_code_patch |
Applies atomic file modifications with post-write language syntax verification (cargo check, py_compile, node --check) and automated rollback on failure. |
search_stack_overflow |
Queries Stack Exchange API for relevant error signatures using sanitized, redacted search terms. |
audit_context_health |
Audits raw logs, traces, or prompt payloads for token bloat, framework noise, and credentials. Returns M2M telemetry, savings metrics, and context health grades. |
๐ Supported Polyglot Ecosystems
| Language | Frameworks Supported | Excluded Framework Internals |
|---|---|---|
| Rust | Tokio, Actix-web, Axum | .cargo/registry, .rustup, target/debug/build |
| TypeScript / JS | Next.js, Express, NestJS, Vite | node_modules, .next, dist, webpack internals |
| Python | Django, FastAPI, Flask, PyTorch | site-packages, dist-packages, venv, __pycache__ |
| Golang | Gin, Fiber, Stdlib Panics | go/src (stdlib), go/pkg/mod, vendor |
| Java / Kotlin | Spring Boot 3, Tomcat, Netty | .m2/repository, .gradle/caches, internal bytecode |
| C / C++ | AddressSanitizer, GDB / LLDB | /usr/include, /usr/lib, vcpkg_installed |
| C# (.NET) | ASP.NET Core, .NET Runtime | System.Private.CoreLib, Microsoft.AspNetCore |
| Ruby on Rails | Rails, Sinatra, Bundler | /gems/, ruby/gems, internal rack handlers |
| PHP | Laravel, Symfony | vendor/composer, vendor/symfony |
๐ฆ Installation Options
Method 1: Instant via npx (Zero Toolchain Setup)
npx -y tokenectomy-razor --mcp
Method 2: Cargo (crates.io)
cargo install tokenectomy
Method 3: Precompiled Standalone Binaries
Zero-dependency, standalone release binaries available on GitHub Releases:
- Linux:
x86_64-unknown-linux-gnu,x86_64-unknown-linux-musl,aarch64-unknown-linux-gnu - macOS:
aarch64-apple-darwin(Apple Silicon M1/M2/M3/M4),x86_64-apple-darwin(Intel) - Windows:
x86_64-pc-windows-msvc.exe
Method 4: Multi-Arch Docker Container (GHCR)
docker pull ghcr.io/tokenectomy-labs/razor:latest
docker run -i ghcr.io/tokenectomy-labs/razor:latest --mcp
Tokenectomy Razor MCP questions
What tools does Tokenectomy Razor MCP provide?
It exposes 5 tools, including get_error_context, analyze_code, apply_code_patch, search_stack_overflow, audit_context_health.
How does Tokenectomy Razor help with AI rate limits?
It excises framework noise from terminal error logs, reducing token usage by 41.7% to 99.7% so you don't burn through your session limits with third-party library code.