@mermalaid/mcp 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EACL,WAAW,EACX,gBAAgB,GAajB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAGhD,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD;QACE,KAAK,CAAC,kCAAkC,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAA;IACvC,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,EAAU,EAAE,SAAiB;QACvC,KAAK,CAAC,8BAA8B,EAAE,YAAY,SAAS,IAAI,CAAC,CAAA;QAChE,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;IAClC,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAA;IACvC,CAAC;CACF;AAmDD;;;GAGG;AACH,MAAM,OAAO,aAAa;IASK;IARrB,MAAM,GAA4B,IAAI,CAAA;IACtC,UAAU,GAA4B,IAAI,CAAA;IAC1C,YAAY,GAA8B,IAAI,CAAA;IAC9C,MAAM,GAAuB,IAAI,CAAA;IACxB,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAA;IAC7C,OAAO,GAAa,EAAE,CAAA;IACb,oBAAoB,GAAsB,EAAE,CAAA;IAE7D,YAA6B,IAAoB;QAApB,SAAI,GAAJ,IAAI,CAAgB;IAAG,CAAC;IAErD,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,KAAK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A;QAC3B,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,cAAc;QACpB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;YACrB,CAAC,CAAC,OAAO,EAAE,CAAA;QACb,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,QAAQ;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,cAAc,EAAE,IAAI,CAAC,MAAM,KAAK,IAAI;YACpC,YAAY,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI;YACtC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI;SACtC,CAAA;IACH,CAAC;IAED,sEAAsE;IACtE,OAAO;QACL,IAAI,CAAC,cAAc,CAAC,IAAI,uBAAuB,CAAC,sBAAsB,CAAC,CAAC,CAAA;QACxE,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7B,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;YACrB,CAAC,CAAC,MAAM,CAAC,IAAI,uBAAuB,CAAC,sBAAsB,CAAC,CAAC,CAAA;QAC/D,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IACpB,CAAC;CACF"}
@@ -0,0 +1,233 @@
1
+ // Static Mermaid syntax cheat-sheets served by the `get_syntax_reference` tool.
2
+ // Grounding the agent in correct syntax up front means fewer invalid `set_diagram` calls.
3
+ const ENTRIES = [
4
+ {
5
+ type: 'flowchart',
6
+ title: 'Flowchart',
7
+ summary: 'Nodes connected by arrows. Also written as `graph`. Directions: TD/TB, LR, RL, BT.',
8
+ snippet: [
9
+ 'flowchart TD',
10
+ ' A[Start] --> B{Decision?}',
11
+ ' B -->|Yes| C[Do thing]',
12
+ ' B -->|No| D[Other thing]',
13
+ ' C --> E([Rounded end])',
14
+ ' D --> E',
15
+ ' subgraph Group',
16
+ ' C',
17
+ ' end',
18
+ ].join('\n'),
19
+ tips: [
20
+ 'Quote labels containing spaces or special chars: A["Label (with parens)"].',
21
+ 'Node shapes: [rect], (round), ([stadium]), [[subroutine]], [(cylinder)], {diamond}, {{hexagon}}.',
22
+ 'Edges: --> arrow, --- line, -.-> dotted, ==> thick, -->|label| labelled.',
23
+ 'Subgraphs end with `end` (never `end sub`).',
24
+ ],
25
+ },
26
+ {
27
+ type: 'sequence',
28
+ title: 'Sequence diagram',
29
+ summary: 'Actors exchanging messages over time.',
30
+ snippet: [
31
+ 'sequenceDiagram',
32
+ ' participant A as Alice',
33
+ ' participant B as Bob',
34
+ ' A->>B: Solid arrow (call)',
35
+ ' B-->>A: Dashed arrow (return)',
36
+ ' Note over A,B: A note spanning both',
37
+ ' loop Every minute',
38
+ ' A->>B: Ping',
39
+ ' end',
40
+ ' alt is ok',
41
+ ' B->>A: Yes',
42
+ ' else not ok',
43
+ ' B->>A: No',
44
+ ' end',
45
+ ].join('\n'),
46
+ tips: [
47
+ 'Arrows: ->> solid, -->> dashed, -x with cross, use +/- for activations (A->>+B, B-->>-A).',
48
+ 'Blocks: loop, alt/else, opt, par/and, critical, break — each closed by `end`.',
49
+ ],
50
+ },
51
+ {
52
+ type: 'class',
53
+ title: 'Class diagram',
54
+ summary: 'Classes, members, and relationships.',
55
+ snippet: [
56
+ 'classDiagram',
57
+ ' class Animal {',
58
+ ' +String name',
59
+ ' +int age',
60
+ ' +makeSound() void',
61
+ ' }',
62
+ ' class Dog',
63
+ ' Animal <|-- Dog : inherits',
64
+ ' Animal "1" o-- "many" Leg : has',
65
+ ].join('\n'),
66
+ tips: [
67
+ 'Relations: <|-- inheritance, *-- composition, o-- aggregation, --> association, ..> dependency.',
68
+ 'Visibility: + public, - private, # protected, ~ package.',
69
+ 'Cardinality in quotes: "1", "0..*", "many".',
70
+ ],
71
+ },
72
+ {
73
+ type: 'state',
74
+ title: 'State diagram',
75
+ summary: 'States and transitions. Use `stateDiagram-v2`.',
76
+ snippet: [
77
+ 'stateDiagram-v2',
78
+ ' [*] --> Idle',
79
+ ' Idle --> Running : start',
80
+ ' Running --> Idle : stop',
81
+ ' Running --> [*] : shutdown',
82
+ ' state Running {',
83
+ ' [*] --> Working',
84
+ ' Working --> Paused : pause',
85
+ ' }',
86
+ ].join('\n'),
87
+ tips: [
88
+ '[*] marks start and end states.',
89
+ 'Composite states use `state Name { ... }`.',
90
+ 'Choice/fork/join via `state x <<choice>>` etc.',
91
+ ],
92
+ },
93
+ {
94
+ type: 'er',
95
+ title: 'Entity relationship diagram',
96
+ summary: 'Entities and their relationships with crow’s-foot cardinality.',
97
+ snippet: [
98
+ 'erDiagram',
99
+ ' CUSTOMER ||--o{ ORDER : places',
100
+ ' ORDER ||--|{ LINE_ITEM : contains',
101
+ ' CUSTOMER {',
102
+ ' string name',
103
+ ' string email',
104
+ ' }',
105
+ ].join('\n'),
106
+ tips: [
107
+ 'Cardinality: || one-and-only-one, o{ zero-or-many, |{ one-or-many, o| zero-or-one.',
108
+ 'Left/right symbols mirror each other around the -- line.',
109
+ ],
110
+ },
111
+ {
112
+ type: 'gantt',
113
+ title: 'Gantt chart',
114
+ summary: 'Project schedule with tasks and dates.',
115
+ snippet: [
116
+ 'gantt',
117
+ ' title Project plan',
118
+ ' dateFormat YYYY-MM-DD',
119
+ ' section Design',
120
+ ' Research :a1, 2024-01-01, 7d',
121
+ ' Mockups :after a1, 5d',
122
+ ' section Build',
123
+ ' Implement :2024-01-15, 10d',
124
+ ].join('\n'),
125
+ tips: [
126
+ 'Task syntax: name :id, start, duration (e.g. 5d) or `after <id>`.',
127
+ 'States: done, active, crit prefix the task, e.g. `:crit, active, ...`.',
128
+ ],
129
+ },
130
+ {
131
+ type: 'pie',
132
+ title: 'Pie chart',
133
+ summary: 'Proportional slices.',
134
+ snippet: ['pie title Browser share', ' "Chrome" : 65', ' "Safari" : 20', ' "Other" : 15'].join('\n'),
135
+ tips: ['Each slice is a quoted label and a number.', 'Add `showData` after `pie` to print values.'],
136
+ },
137
+ {
138
+ type: 'mindmap',
139
+ title: 'Mindmap',
140
+ summary: 'Indentation-based hierarchy from a root.',
141
+ snippet: [
142
+ 'mindmap',
143
+ ' root((Central idea))',
144
+ ' Branch A',
145
+ ' Leaf 1',
146
+ ' Leaf 2',
147
+ ' Branch B',
148
+ ' Leaf 3',
149
+ ].join('\n'),
150
+ tips: ['Hierarchy is set purely by indentation.', 'Root shapes: ((circle)), [square], (rounded)).'],
151
+ },
152
+ {
153
+ type: 'journey',
154
+ title: 'User journey',
155
+ summary: 'Steps scored by sentiment across sections.',
156
+ snippet: [
157
+ 'journey',
158
+ ' title My working day',
159
+ ' section Morning',
160
+ ' Wake up: 3: Me',
161
+ ' Commute: 2: Me',
162
+ ' section Office',
163
+ ' Standup: 4: Me, Team',
164
+ ].join('\n'),
165
+ tips: ['Step syntax: `Task: <score 1-5>: <actors>`.'],
166
+ },
167
+ {
168
+ type: 'gitgraph',
169
+ title: 'Git graph',
170
+ summary: 'Branch/commit/merge history.',
171
+ snippet: [
172
+ 'gitGraph',
173
+ ' commit',
174
+ ' branch develop',
175
+ ' checkout develop',
176
+ ' commit',
177
+ ' checkout main',
178
+ ' merge develop',
179
+ ].join('\n'),
180
+ tips: ['Commands: commit, branch <name>, checkout <name>, merge <name>, cherry-pick.'],
181
+ },
182
+ ];
183
+ // Additional diagram types Mermaid supports that aren't given a full cheat-sheet here.
184
+ const ADDITIONAL_TYPES = [
185
+ 'timeline',
186
+ 'quadrantChart',
187
+ 'requirementDiagram',
188
+ 'c4',
189
+ 'sankey-beta',
190
+ 'xychart-beta',
191
+ 'block-beta',
192
+ 'packet-beta',
193
+ 'kanban',
194
+ 'architecture-beta',
195
+ ];
196
+ const ALIASES = {
197
+ graph: 'flowchart',
198
+ flow: 'flowchart',
199
+ flowchart: 'flowchart',
200
+ sequence: 'sequence',
201
+ sequencediagram: 'sequence',
202
+ class: 'class',
203
+ classdiagram: 'class',
204
+ state: 'state',
205
+ statediagram: 'state',
206
+ statediagramv2: 'state',
207
+ er: 'er',
208
+ erdiagram: 'er',
209
+ entity: 'er',
210
+ gantt: 'gantt',
211
+ pie: 'pie',
212
+ mindmap: 'mindmap',
213
+ journey: 'journey',
214
+ userjourney: 'journey',
215
+ git: 'gitgraph',
216
+ gitgraph: 'gitgraph',
217
+ };
218
+ export function normalizeDiagramType(input) {
219
+ return input.trim().toLowerCase().replace(/[\s_-]+/g, '');
220
+ }
221
+ export function getSyntaxEntry(type) {
222
+ const key = ALIASES[normalizeDiagramType(type)];
223
+ if (!key)
224
+ return null;
225
+ return ENTRIES.find((e) => e.type === key) ?? null;
226
+ }
227
+ export function getSyntaxIndex() {
228
+ return {
229
+ documented: ENTRIES.map((e) => ({ type: e.type, title: e.title, summary: e.summary })),
230
+ additionalTypes: ADDITIONAL_TYPES,
231
+ };
232
+ }
233
+ //# sourceMappingURL=syntaxReference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntaxReference.js","sourceRoot":"","sources":["../src/syntaxReference.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,0FAA0F;AAU1F,MAAM,OAAO,GAAkB;IAC7B;QACE,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW;QAClB,OAAO,EAAE,oFAAoF;QAC7F,OAAO,EAAE;YACP,cAAc;YACd,+BAA+B;YAC/B,4BAA4B;YAC5B,8BAA8B;YAC9B,4BAA4B;YAC5B,aAAa;YACb,oBAAoB;YACpB,WAAW;YACX,SAAS;SACV,CAAC,IAAI,CAAC,IAAI,CAAC;QACZ,IAAI,EAAE;YACJ,4EAA4E;YAC5E,kGAAkG;YAClG,0EAA0E;YAC1E,6CAA6C;SAC9C;KAC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AAA;IACrB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,cAAc;IAI5B,OAAO;QACL,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACtF,eAAe,EAAE,gBAAgB;KAClC,CAAA;AACH,CAAC"}
package/dist/tools.js ADDED
@@ -0,0 +1,219 @@
1
+ import { z } from 'zod';
2
+ import { formatPairingCode } from './pairing.js';
3
+ import { BridgeNotConnectedError, BridgeTimeoutError, } from './session.js';
4
+ import { getSyntaxEntry, getSyntaxIndex } from './syntaxReference.js';
5
+ function json(value) {
6
+ return { content: [{ type: 'text', text: JSON.stringify(value, null, 2) }] };
7
+ }
8
+ function errorText(text) {
9
+ return { content: [{ type: 'text', text }], isError: true };
10
+ }
11
+ /** Shared result shape for tools that apply a diagram and report post-apply validity. */
12
+ function applyResultJson(res, invalidNote) {
13
+ return res.valid
14
+ ? json({ ok: true, revision: res.rev, valid: true })
15
+ : json({ ok: true, revision: res.rev, valid: false, error: res.error, note: invalidNote });
16
+ }
17
+ function pairingInstructions(ctx) {
18
+ return [
19
+ 'No Mermalaid editor is connected yet. Ask the user to:',
20
+ ' 1. Open Mermalaid — the desktop app, or https://mermalaid.com/editor in Chrome/Edge (a local dev server works too).',
21
+ ' 2. Click the "AI Agent" button in the toolbar.',
22
+ ` 3. Enter the pairing code: ${formatPairingCode(ctx.pairingCode)}`,
23
+ 'Then retry this tool.',
24
+ ].join('\n');
25
+ }
26
+ function toToolError(err, ctx) {
27
+ if (err instanceof BridgeNotConnectedError)
28
+ return errorText(pairingInstructions(ctx));
29
+ if (err instanceof BridgeTimeoutError) {
30
+ return errorText(`The editor did not respond in time (${err.message}). It may be busy, mid-render, or disconnected — try again in a moment.`);
31
+ }
32
+ return errorText(`Bridge error: ${err instanceof Error ? err.message : String(err)}`);
33
+ }
34
+ /** Register the milestone-1 tool surface (status / pairing / read / write). */
35
+ export function registerTools(server, ctx) {
36
+ server.registerTool('get_connection_status', {
37
+ title: 'Get connection status',
38
+ description: 'Check whether a Mermalaid editor is connected and paired with this agent. When not paired, the response includes the pairing code to give the user.',
39
+ inputSchema: {},
40
+ annotations: { readOnlyHint: true, openWorldHint: false },
41
+ }, async () => {
42
+ const st = ctx.session.status();
43
+ return json({
44
+ paired: st.paired,
45
+ editor: st.editorInfo,
46
+ pairingCode: st.paired ? undefined : formatPairingCode(ctx.pairingCode),
47
+ bridgePort: ctx.port,
48
+ lastKnownRevision: st.lastRevision,
49
+ lastKnownValid: st.lastValid,
50
+ });
51
+ });
52
+ server.registerTool('get_pairing_code', {
53
+ title: 'Get pairing code',
54
+ description: "Return the pairing code the user must type into Mermalaid's AI Agent panel to connect the live editor to this agent. Tell the user this code.",
55
+ inputSchema: {},
56
+ annotations: { readOnlyHint: true, openWorldHint: false },
57
+ }, async () => json({
58
+ pairingCode: formatPairingCode(ctx.pairingCode),
59
+ bridgePort: ctx.port,
60
+ instructions: 'In Mermalaid, click the "AI Agent" button in the toolbar and enter this code to connect the live editor.',
61
+ }));
62
+ server.registerTool('wait_for_editor', {
63
+ title: 'Wait for editor to connect',
64
+ description: 'Block until a Mermalaid editor connects and pairs, or until the timeout elapses. Use right after telling the user the pairing code.',
65
+ inputSchema: {
66
+ timeoutMs: z
67
+ .number()
68
+ .int()
69
+ .positive()
70
+ .max(600_000)
71
+ .optional()
72
+ .describe('How long to wait for the editor to pair. Default 120000 (2 min).'),
73
+ },
74
+ annotations: { readOnlyHint: true, openWorldHint: false },
75
+ }, async ({ timeoutMs }) => {
76
+ try {
77
+ await ctx.session.waitForEditor(timeoutMs ?? 120_000);
78
+ const st = ctx.session.status();
79
+ return json({ paired: true, editor: st.editorInfo });
80
+ }
81
+ catch {
82
+ return errorText(`No editor paired within the timeout.\n\n${pairingInstructions(ctx)}`);
83
+ }
84
+ });
85
+ server.registerTool('get_diagram', {
86
+ title: 'Get current diagram',
87
+ description: 'Read the current Mermaid source from the connected editor, plus whether it currently renders without errors. Served from the live cache; pass fresh=true to force a round-trip.',
88
+ inputSchema: {
89
+ fresh: z
90
+ .boolean()
91
+ .optional()
92
+ .describe('Force a fresh read from the editor instead of the cached last-known state.'),
93
+ },
94
+ annotations: { readOnlyHint: true, openWorldHint: false },
95
+ }, async ({ fresh }) => {
96
+ try {
97
+ const d = await ctx.session.getDiagram(fresh ?? false);
98
+ return json({ code: d.code, revision: d.rev, valid: d.valid, error: d.error });
99
+ }
100
+ catch (err) {
101
+ return toToolError(err, ctx);
102
+ }
103
+ });
104
+ server.registerTool('set_diagram', {
105
+ title: 'Set diagram',
106
+ description: "Replace the entire Mermaid diagram in the connected editor. The change appears live in the user's editor. Returns whether the new diagram renders without errors — if not, fix the syntax and call again.",
107
+ inputSchema: {
108
+ code: z.string().describe('The full Mermaid diagram source to place in the editor.'),
109
+ reason: z
110
+ .string()
111
+ .optional()
112
+ .describe('Short human-readable note about the change (may be shown to the user).'),
113
+ },
114
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
115
+ }, async ({ code, reason }) => {
116
+ try {
117
+ const res = await ctx.session.setDiagram(code, reason);
118
+ return applyResultJson(res, 'The diagram was placed in the editor but does not render yet. Fix the error and call set_diagram again.');
119
+ }
120
+ catch (err) {
121
+ return toToolError(err, ctx);
122
+ }
123
+ });
124
+ server.registerTool('append_to_diagram', {
125
+ title: 'Append to diagram',
126
+ description: 'Append text to the end of the current diagram (e.g. add a node or edge) without resending the whole source. Reads the current diagram, appends, and applies it live. Returns post-apply validity.',
127
+ inputSchema: {
128
+ content: z.string().describe('Text to append to the end of the current Mermaid source.'),
129
+ separator: z
130
+ .string()
131
+ .optional()
132
+ .describe('Separator between the existing source and the appended text. Default is a newline.'),
133
+ },
134
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
135
+ }, async ({ content, separator }) => {
136
+ try {
137
+ const current = await ctx.session.getDiagram(true);
138
+ const base = current.code.replace(/\n+$/, '');
139
+ const combined = base.length ? `${base}${separator ?? '\n'}${content}` : content;
140
+ const res = await ctx.session.setDiagram(combined, 'append');
141
+ return applyResultJson(res, 'Appended, but the diagram does not render yet. Fix the error and try again.');
142
+ }
143
+ catch (err) {
144
+ return toToolError(err, ctx);
145
+ }
146
+ });
147
+ server.registerTool('validate_diagram', {
148
+ title: 'Validate diagram',
149
+ description: "Check whether Mermaid source is syntactically valid, using the connected editor's Mermaid engine. Validates the given code, or the current diagram when code is omitted.",
150
+ inputSchema: {
151
+ code: z
152
+ .string()
153
+ .optional()
154
+ .describe('Mermaid source to validate. Omit to validate the current diagram.'),
155
+ },
156
+ annotations: { readOnlyHint: true, openWorldHint: false },
157
+ }, async ({ code }) => {
158
+ try {
159
+ const res = await ctx.session.validate(code);
160
+ return json({ valid: res.valid, error: res.error, diagramType: res.diagramType ?? null });
161
+ }
162
+ catch (err) {
163
+ return toToolError(err, ctx);
164
+ }
165
+ });
166
+ server.registerTool('render_diagram', {
167
+ title: 'Render diagram',
168
+ description: 'Render the diagram to an image via the connected editor so you can see the result. PNG returns an image you can view; SVG returns markup. Renders the given code, or the current diagram when omitted.',
169
+ inputSchema: {
170
+ code: z.string().optional().describe('Mermaid source to render. Omit to render the current diagram.'),
171
+ format: z.enum(['svg', 'png']).optional().describe('Output format. Default png.'),
172
+ scale: z.number().min(1).max(4).optional().describe('PNG scale factor (1–4). Default 2.'),
173
+ theme: z.string().optional().describe('Optional Mermaid theme, e.g. "dark".'),
174
+ },
175
+ annotations: { readOnlyHint: true, openWorldHint: false },
176
+ }, async ({ code, format, scale, theme }) => {
177
+ const fmt = format ?? 'png';
178
+ try {
179
+ const res = await ctx.session.render(fmt, { code, scale, theme });
180
+ if (!res.ok)
181
+ return errorText(`Render failed: ${res.error ?? 'unknown error'}`);
182
+ if (fmt === 'svg') {
183
+ return { content: [{ type: 'text', text: res.data }] };
184
+ }
185
+ return {
186
+ content: [
187
+ { type: 'image', data: res.data, mimeType: res.mimeType },
188
+ { type: 'text', text: `Rendered ${res.width ?? '?'}×${res.height ?? '?'}px PNG.` },
189
+ ],
190
+ };
191
+ }
192
+ catch (err) {
193
+ return toToolError(err, ctx);
194
+ }
195
+ });
196
+ server.registerTool('get_syntax_reference', {
197
+ title: 'Get Mermaid syntax reference',
198
+ description: 'Get a concise Mermaid syntax cheat-sheet for a diagram type (flowchart, sequence, class, state, er, gantt, pie, mindmap, journey, gitgraph). Omit diagramType for the index of available types. Use this before authoring a diagram to avoid syntax errors. Answered locally — no editor needed.',
199
+ inputSchema: {
200
+ diagramType: z
201
+ .string()
202
+ .optional()
203
+ .describe('Diagram type, e.g. "flowchart" or "sequence". Omit for the index.'),
204
+ },
205
+ annotations: { readOnlyHint: true, openWorldHint: false },
206
+ }, async ({ diagramType }) => {
207
+ if (!diagramType)
208
+ return json(getSyntaxIndex());
209
+ const entry = getSyntaxEntry(diagramType);
210
+ if (!entry) {
211
+ return json({
212
+ error: `No cheat-sheet for "${diagramType}".`,
213
+ ...getSyntaxIndex(),
214
+ });
215
+ }
216
+ return json(entry);
217
+ });
218
+ }
219
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GAEnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAQrE,SAAS,IAAI,CAAC,KA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AK,EAAE;KAC1D,EACD,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;QACxB,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC,CAAA;QAC/C,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC,CAAA;QACzC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;gBACV,KAAK,EAAE,uBAAuB,WAAW,IAAI;gBAC7C,GAAG,cAAc,EAAE;aACpB,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC,CACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,133 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { WebSocketServer } from 'ws';
3
+ import { MessageType, PROTOCOL_VERSION, parseBridgeMessage, serializeBridgeMessage, } from './protocol.js';
4
+ function isAddrInUse(err) {
5
+ return (!!err &&
6
+ typeof err === 'object' &&
7
+ err.code === 'EADDRINUSE');
8
+ }
9
+ /**
10
+ * Hosts the localhost WebSocket the Mermalaid editor connects to. Owns the raw `ws`
11
+ * sockets, enforces the Origin allowlist at the upgrade, runs the ping/pong heartbeat,
12
+ * and forwards parsed messages to the session. Bound to loopback only.
13
+ */
14
+ export class BridgeWsServer {
15
+ opts;
16
+ handlers;
17
+ wss = null;
18
+ heartbeat = null;
19
+ conns = new Map();
20
+ port = 0;
21
+ constructor(opts, handlers) {
22
+ this.opts = opts;
23
+ this.handlers = handlers;
24
+ }
25
+ /** Bind the first available port from `opts.ports`. Returns the chosen port. */
26
+ async start() {
27
+ let lastErr;
28
+ for (const port of this.opts.ports) {
29
+ try {
30
+ this.wss = await this.listen(this.opts.host, port);
31
+ const addr = this.wss.address();
32
+ this.port = addr && typeof addr === 'object' ? addr.port : port;
33
+ this.wss.on('connection', (socket, req) => this.onConnection(socket, req));
34
+ this.startHeartbeat();
35
+ return this.port;
36
+ }
37
+ catch (err) {
38
+ lastErr = err;
39
+ if (!isAddrInUse(err))
40
+ throw err;
41
+ }
42
+ }
43
+ throw lastErr ?? new Error('No configured bridge port could be bound');
44
+ }
45
+ listen(host, port) {
46
+ return new Promise((resolve, reject) => {
47
+ const wss = new WebSocketServer({
48
+ host,
49
+ port,
50
+ maxPayload: this.opts.maxPayloadBytes,
51
+ verifyClient: (info, cb) => {
52
+ const origin = info.origin ?? null;
53
+ if (this.opts.allowOrigin(origin))
54
+ cb(true);
55
+ else
56
+ cb(false, 403, 'Origin not allowed');
57
+ },
58
+ });
59
+ const onError = (err) => {
60
+ wss.off('listening', onListening);
61
+ wss.close(); // release the failed listener (e.g. on EADDRINUSE before the fallback scan)
62
+ reject(err);
63
+ };
64
+ const onListening = () => {
65
+ wss.off('error', onError);
66
+ resolve(wss);
67
+ };
68
+ wss.once('error', onError);
69
+ wss.once('listening', onListening);
70
+ });
71
+ }
72
+ onConnection(socket, req) {
73
+ const conn = {
74
+ id: randomUUID(),
75
+ origin: req.headers.origin ?? null,
76
+ isAlive: true,
77
+ send: (msg) => {
78
+ if (socket.readyState === socket.OPEN)
79
+ socket.send(serializeBridgeMessage(msg));
80
+ },
81
+ close: (code, reason) => socket.close(code, reason),
82
+ };
83
+ this.conns.set(socket, conn);
84
+ socket.on('pong', () => {
85
+ conn.isAlive = true;
86
+ });
87
+ socket.on('message', (data) => {
88
+ const raw = typeof data === 'string' ? data : data.toString('utf8');
89
+ const msg = parseBridgeMessage(raw);
90
+ if (msg)
91
+ this.handlers.onMessage(conn, msg);
92
+ });
93
+ socket.on('close', () => {
94
+ this.conns.delete(socket);
95
+ this.handlers.onClose(conn);
96
+ });
97
+ socket.on('error', () => {
98
+ // A `close` event always follows; nothing to do beyond preventing an unhandled throw.
99
+ });
100
+ }
101
+ startHeartbeat() {
102
+ this.heartbeat = setInterval(() => {
103
+ for (const [socket, conn] of this.conns) {
104
+ if (!conn.isAlive) {
105
+ socket.terminate();
106
+ continue;
107
+ }
108
+ conn.isAlive = false;
109
+ socket.ping();
110
+ // Also send an app-level ping the browser client can observe (native ping frames
111
+ // are invisible to a browser WebSocket) so its inactivity watchdog stays fed.
112
+ conn.send({ v: PROTOCOL_VERSION, type: MessageType.Ping });
113
+ }
114
+ }, this.opts.heartbeatIntervalMs);
115
+ this.heartbeat.unref?.();
116
+ }
117
+ async stop() {
118
+ if (this.heartbeat) {
119
+ clearInterval(this.heartbeat);
120
+ this.heartbeat = null;
121
+ }
122
+ for (const socket of this.conns.keys())
123
+ socket.terminate();
124
+ this.conns.clear();
125
+ await new Promise((resolve) => {
126
+ if (!this.wss)
127
+ return resolve();
128
+ this.wss.close(() => resolve());
129
+ });
130
+ this.wss = null;
131
+ }
132
+ }
133
+ //# sourceMappingURL=wsServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsServer.js","sourceRoot":"","sources":["../src/wsServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,eAAe,EAAkB,MAAM,IAAI,CAAA;AACpD,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,GAGvB,MAAM,eAAe,CAAA;AA2BtB,SAAS,WAAW,CAAC,GAAY;IAC/B,OAAO,CACL,CAAC,CAAC,GAAG;QACL,OAAO,GAAG,KAAK,QAAQ;QACtB,GAA6B,CAAC,IAAI,KAAK,YAAY,CACrD,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAON;IACA;IAPX,GAAG,GAA2B,IAAI,CAAA;IAClC,SAAS,GAA0C,IAAI,CAAA;IAC9C,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAA;IAC/D,IAAI,GAAG,CAAC,CAAA;IAER,YACmB,IAAqB,EACrB,QAA0B;QAD1B,SAAI,GAAJ,IAAI,CAAiB;QACrB,aAAQ,GAAR,QAAQ,CAAkB;IAC1C,CAAC;IAEJ,gFAAgF;IAChF,KAAK,CAAC,KAAK;QACT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