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.

January 28, 2026 16:00 CET 2:00:35 ES
pythonmcpai-agentsenergyapisfastapi

Result

Ask “What was today’s electricity price?” → quarter-hourly price table and daily summary in seconds, directly from Claude Code via MCP.

Claude Code querying quarter-hourly OMIE prices via MCP: table with Spain €/MWh prices and daily summary

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.

OMIE electricity market clearing curve showing supply and demand

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.

System architecture: User → AI Agent → MCP Server → FastAPI → OMIE Data

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.

Claude Code building the OMIE service in NeoVim terminal

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:

First MCP query returning OMIE prices from a separate project folder

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

OMIE data connector added to Cloud.ai alongside Asana, Slack, 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:

Interactive OMIE price dashboard rendered directly inside Cloud.ai chat

Reference

API endpoints

EndpointDescriptionExample
GET /api/pricesPrices by date range?start_date=2026-01-20&end_date=2026-01-27
GET /api/prices/aggregateAggregation (mean, min, max, median)?operation=mean&column=price_spain
GET /api/prices/aggregate/groupedGrouped aggregation by date or hour?group_by=date&operation=mean
GET /api/datesAvailable dates?market_type=daily
POST /api/downloadDownload OMIE data?start_date=2026-01-01&end_date=2026-01-31

Project structure

main.pyCLI: download, process, server, mcp
src
omie_service.pyBusiness logic: download, parsing, aggregations
api.pyFastAPI REST endpoints (/api/*)
mcp_server.pyMCP server auto-generated from FastAPI
app.pyCombined server: /api/* + /mcp/*
mcp-appInteractive dashboard (TypeScript)
server.tsMCP server with visualization tools
srcUI rendered in Cloud.ai
data
rawOMIE CSV files
processedOptimized Parquet files

Stack

  • Python 3.12 / FastAPI / FastMCP / Claude Code / Pandas / UV / Cloudflare Tunnel

Resources

Subscribe to our newsletter

Get weekly insights on data, automation, and AI.

© 2026 Datons. All rights reserved.