Introduction
As an AI enthusiast and trainer, I believe high-quality open data is essential for building useful language models and agents. This project - the "Africa Energy Data MCP" - wraps a public Africa Energy Data API and exposes it as MCP tools so LLMs (Claude, Cursor, etc.) can call them directly.
In this short guide you'll find a clear, step-by-step walkthrough for:
- Setting up the project locally
- Understanding the architecture
- Connecting an MCP client (Claude / Cursor)
- Running and testing the tools
- Publishing options (brief)
Special thanks to my friend Denzel (dkkinyua) who developed the underlying API powering this project - check out his work here: https://github.com/dkkinyua/AfricaEnergyDataAPI/tree/main
Why this matters
LLMs become far more useful when they can call tools that fetch real data. This project makes historical electricity, energy and economic indicators for 54 African countries (2000–2022) trivially available to agents, with caching, retries and validation built in.
Quick highlights
- Tools:
get_electricity_data,get_energy_data,get_economic_data,check_api_health,list_countries - Tech: Python 3.11,
httpx,mcpserver, simple in-memory cache, structured logging - Containerization:
Dockerfile+ GitHub Actions example included
Step 1 - Get the code
Clone the repo and enter the project directory:
git clone https://github.com/Navashub/africa_energy_mcp.git
cd africa_energy_mcp
Step 2 - Install dependencies
Create a virtualenv and install requirements:
python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
pip install -r requirements.txt
Step 3 - Add your API key
Copy the example env file and paste your RapidAPI key from the API provider (Denzel's API or the RapidAPI listing):
cp .env.example .env
# edit .env and replace AFRICA_ENERGY_API_KEY with your key
Important: never commit .env or your API key to GitHub. The repo includes a .gitignore already.
Step 4 - Run the MCP server
Start the server locally:
py server.py
You should see structured logs on stderr indicating the MCP server initialized and registered tools. Leave this running — it listens on stdio for MCP clients.
Step 5 - Connect an MCP client (Claude / Cursor)
For local testing, point your MCP-capable client at the server.py process. Examples:
- Claude Desktop (Windows) — edit
%APPDATA%\Claude\claude_desktop_config.jsonand add:
{
"mcpServers": {
"africa-energy": {
"command": "py",
"args": ["D:\\mcp_projects\\africa_energy_mcp\\server.py"]
}
}
}
- Cursor — add the equivalent
mcp.serversentry in Cursor settings pointing to your localserver.py.
Step 6 - Test useful queries
Start with discovery commands so you confirm connectivity:
- "What countries are supported by the Africa Energy Data tool?" — should return the 54-country list (tool
list_countries). - "Is the Africa Energy Data API online?" —
check_api_healthtool should return a health JSON. - Example: "Get electricity data for Kenya in 2022." — will call
get_electricity_dataand return JSON results.
If an endpoint returns a 500, that indicates the remote API backend failed — the error is on the API provider side. The MCP server will surface a clear error message in that case.
Architecture (brief)
-
server.py- MCP server that declares tools and routes calls -
handlers.py- Input validation and mapping of tool arguments to API calls -
api_client.py-httpx.AsyncClientwrapper with retries, 30s timeout, and a 10-minute in-memory cache -
tools.py- Schemas for each MCP tool -
config.py- Environment and constants (including the hardcoded list of 54 countries)
Containerization & CI
If you want remote hosting, the repo includes a Dockerfile and an example GitHub Actions workflow that builds and pushes a container to GHCR. Publishing requires a registry token — we added a workflow that prefers a GHCR_TOKEN secret or falls back to the repo GITHUB_TOKEN when allowed.
Acknowledgements
Huge thanks to Denzel (dkkinyua) for building the underlying Africa Energy Data API — please check his repository: https://github.com/dkkinyua/AfricaEnergyDataAPI/tree/main
Shout-out: This project was adapted and wrapped into an MCP server by an AI enthusiast and trainer (that’s me — Navashub) to make the data accessible to LLMs for education, research and production usage.
Best practices & tips
- Keep your API keys secret - use
.envlocally and repository secrets for CI. - Test with
list_countriesandcheck_api_healthbefore running large queries. - Increase
REQUEST_TIMEOUTinconfig.pyonly if you know the backend requires more time. - For production hosting, use the Docker image and provide secrets through the host or the platform's secret mechanism.
Conclusion
Making structured, historical energy data available to LLMs unlocks better automated analysis, answers, and decision support. This project is a small but practical bridge - thanks to Denzel for the API and to you for exploring it.
Top comments (0)