@createlex/figma-swiftui-mcp 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +37 -344
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,54 +1,32 @@
1
- # Figma to SwiftUI
1
+ # CreateLex Figma to SwiftUI MCP
2
2
 
3
- A Figma plugin and local MCP toolchain for generating SwiftUI code directly from Figma designs. You can export a ready-to-import Xcode package from the plugin UI, or run an MCP-first workflow that inspects the live Figma session and writes generated SwiftUI directly into Xcode. In production, the local MCP runtime is authenticated against CreateLex and only starts for paid subscribers.
3
+ CreateLex Figma to SwiftUI MCP is a paid local runtime for CreateLex subscribers. It connects your live Figma plugin session to CreateLex and lets you inspect designs, generate SwiftUI, export assets, and write output directly into a local Xcode project.
4
4
 
5
- ## Overview
5
+ ## What it does
6
6
 
7
- This project consists of four main components:
7
+ - Connects to the Figma to SwiftUI plugin while the plugin window is open
8
+ - Authenticates against your CreateLex account and subscription
9
+ - Starts the local MCP runtime and localhost bridge automatically
10
+ - Generates SwiftUI and asset output for your selected Figma frame
11
+ - Writes generated files into your local Xcode project
8
12
 
9
- - **Figma Plugin** (`code.ts`): Runs in Figma, converts selected design nodes to SwiftUI code, exports images, and can download an Xcode-ready package from the UI
10
- - **Local Bridge Server** (`companion/bridge-server.cjs`): Runs locally on port 7765, powers the bridge used by both the plugin and agent clients, and writes generated files into a dedicated `FigmaGenerated` area inside your Xcode source folder
11
- - **Bridge Relay** (`companion/bridge-server.cjs` WebSocket path `/bridge`): Relays structured Figma data between the live plugin UI and agent clients
12
- - **MCP Server** (`companion/mcp-server.mjs`): The main runtime entrypoint. Starts the localhost bridge automatically, exposes stdio MCP tools, and writes directly into Xcode
13
+ ## Requirements
13
14
 
14
- ## Architecture
15
+ - An active CreateLex subscription for `figma-swiftui`
16
+ - Node.js 18 or later
17
+ - Figma desktop app with the Figma to SwiftUI plugin open
18
+ - A local Xcode project
15
19
 
16
- ```
17
- ┌──────────────────────────────┐
18
- │ MCP / Agent Client │
19
- │ npx @createlex/figma-swiftui-mcp start │
20
- └──────────────┬───────────────┘
21
- │ stdio MCP
22
-
23
- MCP server boots localhost bridge
24
-
25
-
26
- ws://localhost:7765/bridge
27
-
28
-
29
- Figma UI ── pluginMessage ──> Plugin Code ── HTTP POST ──> Bridge Server ──> Xcode Project
30
- │ │
31
- └──────── bridge events ───────┘
32
- ```
33
-
34
- ## Prerequisites
35
-
36
- - Figma account
37
- - Xcode project
38
- - Node.js (v18 or later) and npm for the MCP server, localhost bridge, or local plugin development
20
+ ## Install
39
21
 
40
- ## Setup & Installation
41
-
42
- ### Production Install
43
-
44
- Users do not need this repo checked out locally. The production flow is:
22
+ Run directly with `npx`:
45
23
 
46
24
  ```bash
47
25
  npx @createlex/figma-swiftui-mcp login
48
26
  npx @createlex/figma-swiftui-mcp start --project /path/to/MyApp/MyApp
49
27
  ```
50
28
 
51
- Or install it once globally:
29
+ Or install globally:
52
30
 
53
31
  ```bash
54
32
  npm install -g @createlex/figma-swiftui-mcp
@@ -56,329 +34,44 @@ figma-swiftui-mcp login
56
34
  figma-swiftui-mcp start --project /path/to/MyApp/MyApp
57
35
  ```
58
36
 
59
- - `login` opens the CreateLex browser flow and writes `~/.createlex/auth.json`
60
- - `start` boots the local MCP runtime and localhost bridge together
61
- - the Figma plugin UI must stay open while you use MCP tools
62
-
63
- ### Development Setup
64
-
65
- ```bash
66
- cd figma-plugin-swiftui
67
- npm install
68
- ```
69
-
70
- `npm install` now installs both the plugin dependencies and the local MCP runtime dependencies.
71
-
72
- ## Building
73
-
74
- Compile the TypeScript plugin code to JavaScript:
75
-
76
- ```bash
77
- npm run build
78
- ```
79
-
80
- Watch for changes during development:
81
-
82
- ```bash
83
- npm run watch
84
- ```
85
-
86
- This will continuously compile `code.ts` → `code.js` as you edit.
87
-
88
- ## Production Access Model
89
-
90
- `figma-swiftui` is a local runtime, but it is not an offline-only product. The MCP process validates the current user against the CreateLex backend before it starts, and revalidates the session while it is running.
91
-
92
- Production expectations:
93
-
94
- - the MCP runtime runs locally on the developer machine
95
- - the user must already be authenticated with CreateLex
96
- - the user must have an active paid subscription
97
- - if the subscription becomes invalid, the local runtime stops accepting bridge and MCP requests
98
- - Supabase auth configuration lives on the backend / DigitalOcean environment, not inside the local MCP package
99
-
100
- Before starting the production runtime:
101
-
102
- 1. Run `npx @createlex/figma-swiftui-mcp login` once.
103
- 2. Ensure the account has an active paid subscription.
104
- 3. Start the local runtime with `npx @createlex/figma-swiftui-mcp start --project /path/to/MyApp/MyApp`.
105
-
106
- Environment overrides for development:
107
-
108
- - `FIGMA_SWIFTUI_BYPASS_AUTH=true` bypasses the CreateLex subscription gate
109
- - `CREATELEX_API_BASE_URL=https://your-domain/api` points validation at a different backend
110
- - `CREATELEX_ACCESS_TOKEN=...` or `FIGMA_SWIFTUI_ACCESS_TOKEN=...` provides a token directly instead of reading `~/.createlex/auth.json`
111
-
112
- ## Running MCP + Bridge
113
-
114
- The MCP server is the only runtime command. It starts the localhost bridge automatically, validates the current CreateLex subscriber session, and that bridge powers both the plugin's **Send to Xcode** button and the MCP tools. You do not need any local runtime for **Download Package**.
115
-
116
- ### Option 1: With project path specified
117
-
118
- ```bash
119
- npx @createlex/figma-swiftui-mcp start --project /path/to/MyApp/MyApp
120
- ```
121
-
122
- Replace `/path/to/MyApp/MyApp` with the actual path to your Xcode project's source folder (the one containing your Swift files and `Assets.xcassets`).
123
-
124
- The companion writes generated files into:
125
-
126
- ```text
127
- {ProjectSource}/FigmaGenerated/Screens/
128
- {ProjectSource}/FigmaGenerated/Components/
129
- {ProjectSource}/FigmaGenerated/Manifest/
130
- ```
131
-
132
- Image sets still go into the existing `Assets.xcassets` for build compatibility.
133
-
134
- ### Option 2: Without project path (set from plugin UI)
135
-
136
- ```bash
137
- npx @createlex/figma-swiftui-mcp start
138
- ```
139
-
140
- Then set the project path through MCP or the Figma plugin UI after connecting.
141
-
142
- The MCP process will also boot the bridge at `http://localhost:7765`.
143
-
144
- Example output:
145
- ```
146
- 🚀 Figma SwiftUI bridge running at http://localhost:7765
147
- 📂 Project path: /Users/you/Projects/MyApp/MyApp
148
- 🌉 Bridge ready at ws://localhost:7765/bridge
149
- MCP server running on stdio
150
- ```
151
-
152
- ## MCP-First Workflow
153
-
154
- If you are using Cursor, Codex, Claude Code, or another MCP-compatible local tool, this is the preferred workflow:
155
-
156
- 1. Start the local bridge and MCP server:
157
-
158
- ```bash
159
- npx @createlex/figma-swiftui-mcp start
160
- ```
161
-
162
- 2. Keep the Figma plugin UI open so the bridge remains attached to the live Figma session.
163
- 3. From the MCP client:
164
- - inspect the design structure
165
- - generate SwiftUI
166
- - write directly into the Xcode project
37
+ ## Login
167
38
 
168
- The MCP server persists the chosen Xcode source folder in:
39
+ `login` opens your browser and signs you in with CreateLex. When login succeeds, the runtime saves your local session to:
169
40
 
170
41
  ```text
171
- ~/Library/Application Support/FigmaSwiftUICompanion/config.json
42
+ ~/.createlex/auth.json
172
43
  ```
173
44
 
174
- You can set that path once through MCP and then write repeatedly from the MCP client.
175
-
176
- ## High-Fidelity Workflow
177
-
178
- For `figma-swiftui`, the local MCP runtime should be the primary inspection and generation tool. The most effective pattern is:
179
-
180
- 1. inspect the design with `figma-swiftui`
181
- 2. generate the first SwiftUI scaffold with `figma-swiftui`
182
- 3. refine assets and visual details with normal code editing
183
-
184
- In practice:
185
- - use `figma-swiftui` for raw facts like SVG-backed icons, nested node structure, screenshots, export planning, and exact generation diagnostics
186
- - use `figma-swiftui` for the initial native SwiftUI scaffold and Xcode export
187
- - use your project/file tools for final polish and wiring
188
-
189
- You only need Figma Dev MCP as a fallback if you want broader Figma platform features outside the `figma-swiftui` workflow.
190
-
191
- Detailed guidance is in [docs/HIGH_FIDELITY_WORKFLOW.md](/Users/alexkissijr/dev/GitHub/AiWebplatform/figma-plugin-swiftui/docs/HIGH_FIDELITY_WORKFLOW.md).
192
-
193
- ## Hybrid Production Model
194
-
195
- For production, the recommended architecture is hybrid:
196
-
197
- - hosted CreateLex services own entitlement checks, signed execution plans, and the long-term home of premium generation logic
198
- - the local `figma-swiftui` runtime stays thin and handles only live Figma access plus local Xcode writes
199
-
200
- The current hybrid foundation and migration path are documented in [docs/HYBRID_ARCHITECTURE.md](/Users/alexkissijr/dev/GitHub/AiWebplatform/figma-plugin-swiftui/docs/HYBRID_ARCHITECTURE.md).
201
-
202
- Today, the first hosted generation path covers recognized single-screen `editable` semantic scaffolds. If the hosted service cannot confidently handle a screen yet, the local runtime falls back to the existing local generator.
203
-
204
- ## Agent Bridge and MCP Mode
205
-
206
- The MCP runtime exposes the bridge endpoints used for agentic tooling:
207
-
208
- - Raw WebSocket bridge: `ws://localhost:7765/bridge`
209
- - Bridge status endpoint: `GET http://localhost:7765/bridge/info`
210
- - MCP runtime: `npx @createlex/figma-swiftui-mcp start`
211
- - Build plugin bundle: `npm run build`
212
- - Bridge smoke test: `npm run test:bridge-smoke`
213
- - High-fidelity inspection smoke: `npm run test:high-fidelity-smoke`
214
- - Auth status tool: `auth_status`
215
-
216
- The bridge only works when the Figma plugin UI is open and connected to the local companion. Once connected, agent clients can inspect document/page/selection data or call the same SwiftUI generation path used by the plugin UI.
217
-
218
- Available bridge-backed MCP tools:
219
-
220
- - `bridge_status`
221
- - `get_project_path`
222
- - `set_project_path`
223
- - `get_metadata`
224
- - `get_design_context`
225
- - `get_screenshot`
226
- - `export_svg`
227
- - `get_document_summary`
228
- - `get_viewport_context`
229
- - `get_selection_snapshot`
230
- - `get_page_snapshot`
231
- - `get_node_snapshot`
232
- - `find_nodes`
233
- - `dump_tree`
234
- - `get_asset_export_plan`
235
- - `extract_reusable_components`
236
- - `write_svg_to_xcode`
237
- - `generate_swiftui`
238
- - `analyze_generation`
239
- - `write_generated_swiftui_to_xcode`
240
- - `write_selection_to_xcode`
241
-
242
- ## Using the Plugin
243
-
244
- ### Loading the Plugin in Figma
45
+ ## Start the runtime
245
46
 
246
- 1. Open Figma
247
- 2. Go to **Plugins** → **Create new plugin**
248
- 3. Select **Link existing plugin** and point to `manifest.json` in this directory
249
- 4. Alternatively, use the Figma dashboard to import this directory as a plugin
47
+ Start the runtime with the Xcode source folder that contains your Swift files and `Assets.xcassets`:
250
48
 
251
- ### Using the Plugin
252
-
253
- 1. Select a component or frame in Figma
254
- 2. Run the plugin (Plugins menu → Figma to SwiftUI)
255
- 3. A UI panel opens with the SwiftUI export controls.
256
- 4. Pick one export path:
257
- - **Download Package** exports a zip containing `{StructName}.swift` plus an `Assets.xcassets` payload. This path does not require any local server.
258
- - **Copy** copies the generated SwiftUI if you only want the code.
259
- 5. In the Xcode sync panel:
260
- - **Choose Folder** opens a native folder picker so you can select the Xcode project source folder
261
- - **Send to Xcode** writes the generated Swift file into `FigmaGenerated/Screens`, updates `FigmaGenerated/Manifest`, and writes exported images into the project's existing `Assets.xcassets`
262
- 6. If the local runtime is running and authorized, the generated code and images can be written directly into your Xcode project
263
-
264
- ### MCP-Only Xcode Sync
265
-
266
- If you want to drive the whole sync from MCP:
267
-
268
- 1. Start the MCP runtime.
269
- 2. Keep the plugin UI open in Figma.
270
- 3. Call `set_project_path` once.
271
- 4. Call `write_selection_to_xcode` to generate from the live selection and write directly into Xcode.
272
-
273
- ### Environment Setup
274
-
275
- The plugin looks for the local bridge at `http://localhost:7765`. Ensure:
276
- - `npx @createlex/figma-swiftui-mcp start` is running before using **Send to Xcode**
277
- - Your Xcode project path is set (either via `--project` flag or the plugin UI)
278
- - If you are using **Download Package**, no local runtime is required
279
- - If you want to use MCP or a raw WebSocket client, keep the plugin UI open so the bridge stays attached to a live Figma session
280
-
281
- ## Project Structure
282
-
283
- ```
284
- figma-plugin-swiftui/
285
- ├── README.md # This file
286
- ├── package.json # Plugin dependencies (TypeScript)
287
- ├── tsconfig.json # TypeScript configuration
288
- ├── manifest.json # Figma plugin manifest
289
- ├── code.ts # Plugin source code (TypeScript)
290
- ├── code.js # Compiled plugin code (generated)
291
- ├── ui.html # Plugin UI (HTML/CSS/JS)
292
-
293
- └── companion/
294
- ├── package.json # Companion + MCP dependencies
295
- ├── bridge-server.cjs # HTTP server + WebSocket bridge relay
296
- ├── server.js # Thin bridge-only wrapper (debug/legacy)
297
- ├── mcp-server.mjs # stdio MCP entrypoint that boots the bridge
298
- ├── xcode-writer.cjs # Shared Xcode write/layout logic
299
- └── node_modules/ # Dependencies
300
- ```
301
-
302
- ## Development
303
-
304
- ### Editing the Plugin
305
-
306
- 1. Edit `code.ts` (the main plugin logic)
307
- 2. Run `npm run watch` to auto-compile on save
308
- 3. The compiled `code.js` is what Figma actually runs
309
-
310
- ### Editing the UI
311
-
312
- Edit `ui.html` directly. It's loaded by the plugin via `figma.showUI()`.
313
-
314
- ### Testing the Runtime
315
-
316
- The server has two main endpoints:
317
-
318
- - `GET /ping` – Health check, returns project path status
319
- - `GET /bridge/info` – Bridge health/status, reports whether a live plugin session is attached
320
- - `POST /set-project` – Saves a manually entered project path after validating it exists
321
- - `POST /choose-project` – Opens a native macOS folder picker and saves the selected path
322
- - `POST /write` – Receives `{ code, structName, images, customPath }`, writes `FigmaGenerated/Screens/{StructName}.swift`, updates `FigmaGenerated/Manifest`, and writes images into `Assets.xcassets`
323
- - `WS /bridge` – Relays structured Figma requests/responses/events between the plugin UI and external clients
324
-
325
- Example POST to test:
326
49
  ```bash
327
- curl -X POST http://localhost:7765/write \
328
- -H "Content-Type: application/json" \
329
- -d '{
330
- "code": "struct MyView: View { var body: some View { Text(\"Hello\") } }",
331
- "structName": "MyView"
332
- }'
50
+ npx @createlex/figma-swiftui-mcp start --project /path/to/MyApp/MyApp
333
51
  ```
334
52
 
335
- ## Troubleshooting
336
-
337
- ### Server not reachable from plugin
338
-
339
- - This only affects **Send to Xcode**. The **Download Package** flow still works without the MCP runtime.
340
- - Ensure the MCP runtime is running: `npx @createlex/figma-swiftui-mcp start`
341
- - Check that it's listening on `http://localhost:7765`
342
- - Check the plugin's `manifest.json` `allowedDomains` includes both `http://localhost:7765` and `ws://localhost:7765`
343
-
344
- ### Bridge or MCP shows no live Figma data
345
-
346
- - The MCP runtime can be running while the bridge is still disconnected from Figma. Open the plugin UI and leave it open.
347
- - Check `http://localhost:7765/bridge/info` and confirm `pluginConnected: true`
348
- - Restart the plugin UI if the bridge stays in `bridge waiting`
349
- - Start the MCP runtime with `npx @createlex/figma-swiftui-mcp start`
350
-
351
- ### MCP runtime exits immediately
53
+ If you omit `--project`, you can set the project path later from the plugin UI or your MCP client.
352
54
 
353
- - Run `npx @createlex/figma-swiftui-mcp login` first so `~/.createlex/auth.json` exists
354
- - Confirm the account has an active paid subscription
355
- - If needed, check `auth_status` from the MCP client after startup
356
- - In local development only, use `FIGMA_SWIFTUI_BYPASS_AUTH=true` to bypass the subscription gate
55
+ ## Before you use it
357
56
 
358
- ### Project path not recognized
57
+ 1. Log in with CreateLex
58
+ 2. Make sure your subscription is active
59
+ 3. Open the Figma to SwiftUI plugin in Figma and keep it open
60
+ 4. Start the local runtime
61
+ 5. Use your MCP client or the plugin UI to generate and sync output
359
62
 
360
- - Verify the path points to the folder containing `.swift` files and `Assets.xcassets`
361
- - The server will create `FigmaGenerated/` and `Assets.xcassets` if they don't exist
362
- - Check filesystem permissions
63
+ ## Subscription and access
363
64
 
364
- ### TypeScript compilation errors
65
+ This package is public to install, but runtime access is gated by CreateLex. If your account is not logged in or does not have an active `figma-swiftui` subscription, the runtime will not start.
365
66
 
366
- - Run `npm install` to ensure all dependencies are installed
367
- - Delete `node_modules` and reinstall if issues persist: `rm -rf node_modules && npm install`
67
+ ## Product page
368
68
 
369
- ## Dependencies
69
+ Manage plans and billing at:
370
70
 
371
- ### Plugin
372
- - `@figma/plugin-typings` – Type definitions for Figma plugin API
373
- - `typescript` – TypeScript compiler
71
+ - https://createlex.com/figma-swiftui
374
72
 
375
- ### MCP Runtime
376
- - `express` – Web server framework
377
- - `cors` – Cross-Origin Resource Sharing middleware
378
- - `ws` – WebSocket bridge relay
379
- - `@modelcontextprotocol/sdk` – MCP server SDK for the stdio wrapper
380
- - `zod` – MCP tool input schemas
73
+ ## Support
381
74
 
382
- ## License
75
+ For help, billing, or onboarding:
383
76
 
384
- Part of the AiWebplatform project.
77
+ - https://createlex.com/contact
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@createlex/figma-swiftui-mcp",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "CreateLex MCP runtime for Figma-to-SwiftUI generation and Xcode export",
5
5
  "bin": {
6
6
  "figma-swiftui-mcp": "bin/figma-swiftui-mcp.js"