Skip to content

Commit 817b19a

Browse files
Merge pull request #3118 from SalesforceCommerceCloud/t/commerce/W-19159067/cleanupForMCPTools
@W-19159067- Cleanup for MCP tools
2 parents 4609936 + a8180f9 commit 817b19a

File tree

4 files changed

+6
-58
lines changed

4 files changed

+6
-58
lines changed

packages/pwa-kit-mcp/src/tools/create-new-component.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import {z} from 'zod'
88
import fs from 'fs/promises'
99
import path from 'path'
10-
import {toKebabCase, toPascalCase, getCopyrightHeader} from '../utils'
10+
import {toKebabCase, toPascalCase} from '../utils'
1111

1212
const systemPrompt = `
1313
You are a smart assistant that helps create new React components.
@@ -126,7 +126,7 @@ class CreateNewComponentTool {
126126
if (entityType === 'product') {
127127
// If options.list is true, generate a list-of-products component
128128
if (options.list) {
129-
code = `${getCopyrightHeader()}
129+
code = `
130130
import React from 'react';
131131
import PropTypes from 'prop-types';
132132
import { Box, Text, Image, Stack } from '@chakra-ui/react';
@@ -165,7 +165,7 @@ export default ${pascalComponentName};
165165
`
166166
} else {
167167
// Single product component (with selectors, image, etc.)
168-
code = `${getCopyrightHeader()}
168+
code = `
169169
import React, { useState } from 'react';
170170
import PropTypes from 'prop-types';
171171
import { Box, Text, Image, Button, HStack, Stack } from '@chakra-ui/react';

packages/pwa-kit-mcp/src/tools/create-new-page-tool.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,7 @@ class CreateNewPageTool {
254254
})
255255
.join('\n')
256256

257-
return `/*
258-
* Copyright (c) ${new Date().getFullYear()}, Salesforce, Inc.
259-
* All rights reserved.
260-
* SPDX-License-Identifier: BSD-3-Clause
261-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
262-
*/
263-
257+
return `
264258
${imports.join('\n')}
265259
266260
/**

packages/pwa-kit-mcp/src/utils/utils.js

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import path from 'path'
1010
import {spawn} from 'cross-spawn'
1111
import {zodToJsonSchema} from 'zod-to-json-schema'
1212
import {z} from 'zod'
13-
import os from 'os'
14-
import {exec} from 'child_process'
1513

1614
// CONSTANTS
1715
const CREATE_APP_VERSION = 'latest'
@@ -156,46 +154,6 @@ export const getCreateAppCommand = () => {
156154
: `@salesforce/pwa-kit-create-app@${CREATE_APP_VERSION}`
157155
}
158156

159-
/**
160-
* Runs an NPX command and captures its output.
161-
*
162-
* @returns {Promise<string>} - Resolves with the command output.
163-
*/
164-
export async function runNpxCommand(NPX_COMMAND, CREATE_APP_COMMAND, DISPLAY_PROGRAM_COMMAND) {
165-
return new Promise((resolve, reject) => {
166-
const tempDir = os.tmpdir()
167-
const outputFilePath = path.join(tempDir, 'npx-output.json')
168-
const errorFilePath = path.join(tempDir, 'npx-error.log')
169-
const command = `${NPX_COMMAND} ${CREATE_APP_COMMAND} ${DISPLAY_PROGRAM_COMMAND} > ${outputFilePath} 2> ${errorFilePath}`
170-
171-
exec(command, (error) => {
172-
if (error) {
173-
reject(error)
174-
return
175-
}
176-
177-
fsPromises.promises
178-
.readFile(outputFilePath, 'utf-8')
179-
.then((data) => resolve(data))
180-
.catch((err) => reject(err))
181-
})
182-
})
183-
}
184-
185-
/**
186-
* Returns the copyright header with the current year
187-
* @returns {string} The copyright header text
188-
*/
189-
export const getCopyrightHeader = () => {
190-
const year = new Date().getFullYear()
191-
return `/*
192-
* Copyright (c) ${year}, Salesforce, Inc.
193-
* All rights reserved.
194-
* SPDX-License-Identifier: BSD-3-Clause
195-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
196-
*/`
197-
}
198-
199157
/**
200158
* Converts a string to kebab-case (e.g., ProductCard -> product-card)
201159
*/
@@ -214,7 +172,7 @@ export async function logMCPMessage(message) {
214172
if (process.env.DEBUG) {
215173
// Check if DEBUG mode is enabled
216174
const logFilePath = path.join(__dirname, 'mcp-debug.log')
217-
const timestamp = new Date().toLocaleString('en-US', {timeZone: 'America/New_York'})
175+
const timestamp = new Date().toLocaleString('en-US', {timeZone: 'GMT'})
218176
const logMessage = `[${timestamp}] ${message}\n`
219177
try {
220178
// Ensure the log file exists, create it if it doesn't

packages/pwa-kit-mcp/src/utils/utils.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import {
1212
isSharedUIBaseComponent,
1313
isLocalComponent,
1414
isLocalSharedUIComponent,
15-
generateComponentImportStatement,
16-
runCommand,
17-
toKebabCase,
18-
toPascalCase,
19-
getCopyrightHeader
15+
generateComponentImportStatement
2016
} from './utils'
2117
import fs from 'fs'
2218
import path from 'path'

0 commit comments

Comments
 (0)