Salesforce CLI MCP server

Exposes Salesforce CLI functionality for interacting with Salesforce orgs, enabling developers to query data, deploy code, and manage orgs through dynamically discovered commands.
Back to servers
Setup instructions
Provider
Kevin Poorman
Release date
Mar 25, 2025
Language
TypeScript
Package
Stats
482 downloads
30 stars

This MCP server provides Salesforce CLI functionality to LLM tools like Claude Desktop by wrapping the sf command-line tool and exposing its commands as MCP tools and resources. This allows AI agents to execute Salesforce CLI commands, view help information, and leverage Salesforce capabilities within AI workflows.

Requirements

  • Node.js 18+ and npm
  • Salesforce CLI (sf) installed and configured
  • Your Salesforce org credentials configured in the CLI

Installation

# Clone the repository
git clone <repository-url>
cd sfMcp

# Install dependencies
npm install

Basic Usage

Starting the Server

# Basic usage
npm start

# With project roots
npm start /path/to/project1 /path/to/project2

# Using the convenience script
npm run with-roots /path/to/project1 /path/to/project2

# As an npx package with roots
npx -y codefriar/sf-mcp /path/to/project1 /path/to/project2

Configuring in Claude Desktop

Add this configuration to your .claude.json file:

{
  "tools": {
    "salesforce": {
      "command": "/path/to/node",
      "args": [
        "/path/to/sf-mcp/build/index.js",
        "/path/to/project1",
        "/path/to/project2"
      ]
    }
  }
}

Or using the npm package directly:

{
  "tools": {
    "salesforce": {
      "command": "/path/to/npx", 
      "args": [
        "-y",
        "codefriar/sf-mcp",
        "/path/to/project1",
        "/path/to/project2"
      ]
    }
  }
}

Available Tools

Core Tools

  • sf_version - Get the Salesforce CLI version information
  • sf_help - Get help information for Salesforce CLI commands
  • sf_cache_clear - Clear the command discovery cache
  • sf_cache_refresh - Refresh the command discovery cache

Project Directory Management

For commands that require a Salesforce project context, you must specify the project directory.

Setting Project Roots

Method 1: Via Command Line Arguments

npm start /path/to/project1 /path/to/project2

Roots will be automatically named root1, root2, etc., with the first one set as default.

Method 2: Using MCP Tools

# Set project directory with a name
sf_set_project_directory --directory=/path/to/your/sfdx/project --name=project1 --isDefault=true

# List all configured roots
sf_list_roots

Method 3: Claude Desktop Configuration Configure project roots in .claude.json as shown in the configuration examples above.

Using Project Roots

Execute commands in specific project roots:

# Using resource URI
sf://roots/project1/commands/project deploy start --sourcedir=force-app

# Using rootName parameter
sf_project_deploy_start --sourcedir=force-app --rootName=project1

Key Command Tools

Organization Management

  • sf_org_list - List Salesforce orgs
    • Parameters: json, verbose
  • sf_auth_list_orgs - List authenticated Salesforce orgs
    • Parameters: json, verbose
  • sf_org_display - Display details about an org
    • Parameters: targetusername, json
  • sf_org_open - Open an org in the browser
    • Parameters: targetusername, path, urlonly

Apex Code

  • sf_apex_run - Run anonymous Apex code
    • Parameters: targetusername, file, apexcode, json
  • sf_apex_test_run - Run Apex tests
    • Parameters: targetusername, testnames, suitenames, classnames, json

Data Management

  • sf_data_query - Execute a SOQL query
    • Parameters: targetusername, query, json
  • sf_schema_list_objects - List sObjects in the org
    • Parameters: targetusername, json
  • sf_schema_describe - Describe a Salesforce object
    • Parameters: targetusername, sobject, json

Deployment

  • sf_project_deploy_start - Deploy the source to an org
    • Parameters: targetusername, sourcedir, json, wait

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 code
  • sf_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 logs
  • sf_org_login_web - Login to an org using web flow

Available Resources

  • sf://help - Main CLI documentation
  • sf://topics/{topic}/help - Topic help documentation
  • sf://commands/{command}/help - Command help documentation
  • sf://topics/{topic}/commands/{command}/help - Topic-command help documentation
  • sf://version - Version information
  • sf://roots - List all configured project roots
  • sf://roots/{root}/commands/{command} - Execute a command in a specific project root

Troubleshooting

If you encounter issues with missing commands or cache problems:

  1. Stop the MCP server
  2. Delete the cache file: rm ~/.sf-mcp/command-cache.json
  3. Restart the server

For missing commands after installing new SF CLI plugins:

  1. Use the sf_cache_refresh tool
  2. Restart the MCP server

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "salesforce" '{"command":"npx","args":["-y","codefriar/sf-mcp"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "salesforce": {
            "command": "npx",
            "args": [
                "-y",
                "codefriar/sf-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "salesforce": {
            "command": "npx",
            "args": [
                "-y",
                "codefriar/sf-mcp"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later