Skip to main content
Glama
README.md
# GeckoGuard MCP

**Grounded Pre-Trade Risk and Rug-Guardrail MCP Server + Trading-Desk Console for Solana Agents**

- **Live Web Console**: https://alphonshhhomenicmtu.github.io/geckoguard-solana-mcp/
- **Demo Video (1080p)**: https://www.youtube.com/watch?v=RlZ3XNbAcB0
- **Repository**: https://github.com/alphonshhhomenicmtu/geckoguard-solana-mcp
- **Data Attribution**: [Data provided by CoinGecko](https://www.coingecko.com/)

Autonomous Solana trading agents fail in predictable ways: they execute stale or poisoned DEX quotes far from fair market value, route large clips into thin pools with double-digit slippage, or buy freshly launched micro-caps with active freeze authorities and fabricated wash volume.

GeckoGuard MCP sits between an agent's swap router and transaction signing. It cross-checks every proposed Solana trade against live CoinGecko fair prices and Solana DEX pool telemetry, enforces fail-closed policy rules (`ALLOW` / `WARN` / `DENY`), attaches SHA-256 citation receipts to every number it returns, and optionally anchors the verdict digest onto Solana Devnet via SPL Memo v2.

---

## Screenshots

### 1. Live Pre-Trade Guardrail Console (JUP `ALLOW`)
![GeckoGuard Live Console ALLOW Verdict](docs/screenshots/01-live-allow-console.png)

### 2. Adversarial Exploit Drill: Spoofed DEX Quote (`+11.4%` -> `DENY`)
![GeckoGuard Spoofed Quote Blocked](docs/screenshots/02-spoofed-quote-blocked.png)

### 3. Thin-Pool Rug Drill, Verifiable CoinGecko Citations, and MCP JSON-RPC Output
![GeckoGuard Rug Drill Citations and MCP Output](docs/screenshots/03-rug-drill-citations-mcp.png)

---

## How CoinGecko API is used

GeckoGuard runs live out of the box with **zero API key required**, and upgrades automatically when `COINGECKO_API_KEY` is provided in `.env` (or entered in memory in the web console):

| Mode | Spot Fair-Price Endpoint | Solana Onchain Pool & Metadata Endpoints | Auth Header |
|---|---|---|---|
| **Public Zero-Key (Default)** | `GET https://api.coingecko.com/api/v3/simple/token_price/solana` (single mint per call) & `/simple/price?ids=solana` | `GET https://api.geckoterminal.com/api/v2/networks/solana/tokens/{mint}?include=top_pools` | None |
| **CoinGecko Demo Key** | `GET https://api.coingecko.com/api/v3/simple/token_price/solana` | `GET https://api.geckoterminal.com/api/v2/networks/solana/tokens/{mint}?include=top_pools` | `x-cg-demo-api-key` |
| **CoinGecko Analyst / Pro Key** | `GET https://pro-api.coingecko.com/api/v3/simple/token_price/solana` | `GET https://pro-api.coingecko.com/api/v3/onchain/networks/solana/tokens/{mint}?include=top_pools` & `/info` (`gt_score`, SPL mint/freeze authority, top-10 holder concentration) | `x-cg-pro-api-key` |

Engineering details inside `src/coingecko-client.ts`:
- **SHA-256 Citation Receipts**: Every upstream response is canonically serialized and hashed (`payloadSha256`) alongside the secret-sanitized endpoint URL, HTTP status, UTC timestamp, and exact extracted fields.
- **Rate-Limit Resilience**: Concurrent requests for the same mint coalesce in flight, responses cache in memory for 30 seconds, and HTTP 429/5xx errors retry with exponential backoff respecting `Retry-After`.
- **Honest Provenance**: If public endpoints rate-limit during an interactive session, curated presets can fall back to deterministic snapshots explicitly tagged `offline-fixture` in both UI and JSON receipts. Strict server workflows can disable fallback (`allowFixtureFallback: false`) to enforce pure fail-closed behavior.

---

## How Solana is used

1. **Strict 32-Byte Base58 Mint & Signer Validation**: Every input address is decoded from Base58 and verified to be an exact 32-byte Solana Ed25519 public key before any upstream API call is made (`src/validation.ts`).
2. **Multi-DEX Solana Pool Depth & Slippage Modeling**: Parses live Solana AMM pools across Raydium, Meteora, Orca, and PumpSwap, computes liquidity-weighted DEX VWAP, measures per-venue basis-point spread against CoinGecko global fair price, simulates constant-product AMM price impact across clip tiers (`$1k`, `$10k`, `$50k`, `$250k`), and computes the maximum safe single-clip size.
3. **SPL Token Security Signals**: Evaluates GeckoTerminal trust scores (`gt_score`), pool creation age, buy/sell orderflow skew, volume-to-liquidity turnover, and mutable SPL mint/freeze authority status when indexed.
4. **Phantom & Solflare Wallet Connect + Solana Devnet Memo Attestation**: The web console connects directly to Phantom or Solflare browser wallets, reads live Devnet SOL balances from `https://api.devnet.solana.com`, and signs real SPL Memo v2 transactions (`MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr`) that permanently anchor the compact guardrail verdict JSON and SHA-256 citation digest on Solana Devnet (guaranteed `<= 566` bytes).

---

## MCP Tools Exposed (`src/mcp-server.ts`)

| Tool Name | Purpose |
|---|---|
| `verify_solana_swap_quote` | Checks a proposed DEX swap price and USD size against CoinGecko fair value, quote freshness, and top pool reserves. Returns `ALLOW` / `WARN` / `DENY` with rule triggers and SHA-256 citations. |
| `audit_solana_token_risk` | Runs standalone token due diligence for any Solana SPL mint: liquidity floor, CoinGecko listing status, wash-volume anomalies, 24h volatility, pool age, GT score, and mutable authority checks. |
| `check_pool_liquidity_depth` | Simulates constant-product price impact across configurable USD clip tiers and returns the recommended maximum safe single-clip size. |
| `compare_dex_vs_coingecko_fair_price` | Compares CoinGecko spot fair price against every top Solana DEX pool in basis points to surface stale pools or venue dislocation. |
| `build_devnet_attestation_memo` | Runs a guardrail audit and packages the verdict + SHA-256 report digest into a verified `<= 566`-byte Solana SPL Memo v2 payload for Devnet anchoring. |

The server also exposes the read-only MCP resource `geckoguard://policy/default` so agents can inspect active policy thresholds before proposing trades.

---

## Pre-Trade Guardrail Policy Matrix

| Rule Code | Severity | Default Trigger Condition |
|---|---|---|
| `FAIL_CLOSED_DENY` | `BLOCK` (`DENY`) | Missing reference fair price or `$0` verified Solana pool liquidity |
| `STALE_QUOTE_BLOCKED` | `BLOCK` (`DENY`) | Quote timestamp older than `90s` or unparseable |
| `BPS_DIVERGENCE_BLOCKED` | `BLOCK` (`DENY`) | `|quoted - fair| / fair > 350 bps` (`3.50%`) |
| `BPS_DIVERGENCE_WARNING` | `WARN` | `|quoted - fair| / fair > 150 bps` (`1.50%`) |
| `THIN_LIQUIDITY_BLOCKED` | `BLOCK` (`DENY`) | Primary Solana pool reserve `< $25,000` |
| `THIN_LIQUIDITY_WARNING` | `WARN` | Primary Solana pool reserve `< $100,000` |
| `HIGH_PRICE_IMPACT_BLOCKED` | `BLOCK` (`DENY`) | Trade size `> 5%` of top pool reserve or constant-product impact `> 600 bps` |
| `HIGH_PRICE_IMPACT_WARNING` | `WARN` | Trade size `> 2%` of top pool reserve or constant-product impact `> 250 bps` |
| `WASH_VOLUME_WARNING` | `WARN` | 24h volume/liquidity `> 18x` on low trader count, or buy/sell count skew `> 5:1` |
| `EXTREME_VOLATILITY_WARNING` | `WARN` | 24h absolute price move `> 35%` |
| `UNVERIFIED_COINGECKO_LISTING` | `WARN` | Mint exists on Solana DEX pools but is not indexed in CoinGecko spot catalog |
| `LOW_GT_SCORE_WARNING` | `WARN` | GeckoTerminal trust score `< 50 / 100` |
| `AUTHORITY_RISK_WARNING` | `WARN` | SPL mint authority or freeze authority remains active |
| `YOUNG_POOL_WARNING` | `WARN` | Primary DEX pool created `< 24 hours` ago |

---

## Local Setup & Commands

### Prerequisites
- Node.js `>= 20` and npm `>= 10`
- No API key is required for default public mode

### 1. Install and Build
```bash
git clone https://github.com/alphonshhhomenicmtu/geckoguard-solana-mcp.git
cd geckoguard-solana-mcp
npm install
cp .env.example .env
npm run build
```

### 2. Run the Live Web Console Locally
```bash
npm run dev:web
```

### 3. Run the CLI Audit Tool
```bash
# Live audit of JUP using public CoinGecko + GeckoTerminal endpoints
npm run audit -- audit JUP

# Simulate a spoofed DEX swap quote (+13% above fair value -> exits with code 2 / DENY)
npm run audit -- verify-swap --mint JUP --quoted-price 0.21 --trade-size 15000 --offline

# Inspect multi-clip liquidity depth and safe single-clip sizing
npm run audit -- liquidity SOL --sizes 5000,25000,100000 --offline

# Generate a compact Solana Devnet SPL Memo v2 attestation payload
npm run audit -- memo SOL --offline
```

### 4. Connect to Claude Desktop, Cursor, or Any MCP Client
Start the stdio MCP server directly:
```bash
npm run mcp
```
Or copy [`examples/mcp-client-config.json`](examples/mcp-client-config.json) into your MCP host configuration:
```json
{
  "mcpServers": {
    "geckoguard-solana": {
      "command": "npx",
      "args": ["-y", "tsx", "./src/mcp-server.ts"],
      "env": {
        "COINGECKO_API_TIER": "public",
        "COINGECKO_API_KEY": "${COINGECKO_API_KEY}"
      }
    }
  }
}
```
Set `COINGECKO_API_TIER=pro` and export `COINGECKO_API_KEY` in your shell environment to upgrade to CoinGecko Analyst/Pro onchain endpoints without storing keys in any config file.

---

## Verification & Security

- **Automated Test Suite**: `npm test` executes **76 Vitest unit, integration, adversarial, CLI, and live in-memory MCP JSON-RPC tests** (`100% PASS`).
- **Type Safety**: `npm run typecheck` checks both Node MCP server (`tsconfig.json`) and browser bundle (`tsconfig.web.json`) under `strict: true`.
- **Zero Leaked Secrets**: Verified with `gitleaks detect --source . --no-git --redact` (`0 leaks`), runtime secret redaction on all error paths, and credential-stripping URL sanitization on every citation receipt.

---

## Attribution & License

Market prices, market capitalization, 24h volume, and Solana DEX pool telemetry are powered by CoinGecko and GeckoTerminal APIs.  
[Data provided by CoinGecko](https://www.coingecko.com/).

Licensed under the [MIT License](LICENSE).