Skip to content

feat(v6.50.0): MCP + CLI relationship tools (ADR-249, #298) - #300

Merged
cgbarlow merged 2 commits into
mainfrom
feature/mcp-relationship-tools
Sep 24, 2026
Merged

cgbarlow merged 2 commits into
mainfrom
feature/mcp-relationship-tools

Conversation

@cgbarlow

Copy link
Copy Markdown
Owner

Problem

Agents using the Iris MCP server or CLI could create elements but had no way to connect them (issue #298):

  • New elements showed no relationships.
  • Diagram edges couldn't point at a real relationshipId.
  • Imported role names and attributes couldn't be corrected.

The backend also couldn't change a relationship's type after creation, or list relationships by set or type.

Fix

Backend

  • New POST /api/batch/relationships/create:
    • Takes 1-100 items; each item succeeds or fails on its own (BatchResultWithIds).
    • Rejects an item with a clear error when its source and target are the same element, are in different sets, or an end is missing. Collection write-scope is checked per item.
  • source_role / target_role are stored as data.sourceRole / data.targetRole, the convention the Sparx importer and canvas already use. Every relationship response now also returns source_role and target_role.
  • PUT /api/relationships/{id} can change relationship_type and accepts role fields.
  • GET /api/relationships gains set_id and relationship_type filters.
  • Diagram-edge auto-create now honours data.relationshipId. An edge naming a live relationship between the same two elements, in either direction, doesn't create a duplicate.
  • The self-reference and cross-set check applies only to the batch path, which MCP and CLI use. The canvas's single POST, the importers and edge auto-create still allow reflexive relationships (canvas self-loops, Sparx reflexive associations; UML permits them). This trade-off is recorded in ADR-249.
  • No backend relationship-type registry exists, so types are not validated against notations; the reason is recorded in ADR-249.

Shared client, MCP and CLI

  • IrisClient gains create_relationships, list_relationships, get_relationship, update_relationship and delete_relationship. The update reads the current version for If-Match and applies a partial merge.
  • New MCP tools: create_relationships, update_relationship, list_relationships, get_relationship, delete_relationship.
  • New CLI commands: iris create relationship|relationships, iris update relationship, iris delete relationship, iris relationships list|get.
  • The MCP server instructions (seed and fallback) point agents at the new tools. They also say list_relationships / get_relationship need sign-in, because the REST reads require auth, unlike element reads.

Surface parity

  • scripts/check_surface_parity.py now enforces relationship.
  • It attributes /api/batch/<entities>/<verb> routes, and plural tool/command names, to their entity.

Tests

  • Backend, full suite (pytest --ignore=tests/test_startup.py): 15 failed, 2076 passed, 9 skipped.
    • All 15 failures also occur on main and are unrelated to this change: 6 in test_entity_indexing::TestElementCrudIndexing, 5 in test_rebuild::TestRebuildSearchIndex, test_convert_raises_for_non_jet4, test_import_accepts_eap_extension, and 2 in test_mnemos.
    • Targeted run of tests/test_relationships, test_batch, test_scripts and test_diagrams: 370 passed.
    • These include the new tests: an edge drawn target -> source reusing a relationship id creates no duplicate (seen failing first, 2 == 1), and a relationshipId belonging to other elements doesn't suppress the create.
  • iris-client: 66 passed.
  • MCP: 275 passed, 3 failed. All 3 fail the same way on main:
    • test_create_element_schema_requires_type_and_name and test_create_element_template_required_fields expect contradictory things.
    • test_info_includes_package_version fails because the package isn't installed as a distribution.
  • CLI: 65 passed. This includes an end-to-end run of the MCP tools against a real backend: batch create with rejections, list, update, reusing an id as an update_diagram edge, and delete.
  • Surface parity: scripts/check_surface_parity.py reports "Parity clean".
  • The MCP and CLI suites were run in a scratch Python 3.14 venv with PYTHONPATH pointing at the branch sources, because the checked-in mcp/cli venvs point at a Python 3.12 that is no longer installed.

Rollout / merge notes

  • Version 6.50.0 in backend, frontend, iris-client and iris-mcp; the CLI stays at 0.2.0, as in earlier feature releases.
  • No schema change and no migration.
  • The branch is based on main after fix(v6.49.2): PATs 500 on Supabase deployments (ADR-247) #297 (v6.49.2), so it merges cleanly today.
  • If the parallel ADR-248 fix (v6.49.3) merges first, CHANGELOG and the version bumps need a trivial rebase.
  • MCP server instructions are re-seeded on backend startup (ADR-177).

ADR / Spec

  • docs/adrs/ADR-249-Relationship-Tools-For-Agents.md
  • docs/adrs/specs/SPEC-249-A-Relationship-Tools-For-Agents.md

Follow-up: the issue's "nice to have" helper that adds nodes/edges to a diagram without resending the whole canvas. It is listed in ADR-249 as out of scope.

Closes #298

🤖 Generated with Claude Code

https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9

Chris Barlow and others added 2 commits September 23, 2026 22:48
Agents could create elements but not connect them: the MCP server and
CLI had no relationship tools, so new elements showed no relationships,
diagram edges couldn't carry a real relationshipId, and imported roles
couldn't be corrected.

Backend
- POST /api/batch/relationships/create (1-100 items, per-item failure
  isolation, BatchResultWithIds). Each item is validated by
  validate_new_relationship (endpoints exist, not self-referencing, same
  set) and checked against collection write-scope via its source element.
- source_role / target_role map to data.sourceRole / data.targetRole (the
  Sparx importer and canvas convention) via apply_role_fields; every
  relationship response now returns derived source_role / target_role.
- PUT /api/relationships/{id}: relationship_type updatable (omit keeps;
  change recorded in change_summary), role fields merge into data.
- GET /api/relationships: set_id (either end) + relationship_type filters.
- The validation is on the agent (batch) path only: create_relationship
  and the single POST keep accepting reflexive relationships, which the
  canvas self-loop, Sparx reflexive associations and edge auto-create rely
  on. No relationship-type registry exists in the backend, so types are
  not validated against notations (recorded in ADR-249).

Shared client / MCP / CLI
- IrisClient: create_relationships, list_relationships, get_relationship,
  update_relationship (reads version for If-Match, partial merge, role
  keys carry over), delete_relationship.
- MCP tools: create_relationships, update_relationship,
  list_relationships, get_relationship, delete_relationship; server
  instructions (seed + fallback) point agents at them.
- CLI: iris create relationship|relationships, iris update relationship,
  iris delete relationship, iris relationships list|get.
- check_surface_parity.py: relationship is a known entity; batch routes
  and plural batch tool/command names are attributed to their entity.

Tests (written first): backend agent-surface suite (batch create, roles,
self/cross-set/missing rejections, scope, type update, list filters,
diagram edge relationshipId reuse without duplicates, single POST
unchanged), parity-script tests, iris-client/MCP/CLI unit tests, and an
end-to-end MCP lifecycle test against a real backend.

Docs: ADR-249, SPEC-249-A, CHANGELOG, README, docs/api.md, docs/mcp.md,
docs/cli.md, mcp + cli READMEs. Version 6.50.0 (backend, frontend,
iris-client, iris-mcp).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9
…ship reads need sign-in (ADR-249, #298)

Review follow-ups on the relationship tools.

Root cause 1: the diagram-edge auto-create ignored edge
data.relationshipId and only deduped on a same-direction source/target
pair. An agent reusing a create_relationships id on an edge drawn
target -> source got a reversed duplicate relationship on save.
Fix: before the pair dedup, skip an edge whose data.relationshipId names a
live relationship linking the same two elements in either direction. A
relationshipId for other elements (stale/copied edge) is ignored. The
create_relationships description now states the edge direction.

Root cause 2: GET /api/relationships[/{id}] require auth, but the MCP
server instructions (seed + fallback) said every get_*/list_* works
without sign-in, so an anonymous agent following the new workflow failed
at list_relationships. Fix: the AUTH RECOVERY text and the
list_relationships / get_relationship descriptions say they need sign-in.
Opening the routes to anonymous callers is recorded as a rejected option
in ADR-249 (changes a pre-existing access contract).

Tests (written first, reversed-edge test seen failing 2 == 1): reversed
edge reuse creates no duplicate; foreign relationshipId doesn't suppress
the create; seed/fallback instructions and tool descriptions mention
sign-in and edge direction.

Docs: ADR-249, SPEC-249-A, CHANGELOG [6.50.0], mcp/README.md.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9
@cgbarlow
cgbarlow merged commit 4f52153 into main Sep 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: add tools to create, update and list relationships

1 participant