create_drawing
Generate and save Excalidraw drawings by specifying a name and content, enabling efficient creation and management of visual sketches via the Excalidraw MCP Server.
Instructions
Create a new Excalidraw drawing
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | ||
| name | Yes |
Implementation Reference
- src/operations/drawings.ts:48-72 (handler)The core handler function that implements the create_drawing tool logic: generates unique ID, saves drawing content and metadata to storage directory.export async function createDrawing(name: string, content: string): Promise<{ id: string, name: string }> { await ensureStorageDir(); // Generate a unique ID for the drawing const id = `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`; // Create the drawing file const filePath = path.join(STORAGE_DIR, `${id}.json`); // Save the drawing content await fs.writeFile(filePath, content, 'utf-8'); // Create a metadata file for the drawing const metadataPath = path.join(STORAGE_DIR, `${id}.meta.json`); const metadata = { id, name, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), }; await fs.writeFile(metadataPath, JSON.stringify(metadata, null, 2), 'utf-8'); return { id, name }; }
- src/operations/drawings.ts:20-23 (schema)Zod schema defining the input parameters for the create_drawing tool: name and content.export const CreateDrawingSchema = z.object({ name: z.string().min(1), content: z.string().min(1), });
- index.ts:63-66 (registration)Tool registration in the listTools handler, specifying name, description, and input schema.name: "create_drawing", description: "Create a new Excalidraw drawing", inputSchema: zodToJsonSchema(drawings.CreateDrawingSchema), },
- index.ts:113-119 (handler)Dispatch handler in callToolRequest that validates arguments using the schema and calls the createDrawing function.case "create_drawing": { const args = drawings.CreateDrawingSchema.parse(request.params.arguments); const result = await drawings.createDrawing(args.name, args.content); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }