Skip to content

Conversation

@stone-w4tch3r
Copy link

@stone-w4tch3r stone-w4tch3r commented Nov 9, 2025

Description

Support pre-caching of Figma document to reduce number of requests to real API from N to 1. This will allow to use this MCP with free Figma account without hitting rate limits.

Summary

  • add FIGMA_CACHING env parsing with platform-specific cache dir defaults
  • add persistent file cache + integrate with FigmaService getRawFile/getRawNode
  • document cache usage and defaults in README
  • configure eslint globals so node/browser/jest references stop triggering false errors
  • add targeted Jest tests for cache helper + FigmaService caching behavior

Testing

  • pnpm exec jest src/services/figma-file-cache.test.ts src/services/figma.service-cache.test.ts
  • pnpm run type-check
  • test manually in AI agent, see that cache file is created, in MCP logs see that 2nd and consequent requests use cache

stone-w4tch3r and others added 6 commits November 9, 2025 16:33
Implements disk-based caching for Figma file responses with configurable TTL
to address Figma's strict rate limits for free tier users. When enabled,
the server fetches each file once and serves subsequent requests from cache.

Key features:
- Atomic writes using temp files to prevent cache corruption
- Async initialization with write permission validation
- Platform-specific default cache directories (XDG compliant on Linux)
- Configurable via FIGMA_CACHING environment variable
- TTL support with multiple time units (ms, s, m, h, d)
- Comprehensive error handling and logging

Technical improvements:
- Added race condition documentation for concurrent requests
- Validates cache directory permissions on startup
- Clear user-facing error messages for cache failures
- Proper async/await initialization pattern

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Codex <[email protected]>
When FIGMA_CACHING is enabled and cached data is served, AI agents now
receive a clear notification prepended to the tool response indicating:
- Data is from cache (not fresh from API)
- When the data was originally fetched
- When the cache will expire
- That caching is enabled via FIGMA_CACHING environment variable

Implementation:
- Modified FigmaService.getRawFile/getRawNode to return cache metadata
- Updated FigmaFileCache.get() to include cachedAt and ttlMs in response
- Added formatCacheNotice() helper for human-readable time formatting
- Prepends notice to YAML/JSON output in get_figma_data tool
- Updated tests to handle new return structure

Example output:
ℹ️ Note: Using cached Figma data (fetched 2h 15m ago, expires in 27d 21h)
due to FIGMA_CACHING environment variable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@stone-w4tch3r stone-w4tch3r changed the title Add disk cache Add disk cache to byass figma rate limits Nov 9, 2025
@stone-w4tch3r stone-w4tch3r marked this pull request as ready for review November 9, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant