Connect AI assistants to Salesforce using Model Context Protocol. Master DX MCP Server, Hosted MCP, OAuth configuration, and mcp-remote setup.
According to the official Salesforce Developers blog, MCP acts as a "universal translator between AI agents and your business data" - similar to how USB standardized device connections. This standardization allows any MCP-compatible AI client to work with any MCP server without custom integrations.
Before MCP, integrating AI assistants with Salesforce required custom code, API wrappers, and significant development effort. With MCP, you can:
Example: "Get me Opportunities from last quarter"
Salesforce provides two official approaches to MCP connectivity, each designed for different use cases. Understanding these options helps you choose the right setup for your workflow.
@salesforce/mcp on npmThe Salesforce DX MCP Server is the recommended approach for developers already using Salesforce CLI. It provides the most comprehensive set of tools and requires minimal configuration.
1. Install Salesforce CLI
Download from Salesforce CLI page or use npm:
npm install -g @salesforce/cli
2. Authorize Your Org
Authenticate your Salesforce org (replace YOUR_ORG_ALIAS with your preferred alias):
sf org login web -a YOUR_ORG_ALIAS
3. Verify Node.js Version
MCP requires Node.js 18 or higher:
node --version
Create or edit your .mcp.json file in your project root (for project-scope) or ~/.claude.json (for user-scope):
{
"mcpServers": {
"Salesforce DX": {
"command": "npx",
"args": [
"-y",
"@salesforce/mcp",
"--orgs", "YOUR_ORG_ALIAS",
"--toolsets", "orgs,metadata,data,users",
"--tools", "run_apex_test",
"--allow-non-ga-tools"
]
}
}
}
| Flag | Required | Description |
|---|---|---|
--orgs |
Yes | Specify authorized orgs. Values: org alias, DEFAULT_TARGET_ORG, DEFAULT_TARGET_DEV_HUB, or ALLOW_ALL_ORGS |
--toolsets |
No | Enable specific tool groups (comma-separated). See section 4 for available toolsets. |
--tools |
No | Enable individual tools beyond selected toolsets |
--allow-non-ga-tools |
No | Include beta/preview tools not yet generally available |
--no-telemetry |
No | Disable anonymous usage data collection |
--debug |
No | Enable verbose logging for troubleshooting |
ALLOW_ALL_ORGS with caution as it grants MCP access to all locally authorized orgs. For better security, explicitly specify only the orgs needed using their aliases.After configuring, restart Claude Code and use the /mcp command to check server status. You should see "Salesforce DX" listed with available tools.
The Salesforce DX MCP Server organizes its 60+ tools into logical toolsets. According to the @salesforce/mcp npm package, you can selectively enable toolsets to reduce context window consumption and improve performance.
| Toolset | Description | Key Capabilities |
|---|---|---|
orgs |
Org management | List orgs, view org details, check connections |
data |
Data operations | SOQL queries, record CRUD, bulk operations |
metadata |
Metadata management | Deploy, retrieve, list metadata components |
users |
User management | Permission sets, profiles, user assignments |
testing |
Test execution | Run Apex tests, agent tests |
lwc-experts |
LWC development | Component analysis, best practices, optimization |
aura-experts |
Aura migration | Aura to LWC migration assistance |
code-analysis |
Static analysis | Code quality checks, security scanning |
mobile |
Mobile development | Mobile app features and testing |
scale-products |
Performance | Apex antipattern detection |
all |
All toolsets | Enables all 60+ tools (use with caution) |
For a typical LWC development workflow, use this focused configuration:
{
"mcpServers": {
"Salesforce DX": {
"command": "npx",
"args": [
"-y",
"@salesforce/mcp",
"--orgs", "my-dev-org",
"--toolsets", "orgs,metadata,lwc-experts,testing"
]
}
}
}
all toolset loads 60+ tools which can significantly impact context window and response times.According to the Salesforce Developers announcement, Hosted MCP Servers run on Salesforce infrastructure and expose specific Salesforce APIs as MCP tools - all without writing code. These servers use OAuth authentication and require the mcp-remote package to connect from stdio-based clients like Claude Code.
| Endpoint | URL Pattern | Purpose |
|---|---|---|
| sObject All | https://api.salesforce.com/platform/mcp/v1-beta.2/sobject-all |
Access to all sObjects and standard operations |
| Invocable Actions | https://api.salesforce.com/platform/mcp/v1-beta.2/invocable_actions |
Execute Flow invocable actions |
Before connecting to Hosted MCP Servers, complete these steps in your Salesforce org:
1. Enable MCP Service (Beta)
Setup > User Interface > User Interface > Enable MCP Service (Beta)
2. Create External Client App
Setup > Apps > App Manager > New External Client App
Configure the External Client App with OAuth settings for MCP access:
3. Configure Security Settings
Set up the security policies for your External Client App:
4. Save Client Credentials
After saving, click "Manage Consumer Details" to copy your Consumer Key (client_id) and Consumer Secret (client_secret) for MCP configuration.
OAuth authentication is required for Salesforce Hosted MCP Servers. According to the Salesforce OAuth documentation, you need to configure specific scopes to enable MCP functionality.
| Scope | Purpose | When Required |
|---|---|---|
api |
Access user data via REST API and Bulk API 2.0 | Always |
refresh_token |
Allow token refresh for persistent sessions | Always |
sfap_api |
Access Salesforce API Platform services | Always for Hosted MCP |
einstein_gpt_api |
Access Einstein GPT and AI services | For Einstein/Agentforce features |
When using mcp-remote with OAuth, the authorization flow uses URLs like this:
https://login.salesforce.com/services/oauth2/authorize?
response_type=code
&client_id=YOUR_CONSUMER_KEY
&code_challenge=GENERATED_CODE_CHALLENGE
&code_challenge_method=S256
&redirect_uri=http://localhost:8080/oauth/callback
&state=UNIQUE_STATE_STRING
&scope=api sfap_api refresh_token einstein_gpt_api
For Hosted MCP Servers, create an External Client App as described in Section 5. The key OAuth settings are:
Callback URL for Claude Code:
http://localhost:8080/oauth/callback
Required OAuth Scopes:
After saving, click "Manage Consumer Details" to copy your Consumer Key (client_id) and Consumer Secret (client_secret).
The mcp-remote package bridges stdio-only MCP clients (like Claude Code) to remote MCP servers with OAuth support. It handles the authentication flow and protocol translation automatically.
Add this to your .mcp.json or ~/.claude.json:
{
"mcpServers": {
"salesforce": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://api.salesforce.com/platform/mcp/v1-beta.2/sobject-all",
"8080",
"--static-oauth-client-info",
"{"client_id":"YOUR_CONSUMER_KEY","client_secret":"YOUR_CONSUMER_SECRET"}"
]
}
}
}
| Flag | Purpose | Example |
|---|---|---|
--static-oauth-client-info |
Provide pre-registered OAuth credentials | "{"client_id":"xxx"}" |
--host |
Set OAuth callback hostname | --host localhost (default) |
--transport |
Protocol preference | http-first, sse-only, http-only |
--header |
Add custom HTTP headers | --header "Authorization:Bearer token" |
--debug |
Enable verbose logging | Logs to ~/.mcp-auth/{hash}_debug.log |
--allow-http |
Allow HTTP (insecure) connections | For trusted private networks only |
For better security, use environment variables instead of inline credentials:
{
"mcpServers": {
"salesforce": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://api.salesforce.com/platform/mcp/v1-beta.2/sobject-all",
"8080",
"--static-oauth-client-info",
"{"client_id":"${SF_CLIENT_ID}","client_secret":"${SF_CLIENT_SECRET}"}"
],
"env": {
"SF_CLIENT_ID": "YOUR_CONSUMER_KEY",
"SF_CLIENT_SECRET": "YOUR_CONSUMER_SECRET"
}
}
}
}
You can also reference a JSON file containing credentials:
# Create credentials file
echo '{"client_id":"YOUR_KEY","client_secret":"YOUR_SECRET"}' > ~/.salesforce-oauth.json
# Reference in configuration
"--static-oauth-client-info", "@/Users/yourname/.salesforce-oauth.json"
http://localhost:8080/oauth/callback. Make sure this matches your Connected App's callback URL setting.This error occurs when OAuth tokens expire or when switching between MCP server endpoints.
# Clear cached credentials
rm -rf ~/.mcp-auth/
# Restart Claude Code and re-authenticate
Check the following:
node --version.mcp.json file/mcp in Claude Code to see detailed error messagesOAuth configuration issues. Verify:
http://localhost:8080/oauth/callbackThe --orgs flag is required. Ensure you've specified at least one authorized org:
# List authorized orgs
sf org list
# Use a valid org alias in your configuration
"--orgs", "your-org-alias"
For DX MCP Server:
{
"args": ["--debug", "--orgs", "my-org", ...]
}
For mcp-remote:
# Add --debug flag
"args": ["mcp-remote", "URL", "--debug"]
# Check logs at
cat ~/.mcp-auth/*_debug.log
MCP (Model Context Protocol) is an open standard by Anthropic that enables AI assistants like Claude to securely interact with external systems. For Salesforce developers, it means Claude Code can directly query data, deploy metadata, run Apex tests, and manage orgs without leaving the IDE. This dramatically accelerates development workflows and enables natural language interactions with your Salesforce environments.
Salesforce DX MCP Server runs locally using Salesforce CLI credentials and provides development-focused tools like metadata deployment, Apex testing, and LWC analysis. It requires Salesforce CLI to be installed but needs no OAuth setup. Salesforce Hosted MCP Servers run on Salesforce infrastructure, use OAuth authentication with Connected Apps, and provide API access to sObjects and invocable actions. Choose DX MCP for development workflows with CLI, and Hosted MCP for OAuth-based access without local CLI requirements.
The required OAuth scopes are: api for REST API access, refresh_token for token persistence, and sfap_api for Salesforce API Platform access. For Einstein and Agentforce features, you may also need einstein_gpt_api scope. Configure these in your Connected App's OAuth settings, and ensure the callback URL matches your mcp-remote configuration (default: http://localhost:8080/oauth/callback).
This error occurs when switching between MCP server endpoints or when OAuth tokens expire. Clear the cached credentials by running rm -rf ~/.mcp-auth/ in your terminal, then restart Claude Code to re-authenticate with fresh tokens. If the issue persists, verify your Connected App settings and ensure the callback URL is correctly configured.
Yes, Salesforce MCP servers work with any MCP-compatible client including Cursor, VS Code with Cline extension, Windsurf, Zed, and Trae. The configuration format is similar across clients, using JSON-based mcpServers configuration. For clients that don't support HTTP+SSE transports natively, use the mcp-remote package to bridge the connection. Check each client's documentation for specific configuration file locations.
Continue your Salesforce and AI development journey with these related guides:
Reference guide for technical terms and abbreviations used throughout this article.