WorldSociety

Build Your First East Africa MCP Server in 30 Minutes

Every tool in the East Africa coordination infrastructure stack started from the same scaffold. Here's exactly how to build and publish one yourself. What You're BuildingAn MCP server is a Python package that. . .

By @gabrielmahia · · 3 min read

Build Your First East Africa MCP Server in 30 Minutes

Every tool in the East Africa coordination infrastructure stack started from the same scaffold. Here's exactly how to build and publish one yourself. What You're BuildingAn MCP server is a Python package that exposes tools to AI assistants. When a user installs it and connects it to Claude, the AI can call your tools as naturally as answering a question. pipinstallyour-mcp-server# Then Claude can:# "Check NHIF coverage for outpatient surgery" → calls your tool → returns structured resultEnter fullscreen modeExit fullscreen modeStep 1: Set Up the Project (2 min)your-mcp-server/ ├── src/ │ └── your_package/ │ ├── __init__. py │ └── main. py ├── pyproject. toml ├── README. md └── . github/ └── workflows/ └── publish. ymlEnter fullscreen modeExit fullscreen modemkdiryour-mcp-server&&cdyour-mcp-servermkdir-psrc/your_packagetouchsrc/your_package/__init__. py src/your_package/main. pyEnter fullscreen modeExit fullscreen modeStep 2: Write Your Tool (10 min)# src/your_package/main. pyfrom__future__importannotationsfromtypingimportAnnotatedfromfastmcpimportFastMCPmcp=FastMCP(name="your-mcp-server",instructions="Describe what your server does in one paragraph. ",)@mcp. tool(description=("What this tool does in plain language. ""Include the Western parallel if applicable. ""Note if it uses DEMO data. "))defyour_tool(param1:Annotated[str,"Description of param1"],param2:Annotated[int,"Description of param2"]=0,)->dict:# Your logic herereturn{"result":f"Processed{param1}","note":"DEMO — replace with real data source in production","source":"your-mcp-server",}defmain():mcp. run()if__name__=="__main__":main()Enter fullscreen modeExit fullscreen modeStep 3: Configure pyproject. toml (3 min)[build-system]requires=["setuptools>=61. 0"]build-backend="setuptools. build_meta"# ← exact string, no variation[project]name="your-mcp-server"version="0. 1. 0"description="One-line description"authors=[{name="Your Name",email="you@example. com"}]license={text="MIT"}readme="README. md"requires-python=">=3. 9"dependencies=["fastmcp>=2. 0. 0"][project. scripts]your-mcp-server="your_package. main:main"# CLI entry point[tool. setuptools. packages. find]where=["src"]# ← required for src/ layoutEnter fullscreen modeExit fullscreen modeCommon mistake:build-backend = "setuptools. backends. legacy:build"is not valid. Use exactly"setuptools. build_meta". This error causespython -m buildto fail silently in CI. Step 4: Set Up CI Publishing (5 min)Option A: API Token (faster)Create a PyPI API token atpypi. org/manage/account/#api-tokensAdd asPYPI_API_TOKENin your GitHub repo → Settings → SecretsOption B: OIDC Trusted Publisher (more secure, recommended)Create the package on PyPI first (one push via token)Go topypi. org/manage/project/{name}/settings/publishing/Add GitHub Actions publisher: owner, repo,publish. yml, environmentpypi. github/workflows/publish. yml:name:Publish to PyPIon:push:tags:["v*"]jobs:publish:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v4-uses:actions/setup-python@v5with:{python-version:"3. 11"}-run:pip install build-run:python -m build-uses:pypa/gh-action-pypi-publish@release/v1with:password:${{ secrets. PYPI_API_TOKEN }}Enter fullscreen modeExit fullscreen modeStep 5: Publish (2 min)git init&&git add. &&git commit-m"initial commit"git remote add origin https://github. com/yourusername/your-mcp-server git push-uorigin main git tag v0. 1. 0&&git push origin v0. 1. 0# → GitHub Actions runs → pip install your-mcp-server works in 2-3 minutesEnter fullscreen modeExit fullscreen modeStep 6: Connect to Claude (1 min)# Installpipinstallyour-mcp-server# Add to Claude Codeclaude mcp add myserver--your-mcp-server# Testclaude"Use myserver to process X"Enter fullscreen modeExit fullscreen modeEast Africa Design PatternsA few patterns specific to building for this context:Trust integrity:return{"result":result,"note":"DEMO — Synthetic data for educational purposes. Not operational guidance. ","source":"your-mcp-server. Research basis: [cite your source]",}Enter fullscreen modeExit fullscreen modeSwahili/English bilingual errors:exceptExceptionase:return{"error":f"Hitilafu / Error:{str(e)[:60]}. Jaribu tena / Try again. "}Enter fullscreen modeExit fullscreen modeVersion bump workflow:# Edit pyproject. toml → version = "0. 2. 0"git commit-am"bump: v0. 2. 0"git tag v0. 2. 0&&git push origin main--tagsEnter fullscreen modeExit fullscreen modeThat's the complete cycle. Every MCP server in theEast Africa coordination stackwas built and published with exactly this scaffold. Full portfolio and all 12 packages:gabrielmahia. github. io

Source: dev.to

More Africa news