UNPKG

@salesforce/pwa-kit-mcp

Version:

MCP server that helps you build Salesforce Commerce Cloud PWA Kit Composable Storefront

109 lines (106 loc) 4.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _zod = require("zod"); var _fs = _interopRequireDefault(require("fs")); var _promises = _interopRequireDefault(require("fs/promises")); var _path = _interopRequireDefault(require("path")); var _constants = require("../utils/constants"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /* * 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 */ const description = `Install the Agent MCP Tool Usage Guidelines for the ${_constants.PWA_KIT_DESCRIPTIVE_NAME} into the project`; const InstallAgentRulesTool = { name: 'pwakit_install_agent_rules', description, inputSchema: { projectRoot: _zod.z.string().describe('Absolute path to the project root'), hostAgent: _zod.z.string().describe('Name of the host IDE/agent invoking this tool (e.g., "cursor")') }, fn: function () { var _ref = _asyncToGenerator(function* ({ projectRoot, hostAgent } = {}) { if (!projectRoot) { return { content: [{ type: 'text', text: 'Missing required argument: projectRoot (absolute path to the project root)' }] }; } const root = projectRoot; // If host agent is Cursor, install the Cursor rule to .cursor/rules const isCursor = !!hostAgent && String(hostAgent).toLowerCase() === 'cursor'; const destDir = isCursor ? _path.default.join(root, '.cursor', 'rules') : root; const destFile = isCursor ? _path.default.join(destDir, 'pwa-kit-mcp.mdc') : _path.default.join(destDir, 'AGENTS.md'); // Resolve source file relative to this tool file const srcFile = _path.default.resolve(__dirname, isCursor ? '../data/ai-instructions/cursor/pwa-kit-mcp.mdc' : '../data/ai-instructions/generic/AGENTS.md'); try { if (!_fs.default.existsSync(srcFile)) { return { content: [{ type: 'text', text: `Source rule file not found at ${srcFile}` }] }; } if (isCursor) { yield _promises.default.mkdir(destDir, { recursive: true }); } const exists = _fs.default.existsSync(destFile); if (exists) { try { const [srcContent, destContent] = yield Promise.all([_promises.default.readFile(srcFile, 'utf8'), _promises.default.readFile(destFile, 'utf8')]); if (srcContent !== destContent) { return { content: [{ type: 'text', text: `You are a smart assistant that can use tools when needed. Use the file edit tools to add the following contents to this file "${destFile}": ${srcContent}` }] }; } } catch (_) { // If we can't read for comparison, fall back to generic already-installed message } return { content: [{ type: 'text', text: `Rule already installed at ${destFile}. No action taken.` }] }; } yield _promises.default.copyFile(srcFile, destFile); return { content: [{ type: 'text', text: `Installed rule to ${destFile}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Failed to install rule: ${error.message}` }] }; } }); return function fn() { return _ref.apply(this, arguments); }; }() }; var _default = exports.default = InstallAgentRulesTool;