MCP Pencil Tools Reference / Tham Chiếu MCP Pencil
Khi Nào Dùng MCP vs Build Scripts
| Tác vụ |
MCP Pencil |
Build Scripts |
| Thiết kế UI realtime |
✅ Dùng MCP |
❌ |
| Xem screenshot |
✅ get_screenshot |
❌ |
| Lấy style guide |
✅ get_style_guide |
❌ |
| Build library từ Atomic |
❌ |
✅ scripts/build.py |
| Merge nhiều files |
❌ |
✅ scripts/build.py -m |
| Extract components |
❌ |
✅ scripts/extract-atomic.py |
Tools Overview
1. Document Management
| Tool |
Mục đích |
open_document |
Mở file .pen hoặc tạo mới ("new") |
get_editor_state |
Lấy state hiện tại: file đang mở, selection, components |
get_variables |
Đọc design tokens (colors, spacing, typography) |
set_variables |
Cập nhật design tokens |
2. Design Operations
| Tool |
Mục đích |
batch_design |
Insert/Update/Replace/Copy/Move/Delete nodes |
batch_get |
Đọc nodes theo ID hoặc search patterns |
snapshot_layout |
Kiểm tra layout structure, tìm overlapping |
find_empty_space_on_canvas |
Tìm vị trí trống để đặt frame mới |
3. Guidelines & Inspiration
| Tool |
Mục đích |
get_guidelines |
Lấy hướng dẫn theo topic: design-system, landing-page, table, code, tailwind |
get_style_guide_tags |
Liệt kê tags có sẵn cho style guide |
get_style_guide |
Lấy style guide theo tags hoặc tên |
4. Verification
| Tool |
Mục đích |
get_screenshot |
Chụp screenshot node để verify |
5. Batch Operations
| Tool |
Mục đích |
search_all_unique_properties |
Tìm all unique values của properties |
replace_all_matching_properties |
Thay thế properties matching |
batch_design Operations
Operations trong batch_design dùng syntax đặc biệt:
Quy Tắc Quan Trọng
Workflow Chuẩn
1. Khởi Đầu
2. Lấy Context
3. Thiết Kế
4. Verify
Ví Dụ: Dashboard Screen
// Batch 1: Structure
screen=I(document, {type: "frame", name: "Dashboard", layout: "horizontal", width: 1440, height: 900, fill: "$--background", placeholder: true})
sidebar=I(screen, {type: "ref", ref: "SidebarComp", height: "fill_container"})
main=I(screen, {type: "frame", layout: "vertical", width: "fill_container", height: "fill_container", padding: 32, gap: 24})
// Batch 2: Sidebar items
item1=I(sidebar+"/contentSlot", {type: "ref", ref: "SidebarItem", descendants: {"labelId": {content: "Dashboard"}}})
item2=I(sidebar+"/contentSlot", {type: "ref", ref: "SidebarItem", descendants: {"labelId": {content: "Users"}}})
// Batch 3: Main content
header=I("mainId", {type: "frame", layout: "horizontal", width: "fill_container", justifyContent: "space_between"})
title=I(header, {type: "text", content: "Dashboard", fontSize: 24, fontWeight: "600", fill: "$--foreground"})
cards=I("mainId", {type: "frame", layout: "horizontal", gap: 16})
card1=I(cards, {type: "ref", ref: "CardComp", width: "fill_container"})
card2=I(cards, {type: "ref", ref: "CardComp", width: "fill_container"})
// Batch 4: Finalize
U("screenId", {placeholder: false})
Common Patterns
Override Component Text
Replace Slot Content
Add Image to Frame
Find Empty Space
Troubleshooting
| Vấn đề |
Giải pháp |
| "A file needs to be open" |
Dùng open_document trước |
| Update descendants fail |
Dùng path: instanceId+"/childId" |
| Copy descendants fail |
Dùng descendants trong Copy, KHÔNG Update riêng |
| Nodes overlap |
Dùng find_empty_space_on_canvas |
| Layout broken |
Kiểm tra snapshot_layout(problemsOnly: true) |
Related