@salesforce/mcp 0.17.1 → 0.17.2-dev.1

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.
Files changed (73) hide show
  1. package/lib/index.d.ts +1 -1
  2. package/lib/index.js +7 -5
  3. package/lib/main-server-provider.d.ts +7 -0
  4. package/lib/main-server-provider.js +31 -0
  5. package/lib/registry.d.ts +3 -29
  6. package/lib/registry.js +9 -113
  7. package/lib/scripts/build-index.js +1 -1
  8. package/lib/services.d.ts +12 -0
  9. package/lib/services.js +34 -0
  10. package/lib/sf-mcp-server.d.ts +12 -7
  11. package/lib/sf-mcp-server.js +6 -21
  12. package/lib/telemetry.d.ts +2 -1
  13. package/lib/tools/sf-enable-tools.d.ts +23 -0
  14. package/lib/tools/sf-enable-tools.js +77 -0
  15. package/lib/tools/sf-list-tools.d.ts +8 -0
  16. package/lib/{modules/platform-cli → tools}/sf-list-tools.js +33 -9
  17. package/lib/tools/sf-suggest-cli-command.d.ts +25 -0
  18. package/lib/{modules/platform-cli → tools}/sf-suggest-cli-command.js +46 -18
  19. package/lib/utils/assets.d.ts +21 -0
  20. package/lib/{assets.js → utils/assets.js} +23 -33
  21. package/lib/{shared → utils}/auth.d.ts +3 -8
  22. package/lib/{shared → utils}/auth.js +2 -42
  23. package/lib/utils/registry-utils.d.ts +4 -0
  24. package/lib/utils/registry-utils.js +87 -0
  25. package/lib/{modules/platform-cli/utils → utils}/tools.js +1 -1
  26. package/lib/utils/types.d.ts +5 -0
  27. package/package.json +8 -4
  28. package/README.md +0 -263
  29. package/lib/assets.d.ts +0 -44
  30. package/lib/modules/platform-cli/index.d.ts +0 -16
  31. package/lib/modules/platform-cli/index.js +0 -32
  32. package/lib/modules/platform-cli/sf-assign-permission-set.d.ts +0 -20
  33. package/lib/modules/platform-cli/sf-assign-permission-set.js +0 -89
  34. package/lib/modules/platform-cli/sf-create-org-snapshot.d.ts +0 -23
  35. package/lib/modules/platform-cli/sf-create-org-snapshot.js +0 -88
  36. package/lib/modules/platform-cli/sf-create-scratch-org.d.ts +0 -50
  37. package/lib/modules/platform-cli/sf-create-scratch-org.js +0 -132
  38. package/lib/modules/platform-cli/sf-delete-org.d.ts +0 -14
  39. package/lib/modules/platform-cli/sf-delete-org.js +0 -65
  40. package/lib/modules/platform-cli/sf-deploy-metadata.d.ts +0 -27
  41. package/lib/modules/platform-cli/sf-deploy-metadata.js +0 -164
  42. package/lib/modules/platform-cli/sf-enable-tools.d.ts +0 -2
  43. package/lib/modules/platform-cli/sf-enable-tools.js +0 -42
  44. package/lib/modules/platform-cli/sf-get-username.d.ts +0 -17
  45. package/lib/modules/platform-cli/sf-get-username.js +0 -109
  46. package/lib/modules/platform-cli/sf-list-all-orgs.d.ts +0 -11
  47. package/lib/modules/platform-cli/sf-list-all-orgs.js +0 -59
  48. package/lib/modules/platform-cli/sf-list-tools.d.ts +0 -2
  49. package/lib/modules/platform-cli/sf-org-open.d.ts +0 -17
  50. package/lib/modules/platform-cli/sf-org-open.js +0 -57
  51. package/lib/modules/platform-cli/sf-query-org.d.ts +0 -20
  52. package/lib/modules/platform-cli/sf-query-org.js +0 -66
  53. package/lib/modules/platform-cli/sf-resume.d.ts +0 -20
  54. package/lib/modules/platform-cli/sf-resume.js +0 -149
  55. package/lib/modules/platform-cli/sf-retrieve-metadata.d.ts +0 -2
  56. package/lib/modules/platform-cli/sf-retrieve-metadata.js +0 -128
  57. package/lib/modules/platform-cli/sf-suggest-cli-command.d.ts +0 -5
  58. package/lib/modules/platform-cli/sf-test-agents.d.ts +0 -21
  59. package/lib/modules/platform-cli/sf-test-agents.js +0 -84
  60. package/lib/modules/platform-cli/sf-test-apex.d.ts +0 -40
  61. package/lib/modules/platform-cli/sf-test-apex.js +0 -132
  62. package/lib/shared/params.d.ts +0 -5
  63. package/lib/shared/params.js +0 -46
  64. package/lib/shared/types.d.ts +0 -33
  65. package/lib/shared/utils.d.ts +0 -11
  66. package/lib/shared/utils.js +0 -71
  67. package/lib/tsconfig.tsbuildinfo +0 -1
  68. /package/lib/{shared → utils}/cache.d.ts +0 -0
  69. /package/lib/{shared → utils}/cache.js +0 -0
  70. /package/lib/{shared → utils}/rate-limiter.d.ts +0 -0
  71. /package/lib/{shared → utils}/rate-limiter.js +0 -0
  72. /package/lib/{modules/platform-cli/utils → utils}/tools.d.ts +0 -0
  73. /package/lib/{shared → utils}/types.js +0 -0
@@ -1,132 +0,0 @@
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 { join } from 'node:path';
17
- import * as fs from 'node:fs';
18
- import { z } from 'zod';
19
- import { Org, scratchOrgCreate } from '@salesforce/core';
20
- import { Duration } from '@salesforce/kit';
21
- import { textResponse } from '../../shared/utils.js';
22
- import { directoryParam, usernameOrAliasParam } from '../../shared/params.js';
23
- /*
24
- * Create a new scratch org
25
- *
26
- * Parameters:
27
- * - directory: directory to change to before running the command
28
- * - usernameOrAlias: Username or alias of the Salesforce DevHub org to use to create from
29
- * - duration: Duration in days of the scratch org to exist, default 7
30
- * - edition: Edition of the scratch org
31
- * - definitionFile: path to the scratch org definition file, default config/project-scratch-def.json
32
- * - alias: Alias to use for the scratch org
33
- * - async: Wait for the scratch org creation process to finish, default false
34
- * - setDefault: set the newly created org as default-target-org
35
- * - snapshot: The snapshot name to use when creating a scratch org
36
- * - sourceOrg: 15-character ID of the org shape that the new scratch org is based on
37
- * - username: Username of the scratch org admin user
38
- * - description: a description given to the scratch org
39
- * - orgName: Name of the scratch org
40
- * - adminEmail: Email address that will be applied to the org's admin user.
41
- * Returns:
42
- * - textResponse:
43
- */
44
- export const createScratchOrgParams = z.object({
45
- directory: directoryParam,
46
- devHub: usernameOrAliasParam.describe('The default devhub username, use the #sf-get-username tool to get the default devhub if unsure'),
47
- duration: z.number().default(7).describe('number of days before the org expires'),
48
- edition: z
49
- .enum([
50
- 'developer',
51
- 'enterprise',
52
- 'group',
53
- 'professional',
54
- 'partner-developer',
55
- 'partner-enterprise',
56
- 'partner-group',
57
- 'partner-professional',
58
- ])
59
- .optional(),
60
- definitionFile: z
61
- .string()
62
- .default(join('config', 'project-scratch-def.json'))
63
- .describe('a normalized path to a scratch definition json file'),
64
- alias: z.string().describe('the alias to be used for the scratch org').optional(),
65
- async: z
66
- .boolean()
67
- .default(false)
68
- .describe('Whether to wait for the org creation process to finish (false) or just quickly return the ID (true)'),
69
- setDefault: z
70
- .boolean()
71
- .optional()
72
- .describe('If true, will set the newly created scratch org to be the default-target-org'),
73
- snapshot: z.string().describe('The snapshot name to use when creating a scratch org').optional(),
74
- sourceOrg: z
75
- .string()
76
- .length(15)
77
- .describe('15-character ID of the org shape that the new scratch org is based on')
78
- .optional(),
79
- username: z.string().describe('Username of the scratch org admin user').optional(),
80
- description: z.string().describe('a description given to the scratch org').optional(),
81
- orgName: z.string().describe('Name of the scratch org').optional(),
82
- adminEmail: z.string().describe("Email address that will be applied to the org's admin user.").optional(),
83
- });
84
- export const createScratchOrg = (server) => {
85
- server.tool('sf-create-scratch-org', `Creates a scratch org with the specified parameters.
86
-
87
- AGENT INSTRUCTIONS:
88
-
89
- Example usage:
90
- Create a scratch org
91
- create a scratch org with the definition file myDefinition.json that lasts 3 days
92
- create a scratch org aliased as MyNewOrg and set as default and don't wait for it to finish
93
- `, createScratchOrgParams.shape, {
94
- title: 'Create a scratch org',
95
- }, async ({ directory, devHub, orgName, adminEmail, description, snapshot, sourceOrg, username, edition, setDefault, async, duration, alias, definitionFile, }) => {
96
- try {
97
- process.chdir(directory);
98
- const hubOrProd = await Org.create({ aliasOrUsername: devHub });
99
- const requestParams = {
100
- hubOrg: hubOrProd,
101
- durationDays: duration,
102
- wait: async ? Duration.minutes(0) : Duration.minutes(10),
103
- orgConfig: {
104
- ...(definitionFile
105
- ? JSON.parse(await fs.promises.readFile(definitionFile, 'utf-8'))
106
- : {}),
107
- ...(edition ? { edition } : {}),
108
- ...(snapshot ? { snapshot } : {}),
109
- ...(username ? { username } : {}),
110
- ...(description ? { description } : {}),
111
- ...(orgName ? { orgName } : {}),
112
- ...(sourceOrg ? { sourceOrg } : {}),
113
- ...(adminEmail ? { adminEmail } : {}),
114
- },
115
- alias,
116
- setDefault,
117
- tracksSource: true,
118
- };
119
- const result = await scratchOrgCreate(requestParams);
120
- if (async) {
121
- return textResponse(`Successfully enqueued scratch org with job Id: ${JSON.stringify(result.scratchOrgInfo?.Id)} use the #sf-resume tool to resume this operation`);
122
- }
123
- else {
124
- return textResponse(`Successfully created scratch org ${JSON.stringify(result)}`);
125
- }
126
- }
127
- catch (e) {
128
- return textResponse(`Failed to create org: ${e instanceof Error ? e.message : 'Unknown error'}`, true);
129
- }
130
- });
131
- };
132
- //# sourceMappingURL=sf-create-scratch-org.js.map
@@ -1,14 +0,0 @@
1
- import { z } from 'zod';
2
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- export declare const deleteOrgParams: z.ZodObject<{
4
- directory: z.ZodEffects<z.ZodString, string, string>;
5
- usernameOrAlias: z.ZodString;
6
- }, "strip", z.ZodTypeAny, {
7
- usernameOrAlias: string;
8
- directory: string;
9
- }, {
10
- usernameOrAlias: string;
11
- directory: string;
12
- }>;
13
- export type DeleteOrgOptions = z.infer<typeof deleteOrgParams>;
14
- export declare const deleteOrg: (server: McpServer) => void;
@@ -1,65 +0,0 @@
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 { AuthRemover, Org } from '@salesforce/core';
18
- import { textResponse } from '../../shared/utils.js';
19
- import { directoryParam, usernameOrAliasParam } from '../../shared/params.js';
20
- /*
21
- * Delete a locally authorized Salesforce org
22
- *
23
- * Parameters:
24
- * - directory: directory to change to before running the command
25
- * - usernameOrAlias: Username or alias of the Salesforce org to delete.
26
- *
27
- * Returns:
28
- * - textResponse: Deletion request response
29
- */
30
- export const deleteOrgParams = z.object({
31
- directory: directoryParam,
32
- usernameOrAlias: usernameOrAliasParam,
33
- });
34
- export const deleteOrg = (server) => {
35
- server.tool('sf-delete-org', `Deletes specified salesforce org.
36
-
37
- AGENT INSTRUCTIONS:
38
- ALWAYS confirm with the user before deleting an org
39
-
40
- Example usage:
41
- Can you delete my org
42
- Can you delete MyAliasedOrg
43
- Can you delete test-fe2n4tc8pgku@example.com
44
- `, deleteOrgParams.shape, {
45
- title: 'Delete an Org',
46
- }, async ({ directory, usernameOrAlias }) => {
47
- try {
48
- process.chdir(directory);
49
- const org = await Org.create({ aliasOrUsername: usernameOrAlias });
50
- await org.delete();
51
- return textResponse(`Successfully deleted ${usernameOrAlias}`);
52
- }
53
- catch (e) {
54
- if (e instanceof Error && e.name === 'DomainNotFoundError') {
55
- // the org has expired, so remote operations won't work
56
- // let's clean up the files locally
57
- const authRemover = await AuthRemover.create();
58
- await authRemover.removeAuth(usernameOrAlias);
59
- return textResponse(`Successfully deleted ${usernameOrAlias}`);
60
- }
61
- return textResponse(`Failed to delete org: ${e instanceof Error ? e.message : 'Unknown error'}`, true);
62
- }
63
- });
64
- };
65
- //# sourceMappingURL=sf-delete-org.js.map
@@ -1,27 +0,0 @@
1
- import { z } from 'zod';
2
- import { SfMcpServer } from '../../sf-mcp-server.js';
3
- declare const deployMetadataParams: z.ZodObject<{
4
- sourceDir: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
5
- manifest: z.ZodOptional<z.ZodString>;
6
- apexTestLevel: z.ZodOptional<z.ZodEnum<["NoTestRun", "RunLocalTests", "RunAllTestsInOrg"]>>;
7
- apexTests: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
8
- usernameOrAlias: z.ZodString;
9
- directory: z.ZodEffects<z.ZodString, string, string>;
10
- }, "strip", z.ZodTypeAny, {
11
- usernameOrAlias: string;
12
- directory: string;
13
- sourceDir?: string[] | undefined;
14
- manifest?: string | undefined;
15
- apexTestLevel?: "NoTestRun" | "RunLocalTests" | "RunAllTestsInOrg" | undefined;
16
- apexTests?: string[] | undefined;
17
- }, {
18
- usernameOrAlias: string;
19
- directory: string;
20
- sourceDir?: string[] | undefined;
21
- manifest?: string | undefined;
22
- apexTestLevel?: "NoTestRun" | "RunLocalTests" | "RunAllTestsInOrg" | undefined;
23
- apexTests?: string[] | undefined;
24
- }>;
25
- export type DeployMetadata = z.infer<typeof deployMetadataParams>;
26
- export declare const deployMetadata: (server: SfMcpServer) => void;
27
- export {};
@@ -1,164 +0,0 @@
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 { Org, SfError, SfProject } from '@salesforce/core';
18
- import { SourceTracking } from '@salesforce/source-tracking';
19
- import { ComponentSet, ComponentSetBuilder } from '@salesforce/source-deploy-retrieve';
20
- import { ensureString } from '@salesforce/ts-types';
21
- import { Duration } from '@salesforce/kit';
22
- import { directoryParam, usernameOrAliasParam } from '../../shared/params.js';
23
- import { textResponse } from '../../shared/utils.js';
24
- import { getConnection } from '../../shared/auth.js';
25
- const deployMetadataParams = z.object({
26
- sourceDir: z
27
- .array(z.string())
28
- .describe('Path to the local source files to deploy. Leave this unset if the user is vague about what to deploy.')
29
- .optional(),
30
- manifest: z.string().describe('Full file path for manifest (XML file) of components to deploy.').optional(),
31
- // `RunSpecifiedTests` is excluded on purpose because the tool sets this level when Apex tests to run are passed in.
32
- //
33
- // Can be left unset to let the org decide which test level to use:
34
- // https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_running_tests.htm
35
- apexTestLevel: z
36
- .enum(['NoTestRun', 'RunLocalTests', 'RunAllTestsInOrg'])
37
- .optional()
38
- .describe(`Apex test level to use during deployment.
39
-
40
- AGENT INSTRUCTIONS
41
- Set this only if the user specifically ask to run apex tests in some of these ways:
42
-
43
- NoTestRun="No tests are run"
44
- RunLocalTests="Run all tests in the org, except the ones that originate from installed managed and unlocked packages."
45
- RunAllTestsInOrg="Run all tests in the org, including tests of managed packages"
46
-
47
- Don't set this param if "apexTests" is also set.
48
- `),
49
- apexTests: z
50
- .array(z.string())
51
- .describe(`Apex tests classes to run.
52
-
53
- Set this param if the user ask an Apex test to be run during deployment.
54
- `)
55
- .optional(),
56
- usernameOrAlias: usernameOrAliasParam,
57
- directory: directoryParam,
58
- });
59
- /*
60
- * Deploy metadata to a Salesforce org.
61
- *
62
- * Parameters:
63
- * - sourceDir: Path to the local source files to deploy.
64
- * - manifest: Full file path for manifest (XML file) of components to deploy.
65
- * - apexTestLevel: Apex test level to use during deployment.
66
- * - apexTests: Apex tests classes to run.
67
- * - usernameOrAlias: Username or alias of the Salesforce org to deploy to.
68
- * - directory: Directory of the local project.
69
- *
70
- * Returns:
71
- * - textResponse: Deploy result.
72
- */
73
- export const deployMetadata = (server) => {
74
- server.tool('sf-deploy-metadata', `Deploy metadata to an org from your local project.
75
-
76
- AGENT INSTRUCTIONS:
77
- If the user doesn't specify what to deploy exactly ("deploy my changes"), leave the "sourceDir" and "manifest" params empty so the tool calculates which files to deploy.
78
-
79
- EXAMPLE USAGE:
80
- Deploy changes to my org
81
- Deploy this file to my org
82
- Deploy the manifest
83
- Deploy X metadata to my org
84
- Deploy X to my org and run A,B and C apex tests.
85
- `, deployMetadataParams.shape, {
86
- title: 'Deploy Metadata',
87
- destructiveHint: true,
88
- openWorldHint: false,
89
- }, async ({ sourceDir, usernameOrAlias, apexTests, apexTestLevel, directory, manifest }) => {
90
- if (apexTests && apexTestLevel) {
91
- return textResponse("You can't specify both `apexTests` and `apexTestLevel` parameters.", true);
92
- }
93
- if (sourceDir && manifest) {
94
- return textResponse("You can't specify both `sourceDir` and `manifest` parameters.", true);
95
- }
96
- if (!usernameOrAlias)
97
- return textResponse('The usernameOrAlias parameter is required, if the user did not specify one use the #sf-get-username tool', true);
98
- // needed for org allowlist to work
99
- process.chdir(directory);
100
- const connection = await getConnection(usernameOrAlias);
101
- const project = await SfProject.resolve(directory);
102
- const org = await Org.create({ connection });
103
- if (!sourceDir && !manifest && !(await org.tracksSource())) {
104
- return textResponse('This org does not have source-tracking enabled or does not support source-tracking. You should specify the files or a manifest to deploy.', true);
105
- }
106
- let jobId = '';
107
- try {
108
- const stl = await SourceTracking.create({
109
- org,
110
- project,
111
- subscribeSDREvents: true,
112
- });
113
- const componentSet = await buildDeployComponentSet(connection, project, stl, sourceDir, manifest);
114
- if (componentSet.size === 0) {
115
- // STL found no changes
116
- return textResponse('No local changes to deploy were found.');
117
- }
118
- const deploy = await componentSet.deploy({
119
- usernameOrConnection: connection,
120
- apiOptions: {
121
- ...(apexTests ? { runTests: apexTests, testLevel: 'RunSpecifiedTests' } : {}),
122
- ...(apexTestLevel ? { testLevel: apexTestLevel } : {}),
123
- },
124
- });
125
- jobId = deploy.id ?? '';
126
- // polling freq. is set dynamically by SDR based on the component set size.
127
- const result = await deploy.pollStatus({
128
- timeout: Duration.minutes(10),
129
- });
130
- return textResponse(`Deploy result: ${JSON.stringify(result.response)}`, !result.response.success);
131
- }
132
- catch (error) {
133
- const err = SfError.wrap(error);
134
- if (err.message.includes('timed out')) {
135
- return textResponse(`
136
- YOU MUST inform the user that the deploy timed out and if they want to resume the deploy, they can use the #sf-resume tool
137
- and ${jobId} for the jobId parameter.`, true);
138
- }
139
- return textResponse(`Failed to deploy metadata: ${err.message}`, true);
140
- }
141
- });
142
- };
143
- async function buildDeployComponentSet(connection, project, stl, sourceDir, manifestPath) {
144
- if (sourceDir || manifestPath) {
145
- return ComponentSetBuilder.build({
146
- apiversion: connection.getApiVersion(),
147
- sourceapiversion: ensureString((await project.resolveProjectConfig()).sourceApiVersion),
148
- sourcepath: sourceDir,
149
- ...(manifestPath
150
- ? {
151
- manifest: {
152
- manifestPath,
153
- directoryPaths: project.getUniquePackageDirectories().map((pDir) => pDir.fullPath),
154
- },
155
- }
156
- : {}),
157
- projectDir: stl?.projectPath,
158
- });
159
- }
160
- // No specific metadata requested to deploy, build component set from STL.
161
- const cs = (await stl.localChangesAsComponentSet(false))[0] ?? new ComponentSet(undefined, stl.registry);
162
- return cs;
163
- }
164
- //# sourceMappingURL=sf-deploy-metadata.js.map
@@ -1,2 +0,0 @@
1
- import { SfMcpServer } from '../../sf-mcp-server.js';
2
- export declare function enableTools(server: SfMcpServer): void;
@@ -1,42 +0,0 @@
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 as utilEnableTools } from './utils/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 enableTools(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 utilEnableTools(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
@@ -1,17 +0,0 @@
1
- import { z } from 'zod';
2
- import { SfMcpServer } from '../../sf-mcp-server.js';
3
- export declare const getUsernameParamsSchema: z.ZodObject<{
4
- defaultTargetOrg: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
5
- defaultDevHub: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
6
- directory: z.ZodEffects<z.ZodString, string, string>;
7
- }, "strip", z.ZodTypeAny, {
8
- directory: string;
9
- defaultTargetOrg: boolean;
10
- defaultDevHub: boolean;
11
- }, {
12
- directory: string;
13
- defaultTargetOrg?: boolean | undefined;
14
- defaultDevHub?: boolean | undefined;
15
- }>;
16
- export type GetUsernameParamsSchema = z.infer<typeof getUsernameParamsSchema>;
17
- export declare const getUsername: (server: SfMcpServer) => void;
@@ -1,109 +0,0 @@
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 { getDefaultTargetOrg, getDefaultTargetDevHub, suggestUsername } from '../../shared/auth.js';
19
- import { directoryParam } from '../../shared/params.js';
20
- /*
21
- * Get username for Salesforce org
22
- *
23
- * Intelligently determines the appropriate username or alias for Salesforce operations.
24
- *
25
- * Parameters:
26
- * - defaultTargetOrg: Force lookup of default target org (optional)
27
- * - defaultDevHub: Force lookup of default dev hub (optional)
28
- * - directory: The directory to run this tool from
29
- *
30
- * Returns:
31
- * - textResponse: Username/alias and org configuration
32
- */
33
- export const getUsernameParamsSchema = z.object({
34
- defaultTargetOrg: z.boolean().optional().default(false).describe(`Try to find default org
35
- AGENT INSTRUCTIONS:
36
- ONLY SET TO TRUE when the user explicitly asks for the default org or default target org.
37
- Leave it as false when the user is vague and says something like "for my org" or "for my-alias".
38
-
39
- USAGE EXAMPLE:
40
- Get username for my default org
41
- ...for my default target org`),
42
- defaultDevHub: z.boolean().optional().default(false).describe(`Try to find default dev hub
43
- AGENT INSTRUCTIONS:
44
- ONLY SET TO TRUE when the user explicitly asks for the default dev hub or default target devhub.
45
- Leave it as false when the user is vague and says something like "for my org" or "for my-alias".
46
-
47
- USAGE EXAMPLE:
48
- Get username for my default dev hub
49
- ...for my default target dev hub
50
- ...for my default devhub`),
51
- directory: directoryParam,
52
- });
53
- export const getUsername = (server) => {
54
- server.tool('sf-get-username', `Intelligently determines the appropriate username or alias for Salesforce operations.
55
-
56
- AGENT/LLM INSTRUCTIONS:
57
- Use this tool when uncertain which username/org a user wants for Salesforce operations.
58
- This tool handles three distinct scenarios:
59
-
60
- 1. When defaultTargetOrg=true: Fetches the default target org configuration
61
- - Use when user says "for my default org" or "for my default target org"
62
-
63
- 2. When defaultDevHub=true: Fetches the default dev hub configuration
64
- - Use when user says "for my default dev hub" or "for my default target dev hub"
65
-
66
- 3. When both are false (default): Uses suggestUsername to intelligently determine the appropriate org
67
- - Use when user is vague and says something like "for my org" or doesn't specify
68
-
69
- EXAMPLE USAGE:
70
- - When user says "Do X for my org" → defaultTargetOrg=false, defaultDevHub=false
71
- - When user says "For my default org" → defaultTargetOrg=true
72
- - When user says "For my default dev hub" → defaultDevHub=true`, getUsernameParamsSchema.shape, {
73
- title: 'Get Username',
74
- readOnlyHint: true,
75
- openWorldHint: false,
76
- }, async ({ defaultTargetOrg, defaultDevHub, directory }) => {
77
- try {
78
- process.chdir(directory);
79
- const generateResponse = (defaultFromConfig) => textResponse(`ALWAYS notify the user the following 3 (maybe 4) pieces of information:
80
- 1. If it is default target-org or target-dev-hub ('.key' on the config)
81
- 2. The value of '.location' on the config
82
- 3. The value of '.value' on the config
83
- 4. IF '.cached' IS TRUE, tell then we are using a cached value and if they have changed it, restart the MCP Server
84
-
85
- - Full config: ${JSON.stringify(defaultFromConfig, null, 2)}
86
-
87
- UNLESS THE USER SPECIFIES OTHERWISE, use this username for the "usernameOrAlias" parameter in future Tool calls.`);
88
- // Case 1: User explicitly asked for default target org
89
- if (defaultTargetOrg)
90
- return generateResponse(await getDefaultTargetOrg());
91
- // Case 2: User explicitly asked for default dev hub
92
- if (defaultDevHub)
93
- return generateResponse(await getDefaultTargetDevHub());
94
- // Case 3: User was vague, so suggest a username
95
- const { aliasForReference, suggestedUsername, reasoning } = await suggestUsername();
96
- if (!suggestedUsername) {
97
- return textResponse("No suggested username found. Please specify a username or alias explicitly. Also check the MCP server's startup args for allowlisting orgs.", true);
98
- }
99
- return textResponse(`
100
- YOU MUST inform the user that we are going to use "${suggestedUsername}" ${aliasForReference ? `(Alias: ${aliasForReference}) ` : ''}for the "usernameOrAlias" parameter.
101
- YOU MUST explain the reasoning for selecting this org, which is: "${reasoning}"
102
- UNLESS THE USER SPECIFIES OTHERWISE, use this username for the "usernameOrAlias" parameter in future Tool calls.`);
103
- }
104
- catch (error) {
105
- return textResponse(`Failed to determine appropriate username: ${error instanceof Error ? error.message : 'Unknown error'}`, true);
106
- }
107
- });
108
- };
109
- //# sourceMappingURL=sf-get-username.js.map
@@ -1,11 +0,0 @@
1
- import { z } from 'zod';
2
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- export declare const listAllOrgsParamsSchema: z.ZodObject<{
4
- directory: z.ZodEffects<z.ZodString, string, string>;
5
- }, "strip", z.ZodTypeAny, {
6
- directory: string;
7
- }, {
8
- directory: string;
9
- }>;
10
- export type ListAllOrgsOptions = z.infer<typeof listAllOrgsParamsSchema>;
11
- export declare const listAllOrgs: (server: McpServer) => void;
@@ -1,59 +0,0 @@
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 { getAllAllowedOrgs } from '../../shared/auth.js';
18
- import { textResponse } from '../../shared/utils.js';
19
- import { directoryParam } from '../../shared/params.js';
20
- /*
21
- * List all Salesforce orgs
22
- *
23
- * Lists all configured Salesforce orgs.
24
- *
25
- * Parameters:
26
- * - directory: directory to change to before running the command
27
- *
28
- * Returns:
29
- * - textResponse: List of configured Salesforce orgs
30
- */
31
- export const listAllOrgsParamsSchema = z.object({
32
- directory: directoryParam,
33
- });
34
- export const listAllOrgs = (server) => {
35
- server.tool('sf-list-all-orgs', `Lists all configured Salesforce orgs.
36
-
37
- AGENT INSTRUCTIONS:
38
- DO NOT use this tool to try to determine which org a user wants, use #sf-get-username instead. Only use it if the user explicitly asks for a list of orgs.
39
-
40
- Example usage:
41
- Can you list all Salesforce orgs for me
42
- List all Salesforce orgs
43
- List all orgs
44
- `, listAllOrgsParamsSchema.shape, {
45
- title: 'List All Orgs',
46
- readOnlyHint: true,
47
- openWorldHint: false,
48
- }, async ({ directory }) => {
49
- try {
50
- process.chdir(directory);
51
- const orgs = await getAllAllowedOrgs();
52
- return textResponse(`List of configured Salesforce orgs:\n\n${JSON.stringify(orgs, null, 2)}`);
53
- }
54
- catch (error) {
55
- return textResponse(`Failed to list orgs: ${error instanceof Error ? error.message : 'Unknown error'}`, true);
56
- }
57
- });
58
- };
59
- //# sourceMappingURL=sf-list-all-orgs.js.map
@@ -1,2 +0,0 @@
1
- import { SfMcpServer } from '../../sf-mcp-server.js';
2
- export declare function listTools(server: SfMcpServer): void;