UI Spec Generator
Generate structured page-component-function hierarchy from design resources and test cases.
Prerequisites
MCP Servers Required
- Pencil MCP: Read
.pendesign files viamcp__pencil__*tools - Figma MCP: Read Figma designs (configured in
.claude/mcp.json)
Input Resources
| Resource | Path | Purpose |
|---|---|---|
| Style spec | specs/design/style.pen, basic.pen |
Design tokens and style rules |
| Components | specs/design/components/*.pen |
Existing component designs |
| Screenshots | specs/design/assets/images/*.png |
Visual/layout reference |
| Page index | specs/design/pages.md |
Page-to-resource mapping with Figma links |
| Test cases | specs/testcases/*.md |
Functional requirements |
Workflow
Step 1: Gather Design Context
- Read
specs/design/style.pento understand design tokens (colors, fonts, spacing) - Read
specs/design/pages.mdto get page list and Figma URLs - Use Figma MCP to fetch component structure from Figma links
- Read existing
.penfiles inspecs/design/components/to catalog current components
Step 2: Analyze Test Cases
- Read all files in
specs/testcases/*.md - Extract implicit UI requirements from test case descriptions:
- What data needs to be displayed?
- What user actions are described?
- What state changes occur?
- Map requirements to pages and components
Step 3: Gap Analysis
Compare test case requirements against existing components:
- Covered: Test case UI needs are met by existing components
- Extendable: Existing component can be modified (see component-reuse-criteria.md)
- Missing: New component needed
Step 4: Design Missing Components
For gaps identified:
- Reference the corresponding screenshot in
specs/design/assets/images/ - Use Figma MCP to get detailed component structure if Figma link exists
- Follow existing design patterns from
style.pen - Prefer extending existing components over creating new ones
Step 5: Generate pages.yaml
Output to specs/design/pages.yaml following the format in output-format.md.
Structure:
pages:
- id: page-id
name: 页面名称
route: /path
sections:
- id: section-id
name: 区块名称
components:
- id: component-id
name: 组件名称
type: card|list-item|button|...
data_source: post|category|user|...
fields: [field1, field2]
actions: [action1, action2]
Using Figma MCP
Extract Figma file key and node ID from URLs in pages.md:
https://www.figma.com/design/{file_key}/...?node-id={node_id}
Use Figma MCP tools to:
- Get file structure and component hierarchy
- Identify grouped elements (frames, groups)
- Extract component names and relationships
Component Reuse Decision
Before creating new components, check references/component-reuse-criteria.md:
- Visual similarity with existing components
- Functional compatibility
- Non-breaking extension possibility
Data Type References
When specifying data_source, use types from specs/data/types.md:
category- 活动/赛事post- 帖子/提案user- 用户group- 团队resource- 资源文件rule- 规则interaction- 互动
Output Validation
After generating pages.yaml:
- Verify all pages from
pages.mdare included - Verify test case UI requirements are addressed
- Confirm component reuse is maximized
- Check YAML syntax validity
Converted and distributed by TomeVault — claim your Tome and manage your conversions.