-
Notifications
You must be signed in to change notification settings - Fork 88
feat(mcp): add HugeGraph MCP V1 tools and harden guarded writes #368
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
UIengF
wants to merge
2
commits into
apache:main
Choose a base branch
from
hugegraph:graph-mcp
base: main
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 |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| # | ||
|
|
||
| name: HugeGraph-MCP CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "main" | ||
| - "release-*" | ||
| paths: | ||
| - "hugegraph-mcp/**" | ||
| - "hugegraph-python-client/**" | ||
| - "pyproject.toml" | ||
| - "uv.lock" | ||
| - ".github/workflows/hugegraph-mcp.yml" | ||
| pull_request: | ||
| paths: | ||
| - "hugegraph-mcp/**" | ||
| - "hugegraph-python-client/**" | ||
| - "pyproject.toml" | ||
| - "uv.lock" | ||
| - ".github/workflows/hugegraph-mcp.yml" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ["3.10", "3.11", "3.12"] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install uv | ||
| run: | | ||
| curl -LsSf https://astral.sh/uv/install.sh | sh | ||
| echo "$HOME/.cargo/bin" >> $GITHUB_PATH | ||
|
|
||
| - name: Cache dependencies | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cache/uv | ||
| key: ${{ runner.os }}-mcp-uv-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml', 'uv.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-mcp-uv-${{ matrix.python-version }}- | ||
|
|
||
| - name: Install MCP dependencies | ||
| run: | | ||
| # The root workspace includes hugegraph-llm (<3.12). Install the | ||
| # MCP packages directly so every matrix entry exercises its stated | ||
| # interpreter instead of silently falling back to Python 3.11. | ||
| uv venv --python "${{ matrix.python-version }}" .mcp-venv | ||
| uv pip install --python .mcp-venv/bin/python \ | ||
| -e ./hugegraph-python-client \ | ||
| -e ./hugegraph-mcp \ | ||
| "pytest~=8.0.0" \ | ||
| "ruff>=0.11.0" | ||
| .mcp-venv/bin/python --version | ||
|
|
||
| - name: Verify isolated wheel install | ||
| if: matrix.python-version == '3.10' | ||
| run: | | ||
| rm -rf wheelhouse isolated-mcp-venv | ||
| uv build --wheel --out-dir wheelhouse hugegraph-python-client | ||
| uv build --wheel --out-dir wheelhouse hugegraph-mcp | ||
| python -m venv isolated-mcp-venv | ||
| isolated-mcp-venv/bin/python -m pip install \ | ||
| --find-links wheelhouse \ | ||
| wheelhouse/hugegraph_python_client-*.whl \ | ||
| wheelhouse/hugegraph_mcp-*.whl | ||
| isolated-mcp-venv/bin/python - <<'PY' | ||
| from importlib.metadata import version | ||
| from types import SimpleNamespace | ||
| from unittest.mock import Mock | ||
|
|
||
| import hugegraph_mcp | ||
| import pyhugegraph | ||
| from hugegraph_mcp.server import main | ||
| from pyhugegraph.api.auth import AuthManager | ||
| from pyhugegraph.utils.huge_config import HGraphConfig | ||
| from pyhugegraph.utils.huge_requests import HGraphSession | ||
|
|
||
| assert version("hugegraph-python-client") == "1.7.0" | ||
| assert version("hugegraph-mcp") == "0.1.0" | ||
|
|
||
| class CaptureSession: | ||
| cfg = SimpleNamespace(graphspace="GS", gs_supported=True) | ||
|
|
||
| def request(self, path, method="GET", **_kwargs): | ||
| self.path = path | ||
| return {"ok": True} | ||
|
|
||
| capture = CaptureSession() | ||
| AuthManager(capture).list_users() | ||
| assert capture.path == "/graphspaces/GS/auth/users" | ||
|
|
||
| config = HGraphConfig( | ||
| "http://127.0.0.1:8080", "admin", "pwd", "g", graphspace="GS" | ||
| ) | ||
| session = HGraphSession(config, session=Mock()) | ||
| assert session.resolve("schema") == ( | ||
| "http://127.0.0.1:8080/graphspaces/GS/graphs/g/schema" | ||
| ) | ||
| PY | ||
|
|
||
| - name: Check MCP formatting | ||
| run: | | ||
| .mcp-venv/bin/ruff format --check hugegraph-mcp/hugegraph_mcp hugegraph-mcp/tests | ||
|
|
||
| - name: Lint MCP | ||
| run: | | ||
| .mcp-venv/bin/ruff check hugegraph-mcp/hugegraph_mcp hugegraph-mcp/tests | ||
|
|
||
| - name: Run MCP tests | ||
| run: | | ||
| .mcp-venv/bin/python -m pytest hugegraph-mcp -m "not live and not integration and not llm" | ||
|
|
||
| real-hugegraph-write-path: | ||
| runs-on: ubuntu-latest | ||
| services: | ||
| hugegraph: | ||
| image: hugegraph/hugegraph:1.7.0 | ||
| env: | ||
| PASSWORD: admin | ||
| options: >- | ||
| --health-cmd="curl -f http://localhost:8080/versions || exit 1" | ||
| --health-interval=10s | ||
| --health-timeout=5s | ||
| --health-retries=12 | ||
| ports: | ||
| - 8080:8080 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python 3.10 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.10" | ||
|
|
||
| - name: Install uv | ||
| run: | | ||
| curl -LsSf https://astral.sh/uv/install.sh | sh | ||
| echo "$HOME/.cargo/bin" >> $GITHUB_PATH | ||
|
|
||
| - name: Cache dependencies | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cache/uv | ||
| key: ${{ runner.os }}-mcp-real-hugegraph-uv-${{ hashFiles('**/pyproject.toml', 'uv.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-mcp-real-hugegraph-uv- | ||
|
|
||
| - name: Install MCP dependencies | ||
| run: | | ||
| uv sync --extra mcp --extra dev | ||
|
|
||
| - name: Run real HugeGraph write-path tests | ||
| working-directory: hugegraph-mcp | ||
| env: | ||
| RUN_MCP_REAL_HUGEGRAPH_TESTS: "1" | ||
| HUGEGRAPH_URL: http://127.0.0.1:8080 | ||
| HUGEGRAPH_GRAPH_PATH: DEFAULT/hugegraph | ||
| HUGEGRAPH_USER: admin | ||
| HUGEGRAPH_PASSWORD: admin | ||
| HUGEGRAPH_MCP_READONLY: "false" | ||
| HUGEGRAPH_MCP_ALLOW_AI: "false" | ||
| run: | | ||
| uv run pytest tests/integration/test_real_write_path.py -m real_hugegraph | ||
|
UIengF marked this conversation as resolved.
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.