When you wire an AI coding agent (Claude Code, Cursor, VS Code Copilot, or Claude Desktop) into a real backend repository, secret leakage rarely happens because someone deliberately uploads .env.production.
It happens silently during normal debugging loops:
- A failing integration test prints a connection error containing
postgresql://svc_billing:Pr0dP4ss!@10.24.8.15:5432/ledger. - A curl trace or Kubernetes ConfigMap dump includes an active
Authorization: Bearer eyJ...JWT, ansk-proj-...OpenAI key, or an internal corporate hostname. - If you manually scrub values into
***REDACTED***before prompting the model, two things break immediately:- Lost referential equality: When
service-a/.envanddocker-compose.ymlhold different API keys (a classic config-drift bug), replacing both with***REDACTED***blinds the LLM to the mismatch. - Broken code round-trips: Every refactored snippet the LLM hands back now has literal
***REDACTED***strings baked in, forcing error-prone manual copy-paste restoration.
- Lost referential equality: When
Here is how we built PasteShield (v1.1.2) — an open-source, zero-dependency local stdio Model Context Protocol (MCP) server (and VS Code / Cursor extension) that solves both problems in volatile local RAM.
Why Zero node_modules Matters for a Security MCP Server
Most MCP tutorials start with npm install @modelcontextprotocol/sdk zod. That is great for general API wrappers,-but a secret-sanitizing MCP server sits directly in front of raw credentials. Pulling in 80+ transitive npm packages creates an unnecessary supply-chain surface.
Because MCP's local stdio transport is simply newline-delimited JSON-RPC 2.0 over stdin / stdout, you can implement a complete, spec-compliant MCP server in ~120 lines of pure built-in Node.js (readline, fs, path):
#!/usr/bin/env node 'use strict'; const readline = require('readline'); const PasteShieldCore = require('../sanitizer-core'); // Volatile in-process RAM vault — never written to disk or sent over the network const sessionVault = PasteShieldCore.createVault(); const rl = readline.createInterface({ input: process.stdin, terminal: false }); function sendJsonRpc(id, result) { process.stdout.write(JSON.stringify({ jsonrpc: '2.0', id, result }) + '\n'); } rl.on('line', async (line) => { if (!line.trim()) return; const msg = JSON.parse(line); if (msg.method === 'initialize') { return sendJsonRpc(msg.id, { protocolVersion: '2024-11-05', capabilities: { tools: {} }, serverInfo: { name: 'pasteshield-secret-sanitizer', version: '1.1.2' } }); } if (msg.method === 'tools/list') { return sendJsonRpc(msg.id, { tools: TOOLS }); } if (msg.method === 'tools/call') { const output = await handleToolCall(msg.params); return sendJsonRpc(msg.id, output); } }); Zero dependencies means:
-
npm auditis permanently0 vulnerabilities. - Cold-start latency over
stdiois<15ms. - Anyone on your security team can audit the entire codebase in five minutes.
Bijective Semantic Placeholders Instead of ***REDACTED***
Instead of destructive masking, sessionVault.sanitize(text) maintains two private Map instances inside a lexical closure (secretToToken and tokenToSecret):
# Raw local snippet: OPENAI_API_KEY=sk-proj-9a8b7c6d5e4f3g2h1i0j9k8l7m6n5o4p FALLBACK_OPENAI_KEY=sk-proj-9a8b7c6d5e4f3g2h1i0j9k8l7m6n5o4p WORKER_OPENAI_KEY=sk-proj-DIFFERENT887766554433221100aabbcc DATABASE_URL="postgresql://svc_app:Pr0dP4ss!@10.24.8.15:5432/orders" Calling sanitize_snippet produces:
OPENAI_API_KEY=<OPENAI_KEY_1> FALLBACK_OPENAI_KEY=<OPENAI_KEY_1> WORKER_OPENAI_KEY=<OPENAI_KEY_2> DATABASE_URL="<DB_URI_1>" Notice what the cloud LLM can still reason about without seeing a single secret byte:
- It sees semantic types (
OPENAI_KEYvsDB_URIvsBEARER_JWTvsINTERNAL_IP). - It immediately spots that
OPENAI_API_KEYandFALLBACK_OPENAI_KEYare identical (<OPENAI_KEY_1>), whereasWORKER_OPENAI_KEYis a second key (<OPENAI_KEY_2>). - When the LLM outputs refactored TypeScript, Python, or YAML referencing
<OPENAI_KEY_1>and<DB_URI_1>, callingrestore_snippetswaps the real credentials back locally in<1ms.
Masked-Only Workspace Secret Audits (audit_workspace_secrets)
Giving an agent raw grep access over .env* files risks dumping live keys straight into the model's context window. PasteShield's third MCP tool, audit_workspace_secrets, scans a directory locally and returns only masked previews (sk-p...5o4p, category, file path, and line number) — so your agent can locate and remediate hardcoded secrets before git commit without ever ingesting the plaintext credential itself.
Try It in 10 Seconds (Claude Desktop, Cursor, VS Code)
Drop this into your claude_desktop_config.json, .cursor/mcp.json, or .vscode/mcp.json (requires Node 16+):
{ "mcpServers": { "pasteshield": { "command": "npx", "args": ["-y", "github:963239327/pasteshield-secret-sanitizer", "--mcp"] } } } Prefer one-keystroke IDE shortcuts (Cmd+Alt+C to copy sanitized code for AI, Cmd+Alt+R to restore AI replies in clipboard)? PasteShield v1.1.2 is also live on both registries:
- GitHub Source & MCP Server (MIT): github.com/963239327/pasteshield-secret-sanitizer
- VS Code Marketplace: craftleaf-studio.pasteshield-ai-secret-sanitizer
- Open VSX (Cursor / Windsurf / VSCodium): open-vsx.org/extension/craftleaf-studio/pasteshield-ai-secret-sanitizer
- Interactive Browser Sandbox (100% Client-Side): Live PasteShield Playground
What guardrails are you running around .env files and local MCP servers in your agent workflows? Happy to compare notes in the comments!

