Skip to content

RangeError: Invalid string length when fetching large Figma files #3

Closed

Description

@mikecfisher

Hi guys this is a really cool concept but I can't seem to get it to work properly. When I include a link to a Figma page I get errors in your MCP app. This happens on full pages. When trying small components it just hangs on "successfully found page"

Bug Description

When fetching certain Figma files, the server crashes with a RangeError: Invalid string length error during JSON stringification.

Steps to Reproduce

  1. Start the server with pnpm dev
  2. Connect to the SSE endpoint
  3. Attempt to fetch a large Figma file (e.g. file ID: 'my-file-id-placeholder')

Error Output

Error fetching file 'my-file-id-placeholder': RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at /Users/mike/dev/personal/mcp/Figma-Context-MCP/src/server.ts:80:28

Expected Behavior

The server should handle large Figma files gracefully, either by:

  • Implementing streaming for large responses
  • Chunking the response data
  • Adding proper error handling with user-friendly messages

Additional Context

  • The error occurs during JSON.stringify() operation
  • Seems to happen with specific large Figma files
  • Successfully finds smaller files (e.g. file ID: 'my-file-id-placeholder') but then hangs

Environment

  • Node.js: v23.6.1
  • pnpm: 9.15.4
  • OS: macOS (darwin 24.3.0)

Activity

  1. GLips commented on Feb 24, 2025

    @GLips
    Owner

    Thanks for the detailed bug report! I'll look into this, but can you provide some more context on your use case? Did you want to feed in an entire Figma file and just have it implement everything in there?

  2. max-arias commented on Feb 24, 2025

    @max-arias

    I'm having the same issue:

    Error fetching file xxxx: { status: 404, err: 'Not found' } Error fetching file xxx: RangeError: Invalid string length at JSON.stringify (<anonymous>) at /Users/maxarias/.npm/_npx/e05028111420be70/node_modules/figma-developer-mcp/dist/server.js:34:58 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async /Users/maxarias/.npm/_npx/e05028111420be70/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js:76:28

    I'm giving it a link to one layer of the figma file, it's not huge but it's not small


    EDIT: Giving it a much smaller piece it worked fine, so yeah it seems that size of the copied section is the issue

  3. mikecfisher commented on Feb 24, 2025

    @mikecfisher
    Author

    Thanks for the detailed bug report! I'll look into this, but can you provide some more context on your use case? Did you want to feed in an entire Figma file and just have it implement everything in there?

    Thanks @GLips my first attempt was to try and push Cursor to see if it could build a full UI and how far it would get. Then I quickly realized that wasn't feasible so I tried to use a smaller component like a card with some features in it. That still gave me the same error so I decided to open up a bug ticket.

  4. GLips commented on Feb 24, 2025

    @GLips
    Owner

    I just pushed an update (version 0.1.4) that should improve problems here.

    Full file responses now get parsed and simplified so the total response returned isn't as large and is better tuned to development needs (i.e. irrelevant Figma design metadata is stripped, making the total response anywhere from 40–60% smaller on average).

    It's also now stringifying each top-level node in the file individually to further reduce the likelihood this crops up.

    I'm now running into MCP server timeout issues though. It looks like a PR was merged into @modelcontextprotocol/typescript-sdk 2 hours ago that might help here, but there's no documentation on how to leverage it yet. I'm keeping an eye on things there—hopefully it'll let us grab Figma files of any size without dealing with the hardcoded timeout currently in the SDK.

    Will keep this thread open for more reports and updates on my end when they're available.

  5. GLips commented on Feb 27, 2025

    @GLips
    Owner

    Closing this for now. Reopen a new issue if it arises again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions