salesforce-mcp-server
CLAUDE.md33 starsChanged 2 months agoMITView on GitHub
This is a Model Context Protocol (MCP) server that enables AI assistants to interact with Salesforce orgs through the Salesforce CLI. The codebase follows a modular architecture with clear separation of concerns. When implementing new tools, follow this pattern: The MCP server provides tools organized by functionality:
- Installs packages
In this repositoryOne other file it gives its agents.
- salesforceSkill
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
19 rules. About 0 are common, 8 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
Permission System: All tools check permissions via src/config/permissions.ts which enforces:
- Distinctive: line 41
When implementing new tools, follow this pattern:
- Very specific: line 98
Create or update the appropriate file in src/tools/
- Very specific: line 102
Make sure new tools are registered in both the tool file and manifest.json
- Distinctive: line 108
Always return structured JSON responses instead of throwing errors
- Very specific: line 109
Use the pattern: { error: "message" } for error responses
- Very specific: line 134
All Salesforce CLI commands should use executeSfCommand() from src/utils/sfCommand.ts
- Distinctive: line 136
Always validate inputs with Zod schemas before processing
- Distinctive: line 137
Check org access permissions before executing any Salesforce operations
- Very specific: line 138
Use --json flag for CLI commands to ensure consistent JSON output
- Very specific: line 140
Do not add indentation to JSON results (use JSON.stringify(result) not JSON.stringify(result, null, 2))
- Distinctive: line 141
Verify permission checks are implemented for all destructive operations
- Distinctive: line 150
Record CRUD Operations: Create, update, and delete Salesforce records via REST API
- Very specific: line 153
Read-Only Mode Support: All write operations respect READ_ONLY permission setting
- Distinctive: line 159
Run prettier on all modified files after making changes
- Very specific: line 160
After making changes, always update documentation in both README.MD and manifest.json
- Very specific: line 161
After making changes, rebuild the project (npm run build) and the MCPB file (npm run build:mcpb)
- Very specific: line 162
Always add the shebang line to build/index.js after creating a new build and before publishing — this is critical
- Distinctive: line 163
Use web search to gather the latest information that may not be in the training dataset — Salesforce CLI command syntax, MCP SDK APIs, npm …
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Build and Development Commands
# Build the TypeScript project
npm run build
# Run development mode with MCP inspector for debugging
npm run dev
# Build MCP Bundle (.mcpb) for distribution
npm run build:mcpb
# Install dependencies
npm installArchitecture Overview
This is a Model Context Protocol (MCP) server that enables AI assistants to interact with Salesforce orgs through the Salesforce CLI. The codebase follows a modular architecture with clear separation of concerns.
Core Components
- Tool Registration Pattern: Each tool category has its own file in
src/tools/that exports a registration function. Tools are registered insrc/index.tsusing functions likeregisterApexTools(server). - Permission System: All tools check permissions via
src/config/permissions.tswhich enforces:READ_ONLYmode: Prevents Apex execution when enabledALLOWED_ORGS: Restricts access to specific org aliases
- Salesforce Integration: Two approaches are used:
- Native API calls via
@salesforce/apex-nodefor Apex operations - CLI commands via
src/utils/sfCommand.tsfor most other operations
- Native API calls via
- Connection Management:
src/shared/connection.tshandles Salesforce authentication by reusing existing Salesforce CLI auth tokens.
Tool Implementation Pattern
When implementing new tools, follow this pattern:
// 1. Define Zod schema for input validation (targetOrg is optional — falls back to SF CLI default)
const MyToolSchema = z.object({
targetOrg: z.string().optional(),
// other parameters
});
// 2. Resolve target org (uses default if not provided)
let targetOrg: string;
try {
targetOrg = await resolveTargetOrg(input.targetOrg);
} catch (error: any) {
return {
content: [
{
type: "text",
text: JSON.stringify({
success: false,
message: error.message,
}),
},
],
};
}
// 3. Check permissions
if (!permissions.canAccessOrg(targetOrg)) {
return { error: "Access denied" };
}
// 4. Execute operation (via CLI or native API)
const result = await executeSfCommand(["command", "args"], targetOrg);
// 5. Return structured response
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };Tool Categories
The MCP server provides tools organized by functionality:
- Apex Tools (
src/tools/apex.ts): Execute anonymous Apex, run tests, get coverage, manage logs, generate classes/triggers - Query Tools (
src/tools/query.ts): Query records with SOQL, export to files - SObject Tools (
src/tools/sobjects.ts): List and describe Salesforce objects - Org Tools (
src/tools/orgs.ts): List connected orgs, login, logout, open org in browser - Admin Tools (
src/tools/admin.ts): Manage permissions, users, metadata - Schema Tools (
src/tools/schema.ts): Generate custom tabs - Package Tools (
src/tools/package.ts): Install and uninstall packages - Code Analysis Tools (
src/tools/code-analyzer.ts,src/tools/scanner.ts): Static code analysis and security scanning - Record Tools (
src/tools/records.ts): Open records in browser, create/update/delete records via REST API - Lightning Tools (
src/tools/lightning.ts): Generate Lightning Web Components and Aura components - Project Tools (
src/tools/project.ts): Deploy metadata to Salesforce orgs
Adding New Tools
- Create or update the appropriate file in
src/tools/ - Define the tool with Zod schema validation
- Implement permission checks if needed
- Register the tool in the export function
- Make sure new tools are registered in both the tool file and
manifest.json - Rebuild the project with
npm run build - Build the MCP Bundle with
npm run build:mcpb
Error Handling
- Always return structured JSON responses instead of throwing errors
- Use the pattern:
{ error: "message" }for error responses - Include helpful context in error messages
Key Files to Understand
src/index.ts- Server initialization and tool registrationsrc/config/permissions.ts- Permission enforcement logicsrc/utils/sfCommand.ts- Salesforce CLI integrationsrc/utils/resolveTargetOrg.ts- Default org resolution with cachingsrc/shared/connection.ts- Salesforce authentication handlingmanifest.json- Desktop Extension configuration and tool metadata
TypeScript Configuration
- Target: ES2022
- Module: Node16
- Output:
./builddirectory - Type: ES modules (
"type": "module"in package.json)
Distribution
The project supports MCP Bundle (.mcpb) packaging for one-click installation. The manifest.json file defines the extension metadata, tools, and user configuration options.
Important Implementation Notes
- All Salesforce CLI commands should use
executeSfCommand()fromsrc/utils/sfCommand.ts - Native Apex operations should use the
@salesforce/apex-nodelibrary when possible for better performance - Always validate inputs with Zod schemas before processing
- Check org access permissions before executing any Salesforce operations
- Use
--jsonflag for CLI commands to ensure consistent JSON output - The server version is maintained in both
package.jsonandsrc/index.ts - Do not add indentation to JSON results (use
JSON.stringify(result)notJSON.stringify(result, null, 2)) - Verify permission checks are implemented for all destructive operations
Recent Features Added
- Lightning Component Generation: Generate Lightning Web Components and Aura components with customizable templates
- Project Deployment: Deploy metadata to Salesforce orgs with various configuration options
- Apex Debug Logs: Fetch and view Apex debug logs from the org
- Apex Code Generation: Generate Apex classes and triggers with metadata
- Record Navigation: Open Salesforce records directly in browser
- Record CRUD Operations: Create, update, and delete Salesforce records via REST API
- Enhanced Error Handling: Improved error messages with more context
- Prettier Integration: Automatic code formatting with
.prettierrcconfiguration - Read-Only Mode Support: All write operations respect READ_ONLY permission setting
- Removed Interactive Schema Tools: Field and object generation tools removed as they require interactive CLI prompts
Workflow Rules
- Always execute tasks and agents in parallel when possible. If multiple independent operations need to be performed (e.g., reading files, running searches, editing unrelated files, running builds), do them simultaneously rather than sequentially. Only run tasks and agents sequentially when there is a dependency between them.
- Run prettier on all modified files after making changes
- After making changes, always update documentation in both
README.MDandmanifest.json - After making changes, rebuild the project (
npm run build) and the MCPB file (npm run build:mcpb) - Always add the shebang line to
build/index.jsafter creating a new build and before publishing — this is critical - Use web search to gather the latest information that may not be in the training dataset — Salesforce CLI command syntax, MCP SDK APIs, npm package versions, Salesforce platform updates, and third-party library documentation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

