get_resource
Retrieve specific Excalidraw resources such as scenes, libraries, themes, or elements using the Excalidraw MCP Server for diagram manipulation and management.
Instructions
Get an Excalidraw resource
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| resource | Yes |
Implementation Reference
- src/index.ts:658-700 (handler)The handler case for 'get_resource' tool execution. Validates input with ResourceSchema, fetches the specified resource ('scene', 'library'/'elements', 'theme') from sceneState or canvas API, and returns JSON stringified result.
case 'get_resource': { const params = ResourceSchema.parse(args); const { resource } = params; logger.info('Getting resource', { resource }); let result: any; switch (resource) { case 'scene': result = { theme: sceneState.theme, viewport: sceneState.viewport, selectedElements: Array.from(sceneState.selectedElements) }; break; case 'library': case 'elements': try { // Get elements from HTTP server const response = await fetch(`${EXPRESS_SERVER_URL}/api/elements`); if (!response.ok) { throw new Error(`HTTP server error: ${response.status} ${response.statusText}`); } const data = await response.json() as ApiResponse; result = { elements: data.elements || [] }; } catch (error) { throw new Error(`Failed to get elements: ${(error as Error).message}`); } break; case 'theme': result = { theme: sceneState.theme }; break; default: throw new Error(`Unknown resource: ${resource}`); } return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } - src/index.ts:314-327 (registration)Registration of the 'get_resource' tool in the tools array, defining its name, description, and input schema for MCP capabilities and list_tools.
{ name: 'get_resource', description: 'Get an Excalidraw resource', inputSchema: { type: 'object', properties: { resource: { type: 'string', enum: ['scene', 'library', 'theme', 'elements'] } }, required: ['resource'] } }, - src/index.ts:227-229 (schema)Zod validation schema (ResourceSchema) used in the handler to parse and validate the tool input parameters.
const ResourceSchema = z.object({ resource: z.enum(['scene', 'library', 'theme', 'elements']) });