Skip to content

MCP-T13 + T14: cgraph init-agent + Docker dual-mode#683

Merged
DvirDukhan merged 5 commits into
stagingfrom
dvirdukhan/mcp-t13-t14-packaging
Jun 9, 2026
Merged

MCP-T13 + T14: cgraph init-agent + Docker dual-mode#683
DvirDukhan merged 5 commits into
stagingfrom
dvirdukhan/mcp-t13-t14-packaging

Conversation

@DvirDukhan

@DvirDukhan DvirDukhan commented May 27, 2026

Copy link
Copy Markdown
Contributor

Prerequisites (merge order)

Merge in order — this PR is stacked on:

  1. feat(mcp): index_repo tool (T4 #652) #678index_repo (T4)
  2. feat(mcp): query tools — get_callers/callees/deps, find_path, search_code (T5/T7/T8) #679 — query tools (T5/T7/T8)
  3. feat(mcp): impact_analysis tool — variable-depth Cypher (T6) #680impact_analysis (T6)
  4. feat(mcp): GraphRAG ask tool — init + prompt seam + tool (T9/T10/T11) #681 — GraphRAG ask (T9/T10/T11)
  5. feat(mcp): auto-init — ensure FalkorDB + opt-in auto-index (T12) #682 — auto-init (T12)

Base: #682.


MCP-T13 + T14 — agent guidance bundle & Docker dual-mode

Stacked on #682 (T12 auto-init). Closes #661 and #662.

T13 — cgraph init-agent

Two canonical guidance files now ship as package data under
api/mcp/templates/:

  • claude_mcp_section.md — full 8-tool table + rules of thumb
    (start with search_code; prefer structural tools over ask;
    run impact_analysis before refactoring).
  • cursorrules.template — Cursor-flavoured tool-selection rules.

New Typer command drops them into the current directory:

cgraph init-agent          # refuses to overwrite
cgraph init-agent --force  # clobber

AGENTS.md updated with the MCP section pointing at this command and
the supported env vars (CODE_GRAPH_AUTO_INDEX, CGRAPH_MODE).

T14 — Dockerised dual-mode

Same image now runs either the FastAPI web app or the MCP stdio
server based on CGRAPH_MODE:

# web (default, unchanged behaviour)
docker compose up code-graph

# mcp stdio
docker compose --profile mcp run --rm -i code-graph-mcp

start.sh dispatches on CGRAPH_MODE=web|mcp. docker-compose.yml
gains an opt-in code-graph-mcp service guarded by the mcp
profile (no impact on the default up). README quickstart covers
both claude mcp add-json and the Docker path.

Tests

  • 4 new CliRunner tests in tests/mcp/test_init_agent.py (write,
    refuse-overwrite, force-overwrite, package-data sanity).
  • Full MCP suite green: 61 passed in 23.3s locally.
  • bash -n start.sh clean.

Followups

Summary by CodeRabbit

  • New Features

    • Added MCP server with support for code indexing, searching symbols, analyzing impacts, and finding call paths
    • New cgraph init-agent CLI command to generate agent guidance files
    • Docker Compose profile for MCP server deployment
  • Documentation

    • Added MCP server documentation with quickstart guides, tool descriptions, and configuration details
  • Tests

    • Added test suite for the init-agent command and MCP server functionality

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces MCP (Model Context Protocol) agent guidance by bundling structured templates, a bootstrapping CLI command (cgraph init-agent), comprehensive test coverage, documentation, container configuration for MCP mode, and an integration smoke test. The changes enable AI coding agents to efficiently use the code-graph knowledge graph.

Changes

MCP Agent Guidance Bundle

Layer / File(s) Summary
Agent guidance templates
api/mcp/templates/claude_mcp_section.md, api/mcp/templates/cursorrules.template
Two Markdown templates guide AI agents on when and how to call each MCP tool (index_repo, search_code, find_symbol, get_neighbors, impact_analysis, find_path), with tool-selection rules and environment variable documentation.
CLI init-agent command and template packaging
api/cli.py, pyproject.toml
The init-agent Typer command writes guidance templates to user CWD as CLAUDE.md and .cursorrules, refuses to overwrite without --force, and outputs JSON status. Templates are packaged via pyproject.toml setuptools configuration.
CLI init-agent command tests
tests/mcp/test_init_agent.py
Four test cases validate file creation, overwrite refusal, force-overwrite behavior, and template packaging; shared CliRunner fixture and temporary directory helpers ensure isolated test execution.
User-facing documentation for MCP
AGENTS.md, README.md
AGENTS.md documents the MCP toolset and cgraph init-agent command; README.md adds MCP server overview, quickstarts for Claude Code and Docker Compose, FalkorDB auto-bootstrap notes, and Docker examples for web and MCP modes.
Container and startup configuration for MCP mode
start.sh, docker-compose.yml
start.sh introduces CGRAPH_MODE variable (defaults to web) that dispatches between cgraph-mcp and uvicorn startup paths; docker-compose.yml adds an opt-in code-graph-mcp service behind the mcp profile with FalkorDB dependency and stdio configuration.
MCP server integration smoke test
scripts/mcp_smoke.py
Async end-to-end smoke test that initializes an MCP client over stdio, validates tool availability, indexes api/ via index_repo, and exercises search_code, find_symbol, get_neighbors, and impact_analysis with flexible response-shape handling and failure tracking.

🎯 3 (Moderate) | ⏱️ ~25 minutes


Suggested reviewers

  • gkorland
  • galshubeli

🐰 Templates flow to agents true,
init-agent shows them what to do,
MCP guides with rules so tight,
Smoke tests prove the code runs right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'MCP-T13 + T14: cgraph init-agent + Docker dual-mode' clearly references the two main feature additions (T13 init-agent command and T14 Docker dual-mode support) and is specific enough to convey the scope.
Linked Issues check ✅ Passed All objectives from issue #661 are fully addressed: AGENTS.md documented with MCP tools, two template files created (claude_mcp_section.md and cursorrules.template), cgraph init-agent command with --force flag implemented, test suite added, and package data configured.
Out of Scope Changes check ✅ Passed All changes are aligned with PR objectives. T13 additions (templates, init-agent CLI, documentation) and T14 additions (Docker dual-mode via CGRAPH_MODE) are within scope; smoke test and fixes are supporting implementation details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dvirdukhan/mcp-t13-t14-packaging

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t12-auto-init branch from 5e376e6 to ead5047 Compare June 8, 2026 13:26
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t13-t14-packaging branch from a18854b to 113ba5c Compare June 8, 2026 13:30
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t12-auto-init branch from ead5047 to de11c6a Compare June 8, 2026 14:06
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t13-t14-packaging branch from 113ba5c to e2c504e Compare June 8, 2026 14:06
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t12-auto-init branch from de11c6a to fec4bac Compare June 8, 2026 16:44
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t13-t14-packaging branch from e2c504e to e22b735 Compare June 8, 2026 16:44
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t12-auto-init branch from fec4bac to e14f7f9 Compare June 8, 2026 17:10
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t13-t14-packaging branch from e22b735 to 5da78b5 Compare June 8, 2026 17:10
@DvirDukhan DvirDukhan requested a review from Copilot June 8, 2026 19:54
@DvirDukhan DvirDukhan marked this pull request as ready for review June 8, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-user/agent onboarding for the MCP server and enables running the same Docker image in either web or MCP-stdio mode, improving agent usability and deployment ergonomics.

Changes:

  • Introduces cgraph init-agent to write bundled agent guidance templates (CLAUDE.md, .cursorrules) into the current directory.
  • Adds Docker “dual-mode” startup via CGRAPH_MODE=web|mcp with a compose code-graph-mcp profile/service for MCP stdio.
  • Updates docs and adds tests + a smoke script for MCP setup/verification.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
api/cli.py Adds init-agent CLI command to copy bundled guidance templates into CWD.
api/mcp/templates/claude_mcp_section.md Provides canonical MCP tool guidance for Claude-style agent instructions.
api/mcp/templates/cursorrules.template Provides Cursor rules template for tool selection/usage.
tests/mcp/test_init_agent.py Adds CliRunner tests covering write/refuse-overwrite/force-overwrite and package-data presence.
pyproject.toml Ensures MCP templates ship as package data (api.mcp/templates/*).
start.sh Dispatches container startup between web and MCP stdio mode using CGRAPH_MODE.
docker-compose.yml Adds an opt-in code-graph-mcp service under the mcp profile for stdio MCP.
README.md Documents MCP server usage and Docker dual-mode quickstarts.
scripts/mcp_smoke.py Adds an end-to-end stdio smoke test for tool availability and basic flows.
AGENTS.md Adds agent-focused MCP section and points to cgraph init-agent.
Comments suppressed due to low confidence (1)

start.sh:12

  • In CGRAPH_MODE=mcp, anything written to stdout before cgraph-mcp starts can corrupt the MCP stdio transport. The local redis-server ... | cat & pipeline currently writes its logs to stdout, which can break MCP when FALKORDB_HOST is localhost/127.0.0.x.
# Start FalkorDB Redis server in background only if using a local address (not an external instance)
if [ "${FALKORDB_HOST}" = "localhost" ] || [[ "${FALKORDB_HOST}" =~ ^127\.0\.0\.[0-9]+$ ]]; then
    redis-server --loadmodule /var/lib/falkordb/bin/falkordb.so | cat &
fi

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Comment thread scripts/mcp_smoke.py Outdated
Comment thread tests/mcp/test_init_agent.py Outdated
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t12-auto-init branch from e14f7f9 to d6bfbde Compare June 8, 2026 20:18
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t13-t14-packaging branch from 5da78b5 to 389ca49 Compare June 8, 2026 20:18
DvirDukhan and others added 3 commits June 9, 2026 00:52
T13 — agent guidance bundle:
  - Add `api/mcp/templates/` shipped as package data (claude_mcp_section.md,
    cursorrules.template) with the canonical 8-tool MCP guidance.
  - Add `cgraph init-agent [--force]` Typer command that drops
    CLAUDE.md and .cursorrules into CWD.
  - Update AGENTS.md with the MCP tool table and env-var reference.

T14 — packaging / image dual-mode:
  - `start.sh` dispatches on `CGRAPH_MODE` env var (web|mcp). Default
    (web) preserves the existing FastAPI behaviour; mcp execs cgraph-mcp.
  - `docker-compose.yml` gains an opt-in `code-graph-mcp` service under
    the `mcp` profile for stdio attach.
  - README quickstart section for both `claude mcp add-json` registration
    and Docker compose profile usage.

Tests: 4 new (CliRunner against tmp_path); MCP suite green at 61 passed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Added scripts/mcp_smoke.py — drives cgraph-mcp over real stdio (mcp
SDK ClientSession + StdioServerParameters) and exercises tool
listing, index_repo, search_code, get_callers, impact_analysis.

Findings folded back into claude_mcp_section.md:
- index_repo takes path_or_url (not path) and derives project name
  from the folder/URL — agents must read it back from the response.
- Collection-returning tools land their array in
  structuredContent.result, not under a {results: [...]} wrapper.

Smoke result on api/ subgraph: 8 tools listed, 6324 nodes / 6228
edges indexed, all calls returned expected payloads.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The MCP surface is the deterministic structural set — the GraphRAG `ask`
tool was dropped (it remains available on the HTTP /api/chat path), and
get_callers/get_callees/get_dependencies were consolidated into a single
`get_neighbors(relation, direction)` with `get_file_neighbors` and
`find_symbol` added.

Update AGENTS.md, README.md, and the init-agent templates
(claude_mcp_section.md, cursorrules.template) to the seven registered
tools: index_repo, search_code, find_symbol, get_neighbors,
get_file_neighbors, impact_analysis, find_path. Fix scripts/mcp_smoke.py
so its expected tool set and the tools it exercises match (search_code
now takes `query`, callers come from get_neighbors direction=IN).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@DvirDukhan DvirDukhan force-pushed the dvirdukhan/mcp-t13-t14-packaging branch from 389ca49 to d5deee2 Compare June 8, 2026 21:52
- smoke: resolve a real symbol_id via find_symbol before exercising
  get_neighbors/impact_analysis (search_code returns FILE hits with
  file_id, never a symbol id, so the previous hits[0]["id"] was always
  None and the symbol-level tools were never actually tested)
- test_init_agent: drop unused `os` import
- README: use the real distribution name `falkordb-code-graph` in the
  MCP quickstart (matches pyproject.toml + earlier install section)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
galshubeli
galshubeli previously approved these changes Jun 9, 2026
Base automatically changed from dvirdukhan/mcp-t12-auto-init to staging June 9, 2026 09:54
@DvirDukhan DvirDukhan dismissed galshubeli’s stale review June 9, 2026 09:54

The base branch was changed.

@DvirDukhan DvirDukhan merged commit 04da6b4 into staging Jun 9, 2026
10 of 13 checks passed
@DvirDukhan DvirDukhan deleted the dvirdukhan/mcp-t13-t14-packaging branch June 9, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP T13 — Agent guidance bundle (AGENTS.md, .cursorrules, cgraph init-agent)

3 participants