-
Notifications
You must be signed in to change notification settings - Fork 10
add page-designer-decorator tool for Storefront Next #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sf-cboscenco
merged 15 commits into
main
from
feature-W-20796544-add-page-designer-decorator-mcp-tool
Feb 18, 2026
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1340563
add page-designer-decorator tool for Storefront Next
sf-cboscenco a693fe1
Add manual test runner for page-designer-decorator tool- Add automate…
sf-cboscenco 63f5f8b
Remove unused zod-to-json-schema dependency
sf-cboscenco 9034319
refactor(b2c-dx-mcp): migrate page-designer-decorator tests from cust…
sf-cboscenco 00be5df
refactor(mcp): use Services.workingDirectory for component discovery
sf-cboscenco d40463e
refactor(mcp): rename page designer decorator tool and reorganize docs
sf-cboscenco f64c084
Merge latest main
sf-cboscenco 6b05769
fix(page-designer-decorator): use lazy Services loading and correct API
sf-cboscenco 2fb636a
refactor(mcp): add RequestHandlerExtra context parameter to tool hand…
sf-cboscenco 3828ba8
Updated the lockfile
sf-cboscenco eb1f0af
fix: update test handlers to include context parameter
sf-cboscenco 4605c1f
Revert the handler signature change
sf-cboscenco 081193c
Add missing dependency
sf-cboscenco caa3ae5
Revert build dependencies changes
sf-cboscenco 3459eca
Additional revert for the workspace file
sf-cboscenco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
255 changes: 255 additions & 0 deletions
255
packages/b2c-dx-mcp/src/tools/page-designer-decorator/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,255 @@ | ||
| # Page Designer Decorator Tool | ||
|
|
||
| Tool for adding Page Designer decorators to React components using native TypeScript template literals. | ||
|
|
||
| ## 🎯 Overview | ||
|
|
||
| This tool analyzes React components and generates Page Designer decorators (`@Component`, `@AttributeDefinition`, `@RegionDefinition`) to make components available in Page Designer for Storefront Next. | ||
|
|
||
| ## ✨ Key Features | ||
|
|
||
| - **Name-Based Lookup**: Find components by name (e.g., "ProductCard") without knowing paths | ||
| - **Auto-Discovery**: Automatically searches common component directories | ||
| - **Type-Safe**: Full TypeScript type inference for all contexts | ||
| - **Fast**: Direct function execution, no file I/O or compilation overhead | ||
| - **Flexible Input**: Supports component names or file paths | ||
| - **Two Modes**: Auto mode for quick setup, Interactive mode for fine-tuned control | ||
|
|
||
| ## 📁 File Structure | ||
|
|
||
| ``` | ||
| page-designer-decorator/ | ||
| ├── analyzer.ts # Component parsing and analysis | ||
| ├── rules.ts # Rule loader and exports | ||
| ├── index.ts # Main tool implementation | ||
| ├── rules/ | ||
| │ ├── 1-mode-selection.ts # Entry point | ||
| │ ├── 2a-auto-mode.ts # Auto mode workflow | ||
| │ ├── 2b-0-interactive-overview.ts # Interactive workflow overview | ||
| │ ├── 2b-1-interactive-analyze.ts # Step 1: Analysis | ||
| │ ├── 2b-2-interactive-select-props.ts # Step 2: Selection | ||
| │ ├── 2b-3-interactive-configure-attrs.ts # Step 3: Configuration | ||
| │ ├── 2b-4-interactive-configure-regions.ts # Step 4: Regions | ||
| │ └── 2b-5-interactive-confirm-generation.ts # Step 5: Generation | ||
| └── templates/ | ||
| └── decorator-generator.ts # Decorator code generation | ||
| ``` | ||
|
|
||
| ## 🚀 Usage | ||
|
|
||
| ### Basic Usage (Name-Based - Recommended) | ||
|
|
||
| ```bash | ||
| # By component name (automatically finds the file) | ||
| add_page_designer_decorator({ | ||
| component: "ProductCard", | ||
| autoMode: true | ||
| }) | ||
|
|
||
| # Interactive mode | ||
| add_page_designer_decorator({ | ||
| component: "Hero", | ||
| conversationContext: { step: "analyze" } | ||
| }) | ||
|
|
||
| # With custom search paths (for unusual locations) | ||
| add_page_designer_decorator({ | ||
| component: "ProductCard", | ||
| searchPaths: ["packages/retail/src", "app/features"], | ||
| autoMode: true | ||
| }) | ||
| ``` | ||
|
|
||
| ### Path-Based Usage | ||
|
|
||
| ```bash | ||
| # If you prefer to specify the exact path | ||
| add_page_designer_decorator({ | ||
| component: "src/components/ProductCard.tsx", | ||
| autoMode: true | ||
| }) | ||
| ``` | ||
|
|
||
| ### Workflow | ||
|
|
||
| 1. **Component Discovery**: Provide name (e.g., "ProductCard") or path | ||
| 2. **Mode Selection**: Choose Auto or Interactive mode | ||
| 3. **Analysis** (Interactive only): Review component props | ||
| 4. **Selection** (Interactive only): Select which props to expose | ||
| 5. **Configuration** (Interactive only): Configure types and defaults | ||
| 6. **Regions** (Interactive only): Configure nested content areas | ||
| 7. **Generation**: Get decorator code | ||
|
|
||
| ### Component Discovery | ||
|
|
||
| The tool automatically searches for components in these locations (in order): | ||
|
|
||
| 1. `src/components/**` (PascalCase and kebab-case) | ||
| 2. `app/components/**` | ||
| 3. `components/**` | ||
| 4. `src/**` (broader search) | ||
| 5. Custom paths (if provided via `searchPaths`) | ||
|
|
||
| **Examples:** | ||
|
|
||
| - `"ProductCard"` → finds `src/components/product-tile/ProductCard.tsx` | ||
| - `"Hero"` → finds `src/components/hero/Hero.tsx` or `app/components/hero.tsx` | ||
| - `"product-card"` → finds `src/components/product-card.tsx` or `product-card/index.tsx` | ||
|
|
||
| **Tips:** | ||
|
|
||
| - Use component name for portability | ||
| - Use path for unusual locations | ||
| - Add `searchPaths` for monorepos or non-standard structures | ||
|
|
||
| ## 🏗️ Architecture | ||
|
|
||
| ### Rule Rendering | ||
|
|
||
| Rules are pure TypeScript functions that return strings: | ||
|
|
||
| ```typescript | ||
| ${context.hasEditableProps | ||
| ? context.editableProps.map(prop => | ||
| `- \`${prop.name}\` (${prop.type})` | ||
| ).join('\n') | ||
| : '' | ||
| } | ||
| ``` | ||
|
|
||
| ### Type Safety | ||
|
|
||
| Every rule has a strongly-typed context interface: | ||
|
|
||
| ```typescript | ||
| export interface AnalyzeStepContext { | ||
| componentName: string; | ||
| file: string; | ||
| hasEditableProps: boolean; | ||
| editableProps: PropInfo[]; | ||
| // ... more fields | ||
| } | ||
|
|
||
| export function renderAnalyzeStep(context: AnalyzeStepContext): string { | ||
| // TypeScript checks all variable access at compile time | ||
| } | ||
| ``` | ||
|
|
||
| ### Template Generation | ||
|
|
||
| Code generation uses pure functions: | ||
|
|
||
| ```typescript | ||
| export function generateDecoratorCode(context: MetadataContext): string { | ||
| const imports = generateImports(context); | ||
| const decorator = generateComponentDecorator(context); | ||
| const attributes = generateAttributes(context); | ||
|
|
||
| return `${imports}${decorator}\nexport class ${context.metadataClassName} {\n${attributes}\n}`; | ||
| } | ||
| ``` | ||
|
|
||
| ## 📦 Build Process | ||
|
|
||
| All rules and templates are compiled into the JavaScript output: | ||
|
|
||
| ```json | ||
| { | ||
| "scripts": { | ||
| "build": "tsc" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## 🎯 When to Use This Tool | ||
|
|
||
| Use this tool when: | ||
|
|
||
| - ✅ You need to add Page Designer support to React components | ||
| - ✅ You want automatic component discovery by name | ||
| - ✅ You prefer type-safe decorator generation | ||
| - ✅ You need both quick auto-mode and detailed interactive workflows | ||
|
|
||
| ## 🔧 Development | ||
|
|
||
| ### Adding a New Rule | ||
|
|
||
| 1. Create a new file in `rules/`: | ||
|
|
||
| ```typescript | ||
| // rules/my-new-rule.ts | ||
| export interface MyRuleContext { | ||
| message: string; | ||
| } | ||
|
|
||
| export function renderMyRule(context: MyRuleContext): string { | ||
| return `# My Rule\n\n${context.message}`; | ||
| } | ||
| ``` | ||
|
|
||
| 2. Export it from `rules.ts`: | ||
|
|
||
| ```typescript | ||
| import {renderMyRule, type MyRuleContext} from './rules/my-new-rule.js'; | ||
|
|
||
| export const pageDesignerDecoratorRules = { | ||
| // ... existing rules | ||
| getMyRule(context: MyRuleContext): string { | ||
| return renderMyRule(context); | ||
| }, | ||
| }; | ||
| ``` | ||
|
|
||
| 3. Use it in `index.ts`: | ||
|
|
||
| ```typescript | ||
| const instructions = pageDesignerDecoratorRules.getMyRule({ | ||
| message: 'Hello World', | ||
| }); | ||
| ``` | ||
|
|
||
| ### Modifying Code Generation | ||
|
|
||
| Edit `templates/decorator-generator.ts` directly. Changes require recompilation. | ||
|
|
||
| ## 📊 Performance | ||
|
|
||
| The tool uses direct function execution with no file I/O or compilation overhead. Typical tool invocations complete in under 1ms. | ||
|
|
||
| ## ✅ Testing | ||
|
|
||
| ### Automated Tests | ||
|
|
||
| ```bash | ||
| pnpm build | ||
| pnpm test | ||
| ``` | ||
|
|
||
| Comprehensive test suite covers all workflow modes, component discovery, and error handling. | ||
|
|
||
| ### Manual Test Runner | ||
|
|
||
| For quick manual verification, use the test runner script: | ||
|
|
||
| ```bash | ||
| cd packages/b2c-dx-mcp | ||
| pnpm build | ||
| node test/tools/page-designer-decorator/index.test.mjs all | ||
| ``` | ||
|
|
||
| Run a specific test case: | ||
| ```bash | ||
| node test/tools/page-designer-decorator/index.test.mjs TC-1.1 | ||
| ``` | ||
|
|
||
| See [`test/tools/page-designer-decorator/README.md`](../../../test/tools/page-designer-decorator/README.md) for detailed testing instructions. | ||
|
|
||
| ## 🎓 Learning Resources | ||
|
|
||
| - [Template Literals (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) | ||
| - [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html) | ||
| - [MCP Tools Documentation](https://modelcontextprotocol.io/docs) | ||
|
|
||
| ## 📝 License | ||
|
|
||
| Apache-2.0 - Copyright (c) 2025, Salesforce, Inc. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.