@aaron-pienza/mcp-server-salesforce 1.0.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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +398 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +392 -0
  5. package/dist/tools/aggregateQuery.d.ts +18 -0
  6. package/dist/tools/aggregateQuery.js +275 -0
  7. package/dist/tools/describe.d.ts +9 -0
  8. package/dist/tools/describe.js +45 -0
  9. package/dist/tools/describeAnalytics.d.ts +13 -0
  10. package/dist/tools/describeAnalytics.js +178 -0
  11. package/dist/tools/dml.d.ts +15 -0
  12. package/dist/tools/dml.js +133 -0
  13. package/dist/tools/executeAnonymous.d.ts +19 -0
  14. package/dist/tools/executeAnonymous.js +139 -0
  15. package/dist/tools/listAnalytics.d.ts +13 -0
  16. package/dist/tools/listAnalytics.js +149 -0
  17. package/dist/tools/manageDebugLogs.d.ts +31 -0
  18. package/dist/tools/manageDebugLogs.js +451 -0
  19. package/dist/tools/manageField.d.ts +32 -0
  20. package/dist/tools/manageField.js +358 -0
  21. package/dist/tools/manageFieldPermissions.d.ts +17 -0
  22. package/dist/tools/manageFieldPermissions.js +256 -0
  23. package/dist/tools/manageObject.d.ts +20 -0
  24. package/dist/tools/manageObject.js +138 -0
  25. package/dist/tools/query.d.ts +17 -0
  26. package/dist/tools/query.js +237 -0
  27. package/dist/tools/readApex.d.ts +28 -0
  28. package/dist/tools/readApex.js +188 -0
  29. package/dist/tools/readApexTrigger.d.ts +28 -0
  30. package/dist/tools/readApexTrigger.js +188 -0
  31. package/dist/tools/refreshDashboard.d.ts +13 -0
  32. package/dist/tools/refreshDashboard.js +91 -0
  33. package/dist/tools/restApi.d.ts +17 -0
  34. package/dist/tools/restApi.js +150 -0
  35. package/dist/tools/runAnalytics.d.ts +30 -0
  36. package/dist/tools/runAnalytics.js +367 -0
  37. package/dist/tools/search.d.ts +14 -0
  38. package/dist/tools/search.js +69 -0
  39. package/dist/tools/searchAll.d.ts +29 -0
  40. package/dist/tools/searchAll.js +258 -0
  41. package/dist/tools/writeApex.d.ts +27 -0
  42. package/dist/tools/writeApex.js +159 -0
  43. package/dist/tools/writeApexTrigger.d.ts +28 -0
  44. package/dist/tools/writeApexTrigger.js +187 -0
  45. package/dist/types/analytics.d.ts +2 -0
  46. package/dist/types/analytics.js +1 -0
  47. package/dist/types/connection.d.ts +52 -0
  48. package/dist/types/connection.js +21 -0
  49. package/dist/types/metadata.d.ts +43 -0
  50. package/dist/types/metadata.js +1 -0
  51. package/dist/types/salesforce.d.ts +33 -0
  52. package/dist/types/salesforce.js +1 -0
  53. package/dist/utils/connection.d.ts +7 -0
  54. package/dist/utils/connection.js +169 -0
  55. package/dist/utils/errorHandler.d.ts +15 -0
  56. package/dist/utils/errorHandler.js +23 -0
  57. package/dist/utils/logging.d.ts +12 -0
  58. package/dist/utils/logging.js +23 -0
  59. package/dist/utils/pagination.d.ts +14 -0
  60. package/dist/utils/pagination.js +26 -0
  61. package/dist/utils/sanitize.d.ts +44 -0
  62. package/dist/utils/sanitize.js +73 -0
  63. package/dist/utils/validate.d.ts +13 -0
  64. package/dist/utils/validate.js +60 -0
  65. package/package.json +52 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tapas Mukherjee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,398 @@
1
+ # Salesforce MCP Server
2
+ [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/tsmztech/mcp-server-salesforce/badge)](https://securityscorecards.dev/viewer/?uri=github.com/tsmztech/mcp-server-salesforce)
3
+
4
+
5
+ An MCP (Model Context Protocol) server implementation that integrates Claude with Salesforce, enabling natural language interactions with your Salesforce data and metadata. This server allows Claude to query, modify, and manage your Salesforce objects and records using everyday language.
6
+
7
+ <a href="https://glama.ai/mcp/servers/kqeniawbr6">
8
+ <img width="380" height="200" src="https://glama.ai/mcp/servers/kqeniawbr6/badge" alt="Salesforce Server MCP server" />
9
+ </a>
10
+
11
+ ## Features
12
+
13
+ * **Object and Field Management**: Create and modify custom objects and fields using natural language
14
+ * **Smart Object Search**: Find Salesforce objects using partial name matches
15
+ * **Detailed Schema Information**: Get comprehensive field and relationship details for any object
16
+ * **Flexible Data Queries**: Query records with relationship support and complex filters
17
+ * **Data Manipulation**: Insert, update, delete, and upsert records with ease
18
+ * **Cross-Object Search**: Search across multiple objects using SOSL
19
+ * **Apex Code Management**: Read, create, and update Apex classes and triggers
20
+ * **Reports & Dashboards**: List, describe, run reports with filter overrides, and retrieve dashboard component data
21
+ * **REST API Passthrough**: Call any Salesforce REST endpoint directly — Reports, Composite API, Files, Limits, and more
22
+ * **Input Sanitization**: SOQL/SOSL injection prevention, identifier validation, and secure query construction
23
+ * **Intuitive Error Handling**: Clear feedback with Salesforce-specific error details
24
+ * **Switchable Authentication**: Supports multiple orgs. Easily switch your active Salesforce org based on the default org configured in your VS Code workspace (use Salesforce_CLI authentication for this feature).
25
+
26
+ ## Installation
27
+
28
+ ### Global Installation (npm)
29
+
30
+ ```bash
31
+ npm install -g @tsmztech/mcp-server-salesforce
32
+ ```
33
+
34
+ ### Claude Desktop Quick Installation
35
+
36
+ For easy setup with Claude Desktop, download the pre-configured extension:
37
+
38
+ 1. Download [`salesforce-mcp-extension.dxt`](./claude-desktop/salesforce-mcp-extension.dxt) from the `claude-desktop/` folder
39
+ 2. Open Claude Desktop → Settings → Extensions
40
+ 3. Drag the `.dxt` file into the Extensions window
41
+ 4. Configure your Salesforce credentials when prompted
42
+
43
+ For manual Claude Desktop configuration, see [Usage with Claude Desktop](#usage-with-claude-desktop) below.
44
+
45
+ ## Tools
46
+
47
+ ### salesforce_search_objects
48
+ Search for standard and custom objects:
49
+ * Search by partial name matches
50
+ * Finds both standard and custom objects
51
+ * Example: "Find objects related to Account" will find Account, AccountHistory, etc.
52
+
53
+ ### salesforce_describe_object
54
+ Get detailed object schema information:
55
+ * Field definitions and properties
56
+ * Relationship details
57
+ * Picklist values
58
+ * Example: "Show me all fields in the Account object"
59
+
60
+ ### salesforce_query_records
61
+ Query records with relationship support:
62
+ * Parent-to-child relationships
63
+ * Child-to-parent relationships
64
+ * Complex WHERE conditions
65
+ * Example: "Get all Accounts with their related Contacts"
66
+ * Note: For queries with GROUP BY or aggregate functions, use salesforce_aggregate_query
67
+
68
+ ### salesforce_aggregate_query
69
+ Execute aggregate queries with GROUP BY:
70
+ * GROUP BY single or multiple fields
71
+ * Aggregate functions: COUNT, COUNT_DISTINCT, SUM, AVG, MIN, MAX
72
+ * HAVING clauses for filtering grouped results
73
+ * Date/time grouping functions
74
+ * Example: "Count opportunities by stage" or "Find accounts with more than 10 opportunities"
75
+
76
+ ### salesforce_dml_records
77
+ Perform data operations:
78
+ * Insert new records
79
+ * Update existing records
80
+ * Delete records
81
+ * Upsert using external IDs
82
+ * Example: "Update status of multiple accounts"
83
+
84
+ ### salesforce_manage_object
85
+ Create and modify custom objects:
86
+ * Create new custom objects
87
+ * Update object properties
88
+ * Configure sharing settings
89
+ * Example: "Create a Customer Feedback object"
90
+
91
+ ### salesforce_manage_field
92
+ Manage object fields:
93
+ * Add new custom fields
94
+ * Modify field properties
95
+ * Create relationships
96
+ * Automatically grants Field Level Security to System Administrator by default
97
+ * Use `grantAccessTo` parameter to specify different profiles
98
+ * Example: "Add a Rating picklist field to Account"
99
+
100
+ ### salesforce_manage_field_permissions
101
+ Manage Field Level Security (Field Permissions):
102
+ * Grant or revoke read/edit access to fields for specific profiles
103
+ * View current field permissions
104
+ * Bulk update permissions for multiple profiles
105
+ * Useful for managing permissions after field creation or for existing fields
106
+ * Example: "Grant System Administrator access to Custom_Field__c on Account"
107
+
108
+ ### salesforce_search_all
109
+ Search across multiple objects:
110
+ * SOSL-based search
111
+ * Multiple object support
112
+ * Field snippets
113
+ * Example: "Search for 'cloud' across Accounts and Opportunities"
114
+
115
+ ### salesforce_read_apex
116
+ Read Apex classes:
117
+ * Get full source code of specific classes
118
+ * List classes matching name patterns
119
+ * View class metadata (API version, status, etc.)
120
+ * Support for wildcards (* and ?) in name patterns
121
+ * Example: "Show me the AccountController class" or "Find all classes matching Account*Cont*"
122
+
123
+ ### salesforce_write_apex
124
+ Create and update Apex classes:
125
+ * Create new Apex classes
126
+ * Update existing class implementations
127
+ * Specify API versions
128
+ * Example: "Create a new Apex class for handling account operations"
129
+
130
+ ### salesforce_read_apex_trigger
131
+ Read Apex triggers:
132
+ * Get full source code of specific triggers
133
+ * List triggers matching name patterns
134
+ * View trigger metadata (API version, object, status, etc.)
135
+ * Support for wildcards (* and ?) in name patterns
136
+ * Example: "Show me the AccountTrigger" or "Find all triggers for Contact object"
137
+
138
+ ### salesforce_write_apex_trigger
139
+ Create and update Apex triggers:
140
+ * Create new Apex triggers for specific objects
141
+ * Update existing trigger implementations
142
+ * Specify API versions and event operations
143
+ * Example: "Create a new trigger for the Account object" or "Update the Lead trigger"
144
+
145
+ ### salesforce_execute_anonymous
146
+ Execute anonymous Apex code:
147
+ * Run Apex code without creating a permanent class
148
+ * View debug logs and execution results
149
+ * Useful for data operations not directly supported by other tools
150
+ * Example: "Execute Apex code to calculate account metrics" or "Run a script to update related records"
151
+
152
+ ### salesforce_manage_debug_logs
153
+ Manage debug logs for Salesforce users:
154
+ * Enable debug logs for specific users
155
+ * Disable active debug log configurations
156
+ * Retrieve and view debug logs
157
+ * Configure log levels (NONE, ERROR, WARN, INFO, DEBUG, FINE, FINER, FINEST)
158
+ * Example: "Enable debug logs for user@example.com" or "Retrieve recent logs for an admin user"
159
+
160
+ ### salesforce_rest_api
161
+ Make direct REST API calls to any Salesforce REST endpoint:
162
+ * Access any Salesforce REST API endpoint not covered by other tools
163
+ * Supports GET, POST, PATCH, PUT, and DELETE methods
164
+ * Automatically handles API version prefixing (`/services/data/vXX.0/`)
165
+ * Supports raw paths for custom Apex REST endpoints (`/services/apexrest/...`)
166
+ * Query parameters and JSON request bodies
167
+ * Configurable API version override
168
+ * Large response truncation to prevent client overload
169
+ * Examples:
170
+ - "Get our org's API limits" → `GET /limits`
171
+ - "Run report 00O5e000004XXXX" → `GET /analytics/reports/{id}`
172
+ - "Get the Composite API to batch requests" → `POST /composite`
173
+ - "Download file content" → `GET /sobjects/ContentVersion/{id}/VersionData`
174
+ - "Call our custom Apex REST endpoint" → `GET /services/apexrest/MyEndpoint` (with `rawPath: true`)
175
+
176
+ ## Setup
177
+
178
+ ### Salesforce Authentication
179
+ You can connect to Salesforce using one of three authentication methods:
180
+
181
+ #### 1. Username/Password Authentication (Default)
182
+ 1. Set up your Salesforce credentials
183
+ 2. Get your security token (Reset from Salesforce Settings)
184
+
185
+ #### 2. OAuth 2.0 Client Credentials Flow
186
+ 1. Create a Connected App in Salesforce
187
+ 2. Enable OAuth settings and select "Client Credentials Flow"
188
+ 3. Set appropriate scopes (typically "api" is sufficient)
189
+ 4. Save the Client ID and Client Secret
190
+ 5. **Important**: Note your instance URL (e.g., `https://your-domain.my.salesforce.com`) as it's required for authentication
191
+
192
+ #### 3. Salesforce CLI Authentication (Recommended for local/dev) (contribution by @andrea9293)
193
+ 1. Install and authenticate Salesforce CLI (`sf`).
194
+ 2. Make sure your org is authenticated and accessible via `sf org display --json` in the root of your Salesforce project.
195
+ 3. The server will automatically retrieve the access token and instance url using the CLI.
196
+
197
+
198
+
199
+ ### Usage with Claude Desktop
200
+
201
+
202
+ Add to your `claude_desktop_config.json`:
203
+
204
+
205
+ #### For Salesforce CLI Authentication:
206
+ ```json
207
+ {
208
+ "mcpServers": {
209
+ "salesforce": {
210
+ "command": "npx",
211
+ "args": ["-y", "@tsmztech/mcp-server-salesforce"],
212
+ "env": {
213
+ "SALESFORCE_CONNECTION_TYPE": "Salesforce_CLI"
214
+ }
215
+ }
216
+ }
217
+ }
218
+ ```
219
+
220
+ #### For Username/Password Authentication:
221
+ ```json
222
+ {
223
+ "mcpServers": {
224
+ "salesforce": {
225
+ "command": "npx",
226
+ "args": ["-y", "@tsmztech/mcp-server-salesforce"],
227
+ "env": {
228
+ "SALESFORCE_CONNECTION_TYPE": "User_Password",
229
+ "SALESFORCE_USERNAME": "your_username",
230
+ "SALESFORCE_PASSWORD": "your_password",
231
+ "SALESFORCE_TOKEN": "your_security_token",
232
+ "SALESFORCE_INSTANCE_URL": "org_url" // Optional. Default value: https://login.salesforce.com
233
+ }
234
+ }
235
+ }
236
+ }
237
+ ```
238
+
239
+ #### For OAuth 2.0 Client Credentials Flow:
240
+ ```json
241
+ {
242
+ "mcpServers": {
243
+ "salesforce": {
244
+ "command": "npx",
245
+ "args": ["-y", "@tsmztech/mcp-server-salesforce"],
246
+ "env": {
247
+ "SALESFORCE_CONNECTION_TYPE": "OAuth_2.0_Client_Credentials",
248
+ "SALESFORCE_CLIENT_ID": "your_client_id",
249
+ "SALESFORCE_CLIENT_SECRET": "your_client_secret",
250
+ "SALESFORCE_INSTANCE_URL": "https://your-domain.my.salesforce.com" // REQUIRED: Must be your exact Salesforce instance URL
251
+ }
252
+ }
253
+ }
254
+ }
255
+ ```
256
+
257
+ > **Note**: For OAuth 2.0 Client Credentials Flow, the `SALESFORCE_INSTANCE_URL` must be your exact Salesforce instance URL (e.g., `https://your-domain.my.salesforce.com`). The token endpoint will be constructed as `<instance_url>/services/oauth2/token`.
258
+
259
+ ## Example Usage
260
+
261
+ ### Searching Objects
262
+ ```
263
+ "Find all objects related to Accounts"
264
+ "Show me objects that handle customer service"
265
+ "What objects are available for order management?"
266
+ ```
267
+
268
+ ### Getting Schema Information
269
+ ```
270
+ "What fields are available in the Account object?"
271
+ "Show me the picklist values for Case Status"
272
+ "Describe the relationship fields in Opportunity"
273
+ ```
274
+
275
+ ### Querying Records
276
+ ```
277
+ "Get all Accounts created this month"
278
+ "Show me high-priority Cases with their related Contacts"
279
+ "Find all Opportunities over $100k"
280
+ ```
281
+
282
+ ### Aggregate Queries
283
+ ```
284
+ "Count opportunities by stage"
285
+ "Show me the total revenue by account"
286
+ "Find accounts with more than 10 opportunities"
287
+ "Calculate average deal size by sales rep and quarter"
288
+ "Get the number of cases by priority and status"
289
+ ```
290
+
291
+ ### Managing Custom Objects
292
+ ```
293
+ "Create a Customer Feedback object"
294
+ "Add a Rating field to the Feedback object"
295
+ "Update sharing settings for the Service Request object"
296
+ ```
297
+ Examples with Field Level Security:
298
+ ```
299
+ # Default - grants access to System Administrator automatically
300
+ "Create a Status picklist field on Custom_Object__c"
301
+
302
+ # Custom profiles - grants access to specified profiles
303
+ "Create a Revenue currency field on Account and grant access to Sales User and Marketing User profiles"
304
+ ```
305
+
306
+ ### Managing Field Permissions
307
+ ```
308
+ "Grant System Administrator access to Custom_Field__c on Account"
309
+ "Give read-only access to Rating__c field for Sales User profile"
310
+ "View which profiles have access to the Custom_Field__c"
311
+ "Revoke field access for specific profiles"
312
+ ```
313
+
314
+ ### Searching Across Objects
315
+ ```
316
+ "Search for 'cloud' in Accounts and Opportunities"
317
+ "Find mentions of 'network issue' in Cases and Knowledge Articles"
318
+ "Search for customer name across all relevant objects"
319
+ ```
320
+
321
+ ### Managing Apex Code
322
+ ```
323
+ "Show me all Apex classes with 'Controller' in the name"
324
+ "Get the full code for the AccountService class"
325
+ "Create a new Apex utility class for handling date operations"
326
+ "Update the LeadConverter class to add a new method"
327
+ ```
328
+
329
+ ### Managing Apex Triggers
330
+ ```
331
+ "List all triggers for the Account object"
332
+ "Show me the code for the ContactTrigger"
333
+ "Create a new trigger for the Opportunity object"
334
+ "Update the Case trigger to handle after delete events"
335
+ ```
336
+
337
+ ### Executing Anonymous Apex Code
338
+ ```
339
+ "Execute Apex code to calculate account metrics"
340
+ "Run a script to update related records"
341
+ "Execute a batch job to process large datasets"
342
+ ```
343
+
344
+ ### Managing Debug Logs
345
+ ```
346
+ "Enable debug logs for user@example.com"
347
+ "Retrieve recent logs for an admin user"
348
+ "Disable debug logs for a specific user"
349
+ "Configure log level to DEBUG for a user"
350
+ ```
351
+
352
+ ### REST API Calls
353
+ ```
354
+ "Check our org's API usage limits"
355
+ "Run the weekly sales report"
356
+ "Get all available REST API resources"
357
+ "Call our custom Apex REST endpoint at /services/apexrest/AccountSync"
358
+ "Use the Composite API to create an Account and Contact in one call"
359
+ ```
360
+
361
+ ## Security
362
+
363
+ This server includes multiple layers of input sanitization and security controls:
364
+
365
+ - **SOQL/SOSL injection prevention** — All user-supplied values are escaped before interpolation into queries. Object and field names are validated against Salesforce identifier patterns.
366
+ - **Credential protection** — Access tokens are never logged. CLI output is redacted before logging.
367
+ - **Audit logging** — Anonymous Apex execution is audit-logged with code length and preview.
368
+ - **Shell injection prevention** — CLI invocation uses `execFile` (no shell) instead of `exec`.
369
+
370
+ For full details, see [SECURITY.md](SECURITY.md).
371
+
372
+ > **Note:** The `salesforce_execute_anonymous` and `salesforce_rest_api` tools are intentionally powerful — they provide full access to Salesforce capabilities within the connected user's permissions. Use Salesforce profiles and permission sets to restrict what the connected user can do.
373
+
374
+ ## Development
375
+
376
+ ### Building from source
377
+ ```bash
378
+ # Clone the repository
379
+ git clone https://github.com/tsmztech/mcp-server-salesforce.git
380
+
381
+ # Navigate to directory
382
+ cd mcp-server-salesforce
383
+
384
+ # Install dependencies
385
+ npm install
386
+
387
+ # Build the project
388
+ npm run build
389
+ ```
390
+
391
+ ## Contributing
392
+ Contributions are welcome! Feel free to submit a Pull Request.
393
+
394
+ ## License
395
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
396
+
397
+ ## Issues and Support
398
+ If you encounter any issues or need support, please file an issue on the [GitHub repository](https://github.com/tsmztech/mcp-server-salesforce/issues).
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};