8000 fix(mcp): cap the page offset of list_recordings, list_entities and list_topics by adeelahmad · Pull Request #200 · adeelahmad/lense · GitHub
[go: up one dir, main page]

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
6 changes: 3 additions & 3 deletions fastapi_backend/app/api/mcp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def list_namespaces(ctx: Context) -> dict[str, Any]:
Arg("media", "string", "only this kind", enum=MEDIA),
Arg("sort", "string", "order: date, title or duration; - first for descending", default="-date", enum=SORTS),
Arg("limit", "integer", "how many", default=20, minimum=1, maximum=100),
Arg("offset", "integer", "skip this many (for the next page)", default=0, minimum=0),
Arg("offset", "integer", "skip this many (for the next page)", default=0, minimum=0, maximum=10000),
)
def list_recordings(
ctx: Context,
Expand Down Expand Up @@ -716,7 +716,7 @@ def _entity_row(e: dict[str, Any]) -> dict[str, Any]:
Arg("recording_id", "integer", "only those mentioned in this recording"),
Arg("sort", "string", "order", default="mentions", enum=("mentions", "recordings", "recent", "rising", "name")),
Arg("limit", "integer", "how many", default=25, minimum=1, maximum=100),
Arg("offset", "integer", "skip this many (for the next page)", default=0, minimum=0),
Arg("offset", "integer", "skip this many (for the next page)", default=0, minimum=0, maximum=10000),
)
def list_entities(
ctx: Context,
Expand Down Expand Up @@ -1058,7 +1058,7 @@ def graph_paths(ctx: Context, from_node: str, to_node: str, max_depth: int, shor
Arg("top", "boolean", "only topics with no broader topic", default=False),
Arg("broader_id", "integer", "only the narrower topics of this one"),
Arg("limit", "integer", "how many", default=50, minimum=1, maximum=200),
Arg("offset", "integer", "skip this many (for the next page)", default=0, minimum=0),
Arg("offset", "integer", "skip this many (for the next page)", default=0, minimum=0, maximum=10000),
)
def list_topics(
ctx: Context, query: str | None, namespace: str | None, top: bool, broader_id: int | None, limit: int, offset: int
Expand Down
2 changes: 2 additions & 0 deletions fastapi_backend/tests/api/test_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def test_entities_and_the_graph(client, env, monkeypatch):
e = tool(client, h, "get_entity", entity_id=dyno["entity_id"], mentions=2)
assert e["name"] == "Dyno Therapeutics" and e["mentions"] == 4 and e["next_mentions_offset"] == 2
assert tool_error(client, h, "get_entity", entity_id=dyno["entity_id"], mentions_offset=10001).startswith("mentions_offset")
for name in ("list_recordings", "list_entities", "list_topics"): # every page offset has the same cap as search's
assert tool_error(client, h, name, offset=10001).startswith("offset"), name
assert {m["name"] for m in e["mentioned_most_by"]} == {"Alice", "Bob", "Carol"}
line = e["lines"][0]
assert line["recording_id"] in (ep1, ep2) and "Dyno Therapeutics" in line["text"]
Expand Down
Loading
0