
Code Firewall Mcp
io.github.egoughnour由 GitHub 帳號 egoughnour 發布v0.7.0更新於 Oct 24, 2026
Structural similarity-based code filter. Stops malicious code pattern reaching execution tools.
概覽
一個本機 MCP 伺服器,在程式碼交給執行工具之前,用危險結構模式黑名單對程式碼進行篩檢。
- 可以做什麼
- 檢查程式碼檔案或程式碼字串與黑名單中危險模式的相似度,回傳允許或攔截結果、相似度分數與原因。新增、列出與移除黑名單模式,並記錄近似變體以改進分類。查看防火牆狀態與統計資訊。檢查系統需求與 Ollama 可用性,並在 macOS Apple Silicon 上安裝或啟動 Ollama 及嵌入模型。
- 適用情境
- 當助理要把模型產生或使用者提供的程式碼交給執行工具時,可作為前置過濾;也適合需要不依賴具體參數、依結構辨識 shell 或 subprocess 等風險模式的場合。
- 執行需求
- 以 Python 套件(Python 3.10 以上、低於 3.14)或 Claude Desktop 安裝包形式透過 stdio 在本機執行。需要 Ollama 伺服器提供嵌入、ChromaDB 做向量儲存,tree-sitter 為選用。透過 FIREWALL_DATA_DIR、OLLAMA_URL、EMBEDDING_MODEL 與 SIMILARITY_THRESHOLD 設定;未宣告身分驗證。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Code Firewall Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Code Firewall MCP
[PyPI] [Claude Desktop] [Tests] [Release] [Python 3.10+] [License: MIT]
[Top Language] [Code Size] [Last Commit] [Repository Size]
A structural similarity-based code security filter for MCP (Model Context Protocol). Blocks dangerous code patterns before they reach execution tools by comparing code structure against a blacklist of known-bad patterns.
How It Works
- Parse code to Concrete Syntax Tree (CST) using tree-sitter
- Normalize by stripping identifiers and literals → structural skeleton
- Embed the normalized structure via Ollama
- Compare against blacklisted patterns in ChromaDB
- Block if similarity exceeds threshold, otherwise allow
Key Insight
Code patterns like os.system("rm -rf /") and os.system("ls") have identical structure. By normalizing away the specific commands/identifiers, we can detect dangerous patterns regardless of the specific arguments used.
Security-sensitive identifiers are preserved during normalization (e.g., eval, exec, os, system, subprocess, Popen, shell) to ensure embeddings remain discriminative for dangerous patterns.
Installation
Quick Start
Option 1: PyPI (Recommended)
Option 2: Claude Desktop One-Click
Download the .mcpb from Releases and double-click to install.
Option 3: From Source
Wire to Claude Code / Claude Desktop
Add to ~/.claude/.mcp.json (Claude Code) or claude_desktop_config.json (Claude Desktop):
Requirements
- Python 3.10+ (< 3.14 due to onnxruntime compatibility)
- Ollama (for embeddings)
- ChromaDB (for vector storage)
- tree-sitter (optional, for better parsing)
Setting Up Ollama (Embeddings)
Code Firewall can automatically install and configure Ollama on macOS with Apple Silicon. There are two installation methods:
Method 1: Homebrew Installation
What this does:
- Installs Ollama via Homebrew (
brew install ollama) - Starts Ollama as a managed background service
- Pulls nomic-embed-text model for embeddings
Method 2: Direct Download (No Sudo)
What this does:
- Downloads Ollama from https://ollama.com
- Extracts to
~/Applications/(no admin needed) - Starts Ollama via
ollama serve - Pulls nomic-embed-text model
Manual Setup
Tools
Setup & Status Tools
Firewall Tools
firewall_check
Check if a code file is safe to pass to execution tools.
firewall_check_code
Check code string directly (no file required).
firewall_blacklist
Add a dangerous pattern to the blacklist.
firewall_record_delta
Record near-miss variants to sharpen the classifier.
firewall_list_patterns
List patterns in the blacklist or delta collection.
firewall_remove_pattern
Remove a pattern from blacklist or deltas.
firewall_status
Get firewall status and statistics.
Configuration
Environment variables:
Usage Pattern
Pre-filter for massive-context-mcp
Use code-firewall-mcp as a gatekeeper before passing code to rlm_exec:
Integrated with massive-context-mcp
Install massive-context-mcp with firewall integration:
When enabled, rlm_exec automatically checks code against the firewall before execution.
Building the Blacklist
The blacklist grows through use:
- Initial seeding: Add known dangerous patterns
- Audit feedback: When
rlm_auto_analyzefinds security issues, add patterns - Delta sharpening: Record near-misses to improve classification boundaries
Structural Normalization
The normalizer strips:
- Identifiers:
my_var→_(except security-sensitive ones) - String literals:
"hello"→"S" - Numbers:
42→N - Comments: Removed entirely
Preserved identifiers (for better pattern matching):
eval,exec,compile,__import__os,system,popen,subprocess,Popen,shellopen,read,write,socket,connectgetattr,setattr,__globals__,__builtins__- And more security-sensitive names...
Example:
Both subprocess.run(["curl", ...]) and subprocess.run(["wget", ...]) normalize to the same structure, so blacklisting one catches both.
License
MIT
來源:README.md,提交 8f3c2b2
工具
0版本歷史
1- v0.7.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分