mcp-secret-sentinel

mcp-secret-sentinel

An MCP server that scans code for exposed secrets (API keys, tokens, private keys, high-entropy strings) with placeholder-aware allowlisting and fully redacted reports, enabling agents to detect leaks before committing.

Category
访问服务器

README

mcp-secret-sentinel

tests

MCP server that scans code for exposed secrets — API keys, tokens, private keys and high-entropy strings — with placeholder-aware allowlisting and redacted reports.

Secrets rarely leak through hackers; they leak through commits. An agent (or a human in a hurry) pastes a webhook URL into a config, stages it, pushes — and from that moment the credential is compromised, even if the next commit deletes it, because history keeps every added line. mcp-secret-sentinel gives an agent a pre-commit checkpoint: scan a snippet, a file, a whole tree, the staged diff, or recent history, and get back a severity-ranked, fully redacted report it can act on before anything leaves the machine. The full secret value never appears in the tool output, so it never enters the conversation transcript either.

Tools

Tool Arguments Returns
scan_text text, source_name="input" Findings for a raw snippet (code, config, diff, logs)
scan_file path Findings for one file; skips binaries (null-byte heuristic) and files over 5 MB
scan_directory path, max_files=500 Recursive scan; skips .git, node_modules, virtualenvs, __pycache__, dist, build, minified JS, lockfiles, and honors simple .gitignore patterns
scan_git_staged repo_path Scans only the lines added in git diff --cached — the exact content the next commit would publish
scan_git_history repo_path, max_commits=50 Scans lines added by the last N commits, tagging each finding with its commit hash
list_patterns — Active detectors with severity and remediation advice, plus the allowlist rules

All scan tools return the same shape:

{
  "clean": false,
  "findings": [
    {
      "file": "config/notify.yaml",
      "line": 14,
      "pattern": "Slack incoming webhook",
      "severity": "high",
      "redacted": "hook…(77 chars)",
      "advice": "Anyone with this URL can post messages to your workspace. Regenerate the webhook in your Slack app settings and load the URL from an environment variable."
    }
  ],
  "files_scanned": 6,
  "summary": "Found 1 potential secret(s) across 6 scanned file(s): 1 high. Do NOT commit or push until these are removed or rotated."
}

What it detects

Nineteen regex detectors: GitHub tokens (classic and fine-grained), OpenAI / Anthropic / NVIDIA / Google / Stripe (live) / Twilio keys, AWS access key IDs and secret access keys, Slack tokens and incoming webhooks, Discord webhooks, JWTs, private key blocks (RSA / EC / OPENSSH / PGP), database and queue connection strings with embedded credentials (Postgres, MySQL, MongoDB, AMQP, Redis), plus generic password / secret / token-style assignments in quoted code and in dotenv-style UPPER_CASE=value lines.

On top of the regexes, a Shannon-entropy detector flags quoted strings of 20+ characters assigned to variables whose empirical entropy reaches 4.5 bits/char — the signature of random credential material — but only when no specific pattern already claimed that span.

What it deliberately ignores (allowlist)

Each candidate value is checked against these placeholder heuristics before being reported:

  • Too short — values under 8 characters are too short to be real credentials.
  • Masked — values that are mostly (≥ 80%) X, x, *, or dots: already redacted by a human, including vendor prefixes followed by an XXXX… run.
  • example — any value containing example (any case): covers example.com / example.org domains and vendor-documented sample keys, such as the AWS docs key ending in EXAMPLE.
  • placeholder, changeme (also change-me / change_me) — conventional fill-me-in markers.
  • your-…-here — fill-in-the-blank markers.
  • <angle brackets> — documentation-style placeholders.
  • ${TEMPLATE_VARIABLES} — the secret is injected elsewhere, not stored here.
  • Environment lookups — values referencing os.environ or process.env: an environment lookup is the fix, not the leak.

Redaction guarantee

Every finding shows only the first 4 characters plus the total length — e.g. "hook…(77 chars)". The full value never appears in the output, the transcript, or the logs. This is enforced in code (a single redact() choke point) and in the test suite, which asserts the raw values are absent from serialized results.

How it works

flowchart TD
    A[Agent calls a scan tool] --> B{Source}
    B -->|scan_text / scan_file| C[Split into lines]
    B -->|scan_directory| D[Walk tree, skip .git, node_modules,<br/>binaries, lockfiles, .gitignore matches] --> C
    B -->|scan_git_staged / scan_git_history| E[git diff / git log with zero context,<br/>keep added lines only] --> C
    C --> F[19 regex detectors,<br/>specific patterns claim spans first]
    C --> G[Shannon entropy >= 4.5 bits/char<br/>on assigned strings of 20+ chars]
    F --> H{Allowlist check:<br/>placeholders, masked values,<br/>example domains, env lookups}
    G --> H
    H -->|placeholder| I[Dropped, not reported]
    H -->|real candidate| J[Redact: first 4 chars + length]
    J --> K[Report: file, line, pattern,<br/>severity, redacted, advice]

Quickstart

pip install -e .

Claude Desktop — add to claude_desktop_config.json:

{
  "mcpServers": {
    "secret-sentinel": {
      "command": "python",
      "args": ["/absolute/path/to/mcp-secret-sentinel/server.py"]
    }
  }
}

Claude Code:

claude mcp add secret-sentinel -- python /absolute/path/to/mcp-secret-sentinel/server.py

Example session

User: I'm about to push acme-app — make sure I'm not leaking anything.

Claude calls scan_git_staged(repo_path="C:/dev/acme-app"):

{
  "clean": false,
  "findings": [
    {
      "file": "config/notify.yaml",
      "line": 14,
      "pattern": "Slack incoming webhook",
      "severity": "high",
      "redacted": "hook…(77 chars)",
      "advice": "Anyone with this URL can post messages to your workspace. Regenerate the webhook in your Slack app settings and load the URL from an environment variable."
    }
  ],
  "files_scanned": 6,
  "summary": "Found 1 potential secret(s) across 6 scanned file(s): 1 high. Do NOT commit or push until these are removed or rotated. Unstage the affected files and strip the secrets before committing."
}

Claude: Hold the push — config/notify.yaml line 14 contains a real Slack webhook URL in the staged diff. Three steps:

  1. Replace the literal URL with an environment lookup, e.g. SLACK_WEBHOOK_URL.
  2. Regenerate the webhook in your Slack app settings — treat the current one as compromised.
  3. Re-stage the file and I'll verify.

User: Done — check again.

Claude calls scan_git_staged(...) → "clean": true, "summary": "Staged changes are clean — 6 file(s) with additions scanned, no secrets in the added lines." — then scan_git_history(repo_path="C:/dev/acme-app", max_commits=20) → "clean": true.

Claude: Clean — the staged changes and the last 20 commits contain no detectable secrets. Safe to push.

Limitations

  • .gitignore support is best-effort: plain names, *.ext globs, dir/ and /anchored patterns from the root .gitignore only. No ! negations, no ** globs, no nested ignore files.
  • Entropy needs diversity: empirical per-string entropy maxes out at log2(distinct characters), so a candidate needs at least 23 distinct characters to clear 4.5 bits/char. Short random strings are covered by the regex detectors instead.
  • Unquoted generic assignments are only detected in dotenv-style UPPER_CASE=value lines — a deliberate trade against false positives in ordinary code.
  • Not a CI replacement: dedicated scanners (gitleaks, trufflehog) with hundreds of rules belong in your pipeline. This server is the fast local checkpoint an agent can run before the commit exists.

Development

pip install -e ".[dev]"
python -m pytest

The test suite exercises every detector, the allowlist, entropy, redaction, directory walking, and real temporary git repositories — and never contains a realistic secret literal: every positive fixture is assembled at runtime by concatenation.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选