Skip to content

feat(mcp): auto-init — ensure FalkorDB + opt-in auto-index (T12)#682

Draft
DvirDukhan wants to merge 1 commit into
dvirdukhan/mcp-t9-t10-t11-askfrom
dvirdukhan/mcp-t12-auto-init
Draft

feat(mcp): auto-init — ensure FalkorDB + opt-in auto-index (T12)#682
DvirDukhan wants to merge 1 commit into
dvirdukhan/mcp-t9-t10-t11-askfrom
dvirdukhan/mcp-t12-auto-init

Conversation

@DvirDukhan
Copy link
Copy Markdown

Implements T12 (#660) — zero-config startup. Fresh users don't need to run cgraph ensure-db and index_repo manually before the agent can use the server.

Stacked on:

What ships

api/mcp/auto_init.py:

  • ensure_falkordb() — pings FalkorDB on $FALKORDB_HOST:$FALKORDB_PORT; if unreachable on a localhost host, shells out to cgraph ensure-db (reuses the existing CLI Docker bootstrap; subprocess rather than in-process so the CLI's stdout JSON doesn't corrupt the MCP stdio transport). Never raises — server start continues even if bootstrap fails.
  • maybe_auto_index(...) — gated by CODE_GRAPH_AUTO_INDEX=true|1|yes|on (off by default). Detects branch via git rev-parse, falls back to _default. Idempotent per-(project, branch).

api/mcp/server.py:

  • main() runs both before app.run(). Module-level import is still I/O-free.

Tests

tests/mcp/test_auto_init.py — 9 tests, all mocked (no Docker, no real FalkorDB writes), <2s:

  • ensure_falkordb: no-op when reachable / runs cgraph when not / refuses non-localhost / handles missing CLI binary.
  • maybe_auto_index: skipped when env unset / indexes when opt-in / idempotent / per-branch / _truthy semantics.

Full MCP suite: 57 passed in 24.6s.

Out of scope (per ticket)

  • Watch mode / re-indexing on FS change.
  • Auto-pulling Docker image (already handled by cgraph ensure-db).
  • Cross-session state.

Closes #660.

Zero-config startup so a fresh user doesn't need to run `cgraph
ensure-db` and `index_repo` manually.

api/mcp/auto_init.py
- ensure_falkordb(): on server boot, ping FalkorDB; if unreachable
  on a localhost host, shell out to `cgraph ensure-db` (reuses the
  existing CLI's Docker bootstrap rather than duplicating it).
  Subprocess (not in-process call) so the CLI's stdout JSON doesn't
  pollute the MCP server's stdio transport. Never raises — server
  start continues even on bootstrap failure so individual tools can
  surface their own errors.
- maybe_auto_index(cwd=None, project=None, branch=None): opt-in
  via CODE_GRAPH_AUTO_INDEX env var (off by default — indexing a
  large repo can take minutes and surprising the user on first call
  is bad UX). Detects current branch via `git rev-parse`, falls
  back to `_default`. Per-(project, branch) idempotency via a
  module-level set; second call for the same key is a no-op.
- _truthy helper accepts 1/true/yes/on (case insensitive).

api/mcp/server.py
- main() now runs ensure_falkordb() and maybe_auto_index() before
  app.run(). Module-level import behaviour unchanged (tests that
  `import api.mcp.server` don't trigger any I/O).

tests/mcp/test_auto_init.py (9 tests)
- ensure_falkordb: no-op when reachable, runs cgraph when not,
  skips Docker for remote hosts, handles missing CLI binary.
- maybe_auto_index: skipped when env unset, indexes when opt-in,
  idempotent across calls for same key, distinct branches each
  get one auto-index, _truthy semantics.

All mocks — no Docker, no real FalkorDB writes — so the tests run
in <2s without external dependencies.

Out of scope per ticket: watch mode / re-indexing on FS change,
auto-pulling Docker image (cgraph ensure-db handles that), cross-
session state.

Closes #660.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 862f5fe9-4424-49f5-b4ba-043832e2a5c2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dvirdukhan/mcp-t12-auto-init

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.

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.

1 participant