security-gate-x402
Agent Security & Hallucination Gate (x402)
README
Agent Output Security & Hallucination Gate (x402) š”ļøā”
A deterministic, ultra-low latency (<10ms) security and hallucination inspection micro-oracle for autonomous AI agents.
- Service Name:
agent-security-gate-x402 - Settlement Rail: HTTP 402 + x402 Protocol on Base network ($0.002 USDC per request)
- Supported Standards: Google AP2 (
/.well-known/ap2), FastMCP, OpenAPI (/docs) - Compliance & Legal: Zero-Data-Retention Policy (
/privacy), Terms of Service & AS-IS Disclaimer (/terms), OFAC Sanctions Screening. - Deployment: Google Cloud Platform (GCP Cloud Run / Cloud Build)
š Key Features
- Prompt Injection & Role Hijacking Guard
- High-speed heuristic detection of instruction override directives, DAN modes, synthetic system tags, and zero-width character evasion.
- Secret & Key Leak Scanner
- Instant scanning for EVM 32-byte private keys, OpenAI / Anthropic API keys, GitHub PATs, AWS access keys, and asymmetric private key blocks.
- AST Dangerous Code Execution Guard
- Python AST analyzer blocking prohibited module imports (
os,subprocess,sys,socket,shutil,pty,ctypes) and dangerous builtins (eval,exec,__import__).
- Python AST analyzer blocking prohibited module imports (
- Numerical & Entity Hallucination Validator (Lightweight NLI)
- Cross-checks numerical claims and named entities in agent outputs against ground truth contexts, pinpointing fabricated numbers and ungrounded entities without heavy external LLM latency.
- OFAC & Mixer Sanctions Screening
- Automatically blocks requests from OFAC-sanctioned mixer contracts (e.g. Tornado Cash) and malicious addresses (403 Forbidden).
- Cryptographic Proof-of-Safety Attestation (EIP-191)
- Generates tamper-proof audit certificates signed by the gate issuer. Downstream orchestrators and smart contracts can verify proof of inspection before releasing task bounties or executing transactions.
- Autonomous Agent Self-Discovery (
llms.txt& Google AP2)- Exposes machine-readable discovery interfaces (
llms.txt,/.well-known/ap2.json,mcp_tool_spec.json) allowing autonomous AI crawlers to discover, bind tools, and settle autonomously without human sign-up.
- Exposes machine-readable discovery interfaces (
- Zero-Retention & Legal Disclaimers (
/terms,/privacy)- Formal in-memory processing policy (no customer data storage) and limitation of liability ($0.002 fee cap).
- One-Click Python SDK &
@gate_inspectDecorator- Seamless integration with built-in
verify_attestation()for LangChain, CrewAI, AutoGen, or custom agent pipelines.
- Seamless integration with built-in
š Project Structure
agent-security-gate-x402/
āāā app/
ā āāā __init__.py
ā āāā main.py # FastAPI server, /terms, /privacy, & x402 payment enforcement
ā āāā security_engine.py # Injection, key leak, AST & NLI verification logic
ā āāā x402_verifier.py # x402 facilitator signature & OFAC verification
ā āāā schemas.py # Pydantic request/response schemas
āāā sdk/
ā āāā __init__.py
ā āāā agent_gate_sdk.py # Python SDK client & @gate_inspect decorator
āāā tests/
ā āāā __init__.py
ā āāā test_client.py # End-to-end payment, security, & SDK test suite
āāā .well-known/
ā āāā ap2.json # Google AP2 manifest
āāā mcp_tool_spec.json # MCP tool definition for Claude/Cursor/LLMs
āāā cloudbuild.yaml # GCP Cloud Build automated pipeline
āāā deploy-gcp.sh # GCP Cloud Run deployment script (Bash)
āāā deploy-gcp.ps1 # GCP Cloud Run deployment script (PowerShell)
āāā Dockerfile # Ultra-lightweight container
āāā requirements.txt # Dependencies
āāā .env.example # Environment template
āāā README.md
š Python SDK & Decorator Usage
Install the client SDK in your agent project and wrap your LLM calls:
from sdk.agent_gate_sdk import SecurityGateClient, gate_inspect
client = SecurityGateClient(
gate_url="https://agent-security-gate-x402-7qxtp3324q-du.a.run.app",
private_key="0xYourAgentEVMKey..."
)
# 1. Direct Inspection
result = client.inspect(
agent_output="The total quarterly net revenue was $1.2M.",
context_ground_truth="Quarterly revenue: $1.2M."
)
print(result["audit"]["verdict"]) # "PASSED"
# 2. Function Decorator Middleware
@gate_inspect(client=client, strict=True)
def run_agent_reasoning(task_prompt: str) -> str:
# Your LLM call (OpenAI, Anthropic, LangChain, etc.)
return llm.invoke(task_prompt)
āļø Google Cloud Platform (GCP Cloud Run) Deployment
Prerequisites
- Install Google Cloud SDK (
gcloud). - Authenticate:
gcloud auth loginandgcloud config set project <YOUR_GCP_PROJECT_ID>.
One-Click Deployment
Linux / macOS
chmod +x deploy-gcp.sh
./deploy-gcp.sh
Windows (PowerShell)
.\deploy-gcp.ps1
Once deployed, your Cloud Run service URL will be printed (e.g. https://agent-security-gate-x402-xxx.a.run.app).
š ļø Local Development & Testing
# 1. Start local server
uvicorn app.main:app --host 0.0.0.0 --port 8080 --reload
# 2. Run test suite
python tests/test_client.py
# or
pytest tests/test_client.py -v
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.