Vibe Coding #2 - Data API + AI Agent | OMIE Electricity Prices with MCP
Built from scratch a data API with FastAPI using OMIE market data, integrated with MCP tools so an AI agent can query electricity prices through natural language.
Result
Ask “What was today’s electricity price?” → quarter-hourly price table and daily summary in seconds, directly from Claude Code via MCP.

The problem
- OMIE electricity market data is publicly available, but accessing it requires downloading CSV files manually
- File formats are cryptic: semicolon-separated columns, market codes, one file per day
- Every question means repeating the process: download, parse, calculate
- No way to query this data in natural language
The solution
We started from the OMIE website, the Iberian electricity market operator, which publishes public day-ahead prices for Spain and Portugal.

Architecture
We designed a three-layer system: raw OMIE data gets processed to Parquet, a FastAPI REST API exposes query endpoints, and an MCP server connects that API to the AI agent.

Building with Claude Code
Claude Code generated the entire project structure — data downloader, OMIE file parser, Pandas-powered aggregation service, REST API and MCP server. We worked with multiple agents: one in Visual Studio Code for initial scaffolding and another in NeoVim to continue development with shared context through the files.

The key insight: API First
The “aha” moment came when the MCP server was duplicating all the API logic. The fix: apply the API First pattern — build the API with FastAPI first, then mount it automatically as an MCP server with a single line:
# mcp_server.py - zero code duplication
mcp = FastMCP.from_fastapi(app=api_app, name="OMIE Energy Prices") Any change to the API is automatically reflected in the MCP server.
Testing the system
With the API working, we tested price queries from a completely separate project — no access to the source code, only through the MCP server:

Then we connected the server to Cloud.ai as a public connector, alongside integrations like Asana, Slack, or Figma:

Interactive dashboard in the chat
The final step was building an MCP App in TypeScript that renders interactive charts directly inside Cloud.ai — no separate web app needed:

Reference
API endpoints
| Endpoint | Description | Example |
|---|---|---|
GET /api/prices | Prices by date range | ?start_date=2026-01-20&end_date=2026-01-27 |
GET /api/prices/aggregate | Aggregation (mean, min, max, median) | ?operation=mean&column=price_spain |
GET /api/prices/aggregate/grouped | Grouped aggregation by date or hour | ?group_by=date&operation=mean |
GET /api/dates | Available dates | ?market_type=daily |
POST /api/download | Download OMIE data | ?start_date=2026-01-01&end_date=2026-01-31 |
Project structure
Stack
- Python 3.12 / FastAPI / FastMCP / Claude Code / Pandas / UV / Cloudflare Tunnel
Resources
- MCP Documentation - the standard protocol for connecting AI to external systems
- OMIE - Iberian Market Operator - electricity price data source
- OMIE Data - File access - downloadable CSV files
- FastAPI - REST API framework
- FastMCP - library to create MCP servers from FastAPI