8000 fix(mcp): type graph_related's relation so the type check passes by adeelahmad · Pull Request #131 · 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
11 changes: 9 additions & 2 deletions fastapi_backend/app/api/mcp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import re
from collections.abc import Callable
from dataclasses import dataclass, field
from typing import Any
from typing import Any, Literal

from fastapi import HTTPException, Request

Expand Down Expand Up @@ -977,7 +977,14 @@ def graph_query(ctx: Context, query: str, namespace: str | None, limit: int) ->
Arg("namespace", "string", "one namespace (else every namespace that shares its graph)"),
Arg("limit", "integer", "nodes at most", default=200, minimum=1, maximum=2000),
)
def graph_related(ctx: Context, node: str, relation: str, depth: int, namespace: str | None, limit: int) -> dict[str, Any]:
def graph_related(
ctx: Context,
node: str,
relation: Literal["children", "parents", "ancestors", "descendants", "neighbours"],
depth: int,
namespace: str | None,
limit: int,
) -> dict[str, Any]:
return graph_routes.graph_related(
ctx.request,
ctx.user,
Expand Down
4 changes: 3 additions & 1 deletion fastapi_backend/tests/api/test_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ def test_graph_tools(client, db, env):
assert q["columns"] == ["s.name", "e.name"] and ["Alice", "Dyno Therapeutics"] in q["rows"]
assert "read-only" in tool_error(client, h, "graph_query", query="MATCH (n) DELETE n")
assert "query error" in tool_error(client, h, "graph_query", query="MATCH (n RETURN n")
dyno = q["rows"][0] and tool(client, h, "graph_query", query="MATCH (e:Entity {name: 'Dyno Therapeutics'}) RETURN e.ids")["rows"][0][0][0]
dyno = (
q["rows"][0] and tool(client, h, "graph_query", query="MATCH (e:Entity {name: 'Dyno Therapeutics'}) RETURN e.ids")["rows"][0][0][0]
)
up = tool(client, h, "graph_related", node=f"e{dyno}", relation="ancestors", depth=4, namespace="pods")
assert {"Recording", "Namespace"} <= {n["labels"][0] for n in up["nodes"]}
alice = tool(client, h, "graph_query", query="MATCH (s:Speaker {name: 'Alice'}) RETURN id(s)", namespace="pods")["rows"][0][0]
Expand Down
Loading
0