committed 09:13PM - 26 Jul 26 UTC
* feat(restapi): add optional MCP endpoint (/mcp) wrapping the REST API
Add an …optional Model Context Protocol (MCP) endpoint at /mcp on the REST
API. It is generated from the existing FastAPI routes via FastMCP's
`from_fastapi`, so every REST endpoint (coverage, stations, values,
interpolate, summarize, stripes, alerts, ...) becomes an MCP tool, proxied
in-process and served over the streamable-HTTP transport in the same app.
- Enabled by the new `mcp` extra (`pip install wetterdienst[mcp]`), which
pulls in `wetterdienst[restapi]` plus fastmcp (>=3.4.4,<4). Without it, the
REST API is unchanged and the /mcp route is simply absent.
- The MCP routes are added to the existing app and the session-manager
lifespan is adopted, so the auto-generated docs routes are not duplicated
and the existing REST endpoints keep working with or without the lifespan.
- Installed in the Docker image (build + dev stages) so the hosted
wetterdienst.eobs.org instance serves /mcp as well.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* feat(mcp): make the MCP tools usable by small models
Optimize the /mcp surface so even a cheap model completes a task like
"recent temperature at Hamburg-Fuhlsbüttel" in a couple of calls instead of
thrashing. Validated by driving the endpoint with Haiku agents: 8 calls (with
a workaround) before -> 3 clean calls after.
Changes (in a new wetterdienst.ui.mcp module):
- Attach a workflow `instructions` block to the server (find a station, then
query its values; DWD defaults; parameter syntax; how to read/narrow results).
- Give the tools clean names (`values` instead of `values_api_values_get`) and
hide the non-data endpoints (index, robots, health, version, auth).
- Write real tool descriptions via the endpoint docstrings (stations, values,
coverage) instead of "Wrap get_* to provide results via restapi.".
- Build the OpenAPIProvider directly with validate_output=False: the endpoints
return a raw JSON string but declare rich response_model unions, so FastMCP's
derived output schemas are wrong and rejected valid results with
"9.0 is not of type 'string'". A permissive schema fixes the `values` tool.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>