Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/pwa-storefront-mcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## v1.0.0-dev.0 (Jun 26, 2025)
- Add `pwa-kit-create-app` guideline tool [#2663](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2663)
105 changes: 30 additions & 75 deletions packages/pwa-storefront-mcp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/pwa-storefront-mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"@babel/runtime": "^7.21.0",
"@modelcontextprotocol/sdk": "^1.0.0",
"node-pty": "1.0.0",
"zod": "^3.25.56"
},
"devDependencies": {
Expand Down
15 changes: 13 additions & 2 deletions packages/pwa-storefront-mcp/src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'
import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'
import {z} from 'zod'
import {DeveloperGuidelinesTool} from '../utils/pwa-developer-guideline-tool.js'
import {CreateNewComponentTool} from '../utils/create-new-component-tool.js'
import {
CreateAppGuidelinesTool,
CreateNewComponentTool,
DeveloperGuidelinesTool
} from '../utils/index.js'
import {HookRecommenderTool} from '../utils/hook-recommender-tool.js'
import productDocument from '../data/ProductDocument.json' with { type: 'json' }
import categoryDocument from '../data/CategoryDocument.json' with { type: 'json' }
Expand Down Expand Up @@ -42,6 +45,14 @@ class PwaStorefrontMCPServerHighLevel {
}

setupTools() {
// Register CreateProjectTool
this.server.tool(
CreateAppGuidelinesTool.name,
CreateAppGuidelinesTool.description,
CreateAppGuidelinesTool.inputSchema,
CreateAppGuidelinesTool.fn
)

// Register DeveloperGuidelinesTool
this.server.tool(
DeveloperGuidelinesTool.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function inferEntityFromComponentName(componentName) {
return null
}

export class CreateNewComponentTool {
class CreateNewComponentTool {
constructor() {
this.currentStep = 0
this.componentData = {
Expand Down Expand Up @@ -498,3 +498,5 @@ export default ${pascalComponentName};
return 'Selected hook/entity not supported for presentational generation.'
}
}

export default CreateNewComponentTool
11 changes: 11 additions & 0 deletions packages/pwa-storefront-mcp/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2025, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import CreateAppGuidelinesTool from './pwa-create-app-guideline-tool.js'
import CreateNewComponentTool from './create-new-component-tool.js'
import DeveloperGuidelinesTool from './pwa-developer-guideline-tool.js'

export {CreateAppGuidelinesTool, CreateNewComponentTool, DeveloperGuidelinesTool}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2025, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import path from 'path'

// Project dependencies
import {EmptyJsonSchema, isMonoRepo, runWithPty} from './utils.js'

// const CREATE_APP_VERSION = 'latest'
const CREATE_APP_VERSION = '3.11.0-nightly-20250630080227'
const CREATE_APP_COMMAND = isMonoRepo()
? path.resolve(
`${process.env.WORKSPACE_FOLDER_PATHS}/packages/pwa-kit-create-app/scripts/create-mobify-app.js`
)
: `@salesforce/pwa-kit-create-app@${CREATE_APP_VERSION}`
const DISPLAY_PROGRAM_COMMAND = '--displayProgram'
const NPX_COMMAND = 'npx'

const guidelinesText = `
# PWA Kit Create App — Agent Usage Guidelines

## Overview

This document defines the behavior agents must follow when using the \`@salesforce/pwa-kit-create-app\` CLI tool to generate new PWA Kit projects. The CLI supports both **presets** and **templates** for project creation, and agents must clearly distinguish between these two modes of operation.
Copy link
Contributor

@yhsieh1 yhsieh1 Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you have a section explains presets and templates options? So that agent knows the difference if asked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent in fact already knows that because it has imported program.json from the create-app package itself which has all the schema's and data for presets and templates.

I did this so that the information defined by the create-app project stays co-located with that project and not in ours where it can become out-of-sync. This way if some we add a feature by means of new template type or preset, or argument to the create app project, the mcp will ingest that information without having to make a change to the tool.


---

## General Rules

- Always use this tool to initiate project creation. Never attempt to manually create a project outside of this process.
- Ask one question at a time when gathering information from the user.
- Do not mix presets and templates. Only show or ask about one based on the user's intent.
- Never proceed with project generation unless all required information has been collected.

---

## Creating a Project Using a Preset

If the user requests a project using a **preset**:

- List only the available presets.
- If a preset is provided, use the \`--preset\` flag with the CLI.
- Do not ask for or display any template options.

---

## Creating a Project Using a Template

If the user requests a project using a **template**:

- List only the available templates.
- If a template is provided:
- Use its associated questions to prompt the user, one at a time.
- Do not proceed with project generation until all required answers have been collected.
- Do not ask for or display any preset options.

---

## Important Reminders

- Never attempt to create a project without using this tool.
- When gathering answers for a template, ask questions one at a time to maintain clarity.
- Presets and templates are mutually exclusive paths. Do not offer both options unless explicitly requested.
- Use the \`${NPX_COMMAND}\` command to run the \`${CREATE_APP_COMMAND}\` CLI tool when creating a new project.
`

export default {
name: 'create-app_guidelines',
description: `This tool is used to provide the agent with the instructions on how to use the @salesforce/pwa-kit-create-app CLI tool to create a new PWA Kit projects. Do not attempt to create a project without using this tool first.`,
inputSchema: EmptyJsonSchema,
fn: async () => {
let programOutput = ''

// Run the display program and get the output.
try {
programOutput = await runWithPty(NPX_COMMAND, [
CREATE_APP_COMMAND,
DISPLAY_PROGRAM_COMMAND
])
} catch (err) {
console.error('Failed to run display program:', err)
}

// Parse the output and get the data, metadata, and schemas.
const {
data,
metadata: {description: cli},
schemas
} = JSON.parse(programOutput)

return {
content: [
{
type: 'text',
text: JSON.stringify(
{
guidelines: guidelinesText,
cli,
schemas,
data
},
null,
2
)
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ This document offers guidelines in the development of Salesforce Commerce Compos
- Follow security best practices for all code.
`

export const DeveloperGuidelinesTool = {
export default {
name: 'development_guidelines',
description: `You must follow this development guidelines before attempting to analyze/ generate / refactor / modify / fix code.
- e.g. "Create a customer service Chat component", "Find bugs in my_script.jsx", "Refactor my_script.jsx to use React Hooks"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {DeveloperGuidelinesTool} from './pwa-developer-guideline-tool.js'
import DeveloperGuidelinesTool from './pwa-developer-guideline-tool.js'
import {EmptyJsonSchema} from './utils.js'

describe('PWA Development Guidelines', () => {
Expand Down
Loading
Loading