Zero-trust security gateway for MCP (Model Context Protocol) tool servers — static scanning, sandbox behavioural profiling, and runtime policy enforcement.
Project description
MCP Zero-Trust Gateway
A security gateway that sits between an LLM agent and the MCP (Model Context Protocol) tool servers it uses, built on the principle that no tool server is trusted by default. Every tool is inspected before it is allowed in, profiled in a sandbox to see what it actually does, constrained by least-privilege policy, and monitored at runtime.
It runs entirely on your machine, ensuring privacy and security. The trust store is a local SQLite file and no telemetry is sent anywhere.
The Vulnerability
An LLM agent discovers tools by reading each MCP server's self-description (tools/list). It then calls them (tools/call) with its own privileges. The agent natively treats the server's description as the absolute truth.
That assumption is a critical vulnerability: a malicious server (via a supply chain attack or direct compromise) can hide instructions in its description (Prompt Poisoning) or perform actions its manifest never declared (e.g., reading SSH keys while claiming to just fetch weather). This Gateway eliminates that default trust.
Core Architecture
The Zero-Trust Gateway implements a multi-layered defensive architecture:
- L1 Static Scanner: Intercepts the
tools/listmanifest during onboarding. It parses the tool's natural language description andinputSchemato automatically infer Declared Capabilities (e.g., inferringFILE_ACCESSif the tool describes itself as a file reader). It also uses heuristic rules to detect and reject Prompt Poisoning attempts in the manifest. - L2 Dynamic Sandbox (Live Profiling): The tool is executed in a highly constrained Docker environment. The Gateway uses
straceas the entrypoint to capture every system call the tool attempts (e.g.,open,socket,execve). These syscalls are mapped to Observed Capabilities. - Automated Seccomp Compiler: Directly addressing the gap in modern dynamic analysis, the Gateway acts as a policy compiler. It parses the unfiltered
stracelogs to extract every unique syscall the tool required, synthesizing a strict, deployment-ready Dockerseccomp.jsonprofile representing the exact behavioral boundaries of the tool. - Zero-Trust Comparator: Compares the Observed Capabilities against the Declared Capabilities.
- Match: If the tool operates strictly within its declared boundaries, the Gateway issues an
allowverdict and outputs the customseccomp.json. - Mismatch: If the tool attempts an undeclared action, the Gateway immediately issues a
quarantineverdict.
- Match: If the tool operates strictly within its declared boundaries, the Gateway issues an
- Runtime Proxy: Every subsequent tool call passes through the gateway. The Gateway dynamically injects the generated
seccomp.jsoninto the container execution, enforcing the exact behavioral profile at the OS kernel level.
Installation & Setup
This repository is optimized for local development and execution on Windows/WSL2 or Linux environments. Docker Desktop is required to run the L2_Sandbox dynamic profiling layer.
Quick Start (Windows)
We provide an automated PowerShell script to install dependencies, set up the environment, and start the Uvicorn gateway server:
.\start_gateway.ps1
Installation & Setup
You can install the Zero-Trust Gateway directly via PyPI, or run it locally from source.
Option 1: Install via PyPI (Recommended)
pip install mcp-ztgateway
Once installed, you can start the gateway using the CLI:
mcp-ztgateway --port 8000
Option 2: Run Locally (Development)
# Clone the repository
git clone https://github.com/nabrahma/MCP_Zero-Trust_Gateway_BTP.git
cd MCP_Zero-Trust_Gateway_BTP
# Create virtual environment
python -m venv venv
.\venv\Scripts\activate
# Install requirements
pip install -r requirements.txt
# Start the gateway
./start_gateway.ps1
How to Use the Gateway
Once the gateway is running on http://127.0.0.1:8000, all MCP tools must be registered and verified through it before an LLM agent is permitted to use them.
Onboarding a New Tool
To register a tool, you send a JSON payload to the /register endpoint containing the Docker command required to run the MCP Server.
Important: The target Docker image must have
straceinstalled to support the live dynamic profiling phase.
Example payload to onboard a legitimate tool:
POST /register
{
"name": "read_file",
"command": ["docker", "run", "-i", "--rm", "real-mcp-image", "mcp-server-filesystem", "/app"],
"image": "real-mcp-image",
"env": {},
"test_tool": "read_file",
"test_args": {"path": "/app/package.json"}
}
The Gateway will automatically:
- Scan the tool's manifest for poisoning.
- Execute the tool in the sandbox using
straceto intercept its system calls. - Compare the actions it took against what it declared in its description.
- Return a
Verdict(Allow, Deny, or Quarantine).
Using the Gateway in Docker
You can also run the Gateway and the accompanying Dashboard using Docker Compose:
docker-compose up --build
# Gateway API -> http://localhost:8000
# Dashboard -> http://localhost:5173
(Note: Live sandbox profiling requires executing Docker commands, which relies on the host's Docker daemon. The provided gateway service requires appropriate volume mounts to execute properly).
Status and Limitations
This project is a final-year B.Tech project focusing on proving the empirical viability of a Zero-Trust architecture for LLM Tool use.
- Dynamic Profiling Evasion: A highly sophisticated tool that stays completely dormant during profiling, specifically detects the sandbox, or only misbehaves on unseen inputs will not be caught during the onboarding phase. This is an inherent limitation of dynamic analysis.
- Coarse Enforcement: Syscall interception maps to broad capability classes (e.g.,
FILE_ACCESS), not exact semantics ("reads of.envspecifically"). Granular per-path decisions are handled by upper-level policy layers.
Tech Stack
- Backend Core: Python, FastAPI
- Sandboxing: Docker,
strace,seccomp - Data/State: SQLite
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_ztgateway-0.2.0.tar.gz.
File metadata
- Download URL: mcp_ztgateway-0.2.0.tar.gz
- Upload date:
- Size: 50.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cdf20927838a85550d2d20614b1da758abdd5286dd24516fc9f429f2a618619
|
|
| MD5 |
86f968e9ec1abcb3a9c9870aebe067d5
|
|
| BLAKE2b-256 |
ba15e391bc5633f2bef38ef9924d19b7be95653733e4f65bf112a5b3ba6e2f89
|
File details
Details for the file mcp_ztgateway-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mcp_ztgateway-0.2.0-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecaf44535be834603631b164edc8d1b0845d582d8a97af73483f5c3eca197a63
|
|
| MD5 |
d6a3f8b3197e72a589840a593a6e28bc
|
|
| BLAKE2b-256 |
ed6ca10182e270edd7b49a592a97e96299b434391c871cde5c4d98f9b5f4a576
|