Integrations
Wraps the Salesforce CLI to provide access to Salesforce org functionality including organization management, Apex code execution, data querying, schema exploration, and deployment capabilities.
Salesforce CLI MCP Server
Model Context Protocol (MCP) server for providing Salesforce CLI functionality to LLM tools like Claude Desktop.
Overview
This MCP server wraps the Salesforce CLI (sf
) command-line tool and exposes its commands as MCP tools and resources, allowing LLM-powered agents to:
- View help information about Salesforce CLI topics and commands
- Execute Salesforce CLI commands with appropriate parameters
- Leverage Salesforce CLI capabilities in AI workflows
Requirements
- Node.js 18+ and npm
- Salesforce CLI (
sf
) installed and configured - Your Salesforce org credentials configured in the CLI
Installation
Usage
Starting the server
The MCP server uses stdio transport, which can be used with MCP clients like the MCP Inspector or Claude Desktop.
Configuring in Claude Desktop
To configure this MCP in Claude Desktop's .claude.json
configuration:
Using the npm package directly:
Development
Available Tools and Resources
This MCP server provides Salesforce CLI commands as MCP tools. It automatically discovers and registers all available commands from the Salesforce CLI, and also specifically implements the most commonly used commands.
Core Tools
sf_version
- Get the Salesforce CLI version informationsf_help
- Get help information for Salesforce CLI commandssf_cache_clear
- Clear the command discovery cachesf_cache_refresh
- Refresh the command discovery cache
Project Directory Management (Roots)
For commands that require a Salesforce project context (like deployments), you must specify the project directory. The MCP supports multiple project directories (roots) similar to the filesystem MCP.
Configuration Methods
Method 1: Via Command Line Arguments
When configured this way, the roots will be automatically named root1
, root2
, etc.,
with the first one set as default.
Method 2: Using MCP Tools
sf_set_project_directory
- Set a Salesforce project directory to use for commands- Parameters:
directory
- Path to a directory containing a sfdx-project.json filename
- (Optional) Name for this project rootdescription
- (Optional) Description for this project rootisDefault
- (Optional) Set this root as the default for command execution
- Parameters:
sf_list_roots
- List all configured project rootssf_detect_project_directory
- Attempt to detect project directory from user messages
Example usage:
Method 3: Claude Desktop Configuration
Configure project roots in .claude.json
as described below.
Using Project Roots
You can execute commands in specific project roots:
Project directory must be specified for commands such as deployments, source retrieval, and other project-specific operations. If multiple roots are configured, the default root will be used unless otherwise specified.
Key Implemented Tools
The following commands are specifically implemented and guaranteed to work:
Organization Management
sf_org_list
- List Salesforce orgs- Parameters:
json
,verbose
- Parameters:
sf_auth_list_orgs
- List authenticated Salesforce orgs- Parameters:
json
,verbose
- Parameters:
sf_org_display
- Display details about an org- Parameters:
targetusername
,json
- Parameters:
sf_org_open
- Open an org in the browser- Parameters:
targetusername
,path
,urlonly
- Parameters:
Apex Code
sf_apex_run
- Run anonymous Apex code- Parameters:
targetusername
,file
,apexcode
,json
- Parameters:
sf_apex_test_run
- Run Apex tests- Parameters:
targetusername
,testnames
,suitenames
,classnames
,json
- Parameters:
Data Management
sf_data_query
- Execute a SOQL query- Parameters:
targetusername
,query
,json
- Parameters:
sf_schema_list_objects
- List sObjects in the org- Parameters:
targetusername
,json
- Parameters:
sf_schema_describe
- Describe a Salesforce object- Parameters:
targetusername
,sobject
,json
- Parameters:
Deployment
sf_project_deploy_start
- Deploy the source to an org- Parameters:
targetusername
,sourcedir
,json
,wait
- Parameters:
Dynamically Discovered Tools
The server discovers all available Salesforce CLI commands and registers them as tools with format: sf_<topic>_<command>
.
For example:
sf_apex_run
- Run anonymous Apex codesf_data_query
- Execute a SOQL query
For nested topic commands, the tool name includes the full path with underscores:
sf_apex_log_get
- Get apex logssf_org_login_web
- Login to an org using web flow
The server also creates simplified aliases for common nested commands where possible:
sf_get
as an alias forsf_apex_log_get
sf_web
as an alias forsf_org_login_web
The available commands vary depending on the installed Salesforce CLI plugins.
Note: Command discovery is cached to improve startup performance. If you install new SF CLI plugins, use the
sf_cache_refresh
tool to update the cache, then restart the server.
Resources
The following resources provide documentation about Salesforce CLI:
sf://help
- Main CLI documentationsf://topics/{topic}/help
- Topic help documentationsf://commands/{command}/help
- Command help documentationsf://topics/{topic}/commands/{command}/help
- Topic-command help documentationsf://version
- Version informationsf://roots
- List all configured project rootssf://roots/{root}/commands/{command}
- Execute a command in a specific project root
How It Works
- At startup, the server checks for a cached list of commands (stored in
~/.sf-mcp/command-cache.json
) - If a valid cache exists, it's used to register commands; otherwise, commands are discovered dynamically
- During discovery, the server queries
sf commands --json
to get a complete list of available commands - Command metadata (including parameters and descriptions) is extracted directly from the JSON output
- All commands are registered as MCP tools with appropriate parameter schemas
- Resources are registered for help documentation
- When a tool is called, the corresponding Salesforce CLI command is executed
Project Roots Management
For commands that require a Salesforce project context:
- The server checks if any project roots have been configured via
sf_set_project_directory
- If multiple roots are configured, it uses the default root unless a specific root is specified
- If no roots are set, the server will prompt the user to specify a project directory
- Commands are executed within the appropriate project directory, ensuring proper context
- The user can add or switch between multiple project roots as needed
Project-specific commands (like deployments, retrievals, etc.) will automatically run in the appropriate project directory. For commands that don't require a project context, the working directory doesn't matter.
You can execute commands in specific project roots by:
- Using the resource URI:
sf://roots/{rootName}/commands/{command}
- Providing a
rootName
parameter to command tools (internal implementation details) - Setting a specific root as the default with
sf_set_project_directory --isDefault=true
Command Caching
To improve startup performance, the MCP server caches discovered commands:
- The cache is stored in
~/.sf-mcp/command-cache.json
- It includes all topics, commands, parameters, and descriptions
- The cache has a validation timestamp and SF CLI version check
- By default, the cache expires after 7 days
- When you install new Salesforce CLI plugins, use
sf_cache_refresh
to update the cache
Troubleshooting Cache Issues
The first run of the server performs a full command discovery which can take some time. If you encounter any issues with missing commands or cache problems:
- Stop the MCP server (if running)
- Manually delete the cache file:
rm ~/.sf-mcp/command-cache.json
- Start the server again:
npm start
This will force a complete rediscovery of all commands using the official CLI metadata.
If specific commands are still missing, or you've installed new SF CLI plugins:
- Use the
sf_cache_refresh
tool from Claude Desktop - Stop and restart the MCP server
Handling Nested Topics
The Salesforce CLI has a hierarchical command structure that can be several levels deep. This MCP server handles these nested commands by:
- Converting colon-separated paths to underscore format (
apex:log:get
→sf_apex_log_get
) - Providing aliases for common deep commands when possible (
sf_get
forsf_apex_log_get
) - Preserving the full command hierarchy in the tool names
- Using the official command structure from
sf commands --json
Nested topic commands are registered twice when possible—once with the full hierarchy name and once with a simplified alias, making them easier to discover and use.
License
ISC
You must be authenticated.
Exposes Salesforce CLI functionality to LLM tools like Claude Desktop, allowing AI agents to execute Salesforce commands, manage orgs, deploy code, and query data through natural language.