-
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
12
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
12 commits
Select commit
Hold shift + click to select a range
4c643b0
sync: preserve local workflow files
github-actions[bot] f3cdbda
feat(mcp): add core server and workspace integration
8b6a675
fix(llm): align APIs and supporting clients
744cfbf
test(ci): add MCP coverage and quality checks
f85f4dd
docs: add MCP guides and update examples
a7bbc63
release(mcp): add trusted PyPI publishing
ecab18e
fix(mcp): close gremlin and schema apply contracts
f217902
fix(mcp): close tokenizer and schema field contract
a784c7c
test(mcp): close schema user data and malformed predicate regressions
15231e3
fix(mcp): enforce write limits, optional inspect counts, and restore …
2b2c1c1
fix(ci): wait for HugeGraph schema readiness
40814c6
fix(mcp): ignore server-managed schema metadata
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,203 @@ | ||
| # | ||
| # 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: | | ||
| # Install the standalone MCP packages with pip. FastMCP 3.x has | ||
| # platform-specific metadata that uv cannot resolve on Linux x86. | ||
| python -m pip install --upgrade pip | ||
| python -m pip install \ | ||
| -e ./hugegraph-python-client \ | ||
| -e ./hugegraph-mcp \ | ||
| "pytest~=8.0.0" \ | ||
| "ruff>=0.11.0" | ||
| 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") == "1.7.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: | | ||
| ruff format --check hugegraph-mcp/hugegraph_mcp hugegraph-mcp/tests | ||
|
|
||
| - name: Lint MCP | ||
| run: | | ||
| ruff check hugegraph-mcp/hugegraph_mcp hugegraph-mcp/tests | ||
|
|
||
| - name: Run MCP tests | ||
| run: | | ||
| 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: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install \ | ||
| -e ./hugegraph-python-client \ | ||
| -e ./hugegraph-mcp \ | ||
| "pytest~=8.0.0" | ||
|
|
||
| - 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: | | ||
| python -m pytest tests/integration/test_real_write_path.py -m real_hugegraph | ||
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,82 @@ | ||
| # | ||
| # 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: Publish HugeGraph MCP | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "mcp-v*" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: astral-sh/setup-uv@v6 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.10" | ||
|
|
||
| - name: Verify release tag | ||
| if: github.event_name == 'push' | ||
| run: | | ||
| package_version=$(uv run --no-project python -c \ | ||
| 'import tomllib; print(tomllib.load(open("hugegraph-mcp/pyproject.toml", "rb"))["project"]["version"])') | ||
| test "${GITHUB_REF_NAME}" = "mcp-v${package_version}" | ||
|
|
||
| - name: Build distributions | ||
| run: uv build --directory hugegraph-mcp --out-dir dist | ||
|
|
||
| - name: Verify distributions | ||
| run: uvx --from twine twine check dist/* | ||
|
|
||
| - name: Verify published dependencies and console script | ||
| run: | | ||
| wheel=$(find dist -name '*.whl' -print -quit) | ||
| uvx --from "$wheel" hugegraph-mcp < /dev/null | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: hugegraph-mcp-distributions | ||
| path: dist/ | ||
| if-no-files-found: error | ||
|
|
||
| publish: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: pypi-hugegraph-mcp | ||
| url: https://pypi.org/p/hugegraph-mcp | ||
| permissions: | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: hugegraph-mcp-distributions | ||
| path: dist/ | ||
|
|
||
| - uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| packages-dir: dist/ |
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,76 @@ | ||
| # | ||
| # 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: Publish HugeGraph Python Client | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "client-v*" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: astral-sh/setup-uv@v6 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.10" | ||
|
|
||
| - name: Verify release tag | ||
| run: | | ||
| package_version=$(uv run --no-project python -c \ | ||
| 'import tomllib; print(tomllib.load(open("hugegraph-python-client/pyproject.toml", "rb"))["project"]["version"])') | ||
| test "${GITHUB_REF_NAME}" = "client-v${package_version}" | ||
|
|
||
| - name: Build distributions | ||
| run: uv build --package hugegraph-python-client --out-dir dist | ||
|
|
||
| - name: Verify distributions | ||
| run: uvx --from twine twine check dist/* | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: hugegraph-python-client-distributions | ||
| path: dist/ | ||
| if-no-files-found: error | ||
|
|
||
| publish: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: pypi-hugegraph-python-client | ||
| url: https://pypi.org/p/hugegraph-python-client | ||
| permissions: | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: hugegraph-python-client-distributions | ||
| path: dist/ | ||
|
|
||
| - uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| packages-dir: dist/ |
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.