Skip to main content

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:

  1. L1 Static Scanner: Intercepts the tools/list manifest during onboarding. It parses the tool's natural language description and inputSchema to automatically infer Declared Capabilities (e.g., inferring FILE_ACCESS if the tool describes itself as a file reader). It also uses heuristic rules to detect and reject Prompt Poisoning attempts in the manifest.
  2. L2 Dynamic Sandbox (Live Profiling): The tool is executed in a highly constrained Docker environment. The Gateway uses strace as the entrypoint to capture every system call the tool attempts (e.g., open, socket, execve). These syscalls are mapped to Observed Capabilities.
  3. Automated Seccomp Compiler: Directly addressing the gap in modern dynamic analysis, the Gateway acts as a policy compiler. It parses the unfiltered strace logs to extract every unique syscall the tool required, synthesizing a strict, deployment-ready Docker seccomp.json profile representing the exact behavioral boundaries of the tool.
  4. 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 allow verdict and outputs the custom seccomp.json.
    • Mismatch: If the tool attempts an undeclared action, the Gateway immediately issues a quarantine verdict.
  5. Runtime Proxy: Every subsequent tool call passes through the gateway. The Gateway dynamically injects the generated seccomp.json into 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 strace installed 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:

  1. Scan the tool's manifest for poisoning.
  2. Execute the tool in the sandbox using strace to intercept its system calls.
  3. Compare the actions it took against what it declared in its description.
  4. 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 .env specifically"). 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

mcp_ztgateway-0.2.1.tar.gz (50.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_ztgateway-0.2.1-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

Details for the file mcp_ztgateway-0.2.1.tar.gz.

File metadata

  • Download URL: mcp_ztgateway-0.2.1.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

Hashes for mcp_ztgateway-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a39131c4ac5e3d847dc7b8766119664500fc865e4fd379a95d0386431fe9e32f
MD5 8247908903f20f387cb5a4875d134499
BLAKE2b-256 d59245a0ebc35d2cb9235571c4f70d4133a53df70223c35ae3f80e954cb591e1

See more details on using hashes here.

File details

Details for the file mcp_ztgateway-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mcp_ztgateway-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 44.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for mcp_ztgateway-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e62f50147da4a67e2814a62c648f86d5d6249b182ad3f565dfb9322023830d3
MD5 5f31c7bc7c9de2d471a384f8d1169b02
BLAKE2b-256 968fcfe262c8013e406c2f32b4b0689ccb86b18f4ec3e0107a70e9b32e02b443

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page