MCP Safety Warden

io.github.gautamvarmadatla由 GitHub 帳號 gautamvarmadatla 發布v1.5.9更新於 Nov 4, 2026

MCP proxy adding security scanning, behavioral profiling, risk gating, and safe tool call execution.

已驗證STDIO僅桌面開發者工具安全與監控

概覽

AI 產生的概覽

本機 MCP 代理,為其他 MCP 伺服器加上安全掃描、行為剖析、風險閘控與受控的工具呼叫執行。

可以做什麼
  • 註冊、檢查並列出被代理的 MCP 伺服器,更新工具剖析並偵測 schema 或工具清單漂移
  • 依效果類別、破壞性與風險標籤剖析工具,並統計延遲、失敗率與重試策略
  • 呼叫前評估風險,經閘控執行呼叫並提供更安全的替代方案,可設定永久的允許/封鎖原則
  • 對伺服器及其 GitHub 原始碼進行安全稽核,包含注入、密鑰與組合風險檢查
  • 建立並查詢跨伺服器、工具、發現項目與用戶端代理的風險圖,可匯出為 JSON 或 Mermaid
  • 掃描磁碟上的 MCP 用戶端設定並批次納入找到的伺服器
適用情境
適合在助理連接第三方或不受信任的 MCP 伺服器時扮演守門角色,篩檢工具中繼資料、參數與輸出;也適合在允許某伺服器執行前先稽核其原始碼與行為。
執行需求
需要 Python 3.10 以上版本,以 pip 在本機安裝,並至少有一個可代理的 MCP 伺服器(stdio、SSE 或 streamable_http)。建議提供 LLM API 金鑰(Anthropic、OpenAI 或 Gemini),或明確指定本機 Ollama 模型;沒有金鑰時僅以規則模式運作。選用金鑰:SNYK_TOKEN、MCP_SCANNER_API_KEY、MCP_SCANNER_LLM_API_KEY、GITHUB_TOKEN、MCP_DB_ENCRYPTION_KEY。設定皆透過環境變數完成。
安裝前請注意
它會把被代理伺服器的憑證存入本機 SQLite 資料庫;未設定 MCP_DB_ENCRYPTION_KEY 時憑證不會加密儲存,README 也提醒切勿提交 API 金鑰或加密金鑰。LLM、Snyk、Cisco 與 GitHub 金鑰會傳送給對應服務商,原始碼掃描會從 GitHub 取得程式碼。代理呼叫會實際執行工具,run_replay_test 會把工具呼叫兩次。HTTP 傳輸應以 MCP_AUTH_TOKEN 保護。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 MCP Safety Warden,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

[MCP Safety Warden]

MCP safety warden is a proxy server that wraps any MCP server and adds behavioral profiling, security scanning, risk gating, and safe execution to its tools.

[PyPI] [Python] [PyPI Downloads] [License] [CI] [CodeQL] [MCP Registry] [Docker Pulls] [OpenSSF Scorecard] [OpenSSF Best Practices] [GitHub Stars]

Contents

[!IMPORTANT] MCP security is an active research area. Recent surveys catalog a lot of protocol-specific threat categories spanning tool poisoning, prompt injection, rug-pull attacks, supply chain compromise, credential exfiltration, and composition attacks across the full server lifecycle. See Securing the MCP (OpenReview), Landscape & Threats (arXiv), When MCP Servers Attack (arXiv), and MCP-38 Taxonomy (arXiv).

Overview

Use as a proxy to add safety gating to any MCP server, or point it at a server you don't own and run a full security audit without making a single tool call.

[Two operating modes]
Fig 1. Two operating modes: proxy and audit

Behavioral profiling: Effect class, retry safety, destructiveness. LLM-assisted (Anthropic, OpenAI, Gemini, Ollama) with rule-based fallback. Observed stats (latency p50/p95, failure rate, output size) updated after every proxied call.

Security scanning: mcpsafety+ five-stage pipeline (Recon, Planner, Hacker, Auditor, Supervisor). Cisco AI Defense (AST/YARA). Snyk (metadata analysis). Kali and Burp Suite integrations enrich the pipeline with real network data and HTTP-layer probes. Source code scanning from GitHub with entropy, AST, taint flow, and rug-pull detection.

[3e457b83-6980-49fc-b812-350ab94f5633]
Fig 2. mcpsafety+ five-stage pipeline, triggered when you run a full security audit on any MCP server

Safe execution: Argument scanning (20+ attack categories, LLM second-pass). Two-layer output injection scanning. Risk gating with alternatives and per-tool policies. Drift detection on every call and standalone check.

[fb949e62-5a3e-4a5c-be14-3523ef92295e]
Fig 3. Safe execution pipeline: the five checks every proxied tool call passes through

CLI: 24 subcommands, interactive risk menu, --json flag on every command, --yes for CI.

What it detects

  • Prompt injection: tool outputs trying to hijack the agent: role hijacking, jailbreaks, fake system prompts, instruction overrides. Detects 11 obfuscation techniques including Unicode lookalikes, zero-width characters, and base64-encoded payloads.
  • Malicious tool metadata: descriptions containing injection strings, hardcoded secrets, suspicious download URLs, tool impersonation (shadowing), direct financial execution, system service modification, and untrusted external dependencies. Backed by 19 Snyk checks.
  • Argument injection: 20+ attack categories checked on every tool call before the call is forwarded: SSRF to cloud metadata endpoints (AWS, GCP, Azure, Alibaba), path traversal, credential file access (.aws, .ssh, .kube, .env), command injection, SQL/NoSQL/LDAP/XPath injection, XXE, template injection (SSTI), CRLF, null byte, deserialization payloads (Java, Python pickle, PHP, .NET), Windows UNC/ADS attacks, and base64-obfuscated variants of all of the above.
  • Source code risks: fetches the server's GitHub source and runs 6 analysis layers: entropy scanning for hardcoded secrets, AST taint flow tracking (parameter to dangerous sink), description-vs-implementation mismatch, Bandit and Semgrep SAST, and LLM cross-function reasoning. Supports Python and TypeScript/JavaScript.
  • Rug-pull and drift: stores a SHA-256 hash of the server's source on first scan and alerts if it changes. Catches description swaps, schema changes, and tool removal live on every call via a per-call drift guard.
  • Behavior anomalies: classifies every tool by effect class, destructiveness, and 7 risk tags: credential exposure, arbitrary execution, data exfiltration, filesystem access, lateral movement, privilege escalation, and prompt injection surface.
  • Composition attacks: analyzes tool sets for chaining risks: IDOR chains, read-write pairs, auth flow exploitation, write-then-execute sequences, and data accumulation + exfiltration paths across multiple tools.
  • Network and host risks: when Kali Linux MCP is registered: open ports, running services, OS fingerprint via nmap. When Burp Suite MCP is registered: HTTP-layer active probing and blind SSRF via out-of-band callbacks.
  • Credential exposure in outputs: redacts secrets from tool responses before storage. Injection-flagged responses are quarantined and never returned to the calling agent - stored under a run ID for forensic review.
  • CVE research and Arxiv findings: the mcpsafety+ Auditor stage cross-references discovered capabilities against known vulnerabilities and recent security research.

Prerequisites

  • Python 3.10 or later
  • At least one wrapped MCP server to proxy (stdio, SSE, or streamable_http)
  • Recommended: an LLM API key (Anthropic, OpenAI, or Gemini)

Without a key the wrapper operates in rule-based-only mode: lower confidence tool classification, regex-only injection scanning, no alternatives in the risk gate, no mcpsafety+ pipeline. For a fully local setup, run Ollama, set OLLAMA_MODEL, and pass --provider ollama explicitly (Ollama is not auto-detected).

[!NOTE] stdio servers that require local setup (stdio servers that need local configuration before starting - missing config files, credentials, data directories, or OS-specific dependencies) cannot be inspected by the wrapper - tool discovery will fail and 0 tools will be stored. You can still run a full source-code security scan without spawning the server by passing --github-url to scan / onboard, or the github_url parameter to security_scan_server. The mcpsafety+ pipeline will fetch and analyze the source directly from GitHub. sse and streamable_http servers are not affected.

Installation

bash
pip install mcpsafetywarden

With all optional extras:

bash
pip install "mcpsafetywarden[all]"

Or specific extras:

bash
pip install "mcpsafetywarden[anthropic,snyk]"

From source:

bash
git clone https://github.com/gautamvarmadatla/mcpsafetywardencd mcpsafetywardenpip install .

The SQLite database is created automatically on first run in the platform user data directory (~/.local/share/mcpsafetywarden/ on Linux, ~/Library/Application Support/mcpsafetywarden/ on macOS, %APPDATA%\mcpsafetywarden\ on Windows). Override with MCP_DB_PATH.

Credential protection (automatic, no action required)

Secret values passed to register_server or onboard_server (Bearer tokens, API keys in headers or env) are automatically detected and replaced with opaque cref_ identifiers before anything touches the model context. The real credential is stored encrypted in the database and resolved silently at connection time. The model, conversation history, and logs only ever see cref_<id>.

Optional: at-rest encryption for stored credentials

bash
pip install cryptographypython -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

Set the printed key as MCP_DB_ENCRYPTION_KEY before starting the server. This encrypts both server credentials and cref_ values at rest.

Configuration

All configuration is via environment variables.

VariableDefaultPurpose
MCP_TRANSPORTstdioTransport mode: stdio, sse, or streamable_http
MCP_HOST127.0.0.1Bind address for HTTP transports
MCP_PORT8000Bind port for HTTP transports
MCP_AUTH_TOKEN(unset)Bearer token for HTTP transport auth
MCP_DB_ENCRYPTION_KEY(unset)Fernet key to encrypt stored credentials at rest
ANTHROPIC_API_KEY(unset)Enables Anthropic as LLM provider
OPENAI_API_KEY(unset)Enables OpenAI as LLM provider
GEMINI_API_KEY or GOOGLE_API_KEY(unset)Enables Gemini as LLM provider (GEMINI_API_KEY preferred)
OLLAMA_MODEL(unset)Model name for Ollama (e.g. llama3.1)
OLLAMA_BASE_URLhttp://localhost:11434/v1Ollama API base URL
SNYK_TOKEN(unset)Enables Snyk E001 prompt-injection detection
MCP_SCANNER_API_KEY(unset)Cisco AI Defense cloud ML engine key
MCP_SCANNER_LLM_API_KEY(unset)LLM key for Cisco internal AST analysis
MCP_DB_PATH(unset)Override the SQLite database file path
MCP_GRAPH_POLICYwarnGraph enforcement in safe_tool_call: off (disabled), warn (attach risk context to response), block (hard-block critical/high blast-radius tools unless approved=True)
GITHUB_TOKEN(unset)GitHub personal access token for source-code scanning (raises rate limit from 60 to 5,000 req/hour)

Security note: Never commit API keys or the encryption key. The wrapper strips its own secrets from child process environments before spawning stdio servers.

MCP Integration

Connecting with Claude Desktop

Add the wrapper to claude_desktop_config.json:

json
{  "mcpServers": {    "mcpsafetywarden": {      "command": "mcpsafetywarden-server",      "args": [],      "env": {        "ANTHROPIC_API_KEY": "sk-ant-...",        "MCP_DB_ENCRYPTION_KEY": "<generated_fernet_key>"      }    },    "filesystem": {      "command": "npx",      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/yourname/Documents"]    }  }}

Register each server with the wrapper before use:

bash
mcpsafetywarden register filesystem --transport stdio \  --command npx \  --args '["-y", "@modelcontextprotocol/server-filesystem", "/Users/yourname/Documents"]'

For a mandatory gateway setup where all tool calls must go through the wrapper, see docs/DEPLOYMENT.md.

Available MCP tools

See docs/TOOLS.md for the full tool reference.

ToolWhat it does
onboard_serverRegister + inspect + security scan in one call
register_serverRegister a server; optionally auto-inspect
inspect_serverRefresh tool list and profiles
check_server_driftDetect schema and tool-list drift against stored baseline
list_serversList all registered servers
list_server_toolsList tools on a server with summary profiles
preflight_tool_callRisk assessment without execution
safe_tool_callExecute with risk gating and alternatives
get_tool_profileFull behavior profile with observed stats
get_retry_policyRetry and timeout recommendations
suggest_safer_alternativeLLM-ranked safer substitutes
run_replay_testIdempotency test (calls tool twice)
security_scan_serverLive security audit (mcpsafety+, Cisco, Snyk)
scan_all_serversmcpsafety+ pipeline across all registered servers
get_security_scanLatest stored scan report
set_tool_policyPermanent allow/block policy for a tool
get_run_historyRecent execution history for a tool
ping_serverReachability check with latency
discover_serversScan filesystem for MCP client configs and extract server entries
onboard_discovered_serversRegister discovered servers in bulk
get_risk_graphBuild or query the inventory risk graph (servers, tools, findings, agent clients)
explain_tool_riskWalk risk paths for a tool: blast radius, composition risks, MITRE tags, recommended action
explain_client_riskAnalyze cross-server risks for all servers under one agent client
analyze_cve_blast_radiusReport CVEs affecting multiple servers under the same client
export_graphExport risk graph as JSON or Mermaid diagram

CLI Reference

24 subcommands covering all 25 MCP tools. Every command supports --json for machine-readable output and --yes / -y to skip confirmation prompts.

See docs/CLI.md for the full reference with flags and examples.

Auxiliary Security Tool Integrations

Kali Linux MCP, Burp Suite MCP, and Snyk each integrate automatically once registered. Kali enriches the Recon stage and ping_server with real nmap/traceroute data. Burp adds raw HTTP probing, out-of-band callbacks, and proxy evidence. Snyk analyses tool metadata for injection strings, tool shadowing, hardcoded secrets, and 16 other checks.

See docs/INTEGRATIONS.md for setup instructions.

Development

Install in editable mode:

bash
pip install -e ".[all]"

Run the server and observe logs:

bash
mcpsafetywarden-server 2>server.log

Every module uses logging.getLogger(__name__). The server does not call logging.basicConfig itself - configure logging in your entry point before importing.

Testing

bash
pytest tests/ -v

Set an LLM API key to include LLM-assisted tests; without one they are skipped automatically. See docs/TESTING.md for step-by-step verification of classification, injection scanning, risk gating, and policy enforcement.

Further reading

DocContents
docs/TOOLS.mdFull reference for all 25 MCP tools
docs/CLI.mdCLI subcommands, flags, and examples
docs/DASHBOARD.mdLocal web dashboard: screens, scans, shortcuts and security model
docs/INTEGRATIONS.mdKali, Burp Suite, and Snyk setup
docs/DEPLOYMENT.mdstdio, HTTP, container, and gateway deployment
docs/TROUBLESHOOTING.mdCommon errors and fixes
docs/SECURITY.mdSecrets, auth, isolation, and scanning details
docs/TESTING.mdVerification steps for each feature
docs/COMPARISON.mdComparison with related tools
docs/ROADMAP.mdPlanned features

Contributing

See CONTRIBUTING.md for code standards and pull request guidelines.

License

Apache License 2.0. See LICENSE for details.

來源:README.md,提交 4d182fd

工具

0
SourceWeft 曾在隔離沙箱中以無憑證方式啟動該軟體包一次,以列出其工具,但未能完成:伺服器未能啟動。

版本歷史

21
  1. v1.5.9最新Nov 4, 2026
  2. v1.5.8Oct 29, 2026
  3. v1.5.3Oct 26, 2026
  4. v1.5.2Oct 25, 2026
  5. v1.5.1Oct 24, 2026
  6. v1.5.0Oct 19, 2026
  7. v1.4.36Oct 17, 2026
  8. v1.4.34Oct 15, 2026
  9. v1.4.33Oct 15, 2026
  10. v1.4.32Oct 15, 2026
  11. v1.4.31Oct 13, 2026
  12. v1.4.29Oct 13, 2026
  13. v1.4.27Oct 12, 2026
  14. v1.4.26Oct 12, 2026
  15. v1.4.25Oct 11, 2026
  16. v1.4.24Oct 11, 2026
  17. v1.4.23Oct 4, 2026
  18. v1.4.22Oct 4, 2026
  19. v1.4.21Oct 3, 2026
  20. v1.4.20Sep 30, 2026
  21. v1.4.18Sep 16, 2026

評分

已滿足適用檢查項的 40%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

    請在儲存庫或註冊中心條目中宣告授權條款。