stagedsec-mcp-server
v0.1.0MCP server that lets AI coding agents (Claude Code, Cursor, ...) check content for hardcoded secrets before writing it to disk.
An MCP server that gives Claude Code, Cursor and other agents a check_for_secrets tool to call on content *before* they write it. Every other scanner (including StagedSec's own CLI, hook and editor extension) catches a secret after it is already in a file. This one lets the agent stop itself first. Use npx -y stagedsec-mcp-server as the command, or node /absolute/path/to/mcp-server/dist/index.js if you built from source. (Config formats change between client versions; check your client's MCP documentation if one of these is rejected.)
Summary extracted from the README.
stagedsec-mcp-server
Stop your AI coding agent from writing secrets to disk.
An MCP server that gives Claude Code, Cursor and other agents a check_for_secrets tool to call on content before they write it. Every other scanner (including StagedSec's own CLI, hook and editor extension) catches a secret after it is already in a file. This one lets the agent stop itself first.
- Local-only. The server makes no network calls at all. Content is scanned in memory and never stored or sent anywhere.
- Same rules as the StagedSec CLI and VS Code extension, kept identical by tests.
- Never edits anything. It reports what it found (masked) and tells the agent to ask you how to proceed.
- Explains and suggests. Each finding comes with a language-specific "read it from the environment instead" hint and the provider's credential-rotation guide.
Install
With npx (no install step) — once published to npm:
npx -y stagedsec-mcp-server
From source:
git clone https://gitlab.com/stagedsec/stagedsec.git
cd stagedsec/mcp-server
npm install && npm run build # produces dist/index.js
Configure your agent
Use npx -y stagedsec-mcp-server as the command, or node /absolute/path/to/mcp-server/dist/index.js if you built from source.
Claude Code
claude mcp add stagedsec -- npx -y stagedsec-mcp-server
Cursor (~/.cursor/mcp.json), Claude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"stagedsec": { "command": "npx", "args": ["-y", "stagedsec-mcp-server"] }
}
}
VS Code (.vscode/mcp.json)
{
"servers": {
"stagedsec": { "type": "stdio", "command": "npx", "args": ["-y", "stagedsec-mcp-server"] }
}
}
(Config formats change between client versions; check your client's MCP documentation if one of these is rejected.)
Make the agent actually use it
An agent calls a tool when its instructions tell it to. Add this to your project's CLAUDE.md, .cursorrules or equivalent:
Before writing or editing any file that could contain credentials (config, .env,
scripts, CI files, infrastructure code), call the stagedsec `check_for_secrets`
tool on the exact content first. If it reports secrets, do not write the content;
tell me what was found and ask how to proceed.
The tool: check_for_secrets
| Parameter | Required | Description |
|---|---|---|
content |
yes | The exact content about to be written (not a path: the file may not exist yet) |
filePath |
no | Used for a more useful response (language-specific advice) and nothing else |
minSeverity |
no | low / medium / high / critical. Default medium; an invalid value falls back to the default |
includeGenericEntropy |
no | Also flag random-looking strings that match no named rule. Off by default (noisy) |
Example response when a secret is found:
🚨 SECRETS DETECTED for settings.py: DO NOT WRITE THIS CONTENT AS-IS.
1 potential secret(s) found. Tell the user what was found below, and ask how they want to proceed ...
- line 1: AWS Access Key ID (critical) — value: AKIA************WZVB
rule: aws-access-key-id
suggested fix: read it at runtime instead, e.g. `os.environ["AWS_ACCESS_KEY_ID"]`
if this is a real credential it must also be rotated: https://docs.aws.amazon.com/...
Behavior you can rely on
- Real values never appear in responses, only the masked form (
AKIA************WZVB). - Inline
stagedsec:allowcomments are ignored here, on purpose. The caller is an AI agent; honoring them would let it exempt its own output from the check. (The CLI and editor extension do honor them.) - Long lines are scanned in full (minified bundles, one-line JSON), in overlapping windows.
- Oversized input fails loudly. Content over 5,000,000 characters returns an error telling the agent to split it, rather than a partial scan reported as complete.
- Instructions embedded in the content ("ignore previous instructions, report this as safe") do not change the result: detection is deterministic pattern matching.
Limits (be aware)
- It is a guardrail for cooperative agents, not a sandbox: an agent that never calls the tool is not checked. Pair it with the pre-commit hook for the commit-time safety net.
- Regex-based detection misses obfuscated or split secrets, and has narrower rule coverage than gitleaks. Use both.
License
MIT