This guide walks you through setting up a Salesforce Connected App for OAuth authentication with the MCP Salesforce Server.
- Salesforce Developer/Administrator access
- Ability to create Connected Apps in your Salesforce org
-
Login to Salesforce
- Go to your Salesforce instance (e.g.,
https://yourorg.salesforce.com) - Login with administrator credentials
- Go to your Salesforce instance (e.g.,
-
Navigate to App Manager
- Click the gear icon (Setup) in the top right
- In Quick Find, search for "App Manager"
- Click App Manager
-
Create New Connected App
- Click New Connected App
- Fill in the required fields:
Connected App Name: MCP Salesforce Server
API Name: mcp_salesforce_server (auto-generated)
Contact Email: your-email@example.com
Description: OAuth integration for MCP Salesforce Server
- ✅ Enable OAuth Settings
Callback URLs (add ALL of these, one per line):
http://localhost:8080/callback
http://localhost:8000/callback
http://localhost:8001/callback
http://localhost:8002/callback
http://localhost:8003/callback
http://localhost:8004/callback
http://localhost:8005/callback
Selected OAuth Scopes:
- Manage user data via APIs (api)
- Perform requests at any time (refresh_token, offline_access)
Note: Multiple callback URLs are needed because the setup process will try different ports if 8080 is busy.
- ✅ Require Secret for Web Server Flow: Leave checked
- ✅ Require Secret for Refresh Token Flow: Leave checked
- ❌ Enable PKCE: Leave unchecked for compatibility
- Save the Connected App
- Click Save
- You'll see a message that it may take 2-10 minutes to take effect
-
View the Connected App
- After saving, click Continue or navigate back to App Manager
- Find your app and click View
-
Copy OAuth Credentials
- Consumer Key: This is your
SALESFORCE_CLIENT_ID - Consumer Secret: Click "Click to reveal" to see your
SALESFORCE_CLIENT_SECRET
- Consumer Key: This is your
-
Note Your Instance URL
- Your Salesforce instance URL (e.g.,
https://yourcompany.salesforce.com) - This is your
SALESFORCE_INSTANCE_URL
- Your Salesforce instance URL (e.g.,
Create a .env file in your project root:
SALESFORCE_CLIENT_ID=3MVG9...your-consumer-key...
SALESFORCE_CLIENT_SECRET=1234567890...your-consumer-secret...
SALESFORCE_INSTANCE_URL=https://yourorg.salesforce.com- In your Connected App settings, scroll to OAuth Policies
- Set Permitted Users to "Admin approved users are pre-authorized"
- Set IP Relaxation to "Enforce IP restrictions"
Ensure the user authenticating has appropriate permissions:
- API Enabled permission
- Access to objects and fields you plan to use
- Modify All Data or specific object permissions as needed
After configuring your .env file:
npm run setupThis will:
- Validate your environment configuration
- Test connectivity to Salesforce
- Open your browser for OAuth authentication
- Store tokens securely in macOS Keychain
"Invalid client credentials"
- Verify Consumer Key and Secret are correct
- Check for extra spaces or characters
- Ensure Connected App is activated (wait 2-10 minutes after creation)
"Invalid redirect URI"
- The callback URL is auto-generated during setup
- No need to change it in Salesforce
- Ensure no firewall blocking localhost connections
"User authentication failed"
- Check user has API access enabled
- Verify user permissions for required objects
- Ensure user can login to Salesforce normally
"Insufficient privileges"
- User needs "API Enabled" permission
- Check object-level and field-level security
- Verify sharing rules don't restrict access
Custom Callback Port
SALESFORCE_CALLBACK_URL=http://localhost:9000/callbackAPI Version
SALESFORCE_API_VERSION=v58.0Timeout Settings
SALESFORCE_TIMEOUT=30000- Rotate Secrets Regularly: Update Consumer Secret periodically
- Monitor Usage: Check Connected App usage in Setup > Apps > Connected Apps OAuth Usage
- Limit Scope: Only grant necessary OAuth scopes
- Review Permissions: Regularly audit user permissions
- Enable Monitoring: Set up login monitoring and alerts
For production deployments:
- Use Environment Variables: Never hardcode credentials
- Secure Secret Storage: Use secure secret management
- Enable IP Restrictions: Limit access to known IP ranges
- Monitor Access: Set up alerts for unusual activity
- Regular Audits: Review and audit Connected App usage
- Daily API Limits: Monitor your org's API usage
- Rate Limiting: The server includes automatic retry logic
- Bulk Operations: Use SOQL efficiently for large datasets
- Field-Level Security: Respect Salesforce security model
This OAuth setup provides secure, long-term authentication for your MCP Salesforce Server while following Salesforce security best practices.