feat(mcp): auto-init — ensure FalkorDB + opt-in auto-index (T12)#682
Draft
DvirDukhan wants to merge 1 commit into
Draft
feat(mcp): auto-init — ensure FalkorDB + opt-in auto-index (T12)#682DvirDukhan wants to merge 1 commit into
DvirDukhan wants to merge 1 commit into
Conversation
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>
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.
Implements T12 (#660) — zero-config startup. Fresh users don't need to run
cgraph ensure-dbandindex_repomanually 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 tocgraph 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 byCODE_GRAPH_AUTO_INDEX=true|1|yes|on(off by default). Detects branch viagit rev-parse, falls back to_default. Idempotent per-(project, branch).api/mcp/server.py:main()runs both beforeapp.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 / runscgraphwhen not / refuses non-localhost / handles missing CLI binary.maybe_auto_index: skipped when env unset / indexes when opt-in / idempotent / per-branch /_truthysemantics.Full MCP suite: 57 passed in 24.6s.
Out of scope (per ticket)
cgraph ensure-db).Closes #660.