security-gate-x402

security-gate-x402

Agent Security & Hallucination Gate (x402)

Category
Visit Server

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

  1. Prompt Injection & Role Hijacking Guard
    • High-speed heuristic detection of instruction override directives, DAN modes, synthetic system tags, and zero-width character evasion.
  2. 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.
  3. 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__).
  4. 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.
  5. OFAC & Mixer Sanctions Screening
    • Automatically blocks requests from OFAC-sanctioned mixer contracts (e.g. Tornado Cash) and malicious addresses (403 Forbidden).
  6. 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.
  7. 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.
  8. Zero-Retention & Legal Disclaimers (/terms, /privacy)
    • Formal in-memory processing policy (no customer data storage) and limitation of liability ($0.002 fee cap).
  9. One-Click Python SDK & @gate_inspect Decorator
    • Seamless integration with built-in verify_attestation() for LangChain, CrewAI, AutoGen, or custom agent pipelines.

šŸ“ 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

  1. Install Google Cloud SDK (gcloud).
  2. Authenticate: gcloud auth login and gcloud 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

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured