Skip to main content
Glama
CMC Agent Toolkit

CMC Agent Toolkit

by adhais23
README.md
# CMC Agent Toolkit

MCP server + CLI demo agent over live CoinMarketCap data — built for the
**Build with CMC: API Hackathon, Round 2** (track: AI Agents and Automation).

An LLM asks market questions in plain language; the agent answers from
real CoinMarketCap data through six tools — including one composed
`cmc_market_brief` call that returns a whole market snapshot at once
(overview + top movers + trending), instead of three separate calls.

## Status: MOCK until the API key arrives

Right now the server runs on **fixture data** (frozen sample snapshot,
`src/fixtures.ts`) because no `CMC_API_KEY` is set yet. Every tool,
test and the demo already work in this mode — the only difference when
the key arrives is the data source. Nothing else changes.

| Mode | How to run | Data |
| --- | --- | --- |
| MOCK (default, no key) | `npm start` | Fixture snapshot, deterministic |
| LIVE | `CMC_API_KEY=... npm start` | CoinMarketCap Pro API v1 |

## Install & run

```bash
npm install
npm run build

# MCP server (stdio) — plug into Claude Code / OpenCode / Inspector:
npm start

# CLI demo agent — answers 3 sample questions from the tools:
npm run demo

# Tests (mock-backed, no network) + MCP smoke check:
npm test
npm run smoke
```

## Tools (MCP + AgentTools toolkit `cmc`)

| Tool | What it does | CMC endpoint |
| --- | --- | --- |
| `cmc_get_quote` | Price, 1h/24h/7d %, market cap, 24h volume (1–10 symbols) | `/v1/cryptocurrency/quotes/latest` |
| `cmc_compare_coins` | Compare 2–5 coins, ranked by 24h change | `/v1/cryptocurrency/quotes/latest` (batched) |
| `cmc_top_movers` | Top gainers & losers 24h, optional min market-cap filter | `/v1/cryptocurrency/listings/latest` |
| `cmc_trending_now` | Coins trending on CoinMarketCap | `/v1/cryptocurrency/trending/latest` |
| `cmc_market_overview` | Total cap, volume, BTC/ETH dominance, Fear & Greed | `/v1/global-metrics/quotes/latest`, `/v1/fear-and-greed/latest` |
| `cmc_market_brief` | Composed: overview + top 5 movers + trending in one call | (the above, combined) |

Every tool accepts `response_format: "markdown" | "json"`. Live responses
are cached 60 seconds to save API credits (one demo question = at most
2–3 API calls).

## API key

Set it in the environment — never commit it:

```bash
cp .env.example .env   # then fill in CMC_API_KEY (or export it directly)
CMC_API_KEY=your-key npm start
```

Free key: https://coinmarketcap.com/api/ (Startup-tier upgrade comes from
the hackathon registration on DoraHacks). See `docs/api-evidence.md`
for the endpoints used and example request/response pairs.

## Layout

```
src/
  index.ts        # MCP server entry (stdio)
  demo-agent.ts   # CLI demo agent (AgentTools SDK, tools-only mode)
  config.ts       # env config (key, mock/live, cache)
  cmc-client.ts   # live + mock clients, error mapping, 60s cache
  fixtures.ts     # mock data (clearly labelled, deterministic)
  toolkit.ts      # AgentTools toolkit "cmc" (same tools as the MCP server)
  tools/
    core.ts       # shared tool logic (used by MCP + toolkit)
    index.ts      # MCP tool registration (SDK v2, Zod v4)
test/             # node:test, mock-backed
scripts/smoke.ts  # MCP self-check over stdio
examples/sample-questions.md
docs/api-evidence.md
```

## License

MIT. Built for the Build with CMC hackathon; the CoinMarketCap
integration is new work for this event.