query_elements
Retrieve specific elements from Excalidraw diagrams using customizable filters, enabling targeted diagram analysis and manipulation via structured API queries.
Instructions
Query Excalidraw elements with optional filters
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | ||
| type | No |
Implementation Reference
- src/index.ts:625-656 (handler)The handler for the 'query_elements' tool. Parses input using QuerySchema, constructs a query to the canvas API (/api/elements/search), fetches matching elements, and returns them as JSON.
case 'query_elements': { const params = QuerySchema.parse(args || {}); const { type, filter } = params; try { // Build query parameters const queryParams = new URLSearchParams(); if (type) queryParams.set('type', type); if (filter) { Object.entries(filter).forEach(([key, value]) => { queryParams.set(key, String(value)); }); } // Query elements from HTTP server const url = `${EXPRESS_SERVER_URL}/api/elements/search?${queryParams}`; const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP server error: ${response.status} ${response.statusText}`); } const data = await response.json() as ApiResponse; const results = data.elements || []; return { content: [{ type: 'text', text: JSON.stringify(results, null, 2) }] }; } catch (error) { throw new Error(`Failed to query elements: ${(error as Error).message}`); } } - src/index.ts:222-225 (schema)Zod schema for validating input parameters (type and filter) used in the query_elements handler.
const QuerySchema = z.object({ type: z.enum(Object.values(EXCALIDRAW_ELEMENT_TYPES) as [ExcalidrawElementType, ...ExcalidrawElementType[]]).optional(), filter: z.record(z.any()).optional() }); - src/index.ts:297-313 (registration)Registration of the 'query_elements' tool in the tools array, including its MCP input schema definition. Used for tool listing and capabilities.
{ name: 'query_elements', description: 'Query Excalidraw elements with optional filters', inputSchema: { type: 'object', properties: { type: { type: 'string', enum: Object.values(EXCALIDRAW_ELEMENT_TYPES) }, filter: { type: 'object', additionalProperties: true } } } }, - src/index.ts:300-311 (schema)JSON schema for the 'query_elements' tool input, defining optional 'type' enum and flexible 'filter' object. Part of tool registration.
inputSchema: { type: 'object', properties: { type: { type: 'string', enum: Object.values(EXCALIDRAW_ELEMENT_TYPES) }, filter: { type: 'object', additionalProperties: true } }