Skip to main content
Glama
henryjameslau

ONS Trade Data API MCP Server

README.md
# ONS Trade Data API — MCP Server

An [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server that exposes UK trade data from:

- https://ons-trade-data-api.netlify.app

Modeled on your previous `ons-baby-names-api-mcp` server: Python + FastMCP, deployable to Vercel, with a streamable HTTP MCP endpoint at `/mcp`.

## Tools

| Tool | Description |
|---|---|
| `health` | Check MCP server and upstream API connectivity |
| `get_schema` | Dataset metadata (version, last_updated, total_records) |
| `get_time_periods` | List available dates |
| `get_countries` | Country code lookup |
| `get_commodities` | Commodity metadata lookup |
| `get_country_index` | Available commodities and periods for a country |
| `fetch_raw` | Direct raw JSON fetch from `/data/...` path |
| `get_trade_file` | Fetch one static trade file with optional filtering |
| `query_trade` | Generic grouped aggregation query over a trade file |

## MCP endpoint

After deployment, connect an MCP client to:

```
https://ons-trade-data-api-mcp.vercel.app/mcp
```

## Environment variable

| Variable | Default | Description |
|---|---|---|
| `TRADE_API_BASE_URL` | `https://ons-trade-data-api.netlify.app` | Upstream trade API base URL |

## Deploy to Vercel

1. Push this repo to GitHub
2. Import it in Vercel
3. Deploy (no custom build needed)

## Local development

```bash
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python app.py
```

Server runs locally at:

```
http://localhost:8000/mcp
```