cftc-cot-mcp
by ajstehle2001
README.md
# cftc-cot-mcp
An MCP server that exposes CFTC Commitments of Traders (COT) positioning as
clean, agent-callable tools. Point any MCP client — Claude, a LangGraph app,
an OpenAI Agents SDK app — at it and ask about managed-money positioning with
no glue code.
## Tools
| Tool | Returns |
|---|---|
| `get_latest_cot` | Most recent weekly report: managed-money long/short/net, open interest, market, date. |
| `query_cot_history` | A `YYYY-MM-DD` date range, or the most recent `last_n` weekly reports. |
| `cot_positioning_signal` | Derived read over a lookback window: net, week-over-week change, min/max, percentile rank, z-score, extreme flag. |
## Architecture
```mermaid
flowchart LR
H[MCP client / agent] -- stdio --> S[cftc-cot server]
S -- read-only --> D[(SQLite: COT table)]
```
Stateless server: a read-only SQLite connection per call, DB path and table
name from the environment, JSON out. Nothing is ever written.
## Design decisions
- **Read-only by construction.** The connection opens `mode=ro`, so a tool
cannot alter the source — a guarantee, not a convention.
- **Config, not hardcoding.** `COT_DB_PATH` and `COT_TABLE` come from the
environment; no deployment path lives in the code.
- **Inputs validated and clamped.** Dates are format-checked; `last_n` and
`lookback` are bounded, so a bad argument can't scan the whole table.
- **Table name whitelisted** against `[A-Za-z_][A-Za-z0-9_]*` before use.
## Failure model
| Failure | Behavior |
|---|---|
| DB file missing | `FileNotFoundError` naming the path and the env var to set |
| Malformed date argument | `ValueError`; the query never runs |
| Invalid table name in config | Server refuses to start |
| Empty table | `get_latest_cot` returns `{}`; signal returns explicit `not enough data` |
## Quick start
```bash
git clone https://github.com/ajstehle2001/cftc-cot-mcp.git
cd cftc-cot-mcp
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # edit .env with your DB path
python test_client.py # spawns the server and exercises all 3 tools
```
## Use it from an MCP client
```json
{
"mcpServers": {
"cftc-cot": {
"command": "/abs/path/.venv/bin/python",
"args": ["/abs/path/server.py"],
"env": {
"COT_DB_PATH": "/abs/path/to/cot.db",
"COT_TABLE": "cot_history_combined"
}
}
}
}
```
## Data
COT is public data published weekly by the US CFTC. Expected columns:
`report_date, mm_long, mm_short, mm_net, open_interest, market, fetched_at`.
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues