feat: add create_page MCP tool - #42
Conversation
Added documentation for the `create_page` function and its usage.
Added a new tool to create a page in the Figma document with optional parameters.
Added 'create_page' command to handle page creation with optional name and current page setting.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds the ChangesPage creation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant MCPClient
participant MCPServer
participant FigmaPlugin
participant FigmaPage
MCPClient->>MCPServer: submit create_page parameters
MCPServer->>FigmaPlugin: forward validated request
FigmaPlugin->>FigmaPage: create and name page
FigmaPlugin->>FigmaPage: optionally select page
FigmaPage-->>FigmaPlugin: return page metadata
FigmaPlugin-->>MCPServer: return standardized result
MCPServer-->>MCPClient: return page ID and metadata
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@plugin/src/main/code.ts`:
- Around line 1251-1276: Update appendToParentIfProvided to detect when the
resolved parent is a PageNode and await its loadAsync() before calling
parent.appendChild(node), including non-current pages created by create_page.
Preserve the existing behavior for all other parent node types.
In `@server/src/schema.ts`:
- Around line 404-407: Update the page name validator in the schema’s name field
to reject whitespace-only values by validating the trimmed string has positive
length, while preserving optionality and acceptance of non-whitespace names.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 560eb11f-49da-4fac-9402-7926cb414503
📒 Files selected for processing (4)
README.mdplugin/src/main/code.tsserver/src/schema.tsserver/src/tools.ts
|
|
|
@julioservan could you sing the CLA please? Pushed also a minor fix, everything looks great! |
Closes #27
Problem
The bridge exposes a fairly complete authoring surface — frames, text, shapes, images, groups, auto-layout, effects — but there is no way to create a page. As reported in #27, agents working in a file have to place everything on the current page, and the common workaround is pushing new frames far off-canvas so they don't collide with existing work.
Solution
Adds a
create_pagetool following the same pattern as the othercreate_*tools:server/src/schema.ts—createPageInput(name?,setAsCurrent?,fileKey?), plus entries intoolInputSchemasandrpcToArgs, so the request goes through the samevalidateRpcpath as every other tool.server/src/tools.ts— registers the tool withparseToolInput/renderResponse, mirroringcreate_frame.plugin/src/main/code.ts— addscreate_pageto theRequestTypeunion and toEDIT_REQUEST_TYPES, and implements the handler.README.md— one row in the tools table and a note under Editing Notes.The tool returns the new page's ID, so it composes with the existing tools without needing to switch the editor:
getParentNodeByIdalready accepts any node withappendChild, soPageNodeworks as aparentIdwith no changes on that path.Notes
setCurrentPageAsync— the manifest setsdocumentAccess: "dynamic-page", where assigningfigma.currentPagedirectly throws. The optionalsetAsCurrentflag uses the async setter instead. It defaults tofalseso creating a page is non-disruptive.create_pageis added toEDIT_REQUEST_TYPESso it returns the existing "requires the design editor" message instead of an opaque runtime error.nameis.min(1)— an empty string would produce an unnamed page, so it's rejected at the schema level.Verification
tsc --noEmitonserver/— clean.tsc --noEmitonplugin/— same pre-existing errors asmain, no new ones.vite build— plugin bundle builds withcreate_pagepresent indist/code.js.create_pageamong them with the expected input schema.{name:""}and{setAsCurrent:"yes"}are rejected with readable messages.Haven't been able to exercise the handler inside a live Figma file yet — happy to test further if useful.
Summary by CodeRabbit
New Features
Documentation