Skip to main content
Glama
README.md
# agent-trade

**MCP server for AI agent trading β€” any agent, any venue.**

Give your AI agent the ability to trade across prediction markets, pre-markets, and DEXs through a single [Model Context Protocol](https://modelcontextprotocol.io) server.

## Features

- πŸ”Œ **Multi-venue** β€” One MCP server, multiple trading venues
- πŸ€– **Agent Mode** β€” Auto-sign trades with a dedicated wallet
- πŸ‘€ **User Mode** β€” Preview trades, sign manually
- πŸ›‘οΈ **Safety built-in** β€” Spend limits, price sanity checks, persistent tracking
- πŸ”— **Multi-chain** β€” Solana, Polygon, 20+ EVM chains
- πŸ“– **Read-only works instantly** β€” No API keys needed for market data

## Supported Venues

| Venue | Type | Read | Trade | Chain |
|-------|------|------|-------|-------|
| [Polymarket](https://polymarket.com) | Prediction Market | βœ… | βœ… | Polygon |
| [Whales Market](https://whales.market) | Pre-market OTC | βœ… | βœ… | Solana, 20+ EVM |

## Quick Start

### With Claude Desktop / Cursor

Add to your MCP config:

```json
{
  "mcpServers": {
    "agent-trade": {
      "command": "npx",
      "args": ["-y", "agent-trade"],
      "env": {}
    }
  }
}
```

That's it β€” market data works immediately with zero config.

### With Claude Code

```bash
claude mcp add agent-trade -- npx -y agent-trade
```

### With OpenClaw

```bash
mcporter add agent-trade --command "npx -y agent-trade"
```

## Tools

### Universal Tools (all venues)

| Tool | Description |
|------|-------------|
| `list_venues` | List available trading venues and their status |
| `search_markets` | Search markets across venues |
| `get_market` | Get detailed market info |
| `get_order_book` | Get order book (bids/asks) |
| `get_recent_trades` | Get recent trades |
| `trade` | Place a buy/sell order |
| `cancel` | Cancel an open order |
| `get_positions` | Get portfolio positions |
| `get_orders` | Get open orders |
| `wallet_status` | Check wallet balance and spend limits |
| `setup_wallet` | Generate or configure wallet |

### Polymarket Tools

| Tool | Description |
|------|-------------|
| `pm_list_tags` | List market categories/tags |
| `pm_get_event` | Get event with all markets by slug |
| `pm_derive_api_key` | Derive API credentials (one-time) |

### Whales Market Tools

| Tool | Description |
|------|-------------|
| `wm_get_token_chart` | Token price chart data |
| `wm_get_market_stats` | Market statistics & overview |
| `wm_get_wallet_info` | Wallet info by address |
| `wm_get_upcoming_tokens` | Upcoming token listings |

## Configuration

### Environment Variables

#### Global

| Variable | Description | Default |
|----------|-------------|---------|
| `AGENT_TRADE_VENUES` | Enabled venues (comma-separated) | All available |
| `AT_WALLET_TYPE` | Wallet type: `solana` or `evm` | `solana` |
| `AT_AGENT_PRIVATE_KEY` | Agent wallet private key | β€” |
| `AT_SPEND_LIMIT_PER_TX` | Max spend per transaction (USD) | `50` |
| `AT_DAILY_LIMIT` | Max daily spend (USD) | `200` |
| `AT_SOLANA_RPC` | Custom Solana RPC URL | Public RPC |
| `AT_EVM_RPC` | Custom EVM RPC URL | Public RPC |
| `MCP_HTTP_PORT` | Enable HTTP transport on this port | β€” (stdio) |
| `MCP_HTTP_HOST` | HTTP bind address | `127.0.0.1` |

#### Polymarket

| Variable | Description | Required |
|----------|-------------|----------|
| `PM_PRIVATE_KEY` | Polygon wallet private key | For trading |
| `PM_API_KEY` | Derived API key | For trading |
| `PM_API_SECRET` | Derived API secret | For trading |
| `PM_API_PASSPHRASE` | Derived API passphrase | For trading |

> **Read-only mode needs zero config.** Set `PM_PRIVATE_KEY` to enable trading. Use `pm_derive_api_key` tool to generate API credentials.

#### Whales Market

| Variable | Description | Required |
|----------|-------------|----------|
| `WM_API_URL` | API base URL | No (defaults to mainnet) |
| `WM_AUTH_TOKEN` | Auth token for private endpoints | For portfolio |

## Trading Modes

### User Mode (default)

Agent previews the trade, you sign and execute manually:

```
You: "Buy 10 YES shares on 'Bitcoin above 100k by July?'"
Agent: "Preview: Buy 10 YES @ $0.62 = $6.20 total. Confirm?"
```

### Agent Mode

Agent signs and executes trades autonomously with a dedicated wallet:

```
You: "Find underpriced markets and buy"
Agent: [executes trade on-chain] "Bought 10 YES @ $0.62, tx: 0x..."
```

**Safety features:**
- Per-transaction spend limit (default $50)
- Daily spend limit (default $200)
- Price sanity checks against market data
- Persistent spend tracking across restarts
- Private key never exposed in responses

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     AI Agent (Claude, etc)  β”‚
β”‚         MCP Client          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ MCP Protocol
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       agent-trade           β”‚
β”‚    Universal MCP Tools      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Wallet  β”‚ β”‚  Safety   β”‚  β”‚
β”‚  β”‚ Manager β”‚ β”‚ (Spend    β”‚  β”‚
β”‚  β”‚         β”‚ β”‚  Tracker) β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β”‚    Adapter  β”‚        β”‚
β”‚       β”‚   Registry  β”‚        β”‚
β”‚  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚Polymar- β”‚ β”‚  Whales   β”‚  β”‚
β”‚  β”‚  ket    β”‚ β”‚  Market   β”‚  β”‚
β”‚  β”‚ Gamma + β”‚ β”‚ API +     β”‚  β”‚
β”‚  β”‚  CLOB   β”‚ β”‚ Solana +  β”‚  β”‚
β”‚  β”‚         β”‚ β”‚ EVM       β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## Adding New Venues

agent-trade uses an adapter pattern. To add a new venue:

1. Create `src/adapters/your-venue/index.ts` implementing `TradingAdapter`
2. Register in `src/registry.ts`
3. That's it β€” universal tools work automatically

```typescript
import { TradingAdapter, Market, TradeIntent, TradeResult } from '../adapter.js';

export class YourVenueAdapter implements TradingAdapter {
  name = 'your-venue';
  displayName = 'Your Venue';

  isConfigured(): boolean { return true; }
  async searchMarkets(params): Promise<Market[]> { /* ... */ }
  async trade(intent: TradeIntent): Promise<TradeResult> { /* ... */ }
  // ... implement remaining methods
}
```

## Development

```bash
git clone https://github.com/bigbearman/agent-trade.git
cd agent-trade
npm install
npm run build
npm run dev  # watch mode
```

### Test with MCP Inspector

```bash
npm run inspect
```

## License

MIT

TDQS

B3.1/5.0

Scored across 24 tools

Disambiguation3/5

Most tools target recognizable resources, but there is real overlap between generic and venue-specific operations. In particular, cancel vs wm_cancel_order, get_market vs venue-specific market/token tools, and wallet_status vs wm_get_wallet_info require careful reading to choose correctly.

Naming Consistency4/5

Names are consistently snake_case and mostly follow a verb_noun or prefix_verb_noun pattern, with wm_ and pm_ prefixes clearly marking venue-specific tools. Minor deviations like bare cancel/trade and noun-style wallet_status keep it from being fully uniform.

Tool Count3/5

At 24 tools the surface is heavy and verges on overloaded. The count is somewhat justified because the server spans generic trading plus Whales Market and Polymarket-specific operations, but there is still visible duplication across categories.

Completeness3/5

Core market, order, position, wallet, and basic trading workflows are covered, and Whales Market has useful offer support. However, gaps remain around personal trade history/order status, order modification, funds movement, and Polymarket-specific trading lifecycle operations beyond market data and API setup.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues