::: title
LM03 MCP (aka Model Context Protocol)
The USB-C standard for connecting AI models to tools and data ::: César Freire::: image

:::
What is MCP?
- Model Context Protocol — an open standard (by Anthropic, 2024) that standardizes how LLM applications connect to external tools, data sources and APIs
- Client–server architecture: the AI application (host) runs MCP clients that talk to MCP servers
- Solves the N×M problem: without MCP, every app needs a custom integration for every tool
MCP Architecture
| Component | Role |
|---|---|
| Host | The AI application (Claude Desktop, IDE, your agent) |
| Client | Connector inside the host that maintains a 1:1 MCP session |
| Server | Exposes capabilities: tools, resources and prompt templates |
Host (LLM app) ── MCP Client ──(JSON-RPC)──▶ MCP Server ──▶ API / DB / files
What a Server offers: Primitives
- Tools — model-controlled functions the LLM can invoke (e.g.
get_province,search) - Resources — application-controlled data to read (files, DB rows, API docs)
- Prompts — user-controlled reusable prompt templates
Tools are chosen by the model, resources by the application, prompts by the user.
Why MCP matters for agents
- Interoperability — one server works with any MCP-compatible client (Claude, VS Code, LangChain, OpenAI Agents…)
- Composability — chain servers: geography API + translation model + charting tool
- Decoupling — tool owners hip updates independently from app developers
DEMO — Portugal weather via IPMA (FastMCP)
- API: IPMA open data — hourly observations from Portuguese weather stations, no auth needed
- Two data sources:
stations.json(station list + coordinates) andobservations.json(hourly values keyed by timestamp) - Three tools:
list_stations(),get_latest_observations(station_id?),get_station_observations(station_id, last_hours) - Production touches: in-memory cache (TTL 300s, API updates hourly), drop
-99.0nodata fields, readable wind-direction names
JSON IPMA API
// GET https://api.ipma.pt/open-data/observation/meteorology/stations/observations.json
{ "2026-10-02T13:00:00": { "1200455":
{ "temperatura": 18.6, "humidade": 71, ... } } }Ask the agent: “Where is it warmer right now, Lisboa or Porto?” → it calls list_stations then get_latest_observations and compares.
DEMO — Reference code: ipma_mcp.py
https://modelcontextprotocol.io