callman-mcp 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/CHANGELOG.md +36 -59
  2. package/README.md +18 -24
  3. package/dist/client/api.d.ts +18 -40
  4. package/dist/client/api.d.ts.map +1 -1
  5. package/dist/client/api.js +7 -54
  6. package/dist/client/api.js.map +1 -1
  7. package/dist/client/types.d.ts +19 -44
  8. package/dist/client/types.d.ts.map +1 -1
  9. package/dist/config.d.ts +4 -0
  10. package/dist/config.d.ts.map +1 -1
  11. package/dist/config.js +5 -0
  12. package/dist/config.js.map +1 -1
  13. package/dist/domain/diagram/build.d.ts +17 -17
  14. package/dist/domain/diagram/build.d.ts.map +1 -1
  15. package/dist/domain/diagram/build.js +3 -3
  16. package/dist/domain/diagram/build.js.map +1 -1
  17. package/dist/domain/diagram/layout.d.ts +1 -3
  18. package/dist/domain/diagram/layout.d.ts.map +1 -1
  19. package/dist/domain/diagram/layout.js +3 -9
  20. package/dist/domain/diagram/layout.js.map +1 -1
  21. package/dist/domain/diagram/patch.d.ts +22 -723
  22. package/dist/domain/diagram/patch.d.ts.map +1 -1
  23. package/dist/domain/diagram/patch.js +0 -53
  24. package/dist/domain/diagram/patch.js.map +1 -1
  25. package/dist/domain/diagram/summarize.d.ts +0 -1
  26. package/dist/domain/diagram/summarize.d.ts.map +1 -1
  27. package/dist/domain/diagram/summarize.js +0 -1
  28. package/dist/domain/diagram/summarize.js.map +1 -1
  29. package/dist/domain/requestIntegrations.d.ts +13 -468
  30. package/dist/domain/requestIntegrations.d.ts.map +1 -1
  31. package/dist/domain/requestIntegrations.js +4 -95
  32. package/dist/domain/requestIntegrations.js.map +1 -1
  33. package/dist/domain/requestShape.d.ts +37 -679
  34. package/dist/domain/requestShape.d.ts.map +1 -1
  35. package/dist/domain/requestShape.js +2 -2
  36. package/dist/domain/requestShape.js.map +1 -1
  37. package/dist/domain/scenario/build.d.ts +6 -6
  38. package/dist/domain/scenario/build.d.ts.map +1 -1
  39. package/dist/domain/scenario/build.js +17 -68
  40. package/dist/domain/scenario/build.js.map +1 -1
  41. package/dist/domain/scenario/nodeConfig.d.ts.map +1 -1
  42. package/dist/domain/scenario/nodeConfig.js +16 -0
  43. package/dist/domain/scenario/nodeConfig.js.map +1 -1
  44. package/dist/domain/scenario/summarize.d.ts +0 -1
  45. package/dist/domain/scenario/summarize.d.ts.map +1 -1
  46. package/dist/domain/scenario/summarize.js +6 -1
  47. package/dist/domain/scenario/summarize.js.map +1 -1
  48. package/dist/index.js +16 -1
  49. package/dist/index.js.map +1 -1
  50. package/dist/resources/docs/collectionScripts.d.ts +2 -0
  51. package/dist/resources/docs/collectionScripts.d.ts.map +1 -0
  52. package/dist/resources/docs/collectionScripts.js +51 -0
  53. package/dist/resources/docs/collectionScripts.js.map +1 -0
  54. package/dist/resources/docs/diagramSchema.d.ts +1 -2
  55. package/dist/resources/docs/diagramSchema.d.ts.map +1 -1
  56. package/dist/resources/docs/diagramSchema.js +4 -63
  57. package/dist/resources/docs/diagramSchema.js.map +1 -1
  58. package/dist/resources/docs/overview.d.ts +1 -1
  59. package/dist/resources/docs/overview.d.ts.map +1 -1
  60. package/dist/resources/docs/overview.js +13 -34
  61. package/dist/resources/docs/overview.js.map +1 -1
  62. package/dist/resources/docs/requestSchema.d.ts +1 -1
  63. package/dist/resources/docs/requestSchema.d.ts.map +1 -1
  64. package/dist/resources/docs/requestSchema.js +11 -16
  65. package/dist/resources/docs/requestSchema.js.map +1 -1
  66. package/dist/resources/generated/aiPacks.d.ts +1 -1
  67. package/dist/resources/generated/aiPacks.js +6 -6
  68. package/dist/resources/generated/aiPacks.js.map +1 -1
  69. package/dist/resources/index.d.ts.map +1 -1
  70. package/dist/resources/index.js +5 -3
  71. package/dist/resources/index.js.map +1 -1
  72. package/dist/run/executeCollection.d.ts.map +1 -1
  73. package/dist/run/executeCollection.js +19 -3
  74. package/dist/run/executeCollection.js.map +1 -1
  75. package/dist/run/loadBundle.d.ts.map +1 -1
  76. package/dist/run/loadBundle.js +28 -3
  77. package/dist/run/loadBundle.js.map +1 -1
  78. package/dist/run/summarize.d.ts +4 -4
  79. package/dist/run/types.d.ts +5 -1
  80. package/dist/run/types.d.ts.map +1 -1
  81. package/dist/server.d.ts +1 -1
  82. package/dist/server.d.ts.map +1 -1
  83. package/dist/server.js +2 -2
  84. package/dist/server.js.map +1 -1
  85. package/dist/tools/catalog.d.ts.map +1 -1
  86. package/dist/tools/catalog.js +3 -11
  87. package/dist/tools/catalog.js.map +1 -1
  88. package/dist/tools/collections.d.ts.map +1 -1
  89. package/dist/tools/collections.js +137 -16
  90. package/dist/tools/collections.js.map +1 -1
  91. package/dist/tools/contracts.js +2 -2
  92. package/dist/tools/contracts.js.map +1 -1
  93. package/dist/tools/diagrams.d.ts.map +1 -1
  94. package/dist/tools/diagrams.js +42 -331
  95. package/dist/tools/diagrams.js.map +1 -1
  96. package/dist/tools/index.d.ts.map +1 -1
  97. package/dist/tools/index.js +4 -3
  98. package/dist/tools/index.js.map +1 -1
  99. package/dist/tools/loadTest.d.ts +4 -0
  100. package/dist/tools/loadTest.d.ts.map +1 -0
  101. package/dist/tools/loadTest.js +299 -0
  102. package/dist/tools/loadTest.js.map +1 -0
  103. package/dist/tools/lookups.d.ts +1 -5
  104. package/dist/tools/lookups.d.ts.map +1 -1
  105. package/dist/tools/lookups.js +0 -41
  106. package/dist/tools/lookups.js.map +1 -1
  107. package/dist/tools/requests.js +3 -3
  108. package/dist/tools/requests.js.map +1 -1
  109. package/dist/tools/run.d.ts +18 -0
  110. package/dist/tools/run.d.ts.map +1 -1
  111. package/dist/tools/run.js +14 -5
  112. package/dist/tools/run.js.map +1 -1
  113. package/dist/tools/scenarios.d.ts +0 -4
  114. package/dist/tools/scenarios.d.ts.map +1 -1
  115. package/dist/tools/scenarios.js +17 -112
  116. package/dist/tools/scenarios.js.map +1 -1
  117. package/dist-cjs/client/api.js +7 -54
  118. package/dist-cjs/config.js +5 -0
  119. package/dist-cjs/domain/diagram/build.js +3 -3
  120. package/dist-cjs/domain/diagram/layout.js +3 -10
  121. package/dist-cjs/domain/diagram/patch.js +1 -54
  122. package/dist-cjs/domain/diagram/summarize.js +0 -1
  123. package/dist-cjs/domain/requestIntegrations.js +4 -95
  124. package/dist-cjs/domain/requestShape.js +2 -2
  125. package/dist-cjs/domain/scenario/build.js +17 -68
  126. package/dist-cjs/domain/scenario/nodeConfig.js +16 -0
  127. package/dist-cjs/domain/scenario/summarize.js +6 -1
  128. package/dist-cjs/resources/docs/collectionScripts.js +53 -0
  129. package/dist-cjs/resources/docs/diagramSchema.js +5 -65
  130. package/dist-cjs/resources/docs/overview.js +13 -34
  131. package/dist-cjs/resources/docs/requestSchema.js +11 -16
  132. package/dist-cjs/resources/generated/aiPacks.js +6 -6
  133. package/dist-cjs/resources/index.js +4 -2
  134. package/dist-cjs/run/executeCollection.js +18 -2
  135. package/dist-cjs/run/loadBundle.js +28 -3
  136. package/dist-cjs/server.js +2 -2
  137. package/dist-cjs/tools/catalog.js +3 -11
  138. package/dist-cjs/tools/collections.js +137 -16
  139. package/dist-cjs/tools/contracts.js +2 -2
  140. package/dist-cjs/tools/diagrams.js +37 -326
  141. package/dist-cjs/tools/index.js +4 -3
  142. package/dist-cjs/tools/loadTest.js +335 -0
  143. package/dist-cjs/tools/lookups.js +1 -46
  144. package/dist-cjs/tools/requests.js +3 -3
  145. package/dist-cjs/tools/run.js +17 -7
  146. package/dist-cjs/tools/scenarios.js +18 -114
  147. package/package.json +3 -3
@@ -1,19 +1,19 @@
1
- import { applyDatabaseEdits, applyDiagramOps, BPMN_GRAMMAR_VERSION, bpmnXmlFromDocument, createEmptyDocument, DATABASE_GRAMMAR_VERSION, DATABASE_LAYOUT_REQUEST, DatabaseEditError, databaseModelFromDocument, databaseModelFromSchema, databaseSchemaView, emptyDatabaseModel, isDatabaseType, isMermaidFlowchart, looksLikeBpmn, looksLikeMermaid, MERMAID_GRAMMAR_VERSION, normalizeDocument, parseBpmn, parseDatabaseModel, parseMermaid, placeBpmnNodesOps, serializeDatabaseModel, } from "callman-core";
1
+ import { applyDiagramOps, BPMN_GRAMMAR_VERSION, bpmnXmlFromDocument, createEmptyDocument, isMermaidFlowchart, looksLikeBpmn, looksLikeMermaid, MERMAID_GRAMMAR_VERSION, normalizeDocument, parseBpmn, parseMermaid, placeBpmnNodesOps, } from "callman-core";
2
2
  import { z } from "zod";
3
3
  import { CallmanApiError, ToolInputError } from "../client/errors.js";
4
4
  import { buildDiagramDocument, diagramInputSchema, toToolError } from "../domain/diagram/build.js";
5
- import { layoutDocument, placeDatabaseNodes, placeNewNodes } from "../domain/diagram/layout.js";
6
- import { applyDiagramPatch, dbRelationshipInputSchema, dbTableInputSchema, diagramPatchOpSchema } from "../domain/diagram/patch.js";
5
+ import { layoutDocument, placeNewNodes } from "../domain/diagram/layout.js";
6
+ import { applyDiagramPatch, diagramPatchOpSchema } from "../domain/diagram/patch.js";
7
7
  import { diagramFullView, diagramGraphView, diagramListView, diagramMermaidView, diagramSourceView } from "../domain/diagram/summarize.js";
8
8
  import { resolvedSummary } from "../domain/resolve.js";
9
9
  import { normalizeName } from "../lib/ids.js";
10
10
  import { sliceWithCursor } from "../lib/pagination.js";
11
- import { diagramFolderPath, diagramFolderRows, loadDiagrams, resolveDiagram, resolveDiagramFolder, workspacesForListing, workspaceTag } from "./lookups.js";
12
- import { confirmArg, cursorArgs, DESTRUCTIVE, dryRunArg, guarded, IDEMPOTENT_WRITE, ok, READ, refArg, requireConfirm, workspaceArg, WRITE } from "./shared.js";
11
+ import { loadDiagrams, resolveDiagram } from "./lookups.js";
12
+ import { confirmArg, cursorArgs, DESTRUCTIVE, dryRunArg, guarded, IDEMPOTENT_WRITE, ok, READ, refArg, requireConfirm, WRITE } from "./shared.js";
13
13
  const directionArg = z.enum(["DOWN", "RIGHT", "UP", "LEFT"]).optional().describe("Layout flow direction (default DOWN)");
14
14
  const sourceArg = z
15
15
  .object({
16
- format: z.enum(["mermaid", "bpmn", "database"]).describe('"mermaid": Mermaid text; "bpmn": a BPMN 2.0 XML file; "database": the JSON database model of a Database Diagram (get_diagram view "source" of one, or the desktop\'s schema export)'),
16
+ format: z.enum(["mermaid", "bpmn"]).describe('"mermaid": Mermaid text; "bpmn": a BPMN 2.0 XML file'),
17
17
  text: z
18
18
  .string()
19
19
  .min(1)
@@ -22,7 +22,7 @@ const sourceArg = z
22
22
  })
23
23
  .strict()
24
24
  .optional()
25
- .describe("Create the diagram from Mermaid text, BPMN 2.0 XML or a database model instead of nodes/edges");
25
+ .describe("Create the diagram from Mermaid text or BPMN 2.0 XML instead of nodes/edges");
26
26
  // A BPMN diagram keeps its truth in BPMN 2.0 XML: the model is derived from it.
27
27
  const bpmnSource = (text) => ({ format: "bpmn", text, diagramType: "bpmn", grammar: BPMN_GRAMMAR_VERSION });
28
28
  // Typed bpmn.* nodes → a BPMN diagram: the model becomes XML, the XML becomes
@@ -33,83 +33,6 @@ const bpmnDocumentFromModel = (model, unpositionedNodeIds, base) => {
33
33
  const document = applyDiagramOps({ ...base, nodes: [], edges: [], source: undefined }, [{ op: "setSource", source: bpmnSource(xml), resync: true }], { now: now() }).doc;
34
34
  return { document, layoutNote: unpositionedNodeIds.length > 0 ? `Written as BPMN 2.0 XML; ${unpositionedNodeIds.length} node(s) placed left to right after their predecessors.` : "Written as BPMN 2.0 XML with the positions given." };
35
35
  };
36
- // A database diagram keeps its truth in the JSON database model.
37
- const databaseSource = (text) => ({ format: "database", text, diagramType: "database", grammar: DATABASE_GRAMMAR_VERSION, valid: true });
38
- const DATABASE_DIALECTS = ["postgres", "mysql", "mssql", "oracle", "mongo", "generic"];
39
- const toolErrorFromDatabaseEdit = (error) => {
40
- if (error instanceof DatabaseEditError)
41
- throw new ToolInputError(error.code, error.message);
42
- throw error;
43
- };
44
- // A database model → a database diagram: the model becomes the source, the
45
- // tables are derived from it and laid out (unrelated tables packed in rows).
46
- const databaseDocumentFromModel = async (model, base, keepPositions = false) => {
47
- const applied = applyDiagramOps({ ...base, ...(keepPositions ? {} : { nodes: [], edges: [] }), source: undefined }, [{ op: "setSource", source: databaseSource(serializeDatabaseModel(model)), resync: true }], { now: now() });
48
- let document = applied.doc;
49
- if (keepPositions) {
50
- const fresh = applied.added.nodes.filter((id) => document.nodes.some((node) => node.id === id));
51
- if (fresh.length > 0)
52
- document = placeDatabaseNodes(document, fresh);
53
- return { document, layoutNote: fresh.length > 0 ? `${fresh.length} new table(s) placed to the right of the existing ones.` : "Positions kept." };
54
- }
55
- if (document.nodes.length === 0)
56
- return { document, layoutNote: "An empty database diagram." };
57
- const laid = await layoutDocument(document, { request: DATABASE_LAYOUT_REQUEST });
58
- return { document: laid.document, layoutNote: laid.warning ?? `${document.nodes.length} table(s) laid out with ${laid.engine} (relationships left to right).` };
59
- };
60
- // Tables + relationships as the create tool takes them → a model.
61
- const databaseModelFromInput = (tables, relationships, dialect) => {
62
- const edits = [
63
- ...tables.map((table) => ({ kind: "addTable", table: { ...table, ...(table.columns ? { columns: table.columns.map((column) => ({ ...column, defaultValue: column.defaultValue ?? undefined, comment: column.comment ?? undefined })) } : {}) } })),
64
- ...relationships.map((relationship) => ({
65
- kind: "addRelationship",
66
- ...(relationship.id ? { id: relationship.id } : {}),
67
- source: relationship.source,
68
- target: relationship.target,
69
- ...(relationship.cardinality ? { cardinality: relationship.cardinality } : {}),
70
- ...(relationship.kind ? { relationshipKind: relationship.kind } : {}),
71
- ...(relationship.name ? { name: relationship.name } : {}),
72
- ...(relationship.label ? { label: relationship.label } : {}),
73
- })),
74
- ];
75
- try {
76
- return applyDatabaseEdits(emptyDatabaseModel(dialect), edits).model;
77
- }
78
- catch (error) {
79
- return toolErrorFromDatabaseEdit(error);
80
- }
81
- };
82
- // A database connection by id or name, in one workspace or across all.
83
- const findDatabaseConnection = async (ctx, workspace, ref) => {
84
- const wanted = ref.trim().toLowerCase();
85
- const workspaces = await workspacesForListing(ctx, workspace);
86
- const matches = [];
87
- for (const ws of workspaces) {
88
- for (const connection of await ctx.api.listConnections(ws.id, "database")) {
89
- if (connection.id === ref.trim() || connection.name.trim().toLowerCase() === wanted)
90
- matches.push({ ws, connection });
91
- }
92
- }
93
- if (matches.length === 0)
94
- throw new ToolInputError("CONNECTION_NOT_FOUND", `No database connection "${ref}"${workspace ? ` in workspace ${workspace}` : " in your workspaces"}. list_connections shows them (type: database).`);
95
- const exact = matches.filter((match) => match.connection.id === ref.trim());
96
- if (exact.length === 1)
97
- return exact[0];
98
- if (matches.length > 1) {
99
- throw new ToolInputError("AMBIGUOUS_CONNECTION", `"${ref}" matches ${matches.length} database connections; pass its id or a \`workspace\`.`, {
100
- candidates: matches.map((match) => ({ id: match.connection.id, name: match.connection.name, workspace: workspaceTag(match.ws) })),
101
- });
102
- }
103
- return matches[0];
104
- };
105
- const schemaQuery = (options) => ({
106
- ...(options.schemas && options.schemas.length > 0 ? { schemas: options.schemas.join(",") } : {}),
107
- ...(options.tables && options.tables.length > 0 ? { tables: options.tables.join(",") } : {}),
108
- ...(options.includeViews !== undefined ? { includeViews: String(options.includeViews) } : {}),
109
- ...(options.objectsOnly ? { objectsOnly: "true" } : {}),
110
- ...(options.maxTables !== undefined ? { maxTables: options.maxTables } : {}),
111
- });
112
- const PROVIDER_LABEL = { postgresql: "PostgreSQL", mysql: "MySQL", mssql: "SQL Server", oracle: "Oracle", mongodb: "MongoDB" };
113
36
  // Every document entering a tool goes through the shared gate (legacy fields
114
37
  // stripped, ids deduped, parents healed) — the same one the studio applies.
115
38
  const loadDocument = (diagram) => {
@@ -132,21 +55,6 @@ const assertEditableStructure = (doc) => {
132
55
  // nodes/edges (positions come from layout); anything else is kept as
133
56
  // source only (the desktop previews it, tools read it back).
134
57
  const documentFromSource = async (title, text, existing, direction, format = "mermaid") => {
135
- if (format === "database") {
136
- const parsed = parseDatabaseModel(text);
137
- if (!parsed.ok)
138
- throw new ToolInputError("DIAGRAM_SOURCE_INVALID", "The text is not a readable database model.", { errors: parsed.errors.slice(0, 20) });
139
- const base = existing ?? createEmptyDocument(title);
140
- const keep = Boolean(existing && existing.source?.format === "database");
141
- let built;
142
- try {
143
- built = await databaseDocumentFromModel(parsed.model, keep ? existing : { ...base, nodes: [], edges: [] }, keep);
144
- }
145
- catch (error) {
146
- return toToolError(error);
147
- }
148
- return { document: built.document, layoutNote: built.layoutNote, warnings: parsed.warnings };
149
- }
150
58
  if (format === "bpmn") {
151
59
  if (!looksLikeBpmn(text))
152
60
  throw new ToolInputError("DIAGRAM_SOURCE_INVALID", "The text is not a BPMN 2.0 document (no <definitions> root).");
@@ -216,59 +124,39 @@ const isConflict = (error) => error instanceof CallmanApiError && error.status =
216
124
  export const registerDiagramTools = (server, ctx) => {
217
125
  server.registerTool("list_diagrams", {
218
126
  title: "List diagrams",
219
- description: "List your system-design diagrams and the ones shared with you (owner, node/edge counts, whether you can edit), with the folder tree of your library: `folders` are your own folders as paths (\"Architecture/Payments\"), each diagram carries its `folder` path (null = the top level; always null for a diagram shared with you — folders are private to their owner). Diagrams belong to users and are shared into workspaces — not workspace-scoped.",
220
- inputSchema: {
221
- query: z.string().max(200).optional(),
222
- folder: z.string().max(300).optional().describe('Only the diagrams in this folder of your library (id, name or path such as "Architecture/Payments"); "/" = the top level only'),
223
- ...cursorArgs,
224
- },
127
+ description: "List your system-design diagrams and the ones shared with you (owner, node/edge counts, whether you can edit). Diagrams belong to users and are shared into workspaces — not workspace-scoped.",
128
+ inputSchema: { query: z.string().max(200).optional(), ...cursorArgs },
225
129
  annotations: READ,
226
- }, guarded(async ({ query, folder, cursor, limit }) => {
227
- const [all, rows] = await Promise.all([loadDiagrams(ctx), diagramFolderRows(ctx)]);
130
+ }, guarded(async ({ query, cursor, limit }) => {
131
+ const all = await loadDiagrams(ctx);
228
132
  const needle = query?.trim().toLowerCase();
229
- const scope = folder?.trim() === "/" ? { item: null, annotation: undefined } : folder ? await resolveDiagramFolder(ctx, folder) : undefined;
230
- const filtered = all.filter((diagram) => {
231
- if (needle && !diagram.name.toLowerCase().includes(needle))
232
- return false;
233
- if (scope === undefined)
234
- return true;
235
- return (diagram.folderId ?? null) === (scope.item?.id ?? null);
236
- });
237
- const page = sliceWithCursor(filtered, cursor, limit, `${needle ?? ""}|${scope?.item?.id ?? (scope ? "/" : "")}`);
238
- return ok({
239
- diagrams: page.items.map((diagram) => ({ ...diagramListView(diagram), folder: diagramFolderPath(rows, diagram.folderId) })),
240
- folders: rows.map((row) => ({ id: row.id, name: row.name, parentId: row.parentId, path: row.path })),
241
- total: page.total,
242
- nextCursor: page.nextCursor,
243
- ...(scope?.item && scope.annotation ? { resolved: [resolvedSummary(folder, scope)] } : {}),
244
- });
133
+ const filtered = needle ? all.filter((diagram) => diagram.name.toLowerCase().includes(needle)) : all;
134
+ const page = sliceWithCursor(filtered, cursor, limit, needle ?? "");
135
+ return ok({ diagrams: page.items.map(diagramListView), total: page.total, nextCursor: page.nextCursor });
245
136
  }));
246
137
  server.registerTool("get_diagram", {
247
138
  title: "Get a diagram",
248
- description: "Read a diagram: `summary` (counts, owner, sharing), `graph` (default — nodes with type/label/parent/style and edges with semantic/color/routing/sides, in the same shape the write tools accept: enough to describe, restyle or edit it), `mermaid` (the diagram rendered as Mermaid flowchart text), `source` (the Mermaid text, BPMN 2.0 XML or JSON database model a source-backed diagram keeps), `schema` (a database diagram's tables with columns, keys and relationships as table.column pairs — read it before database ops) or `full` (the complete stored DiagramDocument with positions, sizes and routes, up to 512 KB).",
249
- inputSchema: { diagram: refArg("Diagram"), view: z.enum(["summary", "graph", "mermaid", "source", "schema", "full"]).default("graph") },
139
+ description: "Read a diagram: `summary` (counts, owner, sharing), `graph` (default — nodes with type/label/parent/style and edges with semantic/color/routing/sides, in the same shape the write tools accept: enough to describe, restyle or edit it), `mermaid` (the diagram rendered as Mermaid flowchart text), `source` (the Mermaid text or BPMN 2.0 XML a source-backed diagram keeps) or `full` (the complete stored DiagramDocument with positions, sizes and routes, up to 512 KB).",
140
+ inputSchema: { diagram: refArg("Diagram"), view: z.enum(["summary", "graph", "mermaid", "source", "full"]).default("graph") },
250
141
  annotations: READ,
251
142
  }, guarded(async ({ diagram, view }) => {
252
143
  const resolved = await resolveDiagram(ctx, diagram);
253
144
  const doc = loadDocument(resolved.item);
254
145
  const summary = diagramListView(resolved.item);
255
- const summaryWithFolder = { ...summary, folder: diagramFolderPath(await diagramFolderRows(ctx), resolved.item.folderId) };
256
146
  const body = view === "summary"
257
- ? summaryWithFolder
147
+ ? summary
258
148
  : view === "graph"
259
149
  ? { ...summary, ...diagramGraphView(doc) }
260
150
  : view === "mermaid"
261
151
  ? { ...summary, ...diagramMermaidView(doc) }
262
152
  : view === "source"
263
153
  ? { ...summary, ...diagramSourceView(doc) }
264
- : view === "schema"
265
- ? { ...summary, schema: databaseSchemaView(doc) }
266
- : { ...summary, ...diagramFullView(doc) };
154
+ : { ...summary, ...diagramFullView(doc) };
267
155
  return ok({ diagram: body, ...(resolved.annotation ? { resolved: [resolvedSummary(diagram, resolved)] } : {}) });
268
156
  }));
269
157
  server.registerTool("create_diagram", {
270
- title: "Create a system-design, process or database diagram",
271
- description: "Create a diagram from typed nodes and edges — or from Mermaid text / BPMN 2.0 XML / a database model (`source`). A BPMN process (`kind: \"bpmn\"`, or nodes typed bpmn.*) is stored as BPMN 2.0 XML the desktop opens in its BPMN editor. A DATABASE diagram (entity-relationship: `kind: \"database\"`, `tables` + `relationships`, nodes typed db.table/db.view/db.collection with the columns in data: { db: { columns } }, or `fromConnection` to read a real database's schema) is stored as the JSON database model the desktop opens on its ERD canvas — tables with columns and keys, relationships with cardinality, laid out left to right. Node `type` must come from callman://diagram/components (e.g. net.service, net.api-gateway, db.postgres, mq.kafka, aws.lambda, flow.process); unknown types are rejected with suggestions unless strictTypes: false. Group nodes inside a container node — frame, pool.horizontal or pool.vertical — with `parent`. Style nodes with `style` (fill / stroke / textColor as CSS colors, strokeWidth, dashed, radius, bold, fontSize, opacity…) and edges with `semantic` (sync default, async, fallback, bus), an optional `color`, `routing` and fixed `sourceSide`/`targetSide`. Layout is automatic when nodes have no positions. Read callman://docs/diagram-schema for every field. Keep it readable: 8–25 nodes, short labels.",
158
+ title: "Create a system-design diagram",
159
+ description: "Create a diagram from typed nodes and edges — or from Mermaid text / BPMN 2.0 XML (`source`). A BPMN process (`kind: \"bpmn\"`, or nodes typed bpmn.*) is stored as BPMN 2.0 XML the desktop opens in its BPMN editor. Node `type` must come from callman://diagram/components (e.g. net.service, net.api-gateway, db.postgres, mq.kafka, aws.lambda, flow.process); unknown types are rejected with suggestions unless strictTypes: false. Group nodes inside a container node — frame, pool.horizontal or pool.vertical — with `parent`. Style nodes with `style` (fill / stroke / textColor as CSS colors, strokeWidth, dashed, radius, bold, fontSize, opacity…) and edges with `semantic` (sync default, async, fallback, bus), an optional `color`, `routing` and fixed `sourceSide`/`targetSide`. Layout is automatic when nodes have no positions. Read callman://docs/diagram-schema for every field. Keep it readable: 8–25 nodes, short labels.",
272
160
  inputSchema: {
273
161
  name: z.string().min(1).max(200).describe("Diagram name (library entry)"),
274
162
  title: diagramInputSchema.shape.title.optional().describe("Diagram title (defaults to the name)"),
@@ -276,76 +164,28 @@ export const registerDiagramTools = (server, ctx) => {
276
164
  edges: diagramInputSchema.shape.edges.optional(),
277
165
  canvas: diagramInputSchema.shape.canvas,
278
166
  source: sourceArg,
279
- kind: z.enum(["canvas", "bpmn", "database", "mermaid"]).optional().describe('"bpmn": model a business process — nodes use bpmn.* types and the diagram is stored as BPMN 2.0 XML; "database": an entity-relationship diagram stored as the JSON database model; "mermaid": a Mermaid diagram — give `source: { format: "mermaid", text }` (default: canvas; inferred from the node types, from `source`, from `tables` and from `fromConnection`)'),
280
- tables: z.array(dbTableInputSchema).max(500).optional().describe("Database diagram: the tables (name, schema?, kind?, columns with dataType / primaryKey / nullable / unique / defaultValue / comment)"),
281
- relationships: z.array(dbRelationshipInputSchema).max(2000).optional().describe('Database diagram: relationships between the tables — source is the child (foreign-key) side as "table.column", target the parent; cardinality source:target (default N:1)'),
282
- dialect: z.enum(DATABASE_DIALECTS).optional().describe("Database diagram: which database the types are written for"),
283
- fromConnection: z
284
- .object({
285
- connection: z.string().min(1).max(200).describe("A database connection by id or name (list_connections, type: database)"),
286
- schemas: z.array(z.string().min(1).max(120)).max(50).optional().describe("Schemas to read (default: every user schema; MySQL: the connection's database; Oracle: the current schema)"),
287
- tables: z.array(z.string().min(1).max(240)).max(2000).optional().describe('Only these tables ("schema.table" or "table"); default: all'),
288
- includeViews: z.boolean().optional(),
289
- })
290
- .strict()
291
- .optional()
292
- .describe("Database diagram: read a real database's schema through one of the workspace's connections and draw it — tables, columns, keys and the relationships the database declares"),
293
- workspace: workspaceArg,
294
- folder: z.string().max(300).optional().describe('File it in a folder of your library (id, name or path such as "Architecture/Payments"; create one with create_diagram_folder). Default: the top level'),
167
+ kind: z.enum(["canvas", "bpmn"]).optional().describe('"bpmn": model a business process — nodes use bpmn.* types and the diagram is stored as BPMN 2.0 XML (default: canvas; inferred as bpmn when every node type starts with "bpmn.")'),
295
168
  autoLayout: z.boolean().optional().describe("Force layout even when positions were given"),
296
169
  direction: directionArg,
297
170
  strictTypes: z.boolean().optional(),
298
171
  dryRun: dryRunArg,
299
172
  },
300
173
  annotations: WRITE,
301
- }, guarded(async ({ name, title, nodes, edges, canvas, source, kind, tables, relationships, dialect, fromConnection, workspace, folder, autoLayout, direction, strictTypes, dryRun }) => {
302
- const targetFolder = folder ? await resolveDiagramFolder(ctx, folder) : null;
303
- const inputs = [nodes ? "nodes" : null, source ? "source" : null, tables ? "tables" : null, fromConnection ? "fromConnection" : null].filter(Boolean);
304
- if (inputs.length === 0)
305
- throw new ToolInputError("NOTHING_TO_CREATE", 'Pass nodes (+ edges), source { format: "mermaid" | "bpmn" | "database", text }, tables (+ relationships) or fromConnection.');
306
- if (inputs.length > 1)
307
- throw new ToolInputError("CONFLICTING_INPUT", `Pass one of nodes, source, tables or fromConnection — not ${inputs.join(" + ")}.`);
308
- if (relationships && !tables)
309
- throw new ToolInputError("CONFLICTING_INPUT", "relationships go with tables.");
310
- if (kind === "mermaid" && source?.format !== "mermaid") {
311
- throw new ToolInputError("MERMAID_NEEDS_SOURCE", 'A Mermaid diagram is created from source: { format: "mermaid", text } — a flowchart becomes nodes, any other Mermaid type is stored as its source.');
312
- }
174
+ }, guarded(async ({ name, title, nodes, edges, canvas, source, kind, autoLayout, direction, strictTypes, dryRun }) => {
175
+ if (!nodes && !source)
176
+ throw new ToolInputError("NOTHING_TO_CREATE", "Pass nodes (+ edges) or source { format: \"mermaid\" | \"bpmn\", text }.");
177
+ if (nodes && source)
178
+ throw new ToolInputError("CONFLICTING_INPUT", "Pass either nodes or source, not both.");
313
179
  let document;
314
180
  let layoutNote;
315
181
  let warnings = [];
316
182
  const bpmnKind = kind === "bpmn" || (kind === undefined && Boolean(nodes && nodes.length > 0 && nodes.every((node) => node.type.startsWith("bpmn."))));
317
- const databaseKind = kind === "database" || Boolean(tables) || Boolean(fromConnection) || (kind === undefined && Boolean(nodes && nodes.length > 0 && nodes.every((node) => isDatabaseType(node.type))));
318
- let connectionNote = {};
319
183
  if (source) {
320
184
  const fromSource = await documentFromSource(title ?? name, source.text, null, direction, source.format);
321
185
  document = canvas ? { ...fromSource.document, canvas: { ...fromSource.document.canvas, ...canvas } } : fromSource.document;
322
186
  layoutNote = fromSource.layoutNote;
323
187
  warnings = fromSource.warnings;
324
188
  }
325
- else if (fromConnection) {
326
- const found = await findDatabaseConnection(ctx, workspace, fromConnection.connection);
327
- const schema = await ctx.api.getConnectionSchema(found.ws.id, found.connection.id, schemaQuery(fromConnection));
328
- const model = databaseModelFromSchema(schema, { connection: { connectionId: found.connection.id, name: found.connection.name, provider: found.connection.provider } });
329
- const built = await databaseDocumentFromModel(model, createEmptyDocument(title ?? name));
330
- document = built.document;
331
- layoutNote = built.layoutNote;
332
- warnings = [...schema.warnings, ...(schema.truncated ? ["The database has more tables than the cap; the list was cut."] : [])];
333
- connectionNote = { connection: { id: found.connection.id, name: found.connection.name, provider: PROVIDER_LABEL[found.connection.provider] ?? found.connection.provider, workspace: workspaceTag(found.ws) }, tables: model.entities.length, relationships: model.relationships.length };
334
- }
335
- else if (tables) {
336
- const model = databaseModelFromInput(tables, relationships ?? [], dialect);
337
- const built = await databaseDocumentFromModel(model, createEmptyDocument(title ?? name));
338
- document = built.document;
339
- layoutNote = built.layoutNote;
340
- }
341
- else if (databaseKind) {
342
- const built = buildDiagramDocument({ title: title ?? name, nodes: nodes ?? [], edges: edges ?? [], canvas }, { strictTypes, kind: "database" });
343
- const model = databaseModelFromDocument({ ...built.document, source: undefined }, dialect);
344
- const database = await databaseDocumentFromModel(model, createEmptyDocument(title ?? name));
345
- document = database.document;
346
- layoutNote = database.layoutNote;
347
- warnings = built.warnings;
348
- }
349
189
  else if (bpmnKind) {
350
190
  const built = buildDiagramDocument({ title: title ?? name, nodes: nodes ?? [], edges: edges ?? [], canvas }, { strictTypes, kind: "bpmn" });
351
191
  const bpmn = bpmnDocumentFromModel(built.document, built.unpositionedNodeIds, createEmptyDocument(title ?? name));
@@ -363,26 +203,21 @@ export const registerDiagramTools = (server, ctx) => {
363
203
  layoutNote = laid.warning ?? `Laid out with ${laid.engine}.`;
364
204
  }
365
205
  }
366
- if (document.source?.format === "database" && canvas && !source)
367
- document = { ...document, canvas: { ...document.canvas, ...canvas } };
368
- const view = document.source?.format === "database" ? { ...diagramGraphView(document), schema: databaseSchemaView(document) } : diagramGraphView(document);
369
206
  if (dryRun) {
370
- return ok({ dryRun: true, diagram: { name, folder: targetFolder?.item.path ?? null, ...view }, warnings, ...connectionNote, ...(layoutNote ? { layout: layoutNote } : {}) });
207
+ return ok({ dryRun: true, diagram: { name, ...diagramGraphView(document) }, warnings, ...(layoutNote ? { layout: layoutNote } : {}) });
371
208
  }
372
- const created = await ctx.api.createDiagram({ name: name.trim(), document, ...(targetFolder ? { folderId: targetFolder.item.id } : {}) });
209
+ const created = await ctx.api.createDiagram({ name: name.trim(), document });
373
210
  ctx.invalidate("diagrams");
374
211
  return ok({
375
- diagram: { ...diagramListView(created), folder: targetFolder?.item.path ?? null, ...view },
212
+ diagram: { ...diagramListView(created), ...diagramGraphView(document) },
376
213
  warnings,
377
- ...connectionNote,
378
214
  ...(layoutNote ? { layout: layoutNote } : {}),
379
- ...(targetFolder?.annotation ? { resolved: [resolvedSummary(folder, targetFolder)] } : {}),
380
- note: `Saved${targetFolder ? ` in ${targetFolder.item.path}` : ""}. Open it in the desktop app (Diagrams → Refresh). Edit with patch_diagram; share with share_diagram.`,
215
+ note: "Saved. Open it in the desktop app (Diagrams → Refresh). Edit with patch_diagram; share with share_diagram.",
381
216
  });
382
217
  }));
383
218
  server.registerTool("update_diagram", {
384
219
  title: "Replace a diagram's content",
385
- description: "Replace a diagram's whole document (nodes + edges, same fields as create_diagram), replace or attach its Mermaid text, BPMN 2.0 XML or database-model `source`, rename it, retitle it, change its canvas and/or move it to a folder of your library (`folder`; null = the top level; only the owner can move) — keeping its identity and sharing. Passing nodes replaces ALL nodes and edges (omitted edges are removed). Passing `source` re-derives nodes and edges from the text (existing ones keep their place; new ones are placed). For small edits — including restyling — prefer patch_diagram.",
220
+ description: "Replace a diagram's whole document (nodes + edges, same fields as create_diagram), replace or attach its Mermaid text or BPMN 2.0 XML `source`, and/or rename it, retitle it or change its canvas — keeping its identity and sharing. Passing nodes replaces ALL nodes and edges (omitted edges are removed). Passing `source` re-derives nodes and edges from the text (existing ones keep their place; new ones are placed). For small edits — including restyling — prefer patch_diagram.",
386
221
  inputSchema: {
387
222
  diagram: refArg("Diagram"),
388
223
  name: z.string().min(1).max(200).optional(),
@@ -391,19 +226,17 @@ export const registerDiagramTools = (server, ctx) => {
391
226
  edges: diagramInputSchema.shape.edges.optional(),
392
227
  canvas: diagramInputSchema.shape.canvas,
393
228
  source: sourceArg,
394
- folder: z.string().max(300).nullable().optional().describe('Move the diagram into this folder of your library (id, name or path); null = the top level'),
395
229
  autoLayout: z.boolean().optional(),
396
230
  direction: directionArg,
397
231
  strictTypes: z.boolean().optional(),
398
232
  },
399
233
  annotations: IDEMPOTENT_WRITE,
400
- }, guarded(async ({ diagram, name, title, nodes, edges, canvas, source, folder, autoLayout, direction, strictTypes }) => {
401
- if (name === undefined && nodes === undefined && title === undefined && canvas === undefined && source === undefined && folder === undefined) {
402
- throw new ToolInputError("NOTHING_TO_UPDATE", "Pass name, title, canvas, source, folder and/or nodes (+ edges).");
234
+ }, guarded(async ({ diagram, name, title, nodes, edges, canvas, source, autoLayout, direction, strictTypes }) => {
235
+ if (name === undefined && nodes === undefined && title === undefined && canvas === undefined && source === undefined) {
236
+ throw new ToolInputError("NOTHING_TO_UPDATE", "Pass name, title, canvas, source and/or nodes (+ edges).");
403
237
  }
404
238
  if (nodes && source)
405
239
  throw new ToolInputError("CONFLICTING_INPUT", "Pass either nodes or source, not both.");
406
- const targetFolder = folder ? await resolveDiagramFolder(ctx, folder) : null;
407
240
  const resolved = await resolveDiagram(ctx, diagram);
408
241
  if (!resolved.item.canEdit)
409
242
  throw new ToolInputError("DIAGRAM_READ_ONLY", "You have read-only access to this diagram.");
@@ -411,19 +244,7 @@ export const registerDiagramTools = (server, ctx) => {
411
244
  let document;
412
245
  let layoutNote;
413
246
  let warnings = [];
414
- if (nodes && existing.source?.format === "database") {
415
- // A database diagram stays one: the tables given become the new model.
416
- const built = buildDiagramDocument({ title: title ?? existing.meta.title, nodes, edges: edges ?? [], canvas: canvas ?? existing.canvas }, { strictTypes, existingId: existing.id, createdAt: existing.meta.createdAt, kind: "database" });
417
- const previous = parseDatabaseModel(existing.source.text).model;
418
- const model = databaseModelFromDocument({ ...built.document, source: undefined }, previous.dialect);
419
- if (previous.connection)
420
- model.connection = previous.connection;
421
- const database = await databaseDocumentFromModel(model, existing, true);
422
- document = database.document;
423
- layoutNote = database.layoutNote;
424
- warnings = [...built.warnings, "The database model was rewritten from the tables given; tables not in the input are gone. Prefer patch_diagram (addTable, addColumn, addRelationship …) for edits."];
425
- }
426
- else if (nodes && existing.source?.format === "bpmn") {
247
+ if (nodes && existing.source?.format === "bpmn") {
427
248
  // A BPMN diagram stays BPMN: the new model is written as fresh XML.
428
249
  const built = buildDiagramDocument({ title: title ?? existing.meta.title, nodes, edges: edges ?? [], canvas: canvas ?? existing.canvas }, { strictTypes, existingId: existing.id, createdAt: existing.meta.createdAt, kind: "bpmn" });
429
250
  const bpmn = bpmnDocumentFromModel(built.document, built.unpositionedNodeIds, existing);
@@ -440,7 +261,7 @@ export const registerDiagramTools = (server, ctx) => {
440
261
  warnings.push(`edges was omitted, so the ${existing.edges.length} existing edge(s) were removed. Pass edges to keep connections, or use patch_diagram for partial edits.`);
441
262
  }
442
263
  if (existing.source)
443
- warnings.push(`The diagram's ${existing.source.format === "mermaid" ? "Mermaid" : existing.source.format} source was detached: nodes and edges were replaced from the input.`);
264
+ warnings.push("The diagram's Mermaid source was detached: nodes and edges were replaced from the input.");
444
265
  if (autoLayout || built.unpositionedNodeIds.length > 0) {
445
266
  const laid = await layoutDocument(document, { direction });
446
267
  document = laid.document;
@@ -470,20 +291,13 @@ export const registerDiagramTools = (server, ctx) => {
470
291
  const updated = await ctx.api.updateDiagram(resolved.item.id, {
471
292
  ...(name !== undefined ? { name: name.trim() } : {}),
472
293
  ...(document ? { document, ...(typeof existing.meta.revision === "number" ? { baseRevision: existing.meta.revision } : {}) } : {}),
473
- ...(folder !== undefined ? { folderId: targetFolder?.item.id ?? null } : {}),
474
294
  });
475
295
  ctx.invalidate("diagrams");
476
- const rows = await diagramFolderRows(ctx);
477
- return ok({
478
- diagram: { ...diagramListView(updated), folder: diagramFolderPath(rows, updated.folderId), ...diagramGraphView(document ?? existing) },
479
- warnings,
480
- ...(layoutNote ? { layout: layoutNote } : {}),
481
- resolved: [resolvedSummary(diagram, resolved), ...(targetFolder?.annotation ? [resolvedSummary(folder, targetFolder)] : [])],
482
- });
296
+ return ok({ diagram: { ...diagramListView(updated), ...diagramGraphView(document ?? existing) }, warnings, ...(layoutNote ? { layout: layoutNote } : {}), resolved: [resolvedSummary(diagram, resolved)] });
483
297
  }));
484
298
  server.registerTool("patch_diagram", {
485
299
  title: "Edit a diagram incrementally",
486
- description: "Apply operations to a diagram without resending it: addNode, updateNode, removeNode (drops its edges, lifts its children out), addEdge, updateEdge, removeEdge, setTitle, moveNode, reparent, setEdgeRoute (routing, fixed sides, bends), reorder (stacking), setCanvas, group (wrap nodes in a container), ungroup, relayout (a hint: new | all). On a DATABASE diagram use the schema ops — addTable, renameTable, removeTable, setTableComment, addColumn, alterColumn, removeColumn, setPrimaryKey, addRelationship (source = child \"table.column\", target = parent), updateRelationship, removeRelationship, hideTable, showTable — read get_diagram view schema first. updateNode `changes` MERGE: style and data keys you pass change, a key set to null is removed. updateEdge can change semantic, color, label, arrows, sides and ends. Moving a node re-routes its edges. `relayout`: none | new (place only new nodes, default) | all (re-run automatic layout). Call get_diagram (view: graph) first to see node ids and current styles. Ops are documented in callman://docs/diagram-schema.",
300
+ description: "Apply operations to a diagram without resending it: addNode, updateNode, removeNode (drops its edges, lifts its children out), addEdge, updateEdge, removeEdge, setTitle, moveNode, reparent, setEdgeRoute (routing, fixed sides, bends), reorder (stacking), setCanvas, group (wrap nodes in a container), ungroup, relayout (a hint: new | all). updateNode `changes` MERGE: style and data keys you pass change, a key set to null is removed. updateEdge can change semantic, color, label, arrows, sides and ends. Moving a node re-routes its edges. `relayout`: none | new (place only new nodes, default) | all (re-run automatic layout). Call get_diagram (view: graph) first to see node ids and current styles. Ops are documented in callman://docs/diagram-schema.",
487
301
  inputSchema: {
488
302
  diagram: refArg("Diagram"),
489
303
  ops: z.array(diagramPatchOpSchema).min(1).max(200),
@@ -507,21 +321,15 @@ export const registerDiagramTools = (server, ctx) => {
507
321
  const wantsAll = relayout === "all" || patched.relayout?.scope === "all";
508
322
  const layoutDirection = direction ?? patched.relayout?.direction;
509
323
  const bpmn = document.source?.format === "bpmn";
510
- const database = document.source?.format === "database";
511
324
  if (wantsAll) {
512
- // A process reads left to right; the BPMN XML follows the moves. An
513
- // ERD packs unrelated tables into rows.
514
- const laid = await layoutDocument(document, { direction: layoutDirection ?? (bpmn || database ? "RIGHT" : undefined), ...(database ? { request: DATABASE_LAYOUT_REQUEST } : {}) });
325
+ // A process reads left to right; the BPMN XML follows the moves.
326
+ const laid = await layoutDocument(document, { direction: layoutDirection ?? (bpmn ? "RIGHT" : undefined) });
515
327
  document = laid.document;
516
328
  layoutNote = laid.warning ?? `Laid out with ${laid.engine}.`;
517
329
  }
518
330
  else if (relayout === "new" && patched.addedNodeIds.length > 0) {
519
331
  const ids = patched.addedNodeIds.filter((id) => document.nodes.some((node) => node.id === id));
520
- if (database) {
521
- document = placeDatabaseNodes(document, ids);
522
- layoutNote = `Placed ${ids.length} new table(s) to the right of the existing ones.`;
523
- }
524
- else if (bpmn) {
332
+ if (bpmn) {
525
333
  document = applyDiagramOps(document, placeBpmnNodesOps(document, ids), { now: now() }).doc;
526
334
  layoutNote = `Placed ${ids.length} new node(s) after their predecessors.`;
527
335
  }
@@ -550,7 +358,7 @@ export const registerDiagramTools = (server, ctx) => {
550
358
  ctx.invalidate("diagrams");
551
359
  const { updated, document, patched, layoutNote } = outcome;
552
360
  return ok({
553
- diagram: { ...diagramListView(updated), ...diagramGraphView(document), ...(document.source?.format === "database" ? { schema: databaseSchemaView(document) } : {}) },
361
+ diagram: { ...diagramListView(updated), ...diagramGraphView(document) },
554
362
  applied: ops.length,
555
363
  added: patched.addedNodeIds,
556
364
  removedNodes: patched.removedNodeIds,
@@ -562,103 +370,6 @@ export const registerDiagramTools = (server, ctx) => {
562
370
  resolved: [resolvedSummary(diagram, resolved)],
563
371
  });
564
372
  }));
565
- server.registerTool("introspect_database", {
566
- title: "Read a database's schema through a connection",
567
- description: "Read the database behind one of the workspace's database connections (list_connections, type: database): schemas, tables and views (MongoDB: collections with fields inferred from a sample), columns with types, nullability, defaults and comments, primary and unique keys, foreign keys with referential actions, indexes. Metadata only — never credentials, never data. Use `objectsOnly` to list names first, then read the tables you need; `create_diagram` with `fromConnection` draws the result as a Database Diagram in one step. Runs on the Callman backend, which must be able to reach the database.",
568
- inputSchema: {
569
- connection: z.string().min(1).max(200).describe("Connection id or name"),
570
- workspace: workspaceArg,
571
- schemas: z.array(z.string().min(1).max(120)).max(50).optional(),
572
- tables: z.array(z.string().min(1).max(240)).max(2000).optional().describe('"schema.table" or "table"'),
573
- includeViews: z.boolean().optional(),
574
- objectsOnly: z.boolean().optional().describe("Names only (no columns / keys) — for a first look at a large database"),
575
- maxTables: z.number().int().min(1).max(20000).optional(),
576
- },
577
- annotations: READ,
578
- }, guarded(async ({ connection, workspace, schemas, tables, includeViews, objectsOnly, maxTables }) => {
579
- const found = await findDatabaseConnection(ctx, workspace, connection);
580
- const schema = await ctx.api.getConnectionSchema(found.ws.id, found.connection.id, schemaQuery({ schemas, tables, includeViews, objectsOnly, maxTables }));
581
- return ok({
582
- connection: { id: found.connection.id, name: found.connection.name, provider: PROVIDER_LABEL[found.connection.provider] ?? found.connection.provider, workspace: workspaceTag(found.ws) },
583
- schema,
584
- ...(schema.truncated ? { note: "The database has more tables than the cap; pass schemas/tables to narrow the read or raise maxTables." } : {}),
585
- });
586
- }));
587
- // ── library folders (private to the token's owner) ──────────────────
588
- const folderView = (row) => ({ id: row.id, name: row.name, parentId: row.parentId, path: row.path });
589
- server.registerTool("create_diagram_folder", {
590
- title: "Create a diagram folder",
591
- description: "Create a folder in your diagram library, optionally inside a parent folder (id, name or path). Folders are yours alone (nobody else sees them; a diagram you share shows at the top level for others), nest up to 8 levels, and sibling names are unique — an existing folder with that name is returned instead of a duplicate. File diagrams with create_diagram / update_diagram `folder`.",
592
- inputSchema: {
593
- name: z.string().min(1).max(120),
594
- parent: z.string().max(300).optional().describe("Parent folder id, name or path; omit for the top level"),
595
- },
596
- annotations: WRITE,
597
- }, guarded(async ({ name, parent }) => {
598
- const parentFolder = parent ? await resolveDiagramFolder(ctx, parent) : null;
599
- const rows = await diagramFolderRows(ctx);
600
- const trimmed = name.trim();
601
- const sibling = rows.find((row) => row.parentId === (parentFolder?.item.id ?? null) && normalizeName(row.name) === normalizeName(trimmed));
602
- if (sibling) {
603
- return ok({ folder: folderView(sibling), existed: true, note: "A folder with that name already exists there — returned instead of creating a duplicate." });
604
- }
605
- const created = await ctx.api.createDiagramFolder({ name: trimmed, parentId: parentFolder?.item.id ?? null });
606
- ctx.invalidate("diagram-folders");
607
- const path = parentFolder ? `${parentFolder.item.path}/${created.name}` : created.name;
608
- return ok({
609
- folder: { id: created.id, name: created.name, parentId: created.parentId, path },
610
- ...(parentFolder?.annotation ? { resolved: [resolvedSummary(parent, parentFolder)] } : {}),
611
- });
612
- }));
613
- server.registerTool("update_diagram_folder", {
614
- title: "Rename or move a diagram folder",
615
- description: "Rename a folder of your diagram library and/or move it under another folder (parent: null = the top level). A folder cannot be moved into itself or one of its subfolders.",
616
- inputSchema: {
617
- folder: refArg("Diagram folder", "(or path)"),
618
- name: z.string().min(1).max(120).optional(),
619
- parent: z.string().max(300).nullable().optional().describe("New parent folder (id, name or path); null = the top level"),
620
- },
621
- annotations: IDEMPOTENT_WRITE,
622
- }, guarded(async ({ folder, name, parent }) => {
623
- if (name === undefined && parent === undefined)
624
- throw new ToolInputError("NOTHING_TO_UPDATE", "Pass name and/or parent.");
625
- const target = await resolveDiagramFolder(ctx, folder);
626
- const parentFolder = parent ? await resolveDiagramFolder(ctx, parent) : null;
627
- if (parentFolder && (parentFolder.item.id === target.item.id || parentFolder.item.path.startsWith(`${target.item.path}/`))) {
628
- throw new ToolInputError("FOLDER_CYCLE", "A folder cannot be moved into itself or one of its subfolders.");
629
- }
630
- const updated = await ctx.api.updateDiagramFolder(target.item.id, {
631
- ...(name !== undefined ? { name: name.trim() } : {}),
632
- ...(parent !== undefined ? { parentId: parentFolder?.item.id ?? null } : {}),
633
- });
634
- ctx.invalidate("diagram-folders");
635
- const rows = await diagramFolderRows(ctx);
636
- const row = rows.find((entry) => entry.id === updated.id);
637
- return ok({
638
- folder: row ? folderView(row) : { id: updated.id, name: updated.name, parentId: updated.parentId, path: updated.name },
639
- resolved: [resolvedSummary(folder, target), ...(parentFolder?.annotation ? [resolvedSummary(parent, parentFolder)] : [])],
640
- });
641
- }));
642
- server.registerTool("delete_diagram_folder", {
643
- title: "Delete a diagram folder",
644
- description: "Delete a folder of your diagram library and its subfolders. No diagram is deleted: everything inside moves to the deleted folder's parent. Confirm with the user first.",
645
- inputSchema: { folder: refArg("Diagram folder", "(or path)"), confirm: confirmArg },
646
- annotations: DESTRUCTIVE,
647
- }, guarded(async ({ folder, confirm }) => {
648
- requireConfirm(confirm, "a diagram folder");
649
- const target = await resolveDiagramFolder(ctx, folder, { exact: true });
650
- const result = await ctx.api.deleteDiagramFolder(target.item.id);
651
- ctx.invalidate("diagram-folders");
652
- ctx.invalidate("diagrams");
653
- const rows = await diagramFolderRows(ctx);
654
- return ok({
655
- deleted: folderView(target.item),
656
- deletedFolderCount: result.deletedFolderIds.length,
657
- movedDiagramCount: result.movedDiagramCount,
658
- movedTo: diagramFolderPath(rows, result.movedToFolderId) ?? "the top level",
659
- resolved: [resolvedSummary(folder, target)],
660
- });
661
- }));
662
373
  server.registerTool("delete_diagram", {
663
374
  title: "Delete a diagram",
664
375
  description: "Delete a diagram you own. Permanent — confirm with the user first.",