@hiabhee/archdraw-mcp-server 1.0.2 → 1.0.5
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.
- package/dist/index.js +5 -742
- package/dist/index.js.map +1 -1
- package/dist/lib/checkpoints.d.ts +4 -0
- package/dist/lib/checkpoints.d.ts.map +1 -1
- package/dist/lib/checkpoints.js +14 -1
- package/dist/lib/checkpoints.js.map +1 -1
- package/dist/lib/diagram-state.d.ts +1 -0
- package/dist/lib/diagram-state.d.ts.map +1 -1
- package/dist/lib/diagram-state.js +5 -2
- package/dist/lib/diagram-state.js.map +1 -1
- package/dist/lib/http.d.ts +12 -0
- package/dist/lib/http.d.ts.map +1 -1
- package/dist/lib/http.js +11 -1
- package/dist/lib/http.js.map +1 -1
- package/dist/lib/preview-links.d.ts +20 -0
- package/dist/lib/preview-links.d.ts.map +1 -0
- package/dist/lib/preview-links.js +22 -0
- package/dist/lib/preview-links.js.map +1 -0
- package/dist/lib/schema.js +2 -2
- package/dist/lib/schema.js.map +1 -1
- package/dist/server.d.ts +32 -34
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +739 -141
- package/dist/server.js.map +1 -1
- package/dist/tools/apply-template.d.ts +1 -0
- package/dist/tools/apply-template.d.ts.map +1 -1
- package/dist/tools/apply-template.js +16 -8
- package/dist/tools/apply-template.js.map +1 -1
- package/dist/tools/export-diagram.d.ts +1 -1
- package/dist/tools/export-diagram.d.ts.map +1 -1
- package/dist/tools/export-diagram.js +6 -6
- package/dist/tools/export-diagram.js.map +1 -1
- package/dist/tools/fix-layout.js +2 -2
- package/dist/tools/fix-layout.js.map +1 -1
- package/dist/tools/generate-diagram.d.ts +2 -0
- package/dist/tools/generate-diagram.d.ts.map +1 -1
- package/dist/tools/generate-diagram.js +29 -211
- package/dist/tools/generate-diagram.js.map +1 -1
- package/dist/tools/read-me.js +1 -1
- package/dist/tools/update-diagram.d.ts +1 -0
- package/dist/tools/update-diagram.d.ts.map +1 -1
- package/dist/tools/update-diagram.js +5 -4
- package/dist/tools/update-diagram.js.map +1 -1
- package/dist/types/index.d.ts +0 -31
- package/dist/types/index.d.ts.map +1 -1
- package/dist/ui/diagram-widget.d.ts +3 -0
- package/dist/ui/diagram-widget.d.ts.map +1 -0
- package/dist/ui/diagram-widget.html +282 -0
- package/dist/ui/diagram-widget.js +4 -0
- package/dist/ui/diagram-widget.js.map +1 -0
- package/package.json +15 -4
- package/dist/lib/__tests__/constants.test.d.ts +0 -2
- package/dist/lib/__tests__/constants.test.d.ts.map +0 -1
- package/dist/lib/__tests__/constants.test.js +0 -47
- package/dist/lib/__tests__/constants.test.js.map +0 -1
- package/dist/lib/__tests__/diagram-state.test.d.ts +0 -2
- package/dist/lib/__tests__/diagram-state.test.d.ts.map +0 -1
- package/dist/lib/__tests__/diagram-state.test.js +0 -82
- package/dist/lib/__tests__/diagram-state.test.js.map +0 -1
- package/dist/lib/__tests__/elk-runner.test.d.ts +0 -2
- package/dist/lib/__tests__/elk-runner.test.d.ts.map +0 -1
- package/dist/lib/__tests__/elk-runner.test.js +0 -87
- package/dist/lib/__tests__/elk-runner.test.js.map +0 -1
- package/dist/lib/elk-runner.d.ts +0 -29
- package/dist/lib/elk-runner.d.ts.map +0 -1
- package/dist/lib/elk-runner.js +0 -532
- package/dist/lib/elk-runner.js.map +0 -1
- package/dist/lib/prompt-builder.d.ts +0 -14
- package/dist/lib/prompt-builder.d.ts.map +0 -1
- package/dist/lib/prompt-builder.js +0 -133
- package/dist/lib/prompt-builder.js.map +0 -1
- package/dist/tools/__tests__/export-diagram.test.d.ts +0 -2
- package/dist/tools/__tests__/export-diagram.test.d.ts.map +0 -1
- package/dist/tools/__tests__/export-diagram.test.js +0 -40
- package/dist/tools/__tests__/export-diagram.test.js.map +0 -1
- package/dist/tools/__tests__/update-diagram.test.d.ts +0 -2
- package/dist/tools/__tests__/update-diagram.test.d.ts.map +0 -1
- package/dist/tools/__tests__/update-diagram.test.js +0 -98
- package/dist/tools/__tests__/update-diagram.test.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,745 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { getReadMe } from './tools/read-me.js';
|
|
11
|
-
import { getDiagramState } from './lib/diagram-state.js';
|
|
12
|
-
import { validateDiagram } from './tools/validate-diagram.js';
|
|
13
|
-
import { updateDiagram } from './tools/update-diagram.js';
|
|
14
|
-
import { saveCheckpoint } from './tools/save-checkpoint.js';
|
|
15
|
-
import { loadCheckpoint } from './tools/load-checkpoint.js';
|
|
16
|
-
import { exportDiagram } from './tools/export-diagram.js';
|
|
17
|
-
import { GenerateDiagramInputSchema, FixLayoutInputSchema, ListNodeTypesInputSchema, ApplyTemplateInputSchema, UpdateDiagramInputSchema, SaveCheckpointInputSchema, LoadCheckpointInputSchema, ExportDiagramInputSchema, } from './lib/schema.js';
|
|
18
|
-
const TOOLS = [
|
|
19
|
-
{
|
|
20
|
-
name: 'generate_diagram',
|
|
21
|
-
description: `Generate a rich architecture diagram with groups, labeled edges, and visual hierarchy.
|
|
22
|
-
|
|
23
|
-
**IMPORTANT**: When this tool returns a 'diagramUrl', tell the user to open that URL in their browser.
|
|
24
|
-
|
|
25
|
-
**INPUT MODES — choose ONE**:
|
|
26
|
-
|
|
27
|
-
**Mode 1 (RECOMMENDED): Mermaid code** — pass a \`graph LR\` / \`graph TD\` diagram in \`mermaid\`.
|
|
28
|
-
This runs the same parser + layout engine the web editor uses, so output is guaranteed to match the product.
|
|
29
|
-
Example:
|
|
30
|
-
graph LR
|
|
31
|
-
subgraph client["Client Tier"]
|
|
32
|
-
Web[Web App]
|
|
33
|
-
Mobile[Mobile App]
|
|
34
|
-
end
|
|
35
|
-
subgraph edge["API Gateway Tier"]
|
|
36
|
-
GW[API Gateway]
|
|
37
|
-
end
|
|
38
|
-
subgraph data["Data Tier"]
|
|
39
|
-
DB[("PostgreSQL")]
|
|
40
|
-
end
|
|
41
|
-
Web --> GW
|
|
42
|
-
Mobile --> GW
|
|
43
|
-
GW --> DB
|
|
44
|
-
Use \`direction\` to pick LR (default) or TD. Any graph \`graph TD\` implies top-down.
|
|
45
|
-
The web parser runs Mermaid → React Flow → Dagre layout, so positions come out clean automatically.
|
|
46
|
-
Optional directives like \`%% archdraw-shape: {"id":"<id>","shape":"shield"}\` are supported for non-native shapes.
|
|
47
|
-
|
|
48
|
-
**Mode 2 (compatibility): Structured JSON** — pass \`nodes\` and \`edges\` arrays (schemas below). ArchDraw converts this input to Mermaid and uses the same editor pipeline.
|
|
49
|
-
|
|
50
|
-
**ALWAYS ALSO PASS** (when you have them):
|
|
51
|
-
- \`userPrompt\`: the user's request verbatim — node subtitles must reflect any tech stack they named.
|
|
52
|
-
- \`techStack\`: explicit list of technologies (["Next.js", "PostgreSQL 15", "Redis"]).
|
|
53
|
-
- \`customFeatures\`: features the user explicitly asked for.
|
|
54
|
-
|
|
55
|
-
**Architecture guidance, not hard rules:** use groups and concise labels where they help comprehension. Model only the components and flows supported by the user’s context. Gateways, event brokers, direct client streams, and domain-specific services are valid when the architecture calls for them.
|
|
56
|
-
|
|
57
|
-
**Privacy:** diagrams stay in this MCP session by default. Set \`publish:true\` only after the user explicitly asks for a browser-accessible link. Retain and resend \`workingSessionId\` from the result when working on more than one diagram in parallel.
|
|
58
|
-
|
|
59
|
-
**WORKFLOW**:
|
|
60
|
-
1. Identify the user’s actual domain and constraints
|
|
61
|
-
2. Model only supported components and relationships
|
|
62
|
-
3. Optionally call list_node_types to find icon names
|
|
63
|
-
4. Design the Mermaid graph: groups (subgraphs) first, then children inside them
|
|
64
|
-
5. Design edges: use correct communicationType, audit Auth Service edges, verify no security bypass
|
|
65
|
-
6. **EDGE AUDIT (mandatory)**: Before calling this tool, scan every edge you planned:
|
|
66
|
-
- Does any edge have a client-tier node as the TARGET? DELETE IT (unless both source and target are client tier)
|
|
67
|
-
- Does any single node receive >45% of all edges? That node is a hub -- redistribute connections
|
|
68
|
-
- Do all edges flow LEFT->RIGHT (lower tier -> higher tier)? If not, fix direction.
|
|
69
|
-
7. Call this tool
|
|
70
|
-
|
|
71
|
-
**NODE FIELDS (JSON mode)**:
|
|
72
|
-
- id (required): snake_case unique ID
|
|
73
|
-
- label (required): 1-3 word display name
|
|
74
|
-
- tier (required): client | edge | compute | async | data | external | observe
|
|
75
|
-
- subtitle (required): specific description of what this service does
|
|
76
|
-
- isGroup: true = swimlane container wrapping child nodes
|
|
77
|
-
- parentId: ID of parent group (places this node inside that group)
|
|
78
|
-
- groupColor: hex background tint for group containers
|
|
79
|
-
- icon: lucide icon name (box, server, database, zap, shield, globe, etc.)
|
|
80
|
-
- accentColor: override highlight color (15 palette options)
|
|
81
|
-
- status: healthy | warning | error | unknown
|
|
82
|
-
- width/height: pixel size (groups: 400-800px wide, 200-400px tall)
|
|
83
|
-
|
|
84
|
-
**EDGE FIELDS (JSON mode)**:
|
|
85
|
-
- source, target (required): node IDs
|
|
86
|
-
- communicationType: sync | async | stream | event | dep
|
|
87
|
-
- label: required for async/stream/event — name the message or event
|
|
88
|
-
- pathType: Smoothstep | bezier | step | straight
|
|
89
|
-
|
|
90
|
-
**TIER COLORS**:
|
|
91
|
-
- client: #64748b (slate) — browsers, mobile apps
|
|
92
|
-
- edge: #6366f1 (indigo) — API gateways, load balancers, CDN
|
|
93
|
-
- compute: #0d9488 (teal) — microservices, workers, APIs
|
|
94
|
-
- async: #d97706 (amber) — queues, event buses, Kafka
|
|
95
|
-
- data: #3b82f6 (blue) — databases, caches, object storage
|
|
96
|
-
- external: #8b5cf6 (violet) — third-party APIs, payment gateways
|
|
97
|
-
- observe: #6b7280 (gray) — monitoring, logging, tracing`,
|
|
98
|
-
inputSchema: {
|
|
99
|
-
type: 'object',
|
|
100
|
-
properties: {
|
|
101
|
-
mermaid: {
|
|
102
|
-
type: 'string',
|
|
103
|
-
description: 'RECOMMENDED: Mermaid code for the diagram (graph LR or graph TD with subgraphs). Uses the web pipeline parser + Dagre layout.',
|
|
104
|
-
},
|
|
105
|
-
nodes: {
|
|
106
|
-
type: 'array',
|
|
107
|
-
description: 'Legacy JSON mode (only if not using mermaid). Array of nodes. RULES: (1) every node needs id+label+tier+subtitle, (2) include at least one isGroup:true node, (3) use parentId to nest nodes inside groups, (4) use accentColor to visually differentiate nodes in the same tier.',
|
|
108
|
-
items: {
|
|
109
|
-
type: 'object',
|
|
110
|
-
properties: {
|
|
111
|
-
id: { type: 'string', description: 'Unique snake_case identifier (e.g. "api_gateway", "postgres_db")' },
|
|
112
|
-
label: { type: 'string', description: 'Short display name (1-3 words)' },
|
|
113
|
-
tier: { type: 'string', description: 'Tier: client | edge | compute | async | data | external | observe' },
|
|
114
|
-
layer: { type: 'string', description: 'Alias for tier' },
|
|
115
|
-
subtitle: { type: 'string', description: 'REQUIRED: Specific description (e.g. "PostgreSQL 15, stores orders and users")' },
|
|
116
|
-
isGroup: { type: 'boolean', description: 'true = swimlane container. Use to cluster related services.' },
|
|
117
|
-
parentId: { type: 'string', description: 'ID of parent group — places this node inside that group' },
|
|
118
|
-
groupColor: { type: 'string', description: 'Background hex for group containers (e.g. "#0f172a")' },
|
|
119
|
-
icon: { type: 'string', description: 'Lucide icon name (server, database, zap, globe, shield, cpu, activity, box, cloud, layers, user, lock, wifi)' },
|
|
120
|
-
tierColor: { type: 'string', description: 'Override tier color hex' },
|
|
121
|
-
accentColor: { type: 'string', description: 'Highlight color: #3b82f6 #0ea5e9 #06b6d4 #14b8a6 #22c55e #f59e0b #f97316 #ef4444 #ec4899 #6b7280 #f43f5e #a855f7 #84cc16 #fb923c' },
|
|
122
|
-
status: { type: 'string', enum: ['healthy', 'warning', 'error', 'unknown'], description: 'Status dot shown on node' },
|
|
123
|
-
width: { type: 'number', description: 'Width px. Groups: 400-800. Nodes: 160-260.' },
|
|
124
|
-
height: { type: 'number', description: 'Height px. Groups: 200-400. Nodes: 60-90.' },
|
|
125
|
-
shape: { type: 'string', enum: ['rectangle', 'diamond', 'ellipse', 'hexagon'], description: 'Node shape' },
|
|
126
|
-
},
|
|
127
|
-
required: ['id', 'label', 'tier', 'subtitle'],
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
edges: {
|
|
131
|
-
type: 'array',
|
|
132
|
-
description: 'Legacy JSON mode (only if not using mermaid). Array of edges. REQUIRED. Add labels to all async/event/stream edges. Do not connect data tier directly to client tier.',
|
|
133
|
-
items: {
|
|
134
|
-
type: 'object',
|
|
135
|
-
properties: {
|
|
136
|
-
id: { type: 'string', description: 'Unique edge identifier' },
|
|
137
|
-
source: { type: 'string', description: 'Source node ID' },
|
|
138
|
-
target: { type: 'string', description: 'Target node ID' },
|
|
139
|
-
communicationType: {
|
|
140
|
-
type: 'string',
|
|
141
|
-
enum: ['sync', 'async', 'stream', 'event', 'dep'],
|
|
142
|
-
default: 'sync',
|
|
143
|
-
description: 'sync=REST/gRPC, async=queue/kafka, stream=WebSocket/SSE, event=pub-sub, dep=dependency',
|
|
144
|
-
},
|
|
145
|
-
pathType: {
|
|
146
|
-
type: 'string',
|
|
147
|
-
enum: ['smooth', 'Smoothstep', 'bezier', 'step', 'straight'],
|
|
148
|
-
default: 'Smoothstep',
|
|
149
|
-
description: 'Edge path style',
|
|
150
|
-
},
|
|
151
|
-
label: { type: 'string', description: 'Edge label. REQUIRED for async/stream/event. Describe the message or event name.' },
|
|
152
|
-
},
|
|
153
|
-
required: ['source', 'target', 'label'],
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
direction: {
|
|
157
|
-
type: 'string',
|
|
158
|
-
enum: ['RIGHT', 'DOWN', 'LEFT', 'UP'],
|
|
159
|
-
default: 'RIGHT',
|
|
160
|
-
description: 'Layout direction: RIGHT (LR, default), DOWN (TB for pipelines)',
|
|
161
|
-
},
|
|
162
|
-
label: { type: 'string', description: 'Diagram title' },
|
|
163
|
-
diagramDescription: { type: 'string', description: 'One-sentence description of what this architecture does' },
|
|
164
|
-
userPrompt: { type: 'string', description: 'The user\'s original request verbatim. Subtitle content must reflect any tech stack/services the user named.' },
|
|
165
|
-
techStack: { type: 'array', items: { type: 'string' }, description: 'Explicit technologies/services extracted from the prompt (e.g. ["Next.js", "PostgreSQL 15"]).' },
|
|
166
|
-
customFeatures: { type: 'array', items: { type: 'string' }, description: 'Custom features/components the user explicitly requested.' },
|
|
167
|
-
publish: { type: 'boolean', default: false, description: 'Set true only after the user explicitly asks for a browser-accessible link.' },
|
|
168
|
-
workingSessionId: { type: 'string', description: 'Opaque local workspace key. Resend it to keep parallel diagrams isolated.' },
|
|
169
|
-
},
|
|
170
|
-
required: [],
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
name: 'fix_layout',
|
|
175
|
-
description: `Apply the same Mermaid → Dagre auto-layout pipeline used by the ArchDraw editor.
|
|
176
|
-
|
|
177
|
-
**USE WHEN**: User provides nodes/edges that need automatic positioning
|
|
178
|
-
**INPUT**: Nodes with their tier assignments, plus edges between them
|
|
179
|
-
**OUTPUT**: Returns nodes with x,y positions computed by the editor pipeline
|
|
180
|
-
|
|
181
|
-
This tool does NOT generate or modify nodes/edges - it only computes optimal positions.
|
|
182
|
-
|
|
183
|
-
**INPUT**:
|
|
184
|
-
- nodes: Array of nodes (id, label, layer/tier required)
|
|
185
|
-
- edges: Array of connections between nodes
|
|
186
|
-
- direction: Layout direction (RIGHT is default, means left-to-right)`,
|
|
187
|
-
inputSchema: {
|
|
188
|
-
type: 'object',
|
|
189
|
-
properties: {
|
|
190
|
-
nodes: {
|
|
191
|
-
type: 'array',
|
|
192
|
-
description: 'Array of nodes with layer assignments',
|
|
193
|
-
items: {
|
|
194
|
-
type: 'object',
|
|
195
|
-
properties: {
|
|
196
|
-
id: { type: 'string', description: 'Unique node identifier' },
|
|
197
|
-
label: { type: 'string', description: 'Node label/name' },
|
|
198
|
-
layer: { type: 'string', description: 'Tier layer: client, edge, compute, async, data, observe, external' },
|
|
199
|
-
width: { type: 'number', default: 180, description: 'Node width' },
|
|
200
|
-
height: { type: 'number', default: 70, description: 'Node height' },
|
|
201
|
-
},
|
|
202
|
-
required: ['id', 'label', 'layer'],
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
edges: {
|
|
206
|
-
type: 'array',
|
|
207
|
-
description: 'Array of edges connecting the nodes',
|
|
208
|
-
items: {
|
|
209
|
-
type: 'object',
|
|
210
|
-
properties: {
|
|
211
|
-
id: { type: 'string', description: 'Unique edge identifier' },
|
|
212
|
-
source: { type: 'string', description: 'Source node ID' },
|
|
213
|
-
target: { type: 'string', description: 'Target node ID' },
|
|
214
|
-
communicationType: {
|
|
215
|
-
type: 'string',
|
|
216
|
-
enum: ['sync', 'async', 'stream', 'event', 'dep'],
|
|
217
|
-
default: 'sync',
|
|
218
|
-
description: 'Communication type between nodes',
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
required: ['source', 'target'],
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
direction: {
|
|
225
|
-
type: 'string',
|
|
226
|
-
enum: ['RIGHT', 'DOWN', 'LEFT', 'UP'],
|
|
227
|
-
default: 'RIGHT',
|
|
228
|
-
description: 'Layout direction',
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
required: ['nodes'],
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
name: 'list_node_types',
|
|
236
|
-
description: `List all available pre-made component types from the ArchDraw component library.
|
|
237
|
-
|
|
238
|
-
**USE WHEN**: You want to see what components are available before generating a diagram
|
|
239
|
-
**OUTPUT**: Categorized list of 150+ component types with their icons and descriptions
|
|
240
|
-
|
|
241
|
-
**FILTERING**:
|
|
242
|
-
- category: Filter by category name (e.g., "AI / ML", "Data Storage", "Compute", "Messaging & Events")
|
|
243
|
-
- search: Search by label, description, or category
|
|
244
|
-
- limit: Max results (default 50, max 200)
|
|
245
|
-
|
|
246
|
-
**CATEGORIES INCLUDE**:
|
|
247
|
-
- Client & Entry (CDN, Load Balancer, API Gateway)
|
|
248
|
-
- Compute (API Server, Auth Service, Workers, Containers)
|
|
249
|
-
- AI / ML (LLM Models, Vector DB, Embedding Service, RAG)
|
|
250
|
-
- Data Storage (PostgreSQL, MongoDB, Redis, S3)
|
|
251
|
-
- Messaging & Events (Kafka, RabbitMQ, SQS)
|
|
252
|
-
- Observability (Prometheus, Grafana, ELK Stack)
|
|
253
|
-
- External Services (Stripe, Twilio, SendGrid)`,
|
|
254
|
-
inputSchema: {
|
|
255
|
-
type: 'object',
|
|
256
|
-
properties: {
|
|
257
|
-
category: {
|
|
258
|
-
type: 'string',
|
|
259
|
-
description: 'Filter by category name (e.g., "AI / ML", "Data Storage", "Compute")',
|
|
260
|
-
},
|
|
261
|
-
search: {
|
|
262
|
-
type: 'string',
|
|
263
|
-
description: 'Search by label, description, or category',
|
|
264
|
-
},
|
|
265
|
-
limit: {
|
|
266
|
-
type: 'number',
|
|
267
|
-
default: 50,
|
|
268
|
-
minimum: 1,
|
|
269
|
-
maximum: 200,
|
|
270
|
-
description: 'Maximum number of results',
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
name: 'apply_template',
|
|
277
|
-
description: `Apply a pre-built architecture template with pre-defined nodes and edges.
|
|
278
|
-
|
|
279
|
-
**IMPORTANT**: When this tool returns a 'diagramUrl', you MUST tell the user to open that URL in their browser to view the diagram. The URL format is: https://archdraw.hiabhee.online/editor?session=<sessionId>
|
|
280
|
-
|
|
281
|
-
**USE WHEN**: User wants a common architecture pattern (e-commerce, chat app, rideshare, etc.)
|
|
282
|
-
**OUTPUT**: Full diagram with positioned nodes and edges from the template. Check the 'message' and 'diagramUrl' fields and tell the user to open the diagramUrl.
|
|
283
|
-
|
|
284
|
-
**AVAILABLE TEMPLATES**:
|
|
285
|
-
- archflow: ArchDraw's own architecture (modern SaaS)
|
|
286
|
-
- chatgpt: LLM chat app with RAG, vector DB, streaming
|
|
287
|
-
- instagram: Social platform with Kafka, media storage, search
|
|
288
|
-
- rideshare: Uber-like with real-time tracking and dynamic pricing
|
|
289
|
-
- ecommerce: Full e-commerce with cart, payments, order management
|
|
290
|
-
|
|
291
|
-
**CUSTOMIZATIONS**:
|
|
292
|
-
- renameNodes: Map of node ID to new label
|
|
293
|
-
- addNodes: Additional nodes to include`,
|
|
294
|
-
inputSchema: {
|
|
295
|
-
type: 'object',
|
|
296
|
-
properties: {
|
|
297
|
-
templateId: {
|
|
298
|
-
type: 'string',
|
|
299
|
-
description: 'Template identifier: archflow, chatgpt, instagram, rideshare, ecommerce',
|
|
300
|
-
},
|
|
301
|
-
customizations: {
|
|
302
|
-
type: 'object',
|
|
303
|
-
description: 'Optional customizations to apply',
|
|
304
|
-
properties: {
|
|
305
|
-
renameNodes: {
|
|
306
|
-
type: 'object',
|
|
307
|
-
description: 'Map of node ID to new label',
|
|
308
|
-
additionalProperties: { type: 'string' },
|
|
309
|
-
},
|
|
310
|
-
addNodes: {
|
|
311
|
-
type: 'array',
|
|
312
|
-
description: 'Additional nodes to add',
|
|
313
|
-
items: {
|
|
314
|
-
type: 'object',
|
|
315
|
-
properties: {
|
|
316
|
-
id: { type: 'string' },
|
|
317
|
-
label: { type: 'string' },
|
|
318
|
-
category: { type: 'string' },
|
|
319
|
-
color: { type: 'string' },
|
|
320
|
-
icon: { type: 'string' },
|
|
321
|
-
},
|
|
322
|
-
},
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
publish: { type: 'boolean', default: false, description: 'Set true only after the user explicitly asks for a browser-accessible link.' },
|
|
327
|
-
workingSessionId: { type: 'string', description: 'Opaque local workspace key for isolating parallel diagrams.' },
|
|
328
|
-
},
|
|
329
|
-
required: ['templateId'],
|
|
330
|
-
},
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
name: 'list_templates',
|
|
334
|
-
description: 'List all available architecture templates with their descriptions',
|
|
335
|
-
inputSchema: {
|
|
336
|
-
type: 'object',
|
|
337
|
-
properties: {},
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
{
|
|
341
|
-
name: 'read_me',
|
|
342
|
-
description: `Returns a compact LLM-optimized reference guide for ArchDraw — tiers, node types,
|
|
343
|
-
edge communication types, layout rules, and best practices. Call this FIRST before generating
|
|
344
|
-
any diagram to produce accurate, professional output.`,
|
|
345
|
-
inputSchema: {
|
|
346
|
-
type: 'object',
|
|
347
|
-
properties: {},
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
name: 'get_diagram_state',
|
|
352
|
-
description: `Returns the current diagram's nodes and edges as structured JSON.
|
|
353
|
-
Call this before update_diagram to read what's on the canvas.
|
|
354
|
-
Optionally pass a sessionId to load that diagram first (e.g. a link the user opened).`,
|
|
355
|
-
inputSchema: {
|
|
356
|
-
type: 'object',
|
|
357
|
-
properties: {
|
|
358
|
-
sessionId: { type: 'string', description: 'Optional session ID to load before returning state (e.g. from a diagramUrl the user shared).' },
|
|
359
|
-
},
|
|
360
|
-
},
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
name: 'update_diagram',
|
|
364
|
-
description: `Surgically modifies an existing diagram. Add nodes, remove nodes,
|
|
365
|
-
add edges, remove edges, or update node properties — without regenerating the whole diagram.`,
|
|
366
|
-
inputSchema: {
|
|
367
|
-
type: 'object',
|
|
368
|
-
properties: {
|
|
369
|
-
addNodes: {
|
|
370
|
-
type: 'array',
|
|
371
|
-
description: 'Nodes to add',
|
|
372
|
-
items: {
|
|
373
|
-
type: 'object',
|
|
374
|
-
properties: {
|
|
375
|
-
id: { type: 'string', description: 'Unique node identifier' },
|
|
376
|
-
label: { type: 'string', description: 'Display name' },
|
|
377
|
-
tier: { type: 'string', description: 'Tier: client, edge, compute, async, data, observe, external' },
|
|
378
|
-
subtitle: { type: 'string', description: 'Optional short description' },
|
|
379
|
-
icon: { type: 'string', description: 'Optional icon name' },
|
|
380
|
-
},
|
|
381
|
-
required: ['id', 'label', 'tier'],
|
|
382
|
-
},
|
|
383
|
-
},
|
|
384
|
-
removeNodeIds: {
|
|
385
|
-
type: 'array',
|
|
386
|
-
description: 'Node IDs to remove',
|
|
387
|
-
items: { type: 'string' },
|
|
388
|
-
},
|
|
389
|
-
addEdges: {
|
|
390
|
-
type: 'array',
|
|
391
|
-
description: 'Edges to add',
|
|
392
|
-
items: {
|
|
393
|
-
type: 'object',
|
|
394
|
-
properties: {
|
|
395
|
-
source: { type: 'string', description: 'Source node ID' },
|
|
396
|
-
target: { type: 'string', description: 'Target node ID' },
|
|
397
|
-
communicationType: { type: 'string', enum: ['sync', 'async', 'stream', 'event', 'dep'] },
|
|
398
|
-
label: { type: 'string', description: 'Optional edge label' },
|
|
399
|
-
},
|
|
400
|
-
required: ['source', 'target'],
|
|
401
|
-
},
|
|
402
|
-
},
|
|
403
|
-
removeEdgeIds: {
|
|
404
|
-
type: 'array',
|
|
405
|
-
description: 'Edge IDs to remove',
|
|
406
|
-
items: { type: 'string' },
|
|
407
|
-
},
|
|
408
|
-
updateNodes: {
|
|
409
|
-
type: 'array',
|
|
410
|
-
description: 'Nodes to update',
|
|
411
|
-
items: {
|
|
412
|
-
type: 'object',
|
|
413
|
-
properties: {
|
|
414
|
-
id: { type: 'string', description: 'Node ID to update' },
|
|
415
|
-
label: { type: 'string', description: 'New label' },
|
|
416
|
-
subtitle: { type: 'string', description: 'New subtitle' },
|
|
417
|
-
tier: { type: 'string', description: 'New tier' },
|
|
418
|
-
},
|
|
419
|
-
required: ['id'],
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
},
|
|
423
|
-
},
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
name: 'validate_diagram',
|
|
427
|
-
description: `Analyses the current diagram and returns a list of structural issues
|
|
428
|
-
and improvement suggestions. Use after generating to catch problems before rendering.`,
|
|
429
|
-
inputSchema: {
|
|
430
|
-
type: 'object',
|
|
431
|
-
properties: {},
|
|
432
|
-
},
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
name: 'save_checkpoint',
|
|
436
|
-
description: `Saves the current diagram state with a named label so it can be restored later.
|
|
437
|
-
Useful for multi-turn workflows: save before a major change, restore if needed.`,
|
|
438
|
-
inputSchema: {
|
|
439
|
-
type: 'object',
|
|
440
|
-
properties: {
|
|
441
|
-
name: { type: 'string', description: 'Checkpoint name (e.g. "before-refactor")' },
|
|
442
|
-
description: { type: 'string', description: 'Optional description' },
|
|
443
|
-
},
|
|
444
|
-
required: ['name'],
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
{
|
|
448
|
-
name: 'load_checkpoint',
|
|
449
|
-
description: `Restores a previously saved diagram state by name.`,
|
|
450
|
-
inputSchema: {
|
|
451
|
-
type: 'object',
|
|
452
|
-
properties: {
|
|
453
|
-
name: { type: 'string', description: 'Checkpoint name to restore' },
|
|
454
|
-
listAvailable: { type: 'boolean', description: 'If true, list all checkpoints without restoring' },
|
|
455
|
-
},
|
|
456
|
-
required: ['name'],
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
name: 'export_diagram',
|
|
461
|
-
description: `Export the current diagram in various formats.
|
|
462
|
-
|
|
463
|
-
**USE WHEN**: User wants to save or download the diagram
|
|
464
|
-
**OUTPUT**: Returns the diagram data or instructions for image export
|
|
465
|
-
|
|
466
|
-
**FORMATS**:
|
|
467
|
-
- json: Returns raw nodes and edges as JSON (recommended for saving)
|
|
468
|
-
- png: Returns instructions to export as PNG from the editor
|
|
469
|
-
- svg: Returns instructions to export as SVG from the editor
|
|
470
|
-
|
|
471
|
-
**REQUIREMENT**: You must have a diagram loaded (generate or apply a template first).`,
|
|
472
|
-
inputSchema: {
|
|
473
|
-
type: 'object',
|
|
474
|
-
properties: {
|
|
475
|
-
sessionId: { type: 'string', description: 'Session ID from a previous diagram operation. Omit to use the most recent session.' },
|
|
476
|
-
format: { type: 'string', enum: ['json', 'png', 'svg'], default: 'json', description: 'Export format' },
|
|
477
|
-
},
|
|
478
|
-
required: [],
|
|
479
|
-
},
|
|
480
|
-
},
|
|
481
|
-
];
|
|
482
|
-
class ArchDrawMCPServer {
|
|
483
|
-
server;
|
|
484
|
-
constructor() {
|
|
485
|
-
this.server = new Server({
|
|
486
|
-
name: 'archdraw-mcp-server',
|
|
487
|
-
version: '1.0.0',
|
|
488
|
-
}, {
|
|
489
|
-
capabilities: {
|
|
490
|
-
tools: {},
|
|
491
|
-
},
|
|
492
|
-
});
|
|
493
|
-
this.setupHandlers();
|
|
494
|
-
}
|
|
495
|
-
setupHandlers() {
|
|
496
|
-
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
497
|
-
return { tools: TOOLS };
|
|
498
|
-
});
|
|
499
|
-
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
500
|
-
const { name, arguments: args } = request.params;
|
|
501
|
-
// Stdio normally has one client, but hosts can multiplex calls. Agents
|
|
502
|
-
// should retain and resend this opaque key to isolate parallel diagrams.
|
|
503
|
-
let workingSession = typeof args?.workingSessionId === 'string' && args.workingSessionId.trim()
|
|
504
|
-
? args.workingSessionId.trim()
|
|
505
|
-
: '';
|
|
506
|
-
if (!workingSession && (name === 'generate_diagram' || name === 'apply_template')) {
|
|
507
|
-
workingSession = randomUUID();
|
|
508
|
-
}
|
|
509
|
-
if (!workingSession)
|
|
510
|
-
workingSession = 'default';
|
|
511
|
-
try {
|
|
512
|
-
switch (name) {
|
|
513
|
-
case 'generate_diagram': {
|
|
514
|
-
const input = GenerateDiagramInputSchema.parse(args);
|
|
515
|
-
const result = await generateDiagram(input);
|
|
516
|
-
if (result.success) {
|
|
517
|
-
const { setDiagramState } = await import('./lib/diagram-state.js');
|
|
518
|
-
setDiagramState({ nodes: result.nodes, edges: result.edges, sessionId: result.sessionId, updateToken: result.updateToken }, workingSession);
|
|
519
|
-
}
|
|
520
|
-
return {
|
|
521
|
-
content: [
|
|
522
|
-
{
|
|
523
|
-
type: 'text',
|
|
524
|
-
text: JSON.stringify({
|
|
525
|
-
success: result.success,
|
|
526
|
-
message: result.message,
|
|
527
|
-
diagramUrl: result.diagramUrl,
|
|
528
|
-
shareUrl: result.shareUrl,
|
|
529
|
-
sessionId: result.sessionId,
|
|
530
|
-
workingSessionId: workingSession,
|
|
531
|
-
metadata: result.metadata,
|
|
532
|
-
errors: result.errors,
|
|
533
|
-
note: "Raw nodes and edges omitted for brevity."
|
|
534
|
-
}, null, 2),
|
|
535
|
-
},
|
|
536
|
-
],
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
case 'fix_layout': {
|
|
540
|
-
const input = FixLayoutInputSchema.parse(args);
|
|
541
|
-
const result = await fixLayout(input);
|
|
542
|
-
return {
|
|
543
|
-
content: [
|
|
544
|
-
{
|
|
545
|
-
type: 'text',
|
|
546
|
-
text: JSON.stringify(result, null, 2),
|
|
547
|
-
},
|
|
548
|
-
],
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
case 'list_node_types': {
|
|
552
|
-
const input = ListNodeTypesInputSchema.parse(args ?? {});
|
|
553
|
-
const result = await listNodeTypes(input);
|
|
554
|
-
return {
|
|
555
|
-
content: [
|
|
556
|
-
{
|
|
557
|
-
type: 'text',
|
|
558
|
-
text: JSON.stringify(result, null, 2),
|
|
559
|
-
},
|
|
560
|
-
],
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
case 'apply_template': {
|
|
564
|
-
const input = ApplyTemplateInputSchema.parse(args);
|
|
565
|
-
const result = await applyTemplate(input);
|
|
566
|
-
if (result.success) {
|
|
567
|
-
const { setDiagramState } = await import('./lib/diagram-state.js');
|
|
568
|
-
setDiagramState({ nodes: result.nodes, edges: result.edges, sessionId: result.sessionId, updateToken: result.updateToken }, workingSession);
|
|
569
|
-
}
|
|
570
|
-
return {
|
|
571
|
-
content: [
|
|
572
|
-
{
|
|
573
|
-
type: 'text',
|
|
574
|
-
text: JSON.stringify({
|
|
575
|
-
success: result.success,
|
|
576
|
-
message: result.message,
|
|
577
|
-
diagramUrl: result.diagramUrl,
|
|
578
|
-
shareUrl: result.shareUrl,
|
|
579
|
-
sessionId: result.sessionId,
|
|
580
|
-
workingSessionId: workingSession,
|
|
581
|
-
errors: result.errors,
|
|
582
|
-
note: "Raw nodes and edges omitted for brevity."
|
|
583
|
-
}, null, 2),
|
|
584
|
-
},
|
|
585
|
-
],
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
case 'list_templates': {
|
|
589
|
-
const templates = getAvailableTemplates();
|
|
590
|
-
return {
|
|
591
|
-
content: [
|
|
592
|
-
{
|
|
593
|
-
type: 'text',
|
|
594
|
-
text: JSON.stringify({ templates }, null, 2),
|
|
595
|
-
},
|
|
596
|
-
],
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
case 'read_me': {
|
|
600
|
-
const readmeContent = getReadMe();
|
|
601
|
-
return {
|
|
602
|
-
content: [
|
|
603
|
-
{
|
|
604
|
-
type: 'text',
|
|
605
|
-
text: readmeContent,
|
|
606
|
-
},
|
|
607
|
-
],
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
case 'get_diagram_state': {
|
|
611
|
-
const { sessionId } = (args ?? {});
|
|
612
|
-
if (typeof sessionId === 'string' && sessionId.trim().length > 0) {
|
|
613
|
-
const { syncDiagramStateFromSession } = await import('./lib/diagram-state.js');
|
|
614
|
-
const synced = await syncDiagramStateFromSession(sessionId.trim(), undefined, workingSession);
|
|
615
|
-
if (!synced) {
|
|
616
|
-
return {
|
|
617
|
-
content: [
|
|
618
|
-
{
|
|
619
|
-
type: 'text',
|
|
620
|
-
text: JSON.stringify({ error: `Could not load session '${sessionId}'. It may not exist or the frontend is unreachable.` }, null, 2),
|
|
621
|
-
},
|
|
622
|
-
],
|
|
623
|
-
isError: true,
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
const state = getDiagramState(workingSession);
|
|
628
|
-
return {
|
|
629
|
-
content: [
|
|
630
|
-
{
|
|
631
|
-
type: 'text',
|
|
632
|
-
text: JSON.stringify(state.nodes.length === 0 && state.edges.length === 0
|
|
633
|
-
? { nodes: [], edges: [], message: 'No diagram loaded yet.' }
|
|
634
|
-
: state, null, 2),
|
|
635
|
-
},
|
|
636
|
-
],
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
case 'update_diagram': {
|
|
640
|
-
const input = UpdateDiagramInputSchema.parse(args);
|
|
641
|
-
const result = await updateDiagram(input, workingSession);
|
|
642
|
-
if (result.success) {
|
|
643
|
-
const { setDiagramState } = await import('./lib/diagram-state.js');
|
|
644
|
-
const previous = getDiagramState(workingSession);
|
|
645
|
-
setDiagramState({ nodes: result.nodes, edges: result.edges, sessionId: result.sessionId, updateToken: previous.updateToken }, workingSession);
|
|
646
|
-
}
|
|
647
|
-
return {
|
|
648
|
-
content: [
|
|
649
|
-
{
|
|
650
|
-
type: 'text',
|
|
651
|
-
text: JSON.stringify({
|
|
652
|
-
success: result.success,
|
|
653
|
-
message: result.message,
|
|
654
|
-
error: result.error,
|
|
655
|
-
changes: result.changes,
|
|
656
|
-
diagramUrl: result.diagramUrl,
|
|
657
|
-
sessionId: result.sessionId,
|
|
658
|
-
workingSessionId: workingSession,
|
|
659
|
-
note: "Raw nodes and edges omitted for brevity."
|
|
660
|
-
}, null, 2),
|
|
661
|
-
},
|
|
662
|
-
],
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
case 'validate_diagram': {
|
|
666
|
-
const result = await validateDiagram(workingSession);
|
|
667
|
-
return {
|
|
668
|
-
content: [
|
|
669
|
-
{
|
|
670
|
-
type: 'text',
|
|
671
|
-
text: JSON.stringify(result, null, 2),
|
|
672
|
-
},
|
|
673
|
-
],
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
case 'save_checkpoint': {
|
|
677
|
-
const input = SaveCheckpointInputSchema.parse(args);
|
|
678
|
-
const result = await saveCheckpoint(input, workingSession);
|
|
679
|
-
return {
|
|
680
|
-
content: [
|
|
681
|
-
{
|
|
682
|
-
type: 'text',
|
|
683
|
-
text: JSON.stringify(result, null, 2),
|
|
684
|
-
},
|
|
685
|
-
],
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
case 'load_checkpoint': {
|
|
689
|
-
const input = LoadCheckpointInputSchema.parse(args);
|
|
690
|
-
const result = await loadCheckpoint(input, workingSession);
|
|
691
|
-
return {
|
|
692
|
-
content: [
|
|
693
|
-
{
|
|
694
|
-
type: 'text',
|
|
695
|
-
text: JSON.stringify(result, null, 2),
|
|
696
|
-
},
|
|
697
|
-
],
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
case 'export_diagram': {
|
|
701
|
-
const input = ExportDiagramInputSchema.parse(args);
|
|
702
|
-
const result = await exportDiagram(input);
|
|
703
|
-
return {
|
|
704
|
-
content: [
|
|
705
|
-
{
|
|
706
|
-
type: 'text',
|
|
707
|
-
text: JSON.stringify(result, null, 2),
|
|
708
|
-
},
|
|
709
|
-
],
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
default:
|
|
713
|
-
return {
|
|
714
|
-
content: [
|
|
715
|
-
{
|
|
716
|
-
type: 'text',
|
|
717
|
-
text: `Unknown tool: ${name}`,
|
|
718
|
-
},
|
|
719
|
-
],
|
|
720
|
-
isError: true,
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
catch (error) {
|
|
725
|
-
return {
|
|
726
|
-
content: [
|
|
727
|
-
{
|
|
728
|
-
type: 'text',
|
|
729
|
-
text: error instanceof Error ? error.message : String(error),
|
|
730
|
-
},
|
|
731
|
-
],
|
|
732
|
-
isError: true,
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
async run() {
|
|
738
|
-
const transport = new StdioServerTransport();
|
|
739
|
-
await this.server.connect(transport);
|
|
740
|
-
console.error('ArchDraw MCP server running on stdio');
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
const server = new ArchDrawMCPServer();
|
|
744
|
-
server.run().catch(console.error);
|
|
3
|
+
import { createArchDrawMCPServer } from './server.js';
|
|
4
|
+
const server = createArchDrawMCPServer();
|
|
5
|
+
server.connect(new StdioServerTransport())
|
|
6
|
+
.then(() => console.error('ArchDraw MCP server running on stdio'))
|
|
7
|
+
.catch(console.error);
|
|
745
8
|
//# sourceMappingURL=index.js.map
|