update_drawing
Modify existing Excalidraw diagrams by providing new content to replace the current version, enabling diagram editing and updates.
Instructions
Update an Excalidraw drawing by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| content | Yes |
Implementation Reference
- src/operations/drawings.ts:130-170 (handler)The main handler function that performs the update logic: validates ID, reads metadata, updates drawing content and metadata timestamp, returns id and name.export async function updateDrawing( id: string, content: string ): Promise<{ id: string; name: string }> { // Validate the ID for security validateFileId(id); await ensureStorageDir(); // Get the drawing file path const filePath = path.join(STORAGE_DIR, `${id}.json`); const metadataPath = path.join(STORAGE_DIR, `${id}.meta.json`); try { // Check if the drawing exists await fs.access(filePath); // Read the metadata const metadataStr = await fs.readFile(metadataPath, "utf-8"); const metadata = safeJsonParse(metadataStr, "drawing metadata"); // Update the drawing content await fs.writeFile(filePath, content, "utf-8"); // Update the metadata metadata.updatedAt = new Date().toISOString(); await fs.writeFile( metadataPath, JSON.stringify(metadata, null, 2), "utf-8" ); return { id, name: metadata.name }; } catch (error) { if (error instanceof ExcalidrawValidationError) { throw error; // Re-throw validation errors as-is } throw new ExcalidrawResourceNotFoundError( sanitizeErrorMessage(error, `Drawing with ID ${id} not found`) ); }
- src/operations/drawings.ts:46-49 (schema)Zod schema defining the input parameters for the update_drawing tool: id and content.export const UpdateDrawingSchema = z.object({ id: z.string().min(1), content: z.string().min(1), });
- src/index.ts:75-79 (registration)Registers the update_drawing tool in the MCP server's listTools response, including name, description, and input schema.{ name: "update_drawing", description: "Update an Excalidraw drawing by ID", inputSchema: zodToJsonSchema(drawings.UpdateDrawingSchema), },
- src/index.ts:134-142 (handler)Dispatch handler in the main CallToolRequestSchema that parses arguments and calls the updateDrawing function.case "update_drawing": { const args = drawings.UpdateDrawingSchema.parse( request.params.arguments ); const result = await drawings.updateDrawing(args.id, args.content); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }