feat(mcp): GraphRAG ask tool — init + prompt seam + tool (T9/T10/T11)#681
Draft
DvirDukhan wants to merge 1 commit into
Draft
feat(mcp): GraphRAG ask tool — init + prompt seam + tool (T9/T10/T11)#681DvirDukhan wants to merge 1 commit into
DvirDukhan wants to merge 1 commit into
Conversation
…10/T11) Bundles three tightly-coupled tickets: T9 builds the per-(project,branch) KnowledgeGraph cache, T10 adds the prompt-override seam, T11 wires both together into the `ask` MCP tool that gives agents natural-language access to the graph. T9 (#657) — api/mcp/graphrag_init.py - get_or_create_kg(project, branch) — process-wide cache keyed by (project, branch). Identity-stable: same key returns the same KG. - reset_cache() for tests. - Reuses the hand-coded ontology from api/llm.define_ontology (200+ lines of File/Class/Function descriptions the LLM relies on for Cypher quality). Do NOT replace with auto-extraction. - Graph name uses the T17 convention `code:{project}:{branch}` so it matches what index_repo writes. T9 — api/llm.py rename - _define_ontology → define_ontology (drop underscore so it's importable). Internal callers updated. No other call sites in the repo. T10 (#658) — api/mcp/code_prompts.py - Thin re-export of api.prompts (CYPHER_GEN_SYSTEM/PROMPT, GRAPH_QA_SYSTEM/PROMPT). The value is the seam: when the MCP ask tool needs agent-flavoured prompts (vs human-chat framing), the divergence happens here without touching api/prompts.py. T11 (#659) — api/mcp/tools/ask.py - ask(question, project, branch=None) MCP tool. - Uses get_or_create_kg + chat_session().send_message() in an executor so the MCP event loop stays responsive. - Returns the design-doc-mandated {answer, cypher_query, context_nodes} shape. cypher_query is the transparency requirement so agents can verify the executed query and learn the schema. - _normalize_response tolerates the graphrag-sdk response shape variance ({response/answer, cypher/query, context/results}). - Errors are surfaced as a structured {error: ...} payload, never as a transport exception — the agent always sees a valid tool result. Tests (14 new, all pass with mocked LiteModel — no network in CI): - tests/mcp/test_code_prompts.py (3): re-exports match originals, __all__ shape, snapshot hash stability. - tests/mcp/test_graphrag_init.py (5): per-branch graph name, cache identity, distinct keys yield distinct instances, ontology reuse, define_ontology is public. - tests/mcp/test_ask.py (6): tool registered, normalised payload, alternate response keys, plain-string response, errors surfaced as payload, JSON serialisable. Full MCP suite still green (48 passed in 27.5s). Out of scope per tickets: real-LLM E2E (Phase 1.5 with API-key secrets), streaming, multi-turn memory, prompt iteration. Closes #657, #658, #659. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bundles T9 (#657) + T10 (#658) + T11 (#659) — the strategic differentiator vs structural-only MCP servers. Three tightly coupled tickets land together because T11 needs T9 + T10 to do anything.
Stacked on:
What ships
api/mcp/graphrag_init.pyget_or_create_kg(project, branch)— process-wide cache; reuses the hand-coded ontology fromapi/llm.py; graph name follows T17 conventioncode:{project}:{branch}.api/mcp/code_prompts.pyapi/prompts.py; the value is having a place for MCP-flavoured divergence without touching the FastAPI chat prompts.api/mcp/tools/ask.pyask(question, project, branch=None)→{answer, cypher_query, context_nodes}.cypher_queryis the design-doc transparency requirement so agents can verify the executed Cypher.T9 also renames
_define_ontology→define_ontologyinapi/llm.pyso the public-and-importable form is the only one. No other call sites in the repo.Tests
14 new tests, all pass with mocked
LiteModel(no network in CI):tests/mcp/test_code_prompts.py(3) — re-exports match originals,__all__shape, snapshot hash stability.tests/mcp/test_graphrag_init.py(5) — per-branch graph name, cache identity, distinct keys → distinct instances, ontology reuse,define_ontologyis public.tests/mcp/test_ask.py(6) — tool registered, normalised payload, alternate response shapes, plain-string responses, errors as payload, JSON serialisable.Full MCP suite: 48 passed in 27.5s.
Out of scope (per tickets)
Closes #657, #658, #659.