Fix: Change create_view elements from JSON string to typed array#66
Open
anmolxlight wants to merge 1 commit intoexcalidraw:mainfrom
Open
Fix: Change create_view elements from JSON string to typed array#66anmolxlight wants to merge 1 commit intoexcalidraw:mainfrom
anmolxlight wants to merge 1 commit intoexcalidraw:mainfrom
Conversation
The previous z.string() schema required models to generate a JSON string, which frequently produced invalid JSON (trailing commas, unquoted keys, comments). This caused silent "Invalid JSON in elements" errors with no indication of what went wrong. Fix: change elements to z.array(z.record(z.any())). This lets Zod validate the structure directly, enabling structured output / strict tool use from Claude and ChatGPT to generate valid input. The widget (mcp-app.tsx) already handles both string and array inputs via typeof check, so no frontend changes needed. Fixes excalidraw#56
|
@anmolxlight is attempting to deploy a commit to the Excalidraw Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
create_viewacceptselementsasz.string()— a raw JSON array string. Models frequently generate invalid JSON in this string (trailing commas, unquoted keys, comments), causing silent "Invalid JSON in elements" errors. Since the schema doesn't enforce structure, strict tool use features (Claude structured outputs, ChatGPT function calling) can't help.Fix
Changed
elementsfromz.string()toz.array(z.record(z.any())). This lets Zod validate the array structure directly, enabling structured output / strict tool use to generate valid input.Before:
{ "elements": "[{"type": "rectangle", "x": 10}]" }After:
{ "elements": [{"type": "rectangle", "x": 10}] }The widget (
mcp-app.tsxline 432) already handles both string and array inputs viatypeofcheck, so no frontend changes needed.Changes
src/server.ts: Changed schema fromz.string()toz.array(z.record(z.any())), removed manual JSON.parse block, updated size check to useJSON.stringify(elements).lengthCLAUDE.md: Updated create_view descriptionRelated
Fixes #56