DEV Community

AlgoVault.com
AlgoVault.com

Posted on

I Built an MCP Server That Gives AI Trading Agents a Brain — Here's How

Published on Dev.to by AlgoVault Labs


There are 20,000+ MCP servers. Most of the crypto ones do plumbing — read prices, place orders, fetch order books. None of them tell your AI agent what to do with that data.

I built crypto-quant-signal-mcp — a signal interpretation layer for Hyperliquid perpetual futures. It takes raw market data and returns a single verdict: BUY, SELL, or HOLD, with a confidence score and reasoning.

This post covers the architecture, the scoring logic, and the decisions I made along the way.

The Problem

I run quant strategies on Hyperliquid and Binance Futures. When I started using Claude and Cursor to help evaluate positions, the only MCP servers available were raw data readers or order execution tools.

I'd ask Claude: "Should I go long on ETH right now?" and it would say something generic about market conditions because it had no tools to actually analyze live data.

What I wanted was a tool that does what I do manually every day — check RSI, look at the EMA cross, compare funding rates across venues, check OI momentum — and synthesize it into a single answer.

The Architecture

Three tools, one server

Tool What it does x402 Price
get_trade_signal Composite BUY/SELL/HOLD with confidence $0.02/call
scan_funding_arb Cross-venue funding rate arbitrage scanner $0.01/call
get_market_regime TRENDING / RANGING / VOLATILE classification $0.02/call

Remote-first

The product is the hosted API at https://api.algovault.com/mcp, not the npm package. AI agents need HTTP endpoints they can call and pay — they can't npm install your package.

Agent → HTTPS → api.algovault.com/mcp → Hyperliquid API → Composite signal → Agent
Enter fullscreen mode Exit fullscreen mode

The npm package (npx -y crypto-quant-signal-mcp) is a distribution magnet for Claude Desktop users. Free tier, runs locally via stdio.

Dual transport

if (process.env.TRANSPORT === 'stdio') {
  // Local: Claude Desktop, Cursor, etc.
  const transport = new StdioServerTransport();
  await server.connect(transport);
} else {
  // Remote: Express + Streamable HTTP (default)
  app.all('/mcp', express.json(), async (req, res) => {
    // MCP JSON-RPC over HTTP
  });
}
Enter fullscreen mode Exit fullscreen mode

Streamable HTTP is the MCP spec's recommended transport for remote servers (replaced SSE in the 2025-03-26 spec update). Requires @modelcontextprotocol/sdk v1.10.0+.

Exchange adapter pattern

The code talks to an ExchangeAdapter interface, not raw Hyperliquid calls:

interface ExchangeAdapter {
  getName(): string;
  getCandles(asset: string, interval: string, count: number): Promise<Candle[]>;
  getAssetContext(asset: string): Promise<AssetContext>;
  getPredictedFundings(): Promise<FundingRate[]>;
}
Enter fullscreen mode Exit fullscreen mode

Today there's only HyperliquidAdapter. When I add Binance and Bybit, same interface, same tools, more data.

The Signal Scoring Logic

The core of get_trade_signal is a weighted composite score:

Indicator Weight Scoring
RSI(14) 25% <30 bullish (+80), >70 bearish (-80), mean-reversion bias
EMA(9/21) 30% Cross direction + price position relative to EMAs
Funding Rate 20% Negative = bullish (shorts paying longs), vs 24h average
OI Momentum 15% Rising OI + rising price = confirmation
Volume 10% Above average = conviction, below = weak

Each indicator scores on a -100 to +100 scale. Multiply by weight. Sum them. If the composite score is >25 → BUY. <-25 → SELL. In between → HOLD. Confidence = abs(score), capped at 100.

Why these weights? They're based on my experience running quant strategies on HL and Binance. They're opinionated. The plan is to retune monthly based on actual outcome data (more on that below).

Example output:

{
  "verdict": "BUY",
  "confidence": 72,
  "price": 69433,
  "indicators": {
    "rsi": 66.7,
    "emaCross": "bullish",
    "fundingRate": 0.00022,
    "oiChange": 3.9,
    "volume24h": "$2.41B"
  },
  "reasoning": "EMA crossover is bullish but RSI is mid-60s. Funding neutral. OI rising modestly. Watch-and-wait territory — not high conviction."
}
Enter fullscreen mode Exit fullscreen mode

The Cross-Venue Funding Arb Scanner

This is the tool nobody else has via MCP.

Hyperliquid's predictedFundings endpoint returns funding rates for HL and Binance and Bybit in a single call. But there's a catch: HL pays funding hourly, CEX pays every 8 hours. You have to normalize before comparing.

// HL: hourly rate → annualize by ×8760
// CEX: 8h rate → annualize by ×1095
const hlAnnualized = hlRate * 8760;
const cexAnnualized = cexRate * 1095;
const spreadBps = (hlAnnualized - cexAnnualized) * 10000;
Enter fullscreen mode Exit fullscreen mode

The scanner ranks all 200+ HL perps by annualized spread and surfaces arbitrage opportunities. "Short on HL where funding is +0.05%, long on Binance where it's -0.01%" — that kind of thing.

Payments: x402 Micropayments

AI agents can't fill out a Stripe checkout form. They need to pay per HTTP call, programmatically.

We use the x402 protocol — USDC on Base chain:

  1. Agent sends request without payment
  2. Server responds HTTP 402 with payment requirements (price, token, chain, recipient)
  3. Agent signs an ERC-3009 transferWithAuthorization
  4. Server verifies via facilitator (~100ms), responds with data
  5. Settlement happens on-chain asynchronously (~2s)

Self-hosted facilitator (Coinbase's public one is testnet-only as of Apr 2026). Gas wallet funded with ETH on Base — each settlement costs fractions of a cent.

Try It (No Code Required)

The fastest way to try it:

  1. Open Claude → Settings → Integrations
  2. Add custom connector → Name: "Crypto Quant Signal", URL: api.algovault.com/mcp
  3. New chat → "Get me a trade signal for BTC"

That's it. Free tier. No API key. No install.

For developers: npx -y crypto-quant-signal-mcp

Stack

  • TypeScript + @modelcontextprotocol/sdk v1.10+
  • Express + Caddy HTTPS (remote)
  • @x402/core for payment verification
  • PostgreSQL (remote) / SQLite (local)
  • Docker + GitHub Actions CI/CD
  • Hosted on Hetzner VPS

What I Learned

  1. Registry distribution > social media. 111 npm downloads in week 1, entirely from Smithery + Official MCP Registry + awesome-mcp-servers. Zero came from X/Twitter or Reddit.

  2. Streamable HTTP is the future. SSE is deprecated in the MCP spec. If you're building a new server in 2026, go Streamable HTTP from day one.

  3. x402 is real but early. The protocol works. On-chain settlement works. But x402-aware clients barely exist yet. It's a forward bet on AI agents paying for API calls autonomously.

Links

This is tool #1 of 12. Building TradingView for AI agents.

Top comments (0)