
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 分