query_elements
Query and filter diagram elements in Excalidraw for precise selection and manipulation, enabling efficient scene management and diagram customization via structured API calls.
Instructions
Query Excalidraw elements with optional filters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | ||
| type | No |
Implementation Reference
- src/index.js:419-440 (handler)The switch case that implements the core logic for the 'query_elements' tool. It parses the input arguments using QuerySchema, retrieves all elements, filters them optionally by 'type' and custom 'filter' object matching exact property values, and returns the results as a JSON-formatted text content block.case 'query_elements': { const params = QuerySchema.parse(args || {}); const { type, filter } = params; let results = Array.from(elements.values()); if (type) { results = results.filter(element => element.type === type); } if (filter) { results = results.filter(element => { return Object.entries(filter).every(([key, value]) => { return element[key] === value; }); }); } return { content: [{ type: 'text', text: JSON.stringify(results, null, 2) }] }; }
- src/index.js:70-73 (schema)Zod schema defining the input structure for query_elements: optional 'type' enum from EXCALIDRAW_ELEMENT_TYPES and optional 'filter' as a record object for property matching.const QuerySchema = z.object({ type: z.enum(Object.values(EXCALIDRAW_ELEMENT_TYPES)).optional(), filter: z.record(z.any()).optional() });
- src/index.js:155-170 (registration)Registration of the 'query_elements' tool in the MCP server capabilities, including description and inputSchema matching the QuerySchema for MCP protocol compliance.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 } } } },