cmc-market-brief
by xcaracalid
README.md
# CMC Market Brief Agent
**Build with CMC: API Hackathon, Round 2 — Track: AI Agents and Automation**
An MCP server that puts live CoinMarketCap market data in front of any LLM,
plus a CLI agent that composes a daily market brief from the same tools.
Ask your AI assistant *"how is the market doing, and what is 0.5 BTC worth
in euros?"* — it answers from real CMC data instead of its training memory.
## What it does
- **MCP server** (`mcp_server.py`) — exposes four tools over stdio to any
MCP client (Claude Code, Claude Desktop, Cursor, …):
- `get_quotes(symbols)` — latest price, 1h/24h/7d change, market cap, volume
- `get_top_listings(limit)` — top coins by market capitalisation
- `get_global_metrics()` — total market cap, 24h volume, BTC/ETH dominance
- `convert(amount, symbol, convert)` — crypto/fiat price conversion
- **Brief agent** (`brief_agent.py`) — a CLI that calls the same client and
prints a formatted daily brief: market overview, top movers among the top
N listings, and a watchlist table. Pure data composition, no LLM key needed.
## Architecture
```
┌──────────────────┐
LLM / MCP ───▶│ mcp_server.py │──┐
client └──────────────────┘ │
▼
┌──────────────────┐ ┌────────────────────────┐
terminal ────▶│ brief_agent.py │──▶│ cmc_client.py │──▶ CMC Pro API
└──────────────────┘ └────────────────────────┘ (HTTPS + key header)
```
Both entry points share one thin client, so the CLI brief and the MCP tools
can never drift apart.
## CoinMarketCap API endpoints used
Base URL: `https://pro-api.coinmarketcap.com`, key sent in the
`X-CMC_PRO_API_KEY` header. (Paths verified against the official CMC API
documentation.)
| Endpoint | Used by |
|---|---|
| `GET /v2/cryptocurrency/quotes/latest` | `get_quotes` tool, watchlist section |
| `GET /v1/cryptocurrency/listings/latest` | `get_top_listings` tool, top-movers section |
| `GET /v1/global-metrics/quotes/latest` | `get_global_metrics` tool, overview section |
| `GET /v2/tools/price-conversion` | `convert` tool |
## Setup
```bash
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
cp .env.example .env # then paste your CMC Pro API key into .env
```
Get a free key at <https://pro.coinmarketcap.com/signup>. During the
hackathon, registering on DoraHacks with the same email upgrades the key to
the free **Startup tier** for the event period. The key can also be supplied
as the `CMC_API_KEY` environment variable. **Never commit `.env`** (it is in
`.gitignore`), and the key is never logged or written to any output file.
## Run
```bash
# Daily brief (live data)
.venv/bin/python brief_agent.py
.venv/bin/python brief_agent.py --watchlist BTC,ETH,SOL,BNB --limit 50
# Daily brief, offline demo on recorded sample fixtures (no key needed)
.venv/bin/python brief_agent.py --demo
# MCP server (stdio)
.venv/bin/python mcp_server.py
# Offline test suite (fixtures only, no key, no network)
.venv/bin/python -m pytest tests/ -q
```
## MCP client configuration
Claude Code:
```bash
claude mcp add cmc-market-brief -- /ABS/PATH/TO/cmc-hackathon/.venv/bin/python /ABS/PATH/TO/cmc-hackathon/mcp_server.py
```
Generic MCP client JSON:
```json
{
"mcpServers": {
"cmc-market-brief": {
"command": "/ABS/PATH/TO/cmc-hackathon/.venv/bin/python",
"args": ["/ABS/PATH/TO/cmc-hackathon/mcp_server.py"],
"env": { "CMC_API_KEY": "your-key-here" }
}
}
}
```
(If `CMC_API_KEY` is not passed via `env`, the server reads the project
`.env` file instead.)
## Demo
1. `.venv/bin/python brief_agent.py --demo` — prints a full brief from the
recorded sample fixtures in `tests/fixtures/` (clearly banner-labelled
as demo data).
2. With a real key: `.venv/bin/python brief_agent.py` prints the same brief
with live numbers.
3. Point any MCP client at `mcp_server.py` and ask: *"Give me a market
brief: global metrics, the top 10, and quotes for BTC, ETH and SOL."*
## Evidence of real API calls
```bash
.venv/bin/python scripts/capture_evidence.py
```
Runs one real call per endpoint and saves request parameters + full JSON
responses to `evidence/` (git-ignored). The script refuses to run without a
key, and the key itself is never written to disk — the saved request record
shows the auth header as `<redacted — never stored>`.
## What the API made possible / where it got in the way
**Made possible**
- One key and one base URL cover quotes, listings, global metrics and
conversions — the whole brief is four GET calls.
- The listings endpoint's 24h percent-change field makes a "top movers"
section trivial: no OHLCV history needed.
- Measured live on 2026-12-05: `/v1/key/info` costs 0 credits, and the
global-metrics and listings calls cost 1 credit each at brief page
sizes, and all four brief calls together measured 5 credits, so one
full brief run is about 5 credits. The plan on this key
reports 15,000 credits/month and a 50 requests/minute rate limit via
`/v1/key/info`, so a daily brief is a negligible share of the quota.
(Figures are the pre-upgrade values the API reported; the hackathon's
Startup-tier upgrade lands on the same key after DoraHacks
registration with the matching email.)
**Got in the way**
- Field quirks seen live: listings payloads are heavy (full tag lists,
self-reported supply fields, `tvl: null` on most assets), so parse
defensively and pick fields explicitly. Global-metrics duplicates
several values at the top level and again under `quote.USD`. Every
response carries a `status` envelope with `credit_count`, which makes
per-call cost accounting trivial. No sandbox was needed: the key was
verified directly against production with read-only GETs, and error
responses use the same structured `status` envelope
(`error_code` / `error_message`).
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues