-
Notifications
You must be signed in to change notification settings - Fork 50
falkordblite mcp latest #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d909649
feat(mcp): hybrid-ranked search_code + get_neighbors + get_file_neigh…
DvirDukhan 9e05b4b
fix(mcp): address PR #701 review comments + green CI
DvirDukhan 9a930e7
feat(mcp): find_symbol — resolve Function/Class name to symbol_id
DvirDukhan f3eac12
feat(mcp): drop GraphRAG ask from the registered MCP tool surface
DvirDukhan a5abde0
fix(mcp): address PR #702 find_symbol review comments
DvirDukhan eefaa40
Add FalkorDBLite backend support
Naseem77 84ee21a
Document FalkorDBLite configuration
Naseem77 8ec9744
Add MCP context benchmark
Naseem77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| """Database backend selection for CodeGraph. | ||
|
|
||
| The default backend is a regular FalkorDB server addressed by host/port. | ||
| Set ``CODE_GRAPH_DB_BACKEND=lite`` to use FalkorDBLite's embedded server. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
|
|
||
| LITE_BACKENDS = {"lite", "falkordblite"} | ||
| DEFAULT_LITE_PATH = "~/.cache/code-graph/falkordblite.rdb" | ||
|
|
||
|
|
||
| def is_lite_backend() -> bool: | ||
| """Return whether CodeGraph should use the embedded FalkorDBLite backend.""" | ||
| backend = os.getenv("CODE_GRAPH_DB_BACKEND", "falkordb").strip().lower() | ||
| return backend in LITE_BACKENDS | ||
|
|
||
|
|
||
| def _lite_db_path() -> str: | ||
| path = Path(os.getenv("FALKORDB_LITE_PATH", DEFAULT_LITE_PATH)).expanduser() | ||
| path.parent.mkdir(parents=True, exist_ok=True) | ||
| return str(path) | ||
|
|
||
|
|
||
| def _lite_serverconfig() -> dict[str, str]: | ||
| """Return FalkorDBLite server config from env. | ||
|
|
||
| FalkorDBLite defaults to a private Unix socket. Supplying | ||
| ``FALKORDB_LITE_PORT`` additionally exposes a local TCP port, which is | ||
| useful for libraries that only accept host/port connection settings. | ||
| """ | ||
| port = os.getenv("FALKORDB_LITE_PORT") | ||
| if not port: | ||
| return {} | ||
| return { | ||
| "bind": os.getenv("FALKORDB_LITE_HOST", "127.0.0.1"), | ||
| "port": port, | ||
| } | ||
|
|
||
|
|
||
| def create_falkordb() -> Any: | ||
| """Create a sync FalkorDB client for the configured backend.""" | ||
| if is_lite_backend(): | ||
| try: | ||
| from redislite.falkordb_client import FalkorDB as LiteFalkorDB | ||
| except ImportError as e: | ||
| raise RuntimeError( | ||
| "CODE_GRAPH_DB_BACKEND=lite requires the optional " | ||
| "`falkordblite` dependency. Install with " | ||
| "`uv sync --extra light` or `pip install 'falkordb-code-graph[light]'`." | ||
| ) from e | ||
|
|
||
| return LiteFalkorDB(_lite_db_path(), serverconfig=_lite_serverconfig()) | ||
|
|
||
| from falkordb import FalkorDB | ||
|
|
||
| return FalkorDB( | ||
| host=os.getenv("FALKORDB_HOST", "localhost"), | ||
| port=os.getenv("FALKORDB_PORT", 6379), | ||
| username=os.getenv("FALKORDB_USERNAME", None), | ||
| password=os.getenv("FALKORDB_PASSWORD", None), | ||
| ) | ||
|
|
||
|
|
||
| def create_async_falkordb() -> Any: | ||
| """Create an async FalkorDB client for the configured backend.""" | ||
| if is_lite_backend(): | ||
| try: | ||
| from redislite.async_falkordb_client import AsyncFalkorDB as LiteAsyncFalkorDB | ||
| except ImportError as e: | ||
| raise RuntimeError( | ||
| "CODE_GRAPH_DB_BACKEND=lite requires the optional " | ||
| "`falkordblite` dependency. Install with " | ||
| "`uv sync --extra light` or `pip install 'falkordb-code-graph[light]'`." | ||
| ) from e | ||
|
|
||
| client = LiteAsyncFalkorDB(_lite_db_path(), serverconfig=_lite_serverconfig()) | ||
| if not hasattr(client, "aclose"): | ||
| client.aclose = client.close | ||
| return client | ||
|
|
||
| from falkordb.asyncio import FalkorDB as AsyncFalkorDB | ||
|
|
||
| return AsyncFalkorDB( | ||
| host=os.getenv("FALKORDB_HOST", "localhost"), | ||
| port=int(os.getenv("FALKORDB_PORT", 6379)), | ||
| username=os.getenv("FALKORDB_USERNAME", None), | ||
| password=os.getenv("FALKORDB_PASSWORD", None), | ||
| ) | ||
|
|
||
|
|
||
| def create_redis_connection() -> Any: | ||
| """Create a sync Redis-compatible connection for metadata operations.""" | ||
| if is_lite_backend(): | ||
| return create_falkordb().connection | ||
|
|
||
| import redis | ||
|
|
||
| return redis.Redis( | ||
| host=os.getenv("FALKORDB_HOST", "localhost"), | ||
| port=int(os.getenv("FALKORDB_PORT", "6379")), | ||
| username=os.getenv("FALKORDB_USERNAME"), | ||
| password=os.getenv("FALKORDB_PASSWORD"), | ||
| decode_responses=True, | ||
| ) | ||
|
|
||
|
|
||
| def create_async_redis_connection() -> Any: | ||
| """Create an async Redis-compatible connection for metadata operations.""" | ||
| if is_lite_backend(): | ||
| return create_async_falkordb().connection | ||
|
|
||
| import redis.asyncio as aioredis | ||
|
Comment on lines
+113
to
+118
|
||
|
|
||
| return aioredis.Redis( | ||
| host=os.getenv("FALKORDB_HOST", "localhost"), | ||
| port=int(os.getenv("FALKORDB_PORT", "6379")), | ||
| username=os.getenv("FALKORDB_USERNAME"), | ||
| password=os.getenv("FALKORDB_PASSWORD"), | ||
| decode_responses=True, | ||
| ) | ||
|
|
||
|
|
||
| def graphrag_connection_kwargs() -> dict[str, Any]: | ||
| """Return host/port kwargs for GraphRAG SDK constructors. | ||
|
|
||
| GraphRAG SDK accepts host/port only. FalkorDBLite's private Unix socket is | ||
| therefore usable for structural tools but not for GraphRAG unless a local | ||
| TCP port is explicitly enabled with ``FALKORDB_LITE_PORT``. | ||
| """ | ||
| if is_lite_backend(): | ||
| port = os.getenv("FALKORDB_LITE_PORT") | ||
| if not port: | ||
| raise RuntimeError( | ||
| "GraphRAG requires host/port access. When using " | ||
| "CODE_GRAPH_DB_BACKEND=lite, set FALKORDB_LITE_PORT to expose " | ||
| "the embedded FalkorDBLite instance on localhost." | ||
| ) | ||
| create_falkordb() | ||
| return { | ||
| "host": os.getenv("FALKORDB_LITE_HOST", "127.0.0.1"), | ||
| "port": int(port), | ||
| "username": None, | ||
| "password": None, | ||
| } | ||
|
|
||
| return { | ||
| "host": os.getenv("FALKORDB_HOST", "localhost"), | ||
| "port": int(os.getenv("FALKORDB_PORT", 6379)), | ||
| "username": os.getenv("FALKORDB_USERNAME", None), | ||
| "password": os.getenv("FALKORDB_PASSWORD", None), | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle BLE001 explicitly for the intentional catch-all path.
If this broad catch is intentional to guarantee JSON output, annotate it (
# noqa: BLE001) with a short rationale; otherwise narrow to expected startup exceptions.As per coding guidelines, "Run Ruff linter for Python code to check style and quality."
🧰 Tools
🪛 Ruff (0.15.15)
[warning] 71-71: Do not catch blind exception:
Exception(BLE001)
🤖 Prompt for AI Agents
Sources: Coding guidelines, Linters/SAST tools