@salesforce/mcp 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -158,7 +158,7 @@ You can also use special values to control access to orgs:
158
158
  if (toolsetsToEnable.dynamic) {
159
159
  this.logToStderr('Registering dynamic tools');
160
160
  // Individual tool management
161
- dynamic.registerToolEnableTool(server);
161
+ dynamic.registerToolEnableTools(server);
162
162
  dynamic.registerToolListTools(server);
163
163
  }
164
164
  // ************************
@@ -39,6 +39,10 @@ export declare function enableTool(toolName: string): Promise<{
39
39
  success: boolean;
40
40
  message: string;
41
41
  }>;
42
+ export declare function enableTools(tools: string[]): Promise<Array<{
43
+ success: boolean;
44
+ message: string;
45
+ }>>;
42
46
  /**
43
47
  * Disable an individual tool
44
48
  */
@@ -18,7 +18,13 @@ export const TOOLSETS = ['orgs', 'data', 'users', 'metadata', 'testing', 'experi
18
18
  /*
19
19
  * These are tools that are always enabled at startup. They cannot be disabled and they cannot be dynamically enabled.
20
20
  */
21
- export const CORE_TOOLS = ['sf-get-username', 'sf-resume', 'sf-enable-tool', 'sf-list-tools', 'sf-suggest-cli-command'];
21
+ export const CORE_TOOLS = [
22
+ 'sf-get-username',
23
+ 'sf-resume',
24
+ 'sf-enable-tools',
25
+ 'sf-list-tools',
26
+ 'sf-suggest-cli-command',
27
+ ];
22
28
  /**
23
29
  * Determines which toolsets should be enabled based on the provided toolsets array and dynamic tools flag.
24
30
  *
@@ -112,6 +118,25 @@ export async function enableTool(toolName) {
112
118
  toolInfo.tool.enable();
113
119
  return { success: true, message: `Tool ${toolName} enabled` };
114
120
  }
121
+ export async function enableTools(tools) {
122
+ const results = [];
123
+ const cachedTools = await Cache.safeGet('tools');
124
+ for (const tool of tools) {
125
+ const toolInfo = cachedTools.find((t) => t.name === tool);
126
+ if (!toolInfo) {
127
+ results.push({ success: false, message: `Tool ${tool} not found` });
128
+ continue;
129
+ }
130
+ if (toolInfo.tool.enabled) {
131
+ results.push({ success: false, message: `Tool ${tool} is already enabled` });
132
+ continue;
133
+ }
134
+ // Enable the tool directly
135
+ toolInfo.tool.enable();
136
+ results.push({ success: true, message: `Tool ${tool} enabled` });
137
+ }
138
+ return results;
139
+ }
115
140
  /**
116
141
  * Disable an individual tool
117
142
  */
@@ -23,7 +23,18 @@ const suggestCliCommandParamsSchema = z.object({
23
23
  * Suggest a Salesforce CLI (sf) command based on user input.
24
24
  */
25
25
  export const registerToolSuggestCliCommand = (server) => {
26
- server.tool('sf-suggest-cli-command', "Suggests an `sf` CLI command based on a natural language query. It finds relevant commands from a local index and uses an LLM to construct the final, precise command to fulfill the user's request. Use this tool whenever a user asks for guidance on how to use the Salesforce CLI (`sf` or `sfdx`), needs help with command syntax, wants to know what command to run for a specific task, or asks questions like 'how do I...', 'what command...', or 'how to...' related to Salesforce development operations.", suggestCliCommandParamsSchema.shape, {
26
+ server.tool('sf-suggest-cli-command', `Suggests an \`sf\` CLI command based on a natural language query. It finds relevant commands from a local index and uses an LLM to construct the final, precise command to fulfill the user's request.
27
+
28
+ AGENT INSTRUCTIONS:
29
+ Use this tool whenever a user:
30
+ - asks for guidance on how to use the Salesforce CLI (sf or sfdx)
31
+ - needs help with Salesforce CLI (sf or sfdx) command syntax
32
+ - wants to know what Salesforce CLI (sf or sfdx) command to run for a specific task
33
+ - asks questions like 'how do I...', 'what command...', or 'how to...' related to Salesforce development operations.
34
+ NEVER use this tool for enabling Salesforce MCP tools (use sf-enable-tools instead).
35
+ NEVER use this tool for listing available Salesforce MCP tools (use sf-list-tools instead).
36
+ NEVER use this tool for understanding the Salesforce MCP server's capabilities.
37
+ NEVER use this tool for understanding the input schema of a Salesforce MCP tool.`, suggestCliCommandParamsSchema.shape, {
27
38
  readOnlyHint: true,
28
39
  }, async ({ query }) => {
29
40
  const assets = await getAssets();
@@ -1,2 +1,2 @@
1
- export { registerToolEnableTool } from './sf-enable-tool.js';
1
+ export { registerToolEnableTools } from './sf-enable-tools.js';
2
2
  export { registerToolListTools } from './sf-list-tools.js';
@@ -13,6 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { registerToolEnableTool } from './sf-enable-tool.js';
16
+ export { registerToolEnableTools } from './sf-enable-tools.js';
17
17
  export { registerToolListTools } from './sf-list-tools.js';
18
18
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import { SfMcpServer } from '../../sf-mcp-server.js';
2
+ export declare function registerToolEnableTools(server: SfMcpServer): void;
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright 2025, Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { z } from 'zod';
17
+ import { textResponse } from '../../shared/utils.js';
18
+ import { enableTools } from '../../shared/tools.js';
19
+ const enableToolsParamsSchema = z.object({
20
+ tools: z.array(z.string()).describe('The names of the tools to enable'),
21
+ });
22
+ export function registerToolEnableTools(server) {
23
+ server.tool('sf-enable-tools', `Enable one or more of the tools the Salesforce MCP server provides.
24
+
25
+ AGENT INSTRUCTIONS:
26
+ Use sf-list-all-tools first to learn what tools are available for enabling.
27
+ Once you have enabled the tool, you MUST invoke that tool to accomplish the user's original request - DO NOT USE A DIFFERENT TOOL OR THE COMMAND LINE.`, enableToolsParamsSchema.shape, {
28
+ title: 'Enable Salesforce MCP tools',
29
+ readOnlyHint: true,
30
+ openWorldHint: false,
31
+ }, async ({ tools }) => {
32
+ if (tools.length === 0) {
33
+ return textResponse('No tools specified to enable.', true);
34
+ }
35
+ const results = await enableTools(tools);
36
+ server.sendToolListChanged();
37
+ const hasError = results.some((result) => !result.success);
38
+ const resultMessages = results.map((result) => result.message).join('\n');
39
+ return textResponse(resultMessages, hasError);
40
+ });
41
+ }
42
+ //# sourceMappingURL=sf-enable-tools.js.map
@@ -19,10 +19,15 @@ export function registerToolListTools(server) {
19
19
  server.tool('sf-list-tools', `List all available tools this Salesforce MCP server can offer, providing the enabled status and description of each.
20
20
 
21
21
  AGENT INSTRUCTIONS:
22
- Use this when a task could be achieved with a MCP tool and the currently available tools aren't enough.
23
- If there's a tool that can accomplish the user's request, do not use this tool.
24
- Once you find the tool you want to enable, call sf-enable-tool with the tool name.
25
- Once you have enabled the tool, you can invoke the tool to accomplish the user's request.`, {
22
+ DO NOT USE THIS TOOL if you already know what tool you need - try to call the tool directly first.
23
+ ONLY use this tool if:
24
+ 1. You tried to call a tool and got an error that it doesn't exist or isn't enabled
25
+ 2. You genuinely don't know what tools are available for a specific task
26
+ 3. You need to discover new tools for an unfamiliar use case
27
+
28
+ If you find one or more tools you want to enable, call sf-enable-tools with all the tool names.
29
+ Once you have enabled a tool, you MUST invoke the tool to accomplish the user's original request - DO NOT USE A DIFFERENT TOOL OR THE COMMAND LINE.
30
+ Once a tool has been enabled, you do not need to call sf-list-tools again - instead, invoke the desired tool directly.`, {
26
31
  title: 'List all individual tools',
27
32
  readOnlyHint: true,
28
33
  openWorldHint: false,