Skip to main content
Glama

create_relationship

Create relational links between Directus collections—m2o, o2o, o2m, m2m junction, or m2a—while generating the foreign keys and constraints those relationships require.

Instructions

Creates a relationship between collections together with the schema it needs: a m2o or o2o foreign key, an o2m reverse field, a m2m junction collection, or a m2a any-collection link. Use create_field for a plain non-relational column and analyze_relationships to see what already exists. Which parameters are required depends on type: m2m needs junction_collection and both junction fields, m2a needs allowed_collections and collection_field. Creates real tables and constraints and does not roll back when a later step fails, so a half-created m2m may need manual cleanup. on_delete and on_update set the referential actions, where CASCADE means deleting a parent deletes its children.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "type": "<type>",
      "collection": "<collection>",
      "field": "<field>"
    },
    "name": "create_relationship"
  }
}

Input Schema

NameRequiredDescriptionDefault
typeYesRelationship type
fieldYesSource field
on_deleteNoOn delete action
on_updateNoOn update action
collectionYesSource collection
sort_fieldNoSort field
related_fieldNoTarget field
junction_fieldNoJunction field (M2M only)
collection_fieldNoCollection field (M2A only)
primary_key_fieldNoPrimary key field (M2A only)
related_collectionNoTarget collection
allowed_collectionsNoAllowed collections (M2A only)
junction_collectionNoJunction collection (M2M only)
related_junction_fieldNoRelated junction field (M2M only)

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv12.3.3

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=false and openWorldHint=true, so the write/non-rollback nature is partly inferable, but the description adds the crucial fact that it "Creates real tables and constraints and does not roll back when a later step fails, so a half-created m2m may need manual cleanup" — a real operational hazard not in the annotations. It also documents that on_delete/on_update CASCADE means deleting a parent deletes children. It stops short of mentioning required permissions or what the response looks like, which keeps it off a 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose, then alternatives, then per-type requirements, then the transactional caveat, then referential-action semantics — a sensible order with no filler sentences. It is a dense block that could be split or tightened slightly, but every sentence carries information an agent needs.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 14-parameter mutation with no output schema, this covers the hard parts: type-specific required params, the non-atomic failure mode, and referential action meaning. The remaining gap is per-type required parameters beyond m2m/m2a — notably that m2o/o2o need a target collection/field — which an agent could still get wrong on the first attempt.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline would be 3, but the description adds conditional-requirement logic the schema does not encode: the required set varies by type, and only 3 params are globally required, so an agent would otherwise submit incomplete m2m/m2a calls. It also gives semantic meaning to the enum behavior (CASCADE cascades deletes to children). It does not spell out which target-side params m2o/o2o need (related_collection, related_field), leaving one gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ("Creates a relationship between collections together with the schema it needs") and then enumerates exactly which shapes that covers: m2o/o2o foreign key, o2m reverse field, m2m junction collection, m2a any-collection link. This is far more than the name alone and lets an agent distinguish it from create_field and analyze_relationships by behavior rather than guessing.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly routes the agent: "Use create_field for a plain non-relational column and analyze_relationships to see what already exists." Both the alternative and the condition selecting it are named. It also gives per-type prerequisites (m2m needs junction_collection and both junction fields; m2a needs allowed_collections and collection_field), which is the when-to-use detail that actually prevents bad calls.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.