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:

  1. A failing integration test prints a connection error containing postgresql://svc_billing:Pr0dP4ss!@10.24.8.15:5432/ledger.
  2. A curl trace or Kubernetes ConfigMap dump includes an active Authorization: Bearer eyJ... JWT, an sk-proj-... OpenAI key, or an internal corporate hostname.
  3. If you manually scrub values into ***REDACTED*** before prompting the model, two things break immediately:
    • Lost referential equality: When service-a/.env and docker-compose.yml hold 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.

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 audit is permanently 0 vulnerabilities.
  • Cold-start latency over stdio is <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:

  1. It sees semantic types (OPENAI_KEY vs DB_URI vs BEARER_JWT vs INTERNAL_IP).
  2. It immediately spots that OPENAI_API_KEY and FALLBACK_OPENAI_KEY are identical (<OPENAI_KEY_1>), whereas WORKER_OPENAI_KEY is a second key (<OPENAI_KEY_2>).
  3. When the LLM outputs refactored TypeScript, Python, or YAML referencing <OPENAI_KEY_1> and <DB_URI_1>, calling restore_snippet swaps 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:

What guardrails are you running around .env files and local MCP servers in your agent workflows? Happy to compare notes in the comments!