@next-ai-drawio/mcp-server 0.1.2 → 0.1.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/README.md CHANGED
@@ -4,17 +4,22 @@ MCP (Model Context Protocol) server that enables AI agents like Claude Desktop a
4
4
 
5
5
  **Self-contained** - includes an embedded HTTP server, no external dependencies required.
6
6
 
7
- ## Features
7
+ ## Quick Start
8
8
 
9
- - **Real-time Preview**: Diagrams appear and update in your browser as the AI creates them
10
- - **Natural Language**: Describe diagrams in plain text - flowcharts, architecture diagrams, etc.
11
- - **Edit Support**: Modify existing diagrams with natural language instructions
12
- - **Export**: Save diagrams as `.drawio` files
13
- - **Self-contained**: Embedded server, works offline (except draw.io UI which loads from embed.diagrams.net)
9
+ ```json
10
+ {
11
+ "mcpServers": {
12
+ "drawio": {
13
+ "command": "npx",
14
+ "args": ["@next-ai-drawio/mcp-server@latest"]
15
+ }
16
+ }
17
+ }
18
+ ```
14
19
 
15
- ## Quick Start
20
+ ## Installation
16
21
 
17
- ### Claude Desktop Configuration
22
+ ### Claude Desktop
18
23
 
19
24
  Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
20
25
 
@@ -23,43 +28,69 @@ Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_
23
28
  "mcpServers": {
24
29
  "drawio": {
25
30
  "command": "npx",
26
- "args": ["-y", "@next-ai-drawio/mcp-server"]
31
+ "args": ["@next-ai-drawio/mcp-server@latest"]
27
32
  }
28
33
  }
29
34
  }
30
35
  ```
31
36
 
32
- That's it! The MCP server runs its own embedded HTTP server.
37
+ ### VS Code
33
38
 
34
- ### Use with Claude
39
+ Add to your VS Code settings (`.vscode/mcp.json` in workspace or user settings):
35
40
 
36
- 1. Restart Claude Desktop after updating config
37
- 2. Ask Claude to create a diagram:
38
- > "Create a flowchart showing user authentication with login, MFA, and session management"
39
- 3. The diagram appears in your browser in real-time!
41
+ ```json
42
+ {
43
+ "mcpServers": {
44
+ "drawio": {
45
+ "command": "npx",
46
+ "args": ["@next-ai-drawio/mcp-server@latest"]
47
+ }
48
+ }
49
+ }
50
+ ```
40
51
 
41
- ## How It Works
52
+ ### Cursor
53
+
54
+ Add to Cursor MCP config (`~/.cursor/mcp.json`):
42
55
 
56
+ ```json
57
+ {
58
+ "mcpServers": {
59
+ "drawio": {
60
+ "command": "npx",
61
+ "args": ["@next-ai-drawio/mcp-server@latest"]
62
+ }
63
+ }
64
+ }
43
65
  ```
44
- ┌─────────────────┐ stdio ┌─────────────────┐
45
- Claude Desktop │ <───────────> │ MCP Server │
46
- │ (AI Agent) │ │ (this package) │
47
- └─────────────────┘ └────────┬────────┘
48
-
49
- ┌────────▼────────┐
50
- │ Embedded HTTP │
51
- │ Server (:6002) │
52
- └────────┬────────┘
53
-
54
- ┌────────▼────────┐
55
- │ User's Browser │
56
- │ (draw.io embed) │
57
- └─────────────────┘
66
+
67
+ ### Claude Code CLI
68
+
69
+ ```bash
70
+ claude mcp add drawio -- npx @next-ai-drawio/mcp-server@latest
58
71
  ```
59
72
 
60
- 1. **MCP Server** receives tool calls from Claude via stdio
61
- 2. **Embedded HTTP Server** serves the draw.io UI and handles state
62
- 3. **Browser** shows real-time diagram updates via polling
73
+ ### Other MCP Clients
74
+
75
+ Use the standard MCP configuration with:
76
+ - **Command**: `npx`
77
+ - **Args**: `["@next-ai-drawio/mcp-server@latest"]`
78
+
79
+ ## Usage
80
+
81
+ 1. Restart your MCP client after updating config
82
+ 2. Ask the AI to create a diagram:
83
+ > "Create a flowchart showing user authentication with login, MFA, and session management"
84
+ 3. The diagram appears in your browser in real-time!
85
+
86
+ ## Features
87
+
88
+ - **Real-time Preview**: Diagrams appear and update in your browser as the AI creates them
89
+ - **Version History**: Restore previous diagram versions with visual thumbnails - click the clock button (bottom-right) to browse and restore earlier states
90
+ - **Natural Language**: Describe diagrams in plain text - flowcharts, architecture diagrams, etc.
91
+ - **Edit Support**: Modify existing diagrams with natural language instructions
92
+ - **Export**: Save diagrams as `.drawio` files
93
+ - **Self-contained**: Embedded server, works offline (except draw.io UI which loads from embed.diagrams.net)
63
94
 
64
95
  ## Available Tools
65
96
 
@@ -71,7 +102,30 @@ That's it! The MCP server runs its own embedded HTTP server.
71
102
  | `get_diagram` | Get the current diagram XML |
72
103
  | `export_diagram` | Save diagram to a `.drawio` file |
73
104
 
74
- ## Environment Variables
105
+ ## How It Works
106
+
107
+ ```
108
+ ┌─────────────────┐ stdio ┌─────────────────┐
109
+ │ Claude Desktop │ <───────────> │ MCP Server │
110
+ │ (AI Agent) │ │ (this package) │
111
+ └─────────────────┘ └────────┬────────┘
112
+
113
+ ┌────────▼────────┐
114
+ │ Embedded HTTP │
115
+ │ Server (:6002) │
116
+ └────────┬────────┘
117
+
118
+ ┌────────▼────────┐
119
+ │ User's Browser │
120
+ │ (draw.io embed) │
121
+ └─────────────────┘
122
+ ```
123
+
124
+ 1. **MCP Server** receives tool calls from Claude via stdio
125
+ 2. **Embedded HTTP Server** serves the draw.io UI and handles state
126
+ 3. **Browser** shows real-time diagram updates via polling
127
+
128
+ ## Configuration
75
129
 
76
130
  | Variable | Default | Description |
77
131
  |----------|---------|-------------|
@@ -81,7 +135,7 @@ That's it! The MCP server runs its own embedded HTTP server.
81
135
 
82
136
  ### Port already in use
83
137
 
84
- If port 6002 is in use, the server will automatically try the next available port.
138
+ If port 6002 is in use, the server will automatically try the next available port (up to 6020).
85
139
 
86
140
  Or set a custom port:
87
141
  ```json
@@ -89,7 +143,7 @@ Or set a custom port:
89
143
  "mcpServers": {
90
144
  "drawio": {
91
145
  "command": "npx",
92
- "args": ["-y", "@next-ai-drawio/mcp-server"],
146
+ "args": ["@next-ai-drawio/mcp-server@latest"],
93
147
  "env": { "PORT": "6003" }
94
148
  }
95
149
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Simple diagram history - matches Next.js app pattern
3
+ * Stores {xml, svg} entries in a circular buffer
4
+ */
5
+ export declare function addHistory(sessionId: string, xml: string, svg?: string): number;
6
+ export declare function getHistory(sessionId: string): Array<{
7
+ xml: string;
8
+ svg: string;
9
+ }>;
10
+ export declare function getHistoryEntry(sessionId: string, index: number): {
11
+ xml: string;
12
+ svg: string;
13
+ } | undefined;
14
+ export declare function clearHistory(sessionId: string): void;
15
+ export declare function updateLastHistorySvg(sessionId: string, svg: string): boolean;
16
+ //# sourceMappingURL=history.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,SAAK,GAAG,MAAM,CAsB3E;AAED,wBAAgB,UAAU,CACtB,SAAS,EAAE,MAAM,GAClB,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAErC;AAED,wBAAgB,eAAe,CAC3B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACd;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAG1C;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEpD;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAS5E"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Simple diagram history - matches Next.js app pattern
3
+ * Stores {xml, svg} entries in a circular buffer
4
+ */
5
+ import { log } from "./logger.js";
6
+ const MAX_HISTORY = 20;
7
+ const historyStore = new Map();
8
+ export function addHistory(sessionId, xml, svg = "") {
9
+ let history = historyStore.get(sessionId);
10
+ if (!history) {
11
+ history = [];
12
+ historyStore.set(sessionId, history);
13
+ }
14
+ // Dedupe: skip if same as last entry
15
+ const last = history[history.length - 1];
16
+ if (last?.xml === xml) {
17
+ return history.length - 1;
18
+ }
19
+ history.push({ xml, svg });
20
+ // Circular buffer
21
+ if (history.length > MAX_HISTORY) {
22
+ history.shift();
23
+ }
24
+ log.debug(`History: session=${sessionId}, entries=${history.length}`);
25
+ return history.length - 1;
26
+ }
27
+ export function getHistory(sessionId) {
28
+ return historyStore.get(sessionId) || [];
29
+ }
30
+ export function getHistoryEntry(sessionId, index) {
31
+ const history = historyStore.get(sessionId);
32
+ return history?.[index];
33
+ }
34
+ export function clearHistory(sessionId) {
35
+ historyStore.delete(sessionId);
36
+ }
37
+ export function updateLastHistorySvg(sessionId, svg) {
38
+ const history = historyStore.get(sessionId);
39
+ if (!history || history.length === 0)
40
+ return false;
41
+ const last = history[history.length - 1];
42
+ if (!last.svg) {
43
+ last.svg = svg;
44
+ return true;
45
+ }
46
+ return false;
47
+ }
48
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjC,MAAM,WAAW,GAAG,EAAE,CAAA;AACtB,MAAM,YAAY,GAAG,IAAI,GAAG,EAA+C,CAAA;AAE3E,MAAM,UAAU,UAAU,CAAC,SAAiB,EAAE,GAAW,EAAE,GAAG,GAAG,EAAE;IAC/D,IAAI,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IACzC,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,OAAO,GAAG,EAAE,CAAA;QACZ,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACxC,CAAC;IAED,qCAAqC;IACrC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACxC,IAAI,IAAI,EAAE,GAAG,KAAK,GAAG,EAAE,CAAC;QACpB,OAAO,OAAO,CAAC,MAAM,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2
2
  * Embedded HTTP Server for MCP
3
- *
4
- * Serves a static HTML page with draw.io embed and handles state sync.
5
- * This eliminates the need for an external Next.js app.
3
+ * Serves draw.io embed with state sync and history UI
6
4
  */
7
5
  interface SessionState {
8
6
  xml: string;
9
7
  version: number;
10
8
  lastUpdated: Date;
9
+ svg?: string;
10
+ syncRequested?: number;
11
11
  }
12
12
  export declare const stateStore: Map<string, SessionState>;
13
- /**
14
- * Get state for a session
15
- */
16
13
  export declare function getState(sessionId: string): SessionState | undefined;
17
- /**
18
- * Set state for a session
19
- */
20
- export declare function setState(sessionId: string, xml: string): number;
21
- /**
22
- * Start the embedded HTTP server
23
- */
14
+ export declare function setState(sessionId: string, xml: string, svg?: string): number;
15
+ export declare function requestSync(sessionId: string): boolean;
16
+ export declare function waitForSync(sessionId: string, timeoutMs?: number): Promise<boolean>;
24
17
  export declare function startHttpServer(port?: number): Promise<number>;
25
- /**
26
- * Stop the HTTP server
27
- */
28
18
  export declare function stopHttpServer(): void;
29
- /**
30
- * Get the current server port
31
- */
32
19
  export declare function getServerPort(): number;
33
20
  export {};
34
21
  //# sourceMappingURL=http-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../src/http-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,UAAU,YAAY;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,IAAI,CAAA;CACpB;AAGD,eAAO,MAAM,UAAU,2BAAkC,CAAA;AAOzD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAY/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,GAAE,MAAa,GAAG,OAAO,CAAC,MAAM,CAAC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