Skip to content

TradeRouter/cookbook

Repository files navigation

Trade Router cookbook

Copy-paste-ready AI agent examples using @traderouter/trade-router-mcp — non-custodial Solana trading via the Model Context Protocol. Every example here uses the same 1-line install:

npx -y @traderouter/trade-router-mcp

Each example is self-contained, MIT licensed, and ships with a TRADEROUTER_DRY_RUN=true mode so you can run it end-to-end without touching mainnet.

Examples — strategies (raw MCP)

Folder What it does Difficulty
01-instant-swap Smallest possible agent: prompt → swap on multi-DEX with Jito MEV protection beginner
02-dca-bot Buy a fixed SOL amount of a token every N hours via TWAP order beginner
03-trailing-stop Place a trailing-stop sell to lock in gains as price climbs intermediate
04-mcap-trigger Watch a memecoin and limit-buy when its market cap drops below a target intermediate
05-combo-take-profit Limit-then-trailing-then-TWAP: enter at target mcap, ride the trend, exit gradually advanced
08-helius-trade-router-combo Helius for reads (DAS API token discovery) + Trade Router for writes (auto-take-profit on largest position) — the canonical pairing intermediate
09-pumpfun-graduation-sniper Watch a Pump.fun token, fire a MEV-protected limit buy the moment it graduates to PumpSwap/Raydium intermediate

Examples — agent framework integrations

The MCP server works in any framework that supports MCP. Configuration only — no custom code:

Folder Framework Adapter
06-elizaos-agent ElizaOS (90+ official plugins on Solana) @fleek-platform/eliza-plugin-mcp — generic MCP-client for ElizaOS
07-langchain-agent LangChain (Python + TypeScript) langchain-mcp-adapters — official LangChain MCP integration

Solana Agent Kit (SAK): SAK's adapter-mcp package wraps SAK into an MCP server (the inverse of what we need). For SAK agents that want to use Trade Router, the cleanest path is direct REST (api.traderouter.ai/swap + /protect) per our OpenAPI spec, or wrap the MCP server in any of the generic Node MCP clients (e.g. @modelcontextprotocol/sdk's Client class) and feed the tool list to your SAK agent's tool array. We're documenting an SAK example more fully in a future release.

Claude Desktop / Cursor / Cline / any MCP client: Just paste the mcpServers.traderouter block from any example's config.example.json into your client's MCP config file. No framework needed.

What you need before running

  1. A dedicated trading wallet (use a fresh one — see SECURITY.md on the main repo)
  2. The base58 private key in your env: export TRADEROUTER_PRIVATE_KEY=<base58>
  3. Recommended for first runs: export TRADEROUTER_DRY_RUN=true — every write tool returns { dry_run: true, ... } instead of submitting real transactions

How the examples are structured

Each NN-name/ folder has:

  • README.md — what the agent does, when to use it, expected behavior
  • agent.ts (or agent.py) — minimal runnable code
  • config.example.json — Claude Desktop / Cursor / Cline config for the MCP server alongside the agent
  • .env.example — the env vars you need

The MCP server itself does the heavy lifting (multi-DEX routing, Jito bundling, signing, Ed25519 verification). The cookbook code is the strategy layered on top.

Why these examples?

They're the patterns we've seen agent builders ask about most often. Each one demonstrates a different feature of the MCP server's 21 tools:

  • 01auto_swap (swap → sign → /protect in one call)
  • 02place_twap_order (server-monitored time-weighted execution)
  • 03place_trailing_order (trailing percentage)
  • 04place_limit_order triggered by get_mcap polling
  • 05place_limit_trailing_twap_order (the full combo, 11-field params_hash)
  • 08get_holdings indirectly via Helius + auto_swap (production read/write split pattern)
  • 09place_limit_order with trigger_type: "mcap" + connect_websocket + get_fill_log for verified callbacks

All run unmodified against npx -y @traderouter/trade-router-mcp@latest.

Contributing

Built something cool with TradeRouter? Open a PR adding it to this cookbook. Strong preference for examples that:

  • Run in under 30 lines of code
  • Use TRADEROUTER_DRY_RUN=true by default in .env.example
  • Document risks and slippage assumptions
  • Show real-world output from a test wallet (devnet acceptable for screenshots)

Links

License

MIT. See LICENSE.

About

Example AI agents using @traderouter/trade-router-mcp — DCA bot, trailing stop runner, sentiment trader, mcap-trigger bot, portfolio rebalancer. Copy-paste ready, MIT.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors