Skip to content

feat(mcp): add HugeGraph MCP V1 tools and harden guarded writes - #368

Open
UIengF wants to merge 18 commits into
apache:mainfrom
hugegraph:graph-mcp
Open

feat(mcp): add HugeGraph MCP V1 tools and harden guarded writes#368
UIengF wants to merge 18 commits into
apache:mainfrom
hugegraph:graph-mcp

Conversation

@UIengF

@UIengF UIengF commented Jun 29, 2026

Copy link
Copy Markdown

Overview

This PR adds hugegraph-mcp, a standalone thin adapter that gives MCP clients and agents controlled access to HugeGraph and HugeGraph-AI. The MCP layer owns stable tool contracts, configuration and authorization, typed queries, immutable server-side write plans, durable operation receipts, status inspection, and reconciliation.

The default public contract is v2_core; v1 remains available as a compatibility mode. The runtime requires Python >= 3.10 and HugeGraph Server >= 1.7.0; unverified versions, backends, and atomic capabilities fail closed.

Public tool contract

  • v2_core registers 16 tools by default.
  • v1 registers 10 compatibility tools and omits inspect_schema_tool, query_graph_data_tool, mutate_graph_properties_tool, confirm_write_tool, get_write_status_tool, and reconcile_write_tool.
  • The public surface covers graph and schema inspection, typed bounded vertex/edge queries, Gremlin generation, text-to-graph extraction, schema design and validation, and controlled write previews.
  • import_graph_data_tool(mode=table) remains FEATURE_DISABLED; unimplemented table_data and mapping parameters are not exposed in the MCP JSON Schema.
  • Legacy internal aggregate entry points are not registered as MCP tools.
  • Safe defaults remain HUGEGRAPH_MCP_READONLY=true, HUGEGRAPH_MCP_ALLOW_AI=false, and HUGEGRAPH_MCP_ADMIN_MODE=false.

Confirmed-write safety model

The canonical flow is:

structured dry-run
  -> server persists an immutable WritePlan
  -> client receives plan_id
  -> confirm_write_tool(plan_id)
  -> get_write_status_tool(plan_id)
  -> reconcile_write_tool(plan_id), when required
  • Confirmation submits only plan_id. Backend IDs, endpoints, expected and desired state, operation order, graph target, principal, and expiry are loaded from the persisted server plan.
  • The SQLite plan store persists plans, per-operation state, and receipts. Confirming a completed plan_id again returns the durable result without issuing another write.
  • APPLIED, ALREADY_APPLIED, REJECTED, CONFLICT, PARTIAL, UNKNOWN, and RETRYABLE_NOT_APPLIED retain distinct meanings. UNKNOWN and PARTIAL are never retried automatically.
  • Edge endpoints and delete targets are bound to stable backend IDs during dry-run; execution does not re-evaluate mutable property predicates.
  • Legacy plan_hash, nonce, and expires_at fields remain locator-only compatibility inputs for one release. They must be provided together, cannot be mixed with plan_id, and produce a deprecation warning.
  • The bundled plan store currently implements SQLite only and supports one writable MCP instance. Declaring multiple writers fails closed; multi-replica writes require a future shared transactional store.
  • Real schema apply remains disabled in v1.

Executable boundaries

The canonical user-confirmed flow currently supports:

  • One property key, vertex label, or edge label creation per schema plan.
  • Exact edge deletion by a persisted edge ID.

The following operations are preview-only, issue no plan_id, return FEATURE_DISABLED on confirmation, and perform no write:

  • Graph creation/import, because HugeGraph 1.7.0 has no verified atomic create-if-absent primitive.
  • Vertex/edge property append/eliminate, because HugeGraph 1.7.0 has no backend-enforced compare-and-set primitive.
  • Isolated vertex deletion with cascade=false, because Docker concurrency testing reproduced a non-isolated edge-add/delete race.
  • Index create/rebuild, schema drop, and other destructive operations without a registered atomic adapter.

refresh_vid_embeddings_tool remains a separate admin write tool gated by readonly, AI, and admin configuration.

Raw Gremlin boundary

All public Raw Gremlin execution paths are currently disabled:

  • execute_gremlin_read_tool
  • execute_gremlin_write_tool
  • generate_gremlin_tool(execute=true)

Admin mode cannot bypass this gate. Raw execution can only be enabled after the deployment enforces a read-only database principal, server evaluation/wait timeouts, a server-side result cap, and a streaming client-side byte cap. Typed reads and generate_gremlin_tool(execute=false) remain available.

Additional changes

  • Fix HugeGraph edge ID encoding, graphspace/auth routing, and client schema field forwarding.
  • Apply shared validation for SINGLE, LIST, SET, UUID, DATE, BLOB, OBJECT, and numeric bounds.
  • Add typed and bounded connect/read/write timeout and result-budget configuration.
  • Normalize HugeGraph-AI Thin API envelopes with bounded unwrapping and secret-safe error logging.
  • Importing the Python client no longer replaces the host process logging configuration; a narrow contract is added for a future backend property CAS primitive.
  • Add an evidence-backed backend capability matrix; unknown versions, backends, and unverified atomic semantics fail closed.
  • Add immutable-plan, SQLite migration, fault-injection, fencing, reconciliation, concurrency, and Docker coverage.

Verification

Current head 845baaf2:

  • HugeGraph MCP: 784 passed, 17 skipped
  • HugeGraph Python client: 71 passed, 70 skipped
  • HugeGraph-LLM Thin API: 15 passed, with 5 dependency deprecation warnings
  • SQLite migration: 13 passed
  • Executor fault/fencing: 8 passed
  • Deterministic Docker HugeGraph 1.7.0 real-write path: 16 passed
  • A 300-iteration isolated-delete probe reproduced two non-isolated outcomes, so the capability remains disabled
  • Ruff check, Ruff format, ASF License Header, and git diff --check: passed
  • FastMCP stdio: initialize, 16-tool tools/list, and inspect_graph_tool call passed

Out of scope

This PR does not add GraphRAG question answering, SQL/table import, arbitrary Raw Gremlin execution, general unconditional graph-data update, index/rebuild, destructive schema apply, MCP resources, HTTP/SSE transport, or multi-replica writes backed by independent SQLite files.

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels Jun 29, 2026

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current MCP/client changes at head 8842bb53007102b47d50e4eaabb6e2cc51e9b526. I found several install/runtime safety issues that should be addressed before relying on the new MCP package independently. Local non-live checks passed, so these comments focus on behavioral and packaging gaps rather than test failures.

Comment thread hugegraph-mcp/pyproject.toml Outdated
Comment thread hugegraph-mcp/hugegraph_mcp/tools/ingest_graph_data.py
Comment thread hugegraph-mcp/hugegraph_mcp/tools/manage_schema.py
Comment thread hugegraph-mcp/hugegraph_mcp/server.py
Comment thread hugegraph-python-client/src/pyhugegraph/utils/log.py
Comment thread hugegraph-mcp/hugegraph_mcp/hugegraph_ai_client.py Outdated
@UIengF UIengF changed the title feat(mcp): Add HugeGraph MCP serverGraph mcp feat(mcp): add HugeGraph MCP V1 stable tool surface Jun 29, 2026

@VGalaxies VGalaxies left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

  • Blocking: yes
  • Summary: The PR still has blocking correctness and write-safety issues in the new MCP/Thin API surface.
  • Evidence:
    • static review of git diff origin/main...HEAD
    • git diff --check origin/main...HEAD only reports the known blank-line style issue

Comment thread hugegraph-llm/src/hugegraph_llm/api/thin_api.py Outdated
Comment thread hugegraph-mcp/hugegraph_mcp/plan_hash.py
Comment thread hugegraph-llm/src/hugegraph_llm/api/thin_api.py
Comment thread .github/workflows/hugegraph-mcp.yml
Comment thread .github/workflows/hugegraph-mcp.yml Outdated
@UIengF UIengF changed the title feat(mcp): add HugeGraph MCP V1 stable tool surface feat(mcp): add HugeGraph MCP V1 tools and harden guarded writes Jul 11, 2026
@UIengF
UIengF requested review from VGalaxies and imbajin July 11, 2026 05:42
@UIengF
UIengF force-pushed the graph-mcp branch 3 times, most recently from acd7490 to 8dac401 Compare July 16, 2026 11:05
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Jul 16, 2026
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Aug 6, 2026
@github-actions github-actions Bot added the ml label Aug 6, 2026
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. size:XL This PR changes 500-999 lines, ignoring generated files. labels Aug 6, 2026
@UIengF
UIengF force-pushed the graph-mcp branch 3 times, most recently from 73c47ad to e207127 Compare August 12, 2026 05:26
@UIengF
UIengF force-pushed the graph-mcp branch 7 times, most recently from 6b775e3 to d8ffd93 Compare August 14, 2026 09:33
duyifeng01 added 4 commits August 14, 2026 19:42
Change-Id: I067e93324436c8dcc1fa0c0bc3651c40620e7d55
Change-Id: I485e122e5f8da1aedf21736a9ea583a527d4f0d8
Change-Id: Iab12433dd083f901d4999f4d21f3d0560e513f2a
Change-Id: Icc7b4df3633e4f01ab6dda5404592686a825d943
@UIengF
UIengF force-pushed the graph-mcp branch 4 times, most recently from c0b4c73 to 8c7e824 Compare August 14, 2026 12:36
Change-Id: I81854014b95699bd5d613412476a9e9ba3cc66a5
Duyifeng and others added 12 commits August 26, 2026 14:13
…/rag client_config

Apply the GRAPH-47 M4/M3/C2 ruling: reject oversized schema and graph-data
plans before plan_hash, keep inspect counts opt-in with null fields, and
stop hard-400ing /rag client_config without mutating process globals.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Change-Id: Idd2d0d70accb44cc582c230a83c7519b59b99fcd
Change-Id: I7a2f02243fd77686b16f36bf4df63136214a176b
Change-Id: I6e4b6fae84175d4eb8386878c94e31bde2c7b7f0
Change-Id: Iaa86e91bc875bc9ecf4219a9cc686ec30da45c49
Change-Id: I1c21c1a19cb4e229ac3586444554a5c74b6a62c9
Change-Id: I90ef3bb12822ec484c493f07e5d1b386ef34c338
Change-Id: I29be647aa2f41672f91206ab00100cfd36200378
Change-Id: I7024e01e62fc1822ae85d133e80b6bedd61c7d57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request llm ml python-client size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants