Skip to main content
Glama
AysllaGomes

Figma Context Cache MCP

by AysllaGomes
README.md
# 🎨 Figma Context Cache MCP

πŸ‡§πŸ‡· **Leia em portuguΓͺs:** [README.pt-BR.md](README.pt-BR.md)

> **Persistent design context for AI coding agents.**
>
> *Build once. Cache locally. Reuse everywhere.*

An MCP (Model Context Protocol) server that provides **cached, refreshable and structured Figma context** for AI coding assistants such as **Codex**, **Claude Code**, and other MCP-compatible clients.

Instead of querying the Figma API on every request, this server stores node responses locally and exposes tools to retrieve, inspect, synchronize and manage cached design context.

---

# Why?

AI coding assistants frequently need information from Figma while implementing or maintaining frontend applications.

Without a cache layer, every request:

- calls the Figma API
- consumes rate limits
- increases latency
- downloads the same information repeatedly

This project introduces a persistent cache with explicit synchronization capabilities, making Figma context:

- ⚑ Faster
- ♻️ Reusable
- πŸ“¦ Persistent
- πŸ€– AI-friendly

---

# Architecture

```text
                 AI Agent
        (Codex / Claude Code)

                     β”‚
                     β–Ό

               MCP Server

                     β”‚

         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                       β”‚

         β–Ό                       β–Ό

 Local JSON Cache        Figma REST API

         β”‚

         β–Ό

  Persistent Design Context
```

---

# Features

- βœ… Persistent local cache
- βœ… Configurable cache TTL
- βœ… Explicit cache synchronization
- βœ… Cache inspection
- βœ… Selective cache clearing
- βœ… Strongly typed
- βœ… Automated tests with Vitest
- βœ… MCP compatible

---

# MCP Tools

| Tool | Description |
|------|-------------|
| `health_check` | Verifies that the MCP server is running |
| `get_figma_node` | Retrieves a node from cache or directly from Figma |
| `sync_figma_node` | Forces a fresh request to Figma and updates the cache |
| `list_cached_figma_nodes` | Lists cached nodes and their current status |
| `clear_figma_cache` | Removes cache entries selectively |

---

# Cache Lifecycle

```text
get_figma_node

        β”‚

        β–Ό

Cache Hit?
   β”‚
   β”œβ”€β”€ Yes ───────────────► Return cached node
   β”‚
   └── No
        β”‚
        β–Ό

Query Figma API

        β”‚

        β–Ό

Store locally

        β”‚

        β–Ό

Return response


sync_figma_node

        β”‚

        β–Ό

Always query Figma

        β”‚

        β–Ό

Update cache

        β”‚

        β–Ό

Return fresh response
```

---

# Example

Synchronize a node:

```text
Use sync_figma_node with:

fileKey: wdva3WcsFmz54Sg5e6OWJl
nodeId: 4510-5941
depth: 1
```

Example response:

```json
{
  "message": "Node synchronized successfully.",
  "metadata": {
    "source": "figma",
    "cacheUpdated": true
  }
}
```

Subsequent requests:

```text
Use get_figma_node...
```

Response:

```json
{
  "metadata": {
    "source": "cache"
  }
}
```

---

# Project Structure

```text
src/
β”œβ”€β”€ cache/
β”œβ”€β”€ figma/
β”œβ”€β”€ server/
β”œβ”€β”€ tools/
└── sync/

tests/
β”œβ”€β”€ cache/
└── figma/
```

---

# Testing

This project uses **Vitest**.

Current test coverage:

| Component | Coverage |
|-----------|----------|
| CacheService | 90%+ |
| FigmaContextService | 100% |
| FigmaClient | In progress |

Run the test suite:

```bash
npm test
```

Generate coverage:

```bash
npm run test:coverage
```

---

# Installation

```bash
git clone https://github.com/AysllaGomes/figma-context-cache-mcp.git

cd figma-context-cache-mcp

npm install
```

Configure your environment:

```text
FIGMA_API_KEY=your-token
CACHE_TTL_SECONDS=3600
STORAGE_PATH=./storage
```

Start the server:

```bash
npm run dev
```

---

# Roadmap

- [x] Persistent cache
- [x] Cache inspection
- [x] Cache synchronization
- [x] Automated unit tests
- [ ] Structured node metadata
- [ ] Component relationship graph
- [ ] Storybook integration
- [ ] Angular component mapping
- [ ] Design token indexing
- [ ] Semantic search

---

# Vision

This project started as a cache for the Figma API.

Its long-term goal is to evolve into a **Frontend Context Engine**, capable of providing AI coding agents with rich, structured knowledge about design systems, frontend components and software architecture.

Instead of simply retrieving JSON from Figma, the server aims to understand relationships between components, design tokens, Storybook stories and frontend implementations, enabling AI agents to make better architectural and implementation decisions.

---

# License

[MIT](LICENSE)

Maintenance

ActivitySlowing
ResponsivenessNo issues