{"openapi":"3.1.0","info":{"title":"macgram","version":"1","description":"Cloud documents of macgram. Signed in: a Logto access token or an API token (`mg_…`) as Bearer. Live editing: GET /documents/{id}/live (WebSocket) or /documents/{id}/poll; AI tools: POST /mcp (MCP, streamable HTTP), or the same tools under /documents/{id}/tools. The protocols and rules: docs/API.md."},"tags":[{"name":"Documents"},{"name":"Document tools"},{"name":"Live editing"},{"name":"MCP"},{"name":"Account"},{"name":"Friends"},{"name":"Server"}],"servers":[{"url":"https://api.macgram.app"}],"components":{"schemas":{"Plan":{"enum":["free","pro"]},"Me":{"type":"object","properties":{"id":{"type":"integer"},"email":{"type":["string","null"]},"username":{"type":["string","null"]},"name":{"type":["string","null"]},"avatarUrl":{"type":["string","null"],"description":"Logto avatar, or the email’s Gravatar (?d=404&s=160)"},"plan":{"$ref":"#/components/schemas/Plan"},"planExpiresAt":{"type":["string","null"],"format":"date-time","description":"null: no end"},"roles":{"type":"array","items":{"type":"string"},"description":"Lower case: admin, tester…"},"publicProfile":{"type":"boolean"},"theme":{"type":["string","null"],"description":"\"rose\"… or \"#rrggbb\"; null: default"},"font":{"type":["string","null"],"description":"\"inter\"…; null: default"}},"required":["id","email","username","name","avatarUrl","plan","planExpiresAt","roles","publicProfile","theme","font"]},"PublicUser":{"description":"A profile seen by others; private, the username only","oneOf":[{"type":"object","properties":{"username":{"type":["string","null"]},"private":{"const":true}},"required":["username","private"]},{"type":"object","properties":{"username":{"type":["string","null"]},"name":{"type":["string","null"]},"avatarUrl":{"type":["string","null"]},"plan":{"$ref":"#/components/schemas/Plan"},"roles":{"type":"array","items":{"type":"string"}},"createdAt":{"type":"string","format":"date-time"}},"required":["username","name","avatarUrl","plan","roles","createdAt"]}]},"Limits":{"type":"object","description":"null: unlimited","properties":{"documents":{"type":["integer","null"]},"documentSize":{"type":["integer","null"]},"friends":{"type":["integer","null"]},"versions":{"type":["integer","null"]},"reports":{"type":["integer","null"]},"themes":{"type":["integer","null"]},"grid":{"type":["integer","null"]},"noWatermark":{"type":["integer","null"]}}},"Plans":{"type":"object","properties":{"free":{"$ref":"#/components/schemas/Limits"},"pro":{"$ref":"#/components/schemas/Limits"}}},"Token":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"scope":{"enum":["read","write"]},"documentId":{"type":["string","null"],"description":"The only document it opens"},"createdAt":{"type":"string","format":"date-time"},"expiresAt":{"type":["string","null"],"format":"date-time","description":"null: never"},"lastUsedAt":{"type":["string","null"],"format":"date-time","description":"To the minute"}},"required":["id","name","scope","documentId","createdAt","expiresAt","lastUsedAt"]},"DocumentSummary":{"type":"object","properties":{"id":{"type":"string","description":"UUID, in the editor’s URL (/editor/<id>)"},"name":{"type":"string"},"updatedAt":{"type":"string","format":"date-time"}},"required":["id","name","updatedAt"]},"DocumentList":{"type":"object","properties":{"documents":{"type":"array","items":{"$ref":"#/components/schemas/DocumentSummary"},"description":"Own ones, last changed first"},"limit":{"type":["integer","null"],"description":"The `documents` limit"},"shared":{"type":"array","items":{"allOf":[{"$ref":"#/components/schemas/DocumentSummary"},{"type":"object","properties":{"owner":{"$ref":"#/components/schemas/PublicUser"}},"required":["owner"]}]},"description":"Shared with the user"}},"required":["documents","limit","shared"]},"DocumentRef":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"}},"required":["id","name"]},"Members":{"type":"object","properties":{"members":{"type":"array","items":{"type":"string"},"description":"Usernames, oldest first"},"readers":{"type":"array","items":{"type":"string"},"description":"Those of members read-only"},"publicLink":{"type":"boolean"},"publicEdit":{"type":"boolean"}},"required":["members","readers","publicLink","publicEdit"]},"VersionList":{"type":"object","properties":{"versions":{"type":"array","items":{"type":"object","properties":{"id":{"type":"integer"},"manual":{"type":"boolean","description":"Made by hand: never deleted automatically"},"name":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","manual","name","createdAt"]},"description":"Last first"},"limit":{"type":["integer","null"],"description":"The owner’s `versions` limit"}},"required":["versions","limit"]},"Version":{"type":"object","properties":{"id":{"type":"integer"},"content":{"type":"string","description":"Document.encode() of macgram_core"}},"required":["id","content"]},"Friends":{"type":"object","properties":{"friends":{"type":"array","items":{"$ref":"#/components/schemas/PublicUser"}},"incoming":{"type":"array","items":{"$ref":"#/components/schemas/PublicUser"},"description":"Requests received"},"outgoing":{"type":"array","items":{"$ref":"#/components/schemas/PublicUser"},"description":"Requests sent"},"limit":{"type":["integer","null"],"description":"The `friends` limit"}},"required":["friends","incoming","outgoing","limit"]},"AdminStats":{"type":"object","description":"users, documents, versions, friends, usage: counts; days: the 30 last, oldest first; top: the 5 largest owners; live: open now. No email nor document name."}},"securitySchemes":{"bearer":{"type":"http","scheme":"bearer"}}},"security":[{"bearer":[]}],"paths":{"/health":{"parameters":[],"get":{"tags":["Server"],"summary":"Up","security":[],"responses":{"200":{"description":"OK"}}}},"/plans":{"parameters":[],"get":{"tags":["Server"],"summary":"The plans and their limits","security":[],"responses":{"200":{"description":"By plan","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Plans"}}}}}}},"/openapi.json":{"parameters":[],"get":{"tags":["Server"],"summary":"This description","security":[],"responses":{"200":{"description":"OK"}}}},"/docs":{"parameters":[],"get":{"tags":["Server"],"summary":"This description, to read and try","security":[],"responses":{"200":{"description":"OK"}}}},"/documents":{"parameters":[],"get":{"tags":["Documents"],"summary":"Own documents and those shared with the user","description":"Without their content.","responses":{"200":{"description":"The documents","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DocumentList"}}}}}},"post":{"tags":["Documents"],"summary":"Creates a document","description":"The content, if any, is decoded then encoded again (normalised).","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":200},"content":{"type":"string","description":"Document.encode() of macgram_core; none: empty"}},"required":["name"]}}}},"responses":{"201":{"description":"Made","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DocumentRef"}}}},"400":{"description":"`not JSON`, `name`, `content` (not a document)"},"403":{"description":"`quota`: the `documents` limit reached"},"413":{"description":"Over the `documentSize` limit"}}}},"/documents/{id}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"patch":{"tags":["Documents"],"summary":"Renames it (owner)","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":200}},"required":["name"]}}}},"responses":{"200":{"description":"Renamed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DocumentRef"}}}},"400":{"description":"`not JSON`, `name`"},"404":{"description":"Not found, or not the owner"}}},"delete":{"tags":["Documents"],"summary":"Deletes it (owner)","description":"Its live connections close (4404); its versions and members go with it.","responses":{"204":{"description":"OK"},"404":{"description":"Not found, or not the owner"}}}},"/documents/{id}/members":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"get":{"tags":["Documents"],"summary":"Who it is shared with (owner)","responses":{"200":{"description":"Its members and link","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Members"}}}},"404":{"description":"Not found, or not the owner"}}},"put":{"tags":["Documents"],"summary":"Shares it with friends (owner)","description":"Replaces the whole list: those taken off are cut at once (4403), the others get their new access live. Answers what was sent.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"members":{"type":"array","items":{"type":"string"},"description":"Usernames, friends all"},"readers":{"type":"array","items":{"type":"string"},"description":"Those of members read-only; none: unchanged"}},"required":["members"]}}}},"responses":{"200":{"description":"Done"},"400":{"description":"`not JSON`, `not a friend` (unknown, or no friend of the owner)"},"404":{"description":"Not found, or not the owner"}}}},"/documents/{id}/link":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"put":{"tags":["Documents"],"summary":"Its public link (owner)","description":"Turned off, those who came by the link are cut; the others get their new access live. Answers what was sent.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"enabled":{"type":"boolean"},"edit":{"type":"boolean","description":"Signed-in users may edit; none: unchanged"}},"required":["enabled"]}}}},"responses":{"200":{"description":"Done"},"400":{"description":"`not JSON`, `enabled`, `edit`"},"404":{"description":"Not found, or not the owner"}}}},"/documents/{id}/versions":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"get":{"tags":["Documents"],"summary":"Its versions (owner, member)","responses":{"200":{"description":"Its versions","content":{"application/json":{"schema":{"$ref":"#/components/schemas/VersionList"}}}},"404":{"description":"Not found"}}},"post":{"tags":["Documents"],"summary":"Keeps a version of it (owner)","description":"A manual one, of the current content (the one in memory when open). Past the `versions` limit, the oldest automatic ones go, never a manual one.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"}},"required":[]}}}},"responses":{"201":{"description":"Kept"},"400":{"description":"`not JSON`, `name`"},"403":{"description":"`quota`: only manual versions left to delete"},"404":{"description":"Not found, or not the owner"}}}},"/documents/{id}/versions/{vid}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"vid","in":"path","required":true,"schema":{"type":"string"}}],"get":{"tags":["Documents"],"summary":"A version, with its content (owner, member)","description":"No restore route: the client applies it as an ordinary live patch.","responses":{"200":{"description":"The version","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Version"}}}},"404":{"description":"`no such version`, or not found"}}},"delete":{"tags":["Documents"],"summary":"Deletes a version (owner)","responses":{"204":{"description":"OK"},"404":{"description":"`no such version`, or not found"}}}},"/documents/{id}/live":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"get":{"tags":["Live editing"],"summary":"Live editing over a WebSocket","description":"The token comes in the first message, not in a header. The messages both ways and the closing codes: docs/API.md, Live editing.","security":[],"responses":{"101":{"description":"Switching to the WebSocket"}}}},"/documents/{id}/tools/get_schema":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"get_schema","description":"The whole document as JSON: the MCD diagram (entities, associations with their legs and cardinalities, enums, notes, arrows, the position of every box) and the analysis (user stories, actors, modules). Ids start with e- (entity), a- (association), t- (enum), m- (enum copy on the canvas), n- (note), r- (arrow), s- (user story), p- (actor), g- (module), u- (use case), c- (constraint), h- (inheritance).\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"get_schema","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{},"required":[]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/get_mld":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"get_mld","description":"The relational model (tables, primary and foreign keys) derived from the diagram: `_x_` is a primary key, `#x` a foreign key.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"get_mld","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{},"required":[]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/get_sql":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"get_sql","description":"The SQL script creating the tables of the relational model, in a dialect (postgres by default), or its Prisma schema (prisma).\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"get_sql","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"dialect":{"type":"string","enum":["postgres","mysql","sqlite","sqlserver","prisma"]}},"required":[]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_entity":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_entity","description":"Adds an entity and returns its id. Without attributes it gets an `id` identifier.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_entity","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"attributes":{"type":"array","description":"Replaces the whole list. A type is one of string, text, int, decimal, bool, date, datetime, uuid, json, string and decimal taking a size, as string(80) or decimal(10,2), the name of an existing enum, or \"a|b|c\" to create an enum with these values.","items":{"type":"object","properties":{"name":{"type":"string"},"type":{"type":"string"},"id":{"type":"boolean","description":"Part of the identifier (primary key)."},"nullable":{"type":"boolean"},"unique":{"type":"boolean"},"auto":{"type":"boolean","description":"The database generates it: auto-increment (int) or uuid. Only on the single identifier of an entity."},"default":{"type":"string","description":"Default value: a literal (0, draft, true, an enum value), now() or uuid()."},"column":{"type":"string","description":"Column name in the database, if not the attribute's."},"check":{"type":"string","description":"Check constraint, an SQL expression (price >= 0)."},"comment":{"type":"string","description":"What the attribute is; also the column's comment."},"index":{"type":"boolean","description":"The column has an index."}},"required":["name"]}},"x":{"type":"integer","description":"Optional. Left edge, in pixels."},"y":{"type":"integer","description":"Optional. Top edge, in pixels."}},"required":["name"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_association":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_association","description":"Adds an association between entities, or towards an association (an aggregation), and returns its id. It is placed between its ends.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_association","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"ends":{"type":"array","minItems":2,"description":"What the association links: entities, enum copies, or associations (an aggregation: never in a cycle, the foreign key takes that association's key). Twice the same entity makes it reflexive.","items":{"type":"object","properties":{"id":{"type":"string"},"card":{"enum":["0,1","1,1","0,n","1,n"],"description":"How many times one of these takes part in the association. Default 0,n."},"relative":{"type":"boolean","description":"This entity is weak, identified through the association."},"role":{"type":"string","description":"The part this entity plays, shown on the link and naming the foreign key towards it (manager gives manager_id). Tells the ends of a reflexive association apart."},"onDelete":{"enum":["cascade","setNull","restrict","noAction"],"description":"Foreign key action towards this end's entity."},"onUpdate":{"enum":["cascade","setNull","restrict","noAction"],"description":"Foreign key action towards this end's entity."},"column":{"type":"string","description":"Names of the foreign key columns towards this end, comma separated, if not the derived ones."}},"required":["id"]}},"attributes":{"type":"array","description":"Replaces the whole list. A type is one of string, text, int, decimal, bool, date, datetime, uuid, json, string and decimal taking a size, as string(80) or decimal(10,2), the name of an existing enum, or \"a|b|c\" to create an enum with these values.","items":{"type":"object","properties":{"name":{"type":"string"},"type":{"type":"string"},"id":{"type":"boolean","description":"Part of the identifier (primary key)."},"nullable":{"type":"boolean"},"unique":{"type":"boolean"},"auto":{"type":"boolean","description":"The database generates it: auto-increment (int) or uuid. Only on the single identifier of an entity."},"default":{"type":"string","description":"Default value: a literal (0, draft, true, an enum value), now() or uuid()."},"column":{"type":"string","description":"Column name in the database, if not the attribute's."},"check":{"type":"string","description":"Check constraint, an SQL expression (price >= 0)."},"comment":{"type":"string","description":"What the attribute is; also the column's comment."},"index":{"type":"boolean","description":"The column has an index."}},"required":["name"]}}},"required":["ends"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_enum":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_enum","description":"Adds an enum and returns its id. An attribute uses it by taking its name as type. With `place`, a copy is also put on the canvas, which an association can then link like an entity.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_enum","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"values":{"type":"array","items":{"type":"string"},"minItems":1},"place":{"type":"boolean"},"x":{"type":"integer","description":"Optional. Left edge, in pixels."},"y":{"type":"integer","description":"Optional. Top edge, in pixels."}},"required":["name","values"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_constraint":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_constraint","description":"Adds a constraint between associations through a pivot, or a CIF on the legs of one association (drawn on the MCD; a CHECK or a comment in the SQL) and returns its id.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_constraint","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"kind":{"enum":["X","T","XT","S","I","1","CIF"],"description":"X exclusion (never together), T totality (at least one), XT partition (exactly one), S simultaneity (all or none), I inclusion (the source only where the target is), 1 uniqueness, CIF functional integrity (source legs determine the target leg, which leaves the key of the association table)."},"members":{"type":"array","description":"Replaces the members: associations, and at most one pivot, an entity or a leg (leg:<association>:<leg id or index>) with the role pivot. For I, one association has the role source and one the role target. For CIF: only legs (leg:<association>:<leg id or index>) of one association, sources and one target.","items":{"type":"object","properties":{"id":{"type":"string"},"role":{"enum":["source","target","pivot"]}},"required":["id"]}},"x":{"type":"integer","description":"Optional. Left edge, in pixels."},"y":{"type":"integer","description":"Optional. Top edge, in pixels."}},"required":["kind","members"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_inheritance":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_inheritance","description":"Adds an inheritance: sub-types of a super-type, drawn as a triangle between them, and returns its id. The sub-types lose their own identifier for the one they inherit.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_inheritance","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"kind":{"enum":["","X","T","XT"],"description":"Empty for none, X exclusion (at most one sub-type), T totality (at least one), XT partition (exactly one)."},"parent":{"type":"string","description":"The super-type: an entity."},"children":{"type":"array","items":{"type":"string"},"description":"Replaces the sub-types: entities. Each has at most one super-type, no cycle. They inherit the identifier and lose their own."},"strategy":{"enum":["table","down","up"],"description":"How it becomes tables: table (one per entity, the sub-type key a foreign key; default), down (sub-types only, super-type attributes copied), up (one table, sub-type attributes nullable)."},"discriminator":{"type":"string","description":"With strategy up: name of a column telling the sub-types apart. Empty for none."},"x":{"type":"integer","description":"Optional. Left edge, in pixels."},"y":{"type":"integer","description":"Optional. Top edge, in pixels."}},"required":["parent","children"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_note":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_note","description":"Adds a free text note on the canvas and returns its id.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_note","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"x":{"type":"integer","description":"Optional. Left edge, in pixels."},"y":{"type":"integer","description":"Optional. Top edge, in pixels."}},"required":["text"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_arrow":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_arrow","description":"Adds an annotation arrow between two boxes (it has no meaning in the model; a note pointing at an entity, for instance).\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_arrow","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"from":{"type":"string"},"to":{"type":"string"},"label":{"type":"string"}},"required":["from","to"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_story":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_story","description":"Adds a user story and returns its id; its code (USnn) follows the others. Actors and modules are given by name.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_story","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"title":{"type":"string"},"code":{"type":"string","description":"USnn; given on creation."},"priority":{"enum":["high","medium","low","none"]},"status":{"enum":["todo","doing","done","blocked"],"description":"Where its development is."},"estimate":{"type":"string","description":"Time it takes, free text: \"2 h\", \"3 days\"…"},"module":{"type":"string","description":"Name of its module; created if no module has it."},"actor":{"type":"string","description":"The actor of the need (\"As a …\"): a name, created if no actor has it."},"other_actors":{"type":"array","items":{"type":"string"},"description":"Replaces the other actors: names, created if missing."},"use_case":{"type":"string","description":"Its use case, by id or name (see add_use_case); none removes it."},"want":{"type":"string","description":"The need: \"I want …\"."},"so_that":{"type":"string","description":"The need: \"so that …\"."},"details":{"type":"string"},"pre":{"type":"string","description":"Preconditions."},"post":{"type":"string","description":"Postconditions."},"nominal":{"type":"array","items":{"type":"array","items":{"type":"string"},"minItems":2,"maxItems":2},"description":"Replaces the main scenario: steps as [what the user does, what the system does]; either may be empty."},"alternatives":{"type":"array","items":{"type":"string"},"description":"Replaces the alternative scenarios."},"tests":{"type":"array","items":{"type":"array","items":{"type":"string"},"minItems":2,"maxItems":2},"description":"Replaces the tests: [test, expected result]."}},"required":["title"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/add_use_case":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"add_use_case","description":"Adds a use case and returns its id. Its module and actors are given by name, created if missing; a story is linked to it with the use_case field of the story.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"add_use_case","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"module":{"type":"string","description":"Name of its module, created if missing; none removes it."},"actors":{"type":"array","items":{"type":"string"},"description":"Replaces its actors: names, created if missing."},"includes":{"type":"array","items":{"type":"string"},"description":"Replaces the use cases it includes: ids or names."},"extends":{"type":"array","items":{"type":"string"},"description":"Replaces the use cases it extends: ids or names."},"links":{"type":"array","items":{"type":"string"},"description":"Replaces the entities and associations it works with: ids or names."}},"required":["name"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/update":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"update","description":"Changes an element; only the given fields change. An entity takes name, attributes, uniques, mark; an association name, attributes, ends, mark; an enum name, values; a note text; an arrow label; a constraint kind, members; an inheritance parent, children, kind, strategy, discriminator. Entities and associations also take the database settings of their table: table, comment. A user story takes the fields of add_story; a use case those of add_use_case; an actor name, system, parent, links; a module name, links.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"update","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"attributes":{"type":"array","description":"Replaces the whole list. A type is one of string, text, int, decimal, bool, date, datetime, uuid, json, string and decimal taking a size, as string(80) or decimal(10,2), the name of an existing enum, or \"a|b|c\" to create an enum with these values.","items":{"type":"object","properties":{"name":{"type":"string"},"type":{"type":"string"},"id":{"type":"boolean","description":"Part of the identifier (primary key)."},"nullable":{"type":"boolean"},"unique":{"type":"boolean"},"auto":{"type":"boolean","description":"The database generates it: auto-increment (int) or uuid. Only on the single identifier of an entity."},"default":{"type":"string","description":"Default value: a literal (0, draft, true, an enum value), now() or uuid()."},"column":{"type":"string","description":"Column name in the database, if not the attribute's."},"check":{"type":"string","description":"Check constraint, an SQL expression (price >= 0)."},"comment":{"type":"string","description":"What the attribute is; also the column's comment."},"index":{"type":"boolean","description":"The column has an index."}},"required":["name"]}},"uniques":{"type":"array","description":"Replaces the alternate identifiers: groups of attribute names of the entity that are unique together.","items":{"type":"array","items":{"type":"string"},"minItems":1}},"ends":{"type":"array","minItems":2,"description":"What the association links: entities, enum copies, or associations (an aggregation: never in a cycle, the foreign key takes that association's key). Twice the same entity makes it reflexive.","items":{"type":"object","properties":{"id":{"type":"string"},"card":{"enum":["0,1","1,1","0,n","1,n"],"description":"How many times one of these takes part in the association. Default 0,n."},"relative":{"type":"boolean","description":"This entity is weak, identified through the association."},"role":{"type":"string","description":"The part this entity plays, shown on the link and naming the foreign key towards it (manager gives manager_id). Tells the ends of a reflexive association apart."},"onDelete":{"enum":["cascade","setNull","restrict","noAction"],"description":"Foreign key action towards this end's entity."},"onUpdate":{"enum":["cascade","setNull","restrict","noAction"],"description":"Foreign key action towards this end's entity."},"column":{"type":"string","description":"Names of the foreign key columns towards this end, comma separated, if not the derived ones."}},"required":["id"]}},"kind":{"enum":["X","T","XT","S","I","1","CIF",""],"description":"X exclusion (never together), T totality (at least one), XT partition (exactly one), S simultaneity (all or none), I inclusion (the source only where the target is), 1 uniqueness, CIF functional integrity (source legs determine the target leg, which leaves the key of the association table). An inheritance takes empty, X, T or XT."},"members":{"type":"array","description":"Replaces the members: associations, and at most one pivot, an entity or a leg (leg:<association>:<leg id or index>) with the role pivot. For I, one association has the role source and one the role target. For CIF: only legs (leg:<association>:<leg id or index>) of one association, sources and one target.","items":{"type":"object","properties":{"id":{"type":"string"},"role":{"enum":["source","target","pivot"]}},"required":["id"]}},"parent":{"type":"string","description":"Name of the actor it specialises, created if missing; none removes it."},"children":{"type":"array","items":{"type":"string"},"description":"Replaces the sub-types: entities. Each has at most one super-type, no cycle. They inherit the identifier and lose their own."},"strategy":{"enum":["table","down","up"],"description":"How it becomes tables: table (one per entity, the sub-type key a foreign key; default), down (sub-types only, super-type attributes copied), up (one table, sub-type attributes nullable)."},"discriminator":{"type":"string","description":"With strategy up: name of a column telling the sub-types apart. Empty for none."},"values":{"type":"array","items":{"type":"string"}},"text":{"type":"string"},"label":{"type":"string"},"table":{"type":"string","description":"Table name in the database, if not the element's."},"comment":{"type":"string"},"title":{"type":"string"},"code":{"type":"string","description":"USnn; given on creation."},"priority":{"enum":["high","medium","low","none"]},"status":{"enum":["todo","doing","done","blocked"],"description":"Where its development is."},"estimate":{"type":"string","description":"Time it takes, free text: \"2 h\", \"3 days\"…"},"module":{"type":"string","description":"Name of its module, created if missing; none removes it."},"actor":{"type":"string","description":"The actor of the need (\"As a …\"): a name, created if no actor has it."},"other_actors":{"type":"array","items":{"type":"string"},"description":"Replaces the other actors: names, created if missing."},"use_case":{"type":"string","description":"Its use case, by id or name (see add_use_case); none removes it."},"want":{"type":"string","description":"The need: \"I want …\"."},"so_that":{"type":"string","description":"The need: \"so that …\"."},"details":{"type":"string"},"pre":{"type":"string","description":"Preconditions."},"post":{"type":"string","description":"Postconditions."},"nominal":{"type":"array","items":{"type":"array","items":{"type":"string"},"minItems":2,"maxItems":2},"description":"Replaces the main scenario: steps as [what the user does, what the system does]; either may be empty."},"alternatives":{"type":"array","items":{"type":"string"},"description":"Replaces the alternative scenarios."},"tests":{"type":"array","items":{"type":"array","items":{"type":"string"},"minItems":2,"maxItems":2},"description":"Replaces the tests: [test, expected result]."},"actors":{"type":"array","items":{"type":"string"},"description":"Replaces its actors: names, created if missing."},"includes":{"type":"array","items":{"type":"string"},"description":"Replaces the use cases it includes: ids or names."},"extends":{"type":"array","items":{"type":"string"},"description":"Replaces the use cases it extends: ids or names."},"links":{"type":"array","items":{"type":"string"},"description":"Replaces the entities and associations it works with: ids or names."},"system":{"type":"boolean","description":"Another system rather than a person: drawn as a box."},"mark":{"enum":["red","orange","yellow","green","blue","purple","none"],"description":"Colour that marks the entity or association, for the user to find it again in the Marked tab; none removes it."}},"required":["id"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/move":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"move","description":"Moves a box (entity, association, note, enum copy, actor or use case, constraint, inheritance). Positions snap to a 10px grid.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"move","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"},"x":{"type":"integer"},"y":{"type":"integer"}},"required":["id","x","y"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/documents/{id}/tools/delete":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Document tools"],"summary":"delete","description":"Deletes an element by id, with the links that hung on it.\n\nThrough the document’s live room, as `POST /mcp` does; the AI shows as \"API\".","operationId":"delete","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"}},"required":["id"]}}}},"responses":{"200":{"description":"Done: what it did, the element touched","content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string"},"id":{"type":["string","null"]}}}}}},"400":{"description":"Refused: the message says why"},"403":{"description":"Read-only access or token"},"404":{"description":"No such document"},"413":{"description":"Over the size limit"}}}},"/.well-known/oauth-protected-resource":{"parameters":[],"get":{"tags":["MCP"],"summary":"Where an MCP client gets a token (RFC 9728)","security":[],"responses":{"200":{"description":"OK"}}}},"/.well-known/oauth-protected-resource/mcp":{"parameters":[],"get":{"tags":["MCP"],"summary":"The same, for /mcp","security":[],"responses":{"200":{"description":"OK"}}}},"/mcp":{"parameters":[],"get":{"tags":["MCP"],"summary":"No server-sent stream","responses":{"405":{"description":"POST only"}}},"post":{"tags":["MCP"],"summary":"MCP over streamable HTTP (JSON-RPC)","description":"Answers on the POST, no server-sent stream. Methods: initialize, ping, tools/list, tools/call. Tools: list_documents (own and shared: id, name, updatedAt, owner), then every document tool with a `document` argument (its id). A tool error or refusal comes back as an `isError` result the AI reads.\n\n`initialize` answers `Mcp-Session-Id`: the client’s name (clientInfo.name, URL-encoded, 64 characters at most), sent back on each request, the name the others see the AI by; none: IA.\n\nEach call goes through the document’s live room, as one more participant: the access of the live connection, narrowed by the API token; tried on a copy (refused, nothing changes); the patch goes to all and into the undo history of the screen it touches; the AI shows as a cursor, then leaves 5 s after its last call; the room stays open 2 min after it.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object"}}}},"responses":{"200":{"description":"The JSON-RPC answer"},"202":{"description":"A notification taken"},"401":{"description":"No token: `WWW-Authenticate` points at /.well-known/oauth-protected-resource, which names Logto"}}}},"/documents/{id}/poll":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Live editing"],"summary":"Opens a live connection over plain HTTP: {session}","security":[],"responses":{"200":{"description":"OK"}}}},"/documents/{id}/poll/{session}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"session","in":"path","required":true,"schema":{"type":"string"}}],"get":{"tags":["Live editing"],"summary":"The messages for the client, or none after 25 s: {messages}","security":[],"responses":{"200":{"description":"OK"}}},"post":{"tags":["Live editing"],"summary":"Messages from the client, in order","security":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"array"}}}},"responses":{"200":{"description":"OK"}}},"delete":{"tags":["Live editing"],"summary":"The client leaves","security":[],"responses":{"204":{"description":"OK"}}}},"/me":{"parameters":[],"get":{"tags":["Account"],"summary":"The signed-in user, its plan and limits","description":"Roles read again from Logto on each call. Also `limits` (its own) and `friendRequests` (received, pending).","responses":{"200":{"description":"The user","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Me"}}}}}},"patch":{"tags":["Account"],"summary":"Changes its profile and settings","description":"A field left out does not change.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"publicProfile":{"type":"boolean"},"theme":{"type":["string","null"],"pattern":"^([a-z]{1,20}|#[0-9a-f]{6})$"},"font":{"type":["string","null"],"pattern":"^[a-z]{1,20}$"}},"required":[]}}}},"responses":{"200":{"description":"The user, without limits nor friendRequests","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Me"}}}},"400":{"description":"`not JSON`, `publicProfile`, `theme`, `font`, `nothing to change`"},"403":{"description":"`themes`: a theme or font with the `themes` limit at 0"}}},"delete":{"tags":["Account"],"summary":"Deletes the account (Logto session only)","description":"Its Logto account first (failing, all stays), then its open documents close (4404), then the row: documents, friendships and sharing go with it.","responses":{"204":{"description":"OK"},"401":{"description":"`invalid token`, or an API token"},"503":{"description":"`deletion off`: no M2M app"}}}},"/users/{username}":{"parameters":[{"name":"username","in":"path","required":true,"schema":{"type":"string"}}],"get":{"tags":["Account"],"summary":"A public profile","description":"One’s own, always whole, private or not.","responses":{"200":{"description":"The profile","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PublicUser"}}}},"404":{"description":"`no such user`"}}}},"/friends":{"parameters":[],"get":{"tags":["Friends"],"summary":"Friends and requests","responses":{"200":{"description":"Friends, requests both ways, the limit","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Friends"}}}}}}},"/friends/{username}":{"parameters":[{"name":"username","in":"path","required":true,"schema":{"type":"string"}}],"post":{"tags":["Friends"],"summary":"Sends or accepts a friend request","description":"The exact username: there is no search. A request crossing one received accepts it. Sent, it counts against the `friends` limit (friends and requests sent); accepted, against both sides’ friends.","responses":{"200":{"description":"`{relation}`: `outgoing` or `friends`"},"400":{"description":"`yourself`"},"403":{"description":"`friends` (own limit), `their friends` (theirs, on accepting)"},"404":{"description":"`no such user`"}}},"delete":{"tags":["Friends"],"summary":"Unfriends, cancels or declines","description":"Also ends the sharing of documents between the two, both ways, and cuts their live connections to them (4403).","responses":{"204":{"description":"OK"},"404":{"description":"`no such user`"}}}},"/reports":{"parameters":[],"post":{"tags":["Server"],"summary":"Reports a bug or an idea","description":"Opens a GitHub issue, labelled `report` and by type (bug, enhancement, question); its body ends with who, the changelog credit, the version and platform.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"title":{"type":"string","minLength":1,"maxLength":200},"text":{"type":"string","minLength":1,"maxLength":10000},"type":{"enum":["bug","suggestion","question","other"]},"credit":{"type":"boolean","description":"May be credited in the changelog"},"version":{"type":"string","maxLength":40},"platform":{"type":"string","maxLength":40}},"required":["title","text","type"]}}}},"responses":{"201":{"description":"`{number}`: the issue"},"400":{"description":"`title, type or text`"},"429":{"description":"`reports`: the daily limit (UTC)"},"503":{"description":"`reports off`: no GITHUB_TOKEN"}}}},"/admin/stats":{"parameters":[],"get":{"tags":["Server"],"summary":"Figures (admins, Logto session only)","description":"Roles read again from Logto on each call: a role taken back cuts access at once.","responses":{"200":{"description":"The figures","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdminStats"}}}},"403":{"description":"`admins only`, `session only`"}}}},"/me/tokens":{"parameters":[],"get":{"tags":["Account"],"summary":"Its API tokens, never their secret","description":"Newest first.","responses":{"200":{"description":"`{tokens}`","content":{"application/json":{"schema":{"type":"object","properties":{"tokens":{"type":"array","items":{"$ref":"#/components/schemas/Token"}}}}}}}}},"post":{"tags":["Account"],"summary":"Makes an API token (Logto session only)","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":100},"scope":{"enum":["read","write"]},"days":{"type":"integer","minimum":1,"maximum":3650,"description":"None: never ends"},"documentId":{"type":"string","description":"A document owned or shared: the only one it opens"}},"required":["name","scope"]}}}},"responses":{"201":{"description":"The token, with its `secret` (`mg_…`), shown this once","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Token"}}}},"400":{"description":"`not JSON`, `name`, `scope`, `days`, `documentId`"},"403":{"description":"`session only`: called with an API token"}}}},"/me/tokens/{id}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"delete":{"tags":["Account"],"summary":"Revokes an API token (Logto session only)","description":"At once.","responses":{"204":{"description":"OK"},"403":{"description":"`session only`"},"404":{"description":"`no such token`"}}}}}}