-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtest.js
More file actions
executable file
·187 lines (172 loc) · 4.67 KB
/
test.js
File metadata and controls
executable file
·187 lines (172 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env node
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
async function main() {
// Create a transport connected to the server process
const transport = new StdioClientTransport({
command: 'node',
args: ['dist/index.js'],
});
// Create a client
const client = new Client(
{
name: 'excalidraw-mcp-test',
version: '0.1.0',
},
{
capabilities: {
tools: {},
},
}
);
try {
// Connect to the server
await client.connect(transport);
console.log('Connected to server');
// List available tools
const tools = await client.listTools();
console.log('Available tools:', tools);
// Create a drawing
const createResult = await client.callTool({
name: 'create_drawing',
arguments: {
name: 'Test Drawing',
content: JSON.stringify({
type: 'excalidraw',
version: 2,
source: 'excalidraw-mcp-test',
elements: [
{
id: 'rectangle1',
type: 'rectangle',
x: 100,
y: 100,
width: 200,
height: 100,
angle: 0,
strokeColor: '#000000',
backgroundColor: '#ffffff',
fillStyle: 'solid',
strokeWidth: 1,
strokeStyle: 'solid',
roughness: 1,
opacity: 100,
groupIds: [],
strokeSharpness: 'sharp',
seed: 123456,
version: 1,
versionNonce: 1,
isDeleted: false,
boundElementIds: null,
},
],
appState: {
viewBackgroundColor: '#ffffff',
},
}),
},
});
console.log('Created drawing:', createResult);
// Get the drawing ID from the result
const drawingId = JSON.parse(createResult.content[0].text).id;
// Get the drawing
const getResult = await client.callTool({
name: 'get_drawing',
arguments: {
id: drawingId,
},
});
console.log('Retrieved drawing:', getResult);
// Export the drawing to SVG
const svgResult = await client.callTool({
name: 'export_to_svg',
arguments: {
id: drawingId,
},
});
console.log('SVG export:', svgResult);
// Export the drawing to PNG
const pngResult = await client.callTool({
name: 'export_to_png',
arguments: {
id: drawingId,
quality: 0.9,
scale: 2,
exportWithDarkMode: true,
exportBackground: true,
},
});
console.log('PNG export:', pngResult);
// List all drawings
const listResult = await client.callTool({
name: 'list_drawings',
arguments: {
page: 1,
perPage: 10,
},
});
console.log('List of drawings:', listResult);
// Update the drawing
const updateResult = await client.callTool({
name: 'update_drawing',
arguments: {
id: drawingId,
content: JSON.stringify({
type: 'excalidraw',
version: 2,
source: 'excalidraw-mcp-test',
elements: [
{
id: 'rectangle1',
type: 'rectangle',
x: 100,
y: 100,
width: 200,
height: 100,
angle: 0,
strokeColor: '#ff0000', // Changed to red
backgroundColor: '#ffffff',
fillStyle: 'solid',
strokeWidth: 2, // Increased width
strokeStyle: 'solid',
roughness: 1,
opacity: 100,
groupIds: [],
strokeSharpness: 'sharp',
seed: 123456,
version: 2,
versionNonce: 2,
isDeleted: false,
boundElementIds: null,
},
],
appState: {
viewBackgroundColor: '#ffffff',
},
}),
},
});
console.log('Updated drawing:', updateResult);
// Delete the drawing
const deleteResult = await client.callTool({
name: 'delete_drawing',
arguments: {
id: drawingId,
},
});
console.log('Deleted drawing:', deleteResult);
console.log('All tests passed!');
} catch (error) {
console.error('Error:', error);
} finally {
// Close the client connection
await client.close();
}
}
main().catch((error) => {
console.error('Test error:', error);
process.exit(1);
});