Initial commit: Mealie MCP server

Ports a working Hermes agent skill to an MCP server. The skill's value was not
its Mealie endpoints but ~25 operational rules found by running imports against
the live instance; those are now code with tests rather than prompt text.

The server owns deterministic mechanics — auth, the non-default User-Agent
Cloudflare requires, the `extension` field on cover uploads, PATCH instead of
the 500-ing bulk-action endpoints, decimal-comma normalization, and restoring
Swedish display text after parsing. Language and taste judgement stay with the
model, fed by the four reference notes shipped as MCP resources.

verify_recipe runs the finished-import definition as code so an agent cannot
report success on a recipe with an English ingredient line, a missing cover, or
ingredients still in the "Click Parse" state.

Home Assistant is optional and isolated; the Obsidian meal plan is out of scope.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 07:31:10 +02:00
committed by fredamn76
commit f2d233b430
17 changed files with 1643 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
"""Boundary contracts for the verified Mealie instance quirks."""
from __future__ import annotations
import httpx
import pytest
from mealie_mcp import server
def response(status: int, text: str = "") -> httpx.Response:
return httpx.Response(status, text=text, request=httpx.Request("GET", "https://example.test"))
class TestAuthenticationFailures:
def test_401_is_an_auth_problem(self):
with pytest.raises(server.MealieAuthError):
server._raise_for_status(response(401))
def test_cloudflare_1010_is_not_reported_as_bad_token(self):
with pytest.raises(server.MealieBlockedError):
server._raise_for_status(response(403, "error code: 1010"))
class TestUrlImportResponse:
def test_slug_only_import_response_is_resolved_before_reporting(self, monkeypatch):
recipe = {"slug": "lax-med-citron", "name": "Lax med citron", "recipeIngredient": []}
calls: list[tuple[str, str]] = []
def request(method, path, **kwargs):
calls.append((method, path))
assert kwargs["json"] == {"url": "https://example.test/lax"}
return "lax-med-citron"
monkeypatch.setattr(server, "find_by_source_url", lambda _url: [])
monkeypatch.setattr(server, "_request", request)
monkeypatch.setattr(server, "get_recipe", lambda slug: recipe if slug == "lax-med-citron" else None)
result = server.import_recipe_url("https://example.test/lax")
assert calls == [("POST", "/api/recipes/create/url")]
assert result["imported"] is True
assert result["recipe"] == recipe
assert result["report"]["slug"] == "lax-med-citron"
def test_duplicate_source_url_stops_before_creating(self, monkeypatch):
monkeypatch.setattr(
server,
"find_by_source_url",
lambda _url: [{"slug": "redan-finns", "name": "Redan finns"}],
)
monkeypatch.setattr(server, "_request", lambda *_args, **_kwargs: pytest.fail("must not import"))
result = server.import_recipe_url("https://example.test/recept")
assert result == {
"imported": False,
"reason": "duplicate",
"existing": [{"slug": "redan-finns", "name": "Redan finns"}],
}
class TestPatchContract:
def test_patch_recipe_reads_back_the_final_object(self, monkeypatch):
seen = []
updated = {"slug": "soppa", "name": "Soppa", "tags": [{"name": "📅 Vardag"}]}
def request(method, path, **kwargs):
seen.append((method, path, kwargs))
return None
monkeypatch.setattr(server, "_request", request)
monkeypatch.setattr(server, "get_recipe", lambda slug: updated if slug == "soppa" else None)
assert server.patch_recipe("soppa", {"tags": updated["tags"]}) == updated
assert seen == [("PATCH", "/api/recipes/soppa", {"json": {"tags": updated["tags"]}})]