onlook icon indicating copy to clipboard operation
onlook copied to clipboard

feat: Introduce Import from Figma using MCP Functionality

Open iNerdStack opened this issue 7 months ago • 2 comments

Description

This PR introduces import from Figma using MCP, it connects with Figma desktop SSE service. Adds new context option for import from figma in AI chat

Related Issues

Type of Change

  • [ ] Bug fix
  • [x] New feature
  • [ ] Documentation update
  • [ ] Release
  • [ ] Refactor
  • [ ] Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes


[!IMPORTANT] Introduces Figma import feature using MCP, adding new components, context management, and documentation updates.

  • Behavior:
    • Adds FigmaInput component in action-buttons.tsx for importing Figma designs.
    • Connects to Figma desktop SSE service via figmaRouter in routers/figma.ts.
    • Supports link-based and selection-based imports.
  • Context Management:
    • Adds FigmaMessageContext to context.ts for managing Figma design data.
    • Updates getHydratedUserMessage() in provider.ts to include Figma context.
  • Icons:
    • Adds FigmaLogo icon to icons/index.tsx.
  • Documentation:
    • Updates figma-to-onlook/index.mdx and features/index.mdx to include Figma import instructions.

This description was created by Ellipsis for dec7bccf0863b6bd6e6f551c2cc5c3245d816ff8. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Import Figma designs into chat via URL, current selection, or clipboard; add and remove Figma design contexts shown as context pills.
  • Backend

    • New resilient Figma service and API to fetch design assets, code, variables, extract node IDs, and report connection health.
  • UI/Style

    • “Add Figma Design” action and updated tooltip, loading states, success/error toasts, and new Figma icons.
  • Documentation

    • Reworked tutorial covering Figma import workflow, prerequisites, steps, FAQs, and troubleshooting.

iNerdStack avatar Jun 09 '25 21:06 iNerdStack

@iNerdStack is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 09 '25 21:06 vercel[bot]

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds end-to-end Figma import: UI action and modal, new Figma message context and icons, chat-context add/remove APIs, TRPC figma router with an MCP SSE + JSON-RPC client, API wiring, prompt/hydration support, and updated docs for the import workflow.

Changes

Cohort / File(s) Summary of Changes
Chat Input UI
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/action-buttons.tsx, apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/figma-input.tsx
Adds "Add Figma Design" dropdown item and new FigmaInput component. FigmaInput supports URL, selection, and clipboard flows, uses TRPC calls, loading states, toasts, and can be controlled externally or internally.
Context Pills UI
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/context-pills/helpers.tsx
Adds handling for MessageContextType.FIGMA in truncation fallback and maps it to a Figma icon for rendering.
Chat Context Store
apps/web/client/src/components/store/editor/chat/context.ts
Adds Figma contexts support, public addFigmaContext / removeFigmaContext methods, deduplication by nodeId, inserts figma contexts into context composition, and makes image context retrieval synchronous.
Server API: Figma Router & Index/Root
apps/web/client/src/server/api/routers/figma.ts, apps/web/client/src/server/api/routers/index.ts, apps/web/client/src/server/api/root.ts
New figmaRouter exposing endpoints (getDesignFromUrl, getCurrentSelection, checkConnection, extractNodeId, getHealthStatus). Implements ServerSideFigmaMCP with SSE session maintenance, JSON-RPC over HTTP, request tracking/timeouts, helper methods (getCode/getImage/getVariableDefs), and wires router into appRouter; re-exports router.
Models: Message Context Types
packages/models/src/chat/message/context.ts
Adds MessageContextType.FIGMA, defines FigmaMessageContext type, and extends the MessageContext union to include Figma contexts.
UI Icons
packages/ui/src/components/icons/index.tsx
Adds Figma icon exports: Figma (alias to external icon) and inline FigmaLogo SVG component.
AI Prompt Contexts
packages/ai/src/prompt/context.ts, packages/ai/src/prompt/provider.ts
Adds figmaContentPrefix to CONTEXT_PROMPTS. Hydration collects FigmaMessageContext items and appends a dedicated figma-context block via new getFigmaContent helper; adapts prompt assembly to include Figma content.
Docs
docs/content/docs/tutorials/figma-to-onlook.mdx
Rewrites tutorial to cover importing Figma designs: prerequisites, connection/setup, selection vs URL workflows, FAQs, and updated images and guidance.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant WC as Web Client (Chat UI)
  participant TRPC as TRPC figma.getDesignFromUrl
  participant MCP as Figma MCP (SSE + HTTP)
  participant Ctx as ChatContext

  U->>WC: Click "Add Figma Design" (URL)
  WC->>TRPC: getDesignFromUrl(figmaUrl)
  TRPC->>MCP: ensure session + JSON-RPC calls (code/image/vars)
  MCP-->>TRPC: aggregated design data
  TRPC-->>WC: {success, data, nodeId}
  WC->>Ctx: addFigmaContext(figmaUrl, nodeId, displayName, content)
  Ctx-->>WC: context updated
  WC-->>U: Success toast, modal closes
sequenceDiagram
  participant U as User
  participant WC as Web Client (Chat UI)
  participant TRPC as TRPC figma.getCurrentSelection
  participant MCP as Figma MCP
  participant Ctx as ChatContext

  U->>WC: Click "Add Selected Frame from Figma"
  WC->>TRPC: getCurrentSelection()
  TRPC->>MCP: JSON-RPC calls (code/image/vars)
  MCP-->>TRPC: selection design data
  TRPC-->>WC: {success, data}
  WC->>Ctx: addFigmaContext(figma://selection/..., nodeId, displayName, content)
  Ctx-->>WC: context updated
  WC-->>U: Success toast, modal closes

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~110 minutes

Poem

I hop through frames and URL strings bright,
I listen to SSE through the night.
I paste, I fetch, I stitch code and scheme,
Designs become components—what a dream!
Carrots, canvases, and MCP delight. 🥕✨

[!TIP]

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 61cff8a08697c6b0964c42f44aba0545a806574f and adb53b7879e4190e0bcfc1a893dab8de4f5ef07a.

📒 Files selected for processing (2)
  • apps/web/client/src/server/api/routers/figma.ts (1 hunks)
  • packages/ai/src/prompt/context.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/client/src/server/api/routers/figma.ts
  • packages/ai/src/prompt/context.ts
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Aug 16 '25 10:08 coderabbitai[bot]