DeFi Sentinel X MCP Server
Autonomous AI agent monitoring X Layer DeFi protocols via real RPC calls, providing MCP tools for pool scanning, anomaly detection, risk scoring, alerts, position health checks, and audit trails.
README
🛰️ DeFi Sentinel X
Autonomous AI Agent for X Layer DeFi Protocol Monitoring
An autonomous AI agent that monitors X Layer (OKX's EVM-compatible L2, chainId 196) DeFi protocols in real-time — detecting price manipulation, liquidity drains, and unusual trading activity, then generating severity-classified alerts with on-chain risk scores.
Built for the OKX BuildX AI Season Hackathon ($300K prize pool).
🎯 Problem
DeFi protocols on X Layer are vulnerable to attacks that execute in seconds:
- Price manipulation via sandwich attacks and oracle manipulation
- Liquidity drains from pool imbalances and rug pulls
- Unusual trading from MEV bots and exploit frontrunning
Users have no real-time early warning system. By the time a human notices a pool's reserves dropping, the damage is done. Existing monitoring tools are either centralized alerts (slow) or static dashboards (passive).
💡 Solution
DeFi Sentinel X is an autonomous AI agent that:
- Continuously scans X Layer DeFi pools via real on-chain RPC calls
- Detects anomalies using statistical heuristics (reserve imbalance, liquidity drain, unusual activity)
- Computes risk scores (0-100 composite score) factoring anomaly severity, confidence, and type diversity
- Generates alerts with severity classification and recommended actions
- Checks position health for Aave V3 lending positions (health factor, liquidation distance)
The agent uses an MCP-style tool architecture — each capability is a
discrete tool with a JSON Schema input definition, orchestrated by an
agent layer that chains: scan_pool → detect_anomaly → calculate_risk_score → generate_alert.
🌟 Unique Angle
Unlike passive monitoring dashboards, DeFi Sentinel X is an active AI agent that:
- Uses real X Layer RPC (live block numbers, gas prices, eth_call against pool contracts)
- Follows the MCP (Model Context Protocol) tool pattern — 7 tools, each with name, description, and JSON Schema input, callable individually or orchestrated by the agent
- Runs fully on free-tier infrastructure (Vercel serverless + SQLite /tmp + public RPCs)
- Provides deterministic, reproducible agent orchestration (no LLM API key needed for the demo — the tool-chaining logic is the AI layer)
- Deploys as a Vercel serverless function — no servers, no cost, scales to zero
🏗️ Architecture
┌─────────────────────────────────────────────────────┐
│ DeFi Sentinel X Agent │
│ (Autonomous Tool Orchestrator) │
│ │
│ scan_pool → detect_anomaly → risk_score → alert │
│ │
│ Additional: get_position_health, get_chain_status │
│ get_audit_trail │
└──────────────┬──────────────────────┬────────────────┘
│ │
┌───────▼───────┐ ┌────────▼────────┐
│ X Layer RPC │ │ SQLite (/tmp) │
│ (real data) │ │ (audit trail) │
│ │ │ │
│ eth_chainId │ │ scans table │
│ eth_blockNum │ │ anomalies tbl │
│ eth_call │ │ alerts table │
│ eth_getBalance│ │ risk_assess tbl │
└───────────────┘ └─────────────────┘
│
┌───────▼───────┐
│ Vercel │
│ Serverless │
│ (@vercel/py) │
└───────────────┘
MCP Tool Architecture (7 Tools)
| # | Tool | Method | Description |
|---|---|---|---|
| 1 | scan_pool |
GET | Scan a DeFi pool for live reserves & TVL from X Layer RPC |
| 2 | detect_anomaly |
GET | Run anomaly detection heuristics on pool data |
| 3 | calculate_risk_score |
GET | Compute composite risk score (0-100) for a pool |
| 4 | generate_alert |
GET/POST | Generate a severity-classified alert from an anomaly |
| 5 | get_position_health |
GET | Check Aave V3 lending position health factor |
| 6 | get_chain_status |
GET | Get live X Layer chain metadata (block, gas) |
| 7 | get_audit_trail |
GET | Retrieve stored scan/anomaly/alert history |
All tools are also exposed via MCP protocol endpoints:
GET /mcp/tools— MCP tools/listPOST /mcp/call— MCP tools/call (body:{"name": "...", "arguments": {...}})
🛠️ Tech Stack
| Component | Technology | Why |
|---|---|---|
| API Framework | FastAPI 0.115 | Async, auto-docs, Pydantic validation |
| Hosting | Vercel (serverless) | Free tier, auto-scaling, zero config |
| Chain Data | X Layer RPC (real) | Live on-chain data, no API key needed |
| Persistence | SQLite (/tmp) | Serverless-friendly, no external DB |
| Agent Pattern | MCP-style tools | Standardized tool interface |
| Frontend | Vanilla HTML/CSS/JS | No framework, fast load, simple deploy |
| Language | Python 3.12 | Vercel Python runtime |
✅ What's Real vs ⚠️ Mocked
✅ Real (Live On-Chain)
- X Layer RPC calls —
eth_chainId,eth_blockNumber,eth_gasPricereturn live data (chainId 196, current block ~67M) - eth_call against pool contracts —
getReserves(),totalSupply()selectors sent to real X Layer contracts - eth_getBalance — real native balance reads for wallet health checks
- SQLite persistence — scans, anomalies, alerts, and risk assessments stored in
/tmp/defi_sentinel_x.db(survives across warm serverless invocations) - Anomaly detection heuristics — reserve imbalance, liquidity drain, zero liquidity, unusual activity detection run on real pool data
- Composite risk scoring — 0-100 score with severity classification (CRITICAL/HIGH/MODERATE/LOW/MINIMAL)
- Agent orchestration — tool-chaining logic: scan → detect → score → alert (the AI layer)
⚠️ Mocked / Simulated
- Pool reserve values — if
eth_callreturns zeros (demo pool addresses aren't real Uniswap pairs on X Layer), falls back to deterministic simulation based on pool name + block number (reproducible, varies as blocks advance) - Aave V3 health factor — derived from address hash (real Aave integration requires
Pool.getUserAccountData()which needs a funded position; theeth_getBalancecall IS real) - Baseline reserve ratios — hardcoded (production would use a time-series DB like TimescaleDB)
- "Unusual activity" heuristic — uses block-number parity as a proxy for tx volume (production would use mempool/trace data)
- No LLM API key — the agent orchestration is deterministic (reproducible in serverless without external API dependencies)
🚀 Quick Start
Local Development
cd defi-sentinel-x
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000
# Open http://localhost:8000
API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Dashboard UI |
/api/health |
GET | Health check + RPC status |
/api/agent/status |
GET | Agent config + tool inventory |
/api/demo |
GET | Full autonomous agent demo (sweeps all pools) |
/api/sweep |
POST | Single-pool monitoring sweep |
/mcp/tools |
GET | MCP tools/list |
/mcp/call |
POST | MCP tools/call |
/api/tools/scan_pool |
GET | Scan a pool |
/api/tools/detect_anomaly |
GET | Detect anomalies |
/api/tools/calculate_risk_score |
GET | Compute risk score |
/api/tools/generate_alert |
GET/POST | Generate alert |
/api/tools/get_position_health |
GET | Check position health |
/api/tools/get_chain_status |
GET | Live chain metadata |
/api/tools/get_audit_trail |
GET | Stored history |
/api/audit |
GET | Full audit trail |
/api/stats |
GET | Aggregate stats |
/docs |
GET | Swagger UI |
Deploy to Vercel
vercel --prod --yes --token "$VERCEL_TOKEN"
🔗 Links
- Live Demo: https://defi-sentinel-x.vercel.app
- GitHub: https://github.com/0xConsole/defi-sentinel-x
- X Layer: https://www.okx.com/xlayer
- Hackathon: OKX BuildX AI Season ($300K)
📁 Project Structure
defi-sentinel-x/
├── api/
│ └── index.py # Vercel entry point
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI app + routes
│ ├── tools.py # MCP tool registry + handlers (7 tools)
│ ├── agent.py # Agent orchestrator (tool-chaining)
│ ├── xlayer_client.py # X Layer RPC client (real on-chain reads)
│ └── store.py # SQLite persistence layer
├── static/
│ └── index.html # Dark-theme dashboard UI
├── vercel.json # Vercel config
├── requirements.txt # Python deps
├── SUBMISSION.md # Hackathon submission fields
└── README.md # This file
📜 License
MIT License — see LICENSE
Built by 0xConsole for the OKX BuildX AI Season Hackathon.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。