Repository navigation
Description
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_entityinput 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_relationshipinput 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 pathExecuteCommandTooluses. - Permission gating: extend
ExecuteCommandTool.checkPermission-style logic to requireallowInsert(create path) andallowUpdate(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/validTolater.
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/allowUpdateis enabled, naming the missing flag. - Registered in both transports; tests mirror
MCPPermissionsTestfor 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
fix(#4864): validate database arg for a clean error on missing/blank …
refactor(#4864): share require/appendNodeMerge helpers in MCPToolUtil…
docs(#4864): document that no-duplicate/idempotency needs a UNIQUE in…
refactor(#4864): extract appendSetClause; cover composite match keys …
MCP: add upsert_entity and upsert_relationship tools (#4864) (#5301)
MCP: add upsert_entity and upsert_relationship tools (#4864) (#5301)