-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
feat(serve): add multi-graph support to MCP server (#581) #2099
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
Open
YanisGuerault
wants to merge
2
commits into
Graphify-Labs:v8
Choose a base branch
from
YanisGuerault:feat/add-multi-graph-support
base: v8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ build/ | |
| *.egg | ||
| .graphify/ | ||
| graphify-out/ | ||
| .worktrees/ | ||
| .graphify_*.json | ||
| .graphify_python | ||
| .claude/ | ||
|
|
||
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 |
|---|---|---|
| @@ -1,25 +1,15 @@ | ||
| # graphify MCP server as a shared HTTP service (issue #1143). | ||
| # | ||
| # Build: docker build -t graphify . | ||
| # Run: docker run -p 8080:8080 -v "$(pwd)/graphify-out:/data" graphify \ | ||
| # /data/graph.json --transport http --host 0.0.0.0 --api-key "$SECRET" | ||
| # | ||
| # Builds from source so the image includes the Streamable HTTP transport even | ||
| # before it lands on PyPI. The graph.json is mounted at runtime (-v), never | ||
| # baked into the image. | ||
| # graphify MCP server. Mount a repository containing graphify-out/graph.json. | ||
| FROM python:3.12-slim | ||
|
|
||
| WORKDIR /app | ||
| COPY . /app | ||
|
|
||
| # The [mcp] extra pulls mcp + starlette + uvicorn, which the HTTP transport needs. | ||
| RUN pip install --no-cache-dir ".[mcp]" | ||
|
|
||
| # Run as a non-root user — the server is network-exposed. | ||
| # Run as a non-root user because the server is network-exposed. | ||
| RUN useradd --create-home --uid 10001 graphify | ||
| USER graphify | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| ENTRYPOINT ["python", "-m", "graphify.serve"] | ||
| CMD ["/data/graph.json", "--transport", "http", "--host", "0.0.0.0", "--port", "8080"] | ||
| ENTRYPOINT ["graphify"] | ||
| CMD ["/data", "--mcp", "--transport", "http", "--host", "0.0.0.0", "--port", "8080"] |
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,11 @@ | ||
| # Quick start: docker compose -f docker-compose.multi.yml up --build | ||
| # Runs: graphify /repos/frontend /repos/backend --mcp | ||
| services: | ||
| graphify-mcp: | ||
| build: . | ||
| ports: | ||
| - "127.0.0.1:8080:8080" | ||
| volumes: | ||
| - ./repos/frontend:/repos/frontend:ro | ||
| - ./repos/backend:/repos/backend:ro | ||
| command: ["/repos/frontend", "/repos/backend", "--mcp", "--transport", "http", "--host", "0.0.0.0", "--port", "8080"] |
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 |
|---|---|---|
|
|
@@ -479,6 +479,122 @@ def main() -> None: | |
| raise | ||
|
|
||
|
|
||
| def _start_mcp_registry(registry) -> None: | ||
| from graphify.serve import serve | ||
|
|
||
| serve(registry=registry) | ||
|
|
||
|
|
||
| def _serve_mcp_repositories( | ||
| paths: list[str], | ||
| *, | ||
| transport: str, | ||
| host: str = "127.0.0.1", | ||
| port: int = 8080, | ||
| api_key: str | None = None, | ||
| ) -> None: | ||
| from graphify.serve import GraphRegistry | ||
|
|
||
| if not paths: | ||
| print("error: --mcp requires at least one repository path", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| resolved = [Path(path).resolve() for path in paths] | ||
| names = [path.name for path in resolved] | ||
| duplicate = next((name for name in names if names.count(name) > 1), None) | ||
| if duplicate is not None: | ||
| print(f"error: duplicate graph name {duplicate!r}; repository basenames must be unique", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| graph_paths = [] | ||
| for repo in resolved: | ||
| graph_path = repo / _GRAPHIFY_OUT / "graph.json" | ||
| try: | ||
| exists = graph_path.is_file() | ||
| except OSError as exc: | ||
| print(f"error: could not read graph: {graph_path} ({exc})", file=sys.stderr) | ||
| raise SystemExit(1) from None | ||
| if not exists: | ||
| print(f"error: graph not found: {graph_path}", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| graph_paths.append(graph_path) | ||
| try: | ||
| registry = GraphRegistry.from_paths(graph_paths) | ||
| except OSError as exc: | ||
| print(f"error: could not read graph: {exc}", file=sys.stderr) | ||
| raise SystemExit(1) from None | ||
| if transport == "http": | ||
| from graphify.serve import serve_http | ||
|
|
||
| serve_http(registry=registry, host=host, port=port, api_key=api_key) | ||
| else: | ||
| _start_mcp_registry(registry) | ||
|
|
||
|
|
||
| def _run_mcp_cli(args: list[str]) -> bool: | ||
| if "--mcp" not in args: | ||
| return False | ||
|
|
||
| paths: list[str] = [] | ||
| transport = "stdio" | ||
| host = "127.0.0.1" | ||
| port = 8080 | ||
| api_key: str | None = None | ||
| index = 0 | ||
| while index < len(args): | ||
| arg = args[index] | ||
| if arg == "--mcp": | ||
| index += 1 | ||
| elif arg == "--transport": | ||
| index += 1 | ||
| if index == len(args) or args[index] not in {"stdio", "http"}: | ||
| print("error: --transport must be stdio or http", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| transport = args[index] | ||
| index += 1 | ||
| elif arg == "--host": | ||
| index += 1 | ||
| if index == len(args): | ||
| print("error: --host requires a value", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| if args[index].startswith("-"): | ||
| print(f"error: unrecognized MCP option: {args[index]}", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| host = args[index] | ||
| index += 1 | ||
| elif arg == "--port": | ||
| index += 1 | ||
| if index == len(args): | ||
| print("error: --port requires an integer", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| try: | ||
| port = int(args[index]) | ||
| except ValueError: | ||
| print("error: --port requires an integer", file=sys.stderr) | ||
| raise SystemExit(1) from None | ||
| index += 1 | ||
| elif arg == "--api-key": | ||
| index += 1 | ||
| if index == len(args): | ||
| print("error: --api-key requires a value", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| if args[index].startswith("-"): | ||
| print(f"error: unrecognized MCP option: {args[index]}", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| api_key = args[index] | ||
| index += 1 | ||
| elif arg.startswith("-"): | ||
| print(f"error: unrecognized MCP option: {arg}", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| else: | ||
| paths.append(arg) | ||
| index += 1 | ||
|
|
||
| if transport == "stdio" and host == "127.0.0.1" and port == 8080 and api_key is None: | ||
| _serve_mcp_repositories(paths, transport=transport) | ||
| else: | ||
| _serve_mcp_repositories(paths, transport=transport, host=host, port=port, api_key=api_key) | ||
| return True | ||
|
|
||
|
|
||
| def _run_cli() -> None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
high coupling complexity (Ca·Ce = 15). Grounded coupling-delta finding (deterministic), not an LLM guess. |
||
| for _stream in (sys.stdout, sys.stderr): | ||
| if _stream is not None and hasattr(_stream, "reconfigure"): | ||
|
|
@@ -502,10 +618,18 @@ def _run_cli() -> None: | |
| print(f"graphify {__version__}") | ||
| return | ||
|
|
||
| if _run_mcp_cli(sys.argv[1:]): | ||
| return | ||
|
|
||
| if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help", "-?"): | ||
| print("Usage: graphify <command>") | ||
| print() | ||
| print("Commands:") | ||
| print(" <repo>... --mcp serve existing repository graphs over MCP stdio") | ||
| print(" --transport stdio|http transport (default: stdio)") | ||
| print(" --host HOST HTTP bind host (default: 127.0.0.1)") | ||
| print(" --port PORT HTTP bind port (default: 8080)") | ||
| print(" --api-key KEY require this key for HTTP requests") | ||
| print(" install [--platform P] copy skill to platform config dir (claude|windows|codebuddy|codex|opencode|aider|amp|agents|claw|droid|trae|trae-cn|gemini|cursor|antigravity|hermes|kiro|pi|devin)") | ||
| print(" uninstall remove graphify from all detected platforms in one shot") | ||
| print(" --purge also delete graphify-out/ directory") | ||
|
|
||
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.
_serve_mcp_repositories()6 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.