From 85fe3a41f3889a813f54ffcd6d14ab17df8366d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gemma=20Torell=C3=B3?= Date: Thu, 12 Nov 2026 18:52:16 +0100 Subject: [PATCH 1/2] fix(mcp): posts_list_posts stops sending view=summary when the agent picks fields py#90 made view=summary the agents' default for listPosts, and the API answers 400 to fields and view=summary together. Since 13:21 UTC Nov 12, 19-30% of the MCP's GET /v1/posts calls failed that way (78 sessions in 70 minutes). The default view is now left out whenever fields is set. Co-Authored-By: Claude Opus 5.5 --- scripts/generate_mcp_tools.py | 17 ++++++++++++++ src/late/mcp/generated_tools.py | 4 ++-- tests/test_mcp_agent_views.py | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/scripts/generate_mcp_tools.py b/scripts/generate_mcp_tools.py index f238f759..86d5e5be 100644 --- a/scripts/generate_mcp_tools.py +++ b/scripts/generate_mcp_tools.py @@ -470,8 +470,25 @@ def _with_agent_default( ] +def _without_view_when_fields_are_picked(params: list[dict[str, Any]]) -> list[dict[str, Any]]: + if not any(p["name"] == "fields" for p in params): + return params + return [ + { + **p, + "sdk_value": "None if fields else view", + "description": f"{p['description'].strip()} Not sent when fields is set.", + } + if p["name"] == "view" + else p + for p in params + ] + + def _with_agent_view(operation_id: str, params: list[dict[str, Any]]) -> list[dict[str, Any]]: params = _with_agent_default(operation_id, params, name="view", value=AGENT_VIEWS.get(operation_id), hint="pass full for everything.") + if operation_id in AGENT_VIEWS: + params = _without_view_when_fields_are_picked(params) return _with_agent_default( operation_id, params, diff --git a/src/late/mcp/generated_tools.py b/src/late/mcp/generated_tools.py index 8f4e9477..e5cbf9d7 100644 --- a/src/late/mcp/generated_tools.py +++ b/src/late/mcp/generated_tools.py @@ -43052,7 +43052,7 @@ def posts_list_posts( - Each platform: `platform`, `status`, `accountId` (the id), `username`, `scheduledFor`, `publishedAt`, `platformPostId`, `platformPostUrl`, `errorMessage`, `errorCategory`. - Left out: the author (`userId`), `mediaItems`, `metadata`, `recycling`, and each platform's custom content, custom media and `platformSpecificData`. Null values are left out too. - Works with both sources. Send either `fields` or `view=summary`: both together return 400. Defaults to summary here; pass full for everything. + Works with both sources. Send either `fields` or `view=summary`: both together return 400. Defaults to summary here; pass full for everything. Not sent when fields is set. updated_since: Only posts whose `updatedAt` is at or after this ISO 8601 timestamp (an offset or `Z` required). `updatedAt` moves when the post or any of its platforms changes (an edit, a status change, a platform publishing or failing). To keep a copy in sync, send the time of your previous sync instead of reading every page again. @@ -43080,7 +43080,7 @@ def posts_list_posts( offset=offset, cursor=cursor, fields=fields, - view=view, + view=None if fields else view, updated_since=updated_since, source=source, status=status, diff --git a/tests/test_mcp_agent_views.py b/tests/test_mcp_agent_views.py index c1b34753..3ba08a1f 100644 --- a/tests/test_mcp_agent_views.py +++ b/tests/test_mcp_agent_views.py @@ -118,3 +118,42 @@ def test_a_tree_spec_without_the_depth_parameter_warns_and_keeps_its_parameters( assert mcp_generator._with_agent_view("getAdTree", [other]) == [other] assert "getAdTree has no `depth` parameter" in capsys.readouterr().err + + +@pytest.fixture +def posts_api(monkeypatch: pytest.MonkeyPatch): + import respx + + monkeypatch.setenv("ZERNIO_API_KEY", "sk_test") + monkeypatch.setenv("ZERNIO_BASE_URL", "https://api.test.com") + with respx.mock(assert_all_called=False) as router: + yield router.get("https://api.test.com/v1/posts").respond( + 200, json={"posts": [], "pagination": {}} + ) + + +async def _list_posts(arguments: dict) -> None: + from fastmcp import Client + + from late.mcp.server import mcp + + async with Client(mcp) as client: + await client.call_tool( + "call_tool", {"name": "posts_list_posts", "arguments": arguments} + ) + + +async def test_picking_fields_on_posts_leaves_out_the_summary_view_the_api_rejects_with_them( + posts_api, +) -> None: + await _list_posts({"fields": "_id,status", "limit": 1}) + + params = posts_api.calls.last.request.url.params + assert params["fields"] == "_id,status" + assert "view" not in params + + +async def test_posts_without_fields_still_ask_for_the_summary_view(posts_api) -> None: + await _list_posts({"limit": 1}) + + assert posts_api.calls.last.request.url.params["view"] == "summary" From b8894cf7f97d1901e146d61350c3e59131c037aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gemma=20Torell=C3=B3?= Date: Thu, 12 Nov 2026 18:53:13 +0100 Subject: [PATCH 2/2] fix(mcp): an empty fields value is not sent next to the summary view Co-Authored-By: Claude Opus 5.5 --- scripts/generate_mcp_tools.py | 11 ++++++++--- src/late/mcp/generated_tools.py | 2 +- tests/test_mcp_agent_views.py | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/generate_mcp_tools.py b/scripts/generate_mcp_tools.py index 86d5e5be..4528574c 100644 --- a/scripts/generate_mcp_tools.py +++ b/scripts/generate_mcp_tools.py @@ -473,13 +473,18 @@ def _with_agent_default( def _without_view_when_fields_are_picked(params: list[dict[str, Any]]) -> list[dict[str, Any]]: if not any(p["name"] == "fields" for p in params): return params + sdk_values = {"view": "None if fields else view", "fields": "fields or None"} return [ { **p, - "sdk_value": "None if fields else view", - "description": f"{p['description'].strip()} Not sent when fields is set.", + "sdk_value": sdk_values[p["name"]], + **( + {"description": f"{p['description'].strip()} Not sent when fields is set."} + if p["name"] == "view" + else {} + ), } - if p["name"] == "view" + if p["name"] in sdk_values else p for p in params ] diff --git a/src/late/mcp/generated_tools.py b/src/late/mcp/generated_tools.py index e5cbf9d7..65d5fa1c 100644 --- a/src/late/mcp/generated_tools.py +++ b/src/late/mcp/generated_tools.py @@ -43079,7 +43079,7 @@ def posts_list_posts( limit=max(1, min(limit, 40)), offset=offset, cursor=cursor, - fields=fields, + fields=fields or None, view=None if fields else view, updated_since=updated_since, source=source, diff --git a/tests/test_mcp_agent_views.py b/tests/test_mcp_agent_views.py index 3ba08a1f..d958e71d 100644 --- a/tests/test_mcp_agent_views.py +++ b/tests/test_mcp_agent_views.py @@ -153,6 +153,14 @@ async def test_picking_fields_on_posts_leaves_out_the_summary_view_the_api_rejec assert "view" not in params +async def test_an_empty_fields_value_is_not_sent_next_to_the_summary_view(posts_api) -> None: + await _list_posts({"fields": "", "limit": 1}) + + params = posts_api.calls.last.request.url.params + assert "fields" not in params + assert params["view"] == "summary" + + async def test_posts_without_fields_still_ask_for_the_summary_view(posts_api) -> None: await _list_posts({"limit": 1})