PythonAPIMCP

Built Model Context Protocol server integrating wger workout management system with Claude AI for fitness data access.

Code snippet showing MCP server architecture

I built an MCP server that connects the wger workout management system to Claude, letting me query and manage my fitness data through natural conversation.

The Problem

My first attempt used the OpenAPI spec to auto-generate tools. Clean in theory, but it hit event loop conflicts in certain MCP environments. The async context from OpenAPI tooling didn’t play well with how MCP manages its own event loop.

The fix was going manual: I wrote tool definitions directly with FastMCP and made sure the httpx.AsyncClient binds to the correct running event loop every time. More code, but it actually works.

What It Does

The server exposes 8 tools with 100% reliability:

  • 5 for reading data: workout history, exercises, routines, logs
  • 3 for writing: create routines, add workout days, add exercises

A few things I’m happy with:

  • Automatic ID resolution so responses show “Barbell Squat” instead of “exercise_id: 42”
  • Good error messages that actually help with debugging
  • Caching to avoid hammering the API
  • Proper HTTP client lifecycle management (this is where a lot of async code breaks down)

How I Built It

I validated everything against the wger OpenAPI spec to make sure my manual implementations matched the expected schemas. Lots of testing to get multi-step workflows reliable, like creating a routine, adding days to it, then populating those days with exercises.

What I Use It For

I can ask Claude things like “Show me my last workout” or “Add barbell squats to my leg day with 4 sets of 8 reps” and it just works. It’s a small quality-of-life thing, but I like being able to log workouts conversationally instead of clicking through an app.