Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions scripts/generate_mcp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,30 @@ 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": sdk_values[p["name"]],
**(
{"description": f"{p['description'].strip()} Not sent when fields is set."}
if p["name"] == "view"
else {}
),
}
if p["name"] in sdk_values
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,
Expand Down
6 changes: 3 additions & 3 deletions src/late/mcp/generated_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -43079,8 +43079,8 @@ def posts_list_posts(
limit=max(1, min(limit, 40)),
offset=offset,
cursor=cursor,
fields=fields,
view=view,
fields=fields or None,
view=None if fields else view,
updated_since=updated_since,
source=source,
status=status,
Expand Down
47 changes: 47 additions & 0 deletions tests/test_mcp_agent_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,50 @@ 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_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})

assert posts_api.calls.last.request.url.params["view"] == "summary"
Loading