Integrates with Ollama to generate structural embeddings of code syntax trees, enabling similarity-based detection and blocking of dangerous code patterns.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Code Firewall MCPcheck if script.py is safe to execute"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Code Firewall MCP
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 servePulls nomic-embed-text model
Manual Setup
Tools
Setup & Status Tools
Tool | Purpose |
| Check system requirements β verify macOS, Apple Silicon, RAM |
| Install via Homebrew β managed service, auto-updates |
| Install via direct download β no sudo, fully headless |
| Check Ollama availability β verify embeddings are ready |
Firewall Tools
Tool | Purpose |
| Check if a code file is safe to execute |
| Check code string directly (no file required) |
| Add a dangerous pattern to the blacklist |
| Record near-miss variants for classifier sharpening |
| List patterns in blacklist or delta collection |
| Remove a pattern from blacklist or deltas |
| Get firewall status and statistics |
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:
Variable | Default | Description |
|
| Data storage directory |
|
| Ollama server URL |
|
| Ollama embedding model |
|
| Block threshold (0-1) |
|
| Near-miss recording threshold |
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 patternsDelta 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βNComments: 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
This server cannot be installed