TailGuard MCP Server
by xgbtxy
README.md
# TailGuard — Autonomous Solana Long-Tail Risk Scout, Token-2022 Guard & MCP Server

> **On-chain data provided by CoinGecko.**
> Built for the **CoinGecko API × Superteam "Long Tail" Solana Hackathon** (*AI Agents with CoinGecko Data* track).
**TailGuard** fuses both core autonomous-agent safety problems on Solana into one deterministic, zero-mainnet-spend security product:
1. **Autonomous Long-Tail Pool Risk Scout (`tailguard scan`)** — scans CoinGecko Solana trending & newly created pools across PumpSwap, Meteora, Raydium, and Orca, cross-checking every mint live on Solana Mainnet RPC.
2. **Pre-Trade Execution Guard (`tailguard guard` + Native 4-Tool MCP Server `tailguard mcp` + Solana Blink `/api/actions/guard`)** — computes deterministic **`ALLOW` | `WARN` | `BLOCK`** policy verdicts before an AI agent signs a Solana swap.
---
## Why TailGuard?
Autonomous Solana trading agents fail on long-tail pools in six repeatable ways: honeypot zero-sell traps, active SPL/Token-2022 rug authorities (`permanentDelegate`, predatory transfer fees, `transferHook`), extreme whale concentration, router bad-fill quote manipulation (`> 800 bps`), resurrected dead pools with collapsed historical liquidity, and lookalike ticker/mint spoofs.
TailGuard answers the core judging question — *"Does it act reliably on its own, and are its answers grounded in data?"* — with **100% deterministic policy rules grounded in live CoinGecko Onchain telemetry and live read-only Solana RPC state**, never hallucinated LLM intuition.
---
## Mission Control Screenshots
*On-chain data provided by CoinGecko.*
### 1. Live CoinGecko Solana Pools Scanner & Real Mainnet Token-2022 Detection

### 2. Live Solana Mainnet Token-2022 Extension Inspector (PYUSD) & Pre-Trade Swap Guard (`V4` Bad-Fill `BLOCK`)

### 3. 6-Vector Adversarial Rug & Bad-Fill Drill (`6/6 BLOCKED`, `100/100`) + Solana Actions/Blinks & MCP

---
## Quickstart (Clone → Install → Verify → Run in 30 Seconds)
Requirements: **Node.js `>= 20`** (tested on Node `22.21.0`). Zero external runtime npm dependencies.
```bash
git clone https://github.com/xgbtxy/tailguard.git
cd tailguard
npm install
cp .env.example .env
# 1. Type-check, build, and run all 31 deterministic unit/integration tests
npm run typecheck
npm run build
npm test
# 2. Run the 6-Vector Adversarial Rug & Bad-Fill Drill (6/6 BLOCKED, 100/100)
npm run drill
# 3. Live keyless CoinGecko Solana scan + live Solana Mainnet Token-2022 inspection ($0 spend)
# On proxied Windows hosts running Node 22, set NODE_USE_ENV_PROXY=1
npm run cli -- scan --live --limit 6
npm run cli -- inspect 2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo --live
# 4. Launch Mission Control Web UI + REST API + Solana Actions/Blinks server
npm run serve
# Open http://127.0.0.1:3088 (switch between Deterministic Fixture & Live CoinGecko + Solana RPC)
```
### Environment Configuration (`.env.example`)
Never commit `.env` or real API keys to git. TailGuard works **out-of-the-box with zero API key** (live keyless CoinGecko/GeckoTerminal mode + offline deterministic fixtures) and unlocks Pro-tier `/top_holders` automatically when `COINGECKO_API_KEY` is provided:
```dotenv
COINGECKO_API_KEY=
COINGECKO_API_TIER=pro # pro (pro-api.coingecko.com) | demo (api.coingecko.com)
COINGECKO_MODE=fixture # fixture (offline deterministic) | live (real CoinGecko + Solana RPC)
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
PORT=3088
```
---
## How CoinGecko API Is Used
*On-chain data provided by CoinGecko.*
`src/coingecko/client.ts` implements a resilient **3-tier Onchain Solana client**:
1. **Analyst / Pro Tier (`pro-api.coingecko.com/api/v3/onchain`)** via `x-cg-pro-api-key` when `COINGECKO_API_KEY` and `COINGECKO_API_TIER=pro` are set — unlocks `/tokens/{mint}/top_holders` whale concentration checks.
2. **Demo / Keyless Public Tier (`api.coingecko.com/api/v3/onchain` → `api.geckoterminal.com/api/v2` fallback)** — works live immediately for judges without needing a paid key.
3. **Deterministic Offline Fixture Tier (`fixture`)** — guarantees 100% reproducible tests, demos, and air-gapped evaluation on network timeouts (`AbortSignal.timeout(15000)`).
| CoinGecko Endpoint | Purpose in TailGuard |
|---|---|
| `GET /onchain/networks/solana/trending_pools` | Live trending long-tail Solana pool discovery (`reserve_in_usd`, `volume_usd`, `transactions.h24.{buys,sells,unique_traders}`, nullable `market_cap_usd`, `/^solana_/` mint extraction) |
| `GET /onchain/networks/solana/new_pools` | Freshly launched Solana DEX pool monitoring (`pool_created_at` age check `< 60m`) |
| `GET /onchain/networks/solana/tokens/{mint}?include=top_pools` | Independent CoinGecko USD reference spot price, FDV, launchpad graduation state, and deepest pool selection |
| `GET /onchain/networks/solana/pools/{pool}/trades` | Native **`is_anomalous`** swap clustering + buy/sell honeypot ratio verification (`V1`) |
| `GET /onchain/networks/solana/pools/{pool}/ohlcv/minute` | Historical numeric 6-tuple OHLCV drawdown calculation detecting survivorship/dead-pool drains `> 92%` (`V5`) |
| `GET /onchain/networks/solana/tokens/{mint}/top_holders` | Non-LP Top-10 whale concentration verification (`V3`, `> 70%` blocks). When unavailable on Demo/Keyless tier (`401/403`), **degrades fail-closed** as `UNAVAILABLE_ON_DEMO` and escalates non-canonical tokens to `WARN` instead of silently passing |
**Fail-Closed Secret Hygiene:** `redactCoinGeckoHeaders()` and `redactSecretsInText()` strip `x-cg-pro-api-key`, `x-cg-demo-api-key`, `Authorization`, and `CG-...` tokens from every log line, error message, API response, and MCP payload.
---
## How Solana Is Used (`$0` Mainnet Spend, Zero Private Keys)
1. **Live Read-Only SPL & Token-2022 Inspector (`src/solana/inspector.ts`):**
- Calls Solana Mainnet JSON-RPC `getAccountInfo(mint, { encoding: "jsonParsed", commitment: "confirmed" })` directly with zero private keys and `$0` gas.
- Distinguishes classic `spl-token` (`Tokenkeg...`) vs `spl-token-2022` (`TokenzQd...`) and decodes security-critical Token-2022 extensions:
- `permanentDelegate` (holder wallet clawback/burn risk)
- `transferFeeConfig` (`transferFeeBasisPoints` — blocks predatory `>= 500 bps` fees)
- `transferHook` (external program execution on transfer)
- `mintCloseAuthority`
- `confidentialTransferMint` / `confidentialTransferFeeConfig`
- `metadataPointer` & `tokenMetadata`
- Distinguishes regulated institutional issuers (e.g., `PYUSD`, `USDC`) from anonymous long-tail rug traps.
2. **Solana Actions / Blinks v2.2 Pre-Flight Guard (`GET /actions.json`, `GET/POST /api/actions/guard`):**
- Standards-compliant CORS + `X-Action-Version: 2.2` + `X-Blockchain-Ids: solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` endpoints allowing any Solana wallet/Blink client to run a zero-gas pre-flight check before signing a swap.
---
## Native 4-Tool MCP Stdio Server (For AI Agents)
Start the MCP server over stdio (`npm run mcp` or `node dist/mcp/server.js`) and connect it to Claude Code, Cursor, Codex, or Solana Agent Kit:
```json
{
"mcpServers": {
"tailguard": {
"command": "node",
"args": ["dist/mcp/server.js"],
"env": {
"COINGECKO_MODE": "live",
"NODE_USE_ENV_PROXY": "1"
}
}
}
}
```
| MCP Tool | What It Does |
|---|---|
| `scan_long_tail_pools` | Scans CoinGecko trending/new Solana pools + inspects SPL/Token-2022 authorities |
| `inspect_solana_token` | Full CoinGecko token/trades/OHLCV/top_holders + live Solana RPC mint audit |
| `evaluate_swap_guard` | Pre-trade `ALLOW` / `WARN` / `BLOCK` verdict with exact bps divergence & triggered rules |
| `run_rug_drill` | Runs the deterministic 6-Vector Adversarial Rug & Bad-Fill Drill (`6/6 BLOCKED`, `100/100`) |
Every MCP response carries `"attribution": "On-chain data provided by CoinGecko"`.
---
## Verified Test, Drill & Live Run Results
### 6-Vector Adversarial Rug & Bad-Fill Drill (`npm run drill`)
```text
========================================================================
TailGuard — 6-Vector Adversarial Rug & Bad-Fill Security Drill
On-chain data provided by CoinGecko
========================================================================
V1 | PASS [BLOCKED] | Score 100/100 | Honeypot / Zero-Sell Trap
└─ RULE_HONEYPOT_ZERO_SELLS: buys=50, sells=0 (0.0% sells)
V2 | PASS [BLOCKED] | Score 100/100 | Active Mint / Freeze / Permanent Delegate Rug
└─ RULE_ACTIVE_MINT_FREEZE_AUTH: mintAuthority=ACTIVE, freezeAuthority=ACTIVE
V3 | PASS [BLOCKED] | Score 85/100 | Whale Cabal Concentration (> 70%)
└─ RULE_WHALE_CONCENTRATION: top10NonLp=84.6%
V4 | PASS [BLOCKED] | Score 100/100 | Bad-Fill / Quote Manipulation (> 800 bps)
└─ RULE_QUOTE_DIVERGENCE_BPS: divergenceBps=1450 (limit=800)
V5 | PASS [BLOCKED] | Score 90/100 | Dead-Pool / Survivorship Drain
└─ RULE_DEAD_POOL_SURVIVORSHIP: drawdown=97.07%, reserve=$1850
V6 | PASS [BLOCKED] | Score 100/100 | Lookalike Ticker / Mint Spoof
└─ RULE_SPOOF_MINT_MISMATCH: expected=DezXAZ8z..., actual=Sp00fBnk...
------------------------------------------------------------------------
C0 | PASS [ALLOW] | Benign Verified JUP/USDC Swap Control
RESULT: 6/6 BLOCKED | SCORE 100/100 | CONTROL PASS
========================================================================
```
### Live Keyless CoinGecko + Solana Mainnet RPC Sample (`npm run cli -- inspect 2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo --live`)
```text
TailGuard Solana Token Audit — PYUSD (2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo)
On-chain data provided by CoinGecko
Verdict: ALLOW | Risk Score: 0/100 | Holder Check: UNAVAILABLE_ON_DEMO
Solana RPC (solana-rpc-live): program=spl-token-2022 | mintAuth=DRXA1H9S... | freezeAuth=2apBGMsS...
Token-2022 Extensions: mintCloseAuthority, permanentDelegate, transferFeeConfig, confidentialTransferMint, confidentialTransferFeeConfig, transferHook, metadataPointer, tokenMetadata
permanentDelegate: 2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk
transferFeeBps: 0
CoinGecko (geckoterminal-v2): priceUsd=0.9995346286 | reserveUsd=$22.08M | 24hVol=$11.71M
```
### Quality & Security Verification Summary
| Gate | Command / Check | Verified Result |
|---|---|---|
| TypeScript Build | `npm run typecheck && npm run build` | **0 errors** (Node 22 ESM) |
| Automated Test Suite | `npm test` (6 Vitest suites) | **31/31 PASS** (parsers, redaction, Token-2022, V1–V6, MCP, HTTP/Blinks, Zero-XSS) |
| Adversarial Rug Drill | `npm run drill` | **6/6 BLOCKED (`100/100`)** + Benign `JUP` Control `ALLOW` |
| Headless UI & Mobile Audit | Desktop `1280×800` + Mobile `390×844` + 9-step interactive DOM/HTTP smoke | **0 JS errors, 0 network errors, 0 layout/overlap defects, 9/9 PASS** |
| Zero-XSS DOM Enforcement | `test/server-api.test.ts` + strict CSP (`script-src 'self'`) | **0 `innerHTML`/`outerHTML`/`insertAdjacentHTML`/`eval` sinks** |
---
## Repository Structure
```text
src/
├── types.ts # Normalized CoinGecko, Solana Token-2022, Guard & Drill schemas
├── config.ts # Env config + fail-closed redactCoinGeckoHeaders / redactSecretsInText
├── coingecko/client.ts # 3-tier CoinGecko Onchain Solana client (Pro -> Demo/Public -> Fixture)
├── solana/inspector.ts # Read-only Solana Mainnet SPL + Token-2022 jsonParsed mint inspector
├── guard/engine.ts # Deterministic 0-100 risk engine, bps-divergence Swap Guard & service
├── drill/rug-drill.ts # 6-Vector Adversarial Rug & Bad-Fill Drill + benign JUP control
├── mcp/server.ts # Native 4-tool MCP stdio JSON-RPC 2.0 server
├── server.ts # Mission Control HTTP API + Solana Actions/Blinks v2.2 endpoints
├── cli.ts # `scan | inspect | guard | drill | mcp | serve` CLI
└── fixtures/solana-longtail.ts
web/ # Zero-XSS Mission Control UI (createElement/textContent only)
test/ # 6 Vitest suites (31 tests)
docs/THREAT_MODEL.md # Formal trust boundaries & 6-vector threat matrix
AI_USAGE.md # Transparent AI assistance & deterministic grounding disclosure
```
---
## License & Attribution
Released under the [MIT License](LICENSE).
**On-chain data provided by CoinGecko.**
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues