security-gate-x402

security-gate-x402

Agent Security & Hallucination Gate (x402)

Category
访问服务器

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选