Skip to content

MCP: add upsert_entity and upsert_relationship tools #4864

Closed

Description

@robfrank

Part of #4859.

Motivation

ArcadeDB SQL/Cypher already support UPSERT/MERGE semantics, but models reliably build match-key logic wrong (string-concatenated WHERE clauses, missing key normalization) and duplicate nodes as a result — the single most common agent-memory failure mode. Wrapping match-or-create-by-key behind a parameterized, injection-safe tool is a concrete correctness win over raw execute_command. Justification: #1 ergonomic guardrail; secondarily #3 different permissioning (requires composing allowInsert AND allowUpdate, a combination ExecuteCommandTool doesn't need to express as a single unit today).

Proposed design

  • Tool names: upsert_entity, upsert_relationship
  • upsert_entity input schema:
{
  "type": "object",
  "properties": {
    "database": {"type": "string"},
    "type": {"type": "string"},
    "matchKeys": {"type": "object", "description": "property:value pairs used as the match/merge key"},
    "setProperties": {"type": "object"}
  },
  "required": ["database", "type", "matchKeys"]
}
  • upsert_relationship input schema:
{
  "type": "object",
  "properties": {
    "database": {"type": "string"},
    "fromType": {"type": "string"}, "fromMatchKeys": {"type": "object"},
    "toType": {"type": "string"}, "toMatchKeys": {"type": "object"},
    "relType": {"type": "string"},
    "relProperties": {"type": "object"}
  },
  "required": ["database", "fromType", "fromMatchKeys", "toType", "toMatchKeys", "relType"]
}
  • Implementation: build a parameterized Cypher MERGE (bound parameters, not string interpolation — this is the injection-safety justification, not just ergonomics) and execute via the same code path ExecuteCommandTool uses.
  • Permission gating: extend ExecuteCommandTool.checkPermission-style logic to require allowInsert (create path) and allowUpdate (update path) both enabled; report explicitly which flag is missing on rejection.
  • Forward-link: a future bi-temporal/temporal-KG primitive (versioned upserts) is out of scope here, but this schema shouldn't preclude adding an optional validFrom/validTo later.

Acceptance criteria

  • No duplicate node created on repeated calls with identical matchKeys.
  • Relationship upsert does not duplicate edges between the same resolved endpoints.
  • Parameters are bound, not string-concatenated (verify no injection vector — add a test with a malicious value in matchKeys).
  • Rejected clearly when only one of allowInsert/allowUpdate is enabled, naming the missing flag.
  • Registered in both transports; tests mirror MCPPermissionsTest for the two-flag composition case; docs.

Files to touch

server/src/main/java/com/arcadedb/server/mcp/tools/UpsertEntityTool.java, UpsertRelationshipTool.java (new), MCPHttpHandler.java, MCPStdioServer.java, tests, docs.

Dependencies

None (independent of retrieval issues).

Effort estimate

M — injection-safe parameterized MERGE construction, two related tools, composed-permission logic.

Activity

  1. added
    enhancement
    mcp
    on Jul 2, 2026
  2. added this to the 26.8.1 milestone on Jul 2, 2026
  3. self-assigned this
    on Jul 2, 2026
  4. modified the milestones: 26.7.2, 26.8.1 on Jul 8, 2026
  5. added
    mcp
    enhancement
    and removed
    enhancement
    mcp
    on Jul 8, 2026
  6. added 5 commits that reference this issue on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementmcp

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions