
Code Firewall Mcp
io.github.egoughnourPublished by GitHub account egoughnourv0.7.0Updated Oct 24, 2026
Structural similarity-based code filter. Stops malicious code pattern reaching execution tools.
Overview
A local MCP server that screens code against a blacklist of dangerous structural patterns before it is passed to execution tools.
- What you can do
- Check a code file or a raw code string for similarity to blacklisted dangerous patterns and get an allow or block result with a similarity score and reason. Add, list and remove blacklist patterns and record near-miss variants to sharpen the classifier. Read firewall status and statistics. Check system requirements and Ollama availability, and install or start Ollama with an embedding model on macOS Apple Silicon.
- When to use it
- Use it as a pre-filter when an assistant passes model-generated or user-supplied code to execution tools, or when you want a structural, argument-independent check for risky patterns such as shell or subprocess calls.
- Requirements
- Runs locally over stdio as a Python package (Python 3.10+, below 3.14) or a Claude Desktop bundle. Needs an Ollama server for embeddings, ChromaDB for vector storage, and optionally tree-sitter. Configured through FIREWALL_DATA_DIR, OLLAMA_URL, EMBEDDING_MODEL and SIMILARITY_THRESHOLD; no authentication is declared.
Installation
In SourceWeft
- Open Code Firewall Mcp in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
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
Source: README.md at commit 8f3c2b2
Tools
0Version history
1- v0.7.0LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts