UNPKG

@advanced-communities/salesforce-mcp-server

Version:

MCP server enabling AI assistants to interact with Salesforce orgs through the Salesforce CLI

72 lines (71 loc) 2.61 kB
import { z } from "zod"; import { exec } from "node:child_process"; const updateSfCli = async (targetVersion) => { let command = "sf update"; if (targetVersion) { command += ` --version ${targetVersion}`; } else { command += ` stable`; } return new Promise((resolve, reject) => { exec(command, { maxBuffer: 10 * 1024 * 1024, timeout: 300000 }, (error, stdout, stderr) => { if (error) { if (error.message.includes("command not found") || error.message.includes("is not recognized")) { reject(new Error("Salesforce CLI (sf) not found. Please ensure it is installed and accessible. " + "Visit https://developer.salesforce.com/tools/salesforcecli for installation instructions.")); } else { reject(new Error(`Update failed: ${error.message}`)); } return; } const output = stdout || stderr || "Update completed successfully"; resolve({ status: "success", output: output.trim(), message: targetVersion ? `SF CLI updated to version ${targetVersion}` : "SF CLI updated to latest stable version", }); }); }); }; export const registerSystemTools = (server) => { server.tool("sf_update", "Update the Salesforce CLI to the latest version or a specific version", { input: z.object({ version: z .string() .optional() .describe("Specific version to update to (e.g., '2.100.4'). If not provided, updates to latest stable version."), }), }, async ({ input }) => { try { const { version } = input || {}; const result = await updateSfCli(version); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify({ error: error.message || "Failed to update SF CLI", status: "failed", }, null, 2), }, ], }; } }); };