realfastAI/salesforce-mcp-server
If you are the rightful owner of salesforce-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Salesforce MCP Server 0.6.0 by realfast.ai is a Model Context Protocol server designed to provide secure access to Salesforce organizations, enabling AI models to query and explore Salesforce data through standardized tools and resources.
realfast.ai Salesforce MCP Server 0.6.0
Use Claude Desktop with this server to interactively explore, analyse and manage your Salesforce org!
This is Model Context Protocol (MCP) server that provides secure access to Salesforce organizations through OAuth2 authentication, enabling AI models to query and explore Salesforce data through standardized tools and resources.
โ Currently Working: 12 production-validated tools, OAuth2 authentication, comprehensive Salesforce API coverage, and Claude Desktop integration
About Us
realfast.ai is an AI-native Salesforce implementation partner that combines deep data and AI expertise with Salesforce expertise.
We use AI to ship better and faster. We help you do the same!
๐ Features
- OAuth2 PKCE Authentication: Secure browser-based authentication with encrypted token storage
- Object Metadata Tools: Comprehensive Salesforce object schema exploration
- Claude Desktop Integration: Seamless integration with Claude Desktop via MCP protocol
- Type Safety: Full TypeScript implementation with strict type checking
- Production Ready: Comprehensive error handling, logging, and configuration management
- Extensible Architecture: Modular design for adding additional Salesforce tools
โ Currently Implemented Tools (10 Total)
Core Data Access Tools:
describe_object
- Comprehensive object metadata and field information with record typeslist_objects
- List all Salesforce objects with filtering and paginationsoql_query
- Execute SOQL queries with injection prevention and paginationget_record
- Retrieve specific records by ID with field selection and relationship traversalsosl_search
- Multi-object text search with result ranking and field permissions
Field Metadata Tools:
get_picklist_values
- Retrieve picklist field values with dependency analysis and security filtering
Query Analysis Tools:
validate_soql
- SOQL syntax validation and security analysis without executionexplain_query_plan
- Query performance analysis and optimization recommendations
Organization Context Tools:
get_org_limits
- Organization API limits and usage statistics monitoringget_user_info
- Current user profile information with privacy sanitization
Additional Features:
- OAuth2 PKCE authentication flow with automatic token refresh
- Claude Desktop integration via stdio transport
- Encrypted token storage in configurable location
- Comprehensive logging and error handling
๐ง Planned Features
- Resource provider for MCP resources
- Advanced query tools (SOSL search)
- Utility tools (org limits, user info)
๐ Table of Contents
- Installation
- Quick Start
- Configuration
- Authentication
- Available Tools
- Resources
- Development
- Testing
- Contributing
- License
๐ Installation
Prerequisites
- Node.js 18.0 or higher
- tsx (TypeScript executor):
npm install -g tsx
- Salesforce org with OAuth2 Connected App configured
- Claude Desktop (for MCP integration)
Setup from Source
git clone https://github.com/your-org/salesforce-mcp-server.git
cd salesforce-mcp-server
npm install
โก Quick Start
1. Configure Salesforce Connected App
Step-by-Step Connected App Setup
-
Log into Salesforce:
- Go to your Salesforce org (production, sandbox, or developer edition)
- Navigate to Setup (gear icon โ Setup)
-
Create New Connected App:
- In Quick Find, search for "App Manager"
- Click App Manager โ New Connected App
-
Basic Information:
- Connected App Name:
MCP Salesforce Server
(or your preferred name) - API Name: Auto-generated (e.g.,
MCP_Salesforce_Server
) - Contact Email: Your email address
- Description:
MCP server for AI access to Salesforce data
- Connected App Name:
-
API (Enable OAuth Settings):
- โ Check Enable OAuth Settings
- Callback URL:
http://localhost:8080/callback
- Selected OAuth Scopes (add these three):
Access the identity URL service (id)
Perform requests at any time (refresh_token)
Access and manage your data (api)
-
Web App Settings:
- โ Check Require Secret for Web Server Flow
- โ Check Require Secret for Refresh Token Flow
-
Security Settings (Recommended):
- IP Relaxation:
Relax IP restrictions
- Refresh Token Policy:
Refresh token is valid until revoked
- IP Relaxation:
-
Save and Wait:
- Click Save
- Wait 2-10 minutes for the Connected App to propagate
Retrieve Credentials
-
Get Client ID and Secret:
- Go back to App Manager
- Find your Connected App โ View
- Copy Consumer Key (this is your
SFDC_CLIENT_ID
) - Click Click to reveal next to Consumer Secret (this is your
SFDC_CLIENT_SECRET
)
-
Get Instance URL:
- Your Salesforce instance URL format:
- Production:
https://yourcompany.my.salesforce.com
- Sandbox:
https://yourcompany--sandbox.sandbox.my.salesforce.com
- Developer:
https://yourcompany-dev-ed.develop.my.salesforce.com
- Production:
- Your Salesforce instance URL format:
Troubleshooting Connected App Issues
Common Issues:
- "invalid_client_id" error: Wait 2-10 minutes after creating the Connected App
- "redirect_uri_mismatch" error: Ensure callback URL is exactly
http://localhost:8080/callback
- "insufficient_scope" error: Verify all three OAuth scopes are selected
- SSL/TLS errors: Ensure your Salesforce org has proper SSL certificates
Security Considerations:
- The Connected App uses PKCE (Proof Key for Code Exchange) for enhanced security
- Client secret is only used for refresh token flow, not initial authentication
- All tokens are encrypted locally using AES-256-GCM encryption
- No sensitive data is stored in plain text
2. Set up environment variables
cp .env.sample .env
# Edit .env with your Salesforce credentials and file paths
Required environment variables:
SFDC_CLIENT_ID=<your_connected_app_client_id>
SFDC_CLIENT_SECRET=<your_connected_app_client_secret>
SFDC_INSTANCE_URL=https://your-org.my.salesforce.com
MCP_LOG_FILE="/absolute/path/to/your/project/server.log"
SFDC_TOKEN_FILE="/absolute/path/to/your/project/.salesforce-tokens.enc"
3. Add to Claude Desktop Configuration
Add this to your Claude Desktop claude_desktop_config.json
:
{
"mcpServers": {
"salesforce": {
"command": "tsx",
"args": ["/absolute/path/to/salesforce-mcp-server/src/stdio-server.ts"],
"env": {
"SFDC_CLIENT_ID": "your_connected_app_client_id",
"SFDC_CLIENT_SECRET": "your_connected_app_client_secret",
"SFDC_INSTANCE_URL": "https://your-org.my.salesforce.com",
"SFDC_API_VERSION": "v59.0",
"MCP_LOG_FILE": "/absolute/path/to/your/project/server.log",
"SFDC_TOKEN_FILE": "/absolute/path/to/your/project/.salesforce-tokens.enc"
}
}
}
}
4. Test the Integration
- Restart Claude Desktop
- Start a new conversation
- Try using the describe_object tool:
Can you describe the Account object in Salesforce?
The server will automatically open a browser for OAuth2 authentication on first use.
โ๏ธ Configuration
Environment Variables
Variable | Description | Required | Default |
---|---|---|---|
SFDC_CLIENT_ID | OAuth2 Connected App Client ID | Yes | - |
SFDC_CLIENT_SECRET | OAuth2 Connected App Client Secret | Yes | - |
SFDC_INSTANCE_URL | Salesforce instance URL | Yes | - |
SFDC_API_VERSION | Salesforce API version | No | v59.0 |
SFDC_TOKEN_FILE | Path for encrypted token storage | No | .salesforce-tokens.enc |
MCP_LOG_FILE | Path for server log file | No | - (logs to stdout) |
Example Configuration
See .env.sample
for a complete example:
# Required Salesforce OAuth2 Configuration
SFDC_CLIENT_ID=3MVG9...your_client_id
SFDC_CLIENT_SECRET=9CF743...your_client_secret
SFDC_INSTANCE_URL=https://your-org.my.salesforce.com
# File Paths (use absolute paths for Claude Desktop)
MCP_LOG_FILE="/absolute/path/to/your/project/server.log"
SFDC_TOKEN_FILE="/absolute/path/to/your/project/.salesforce-tokens.enc"
# Optional Settings
SFDC_API_VERSION=v59.0
๐ Authentication
The server uses OAuth2 PKCE (Proof Key for Code Exchange) flow for secure authentication with Salesforce.
OAuth2 Setup Process
-
Create Connected App in Salesforce (see detailed steps above):
- Navigate to Setup โ App Manager โ New Connected App
- Configure OAuth settings with proper scopes and callback URL
- Enable secret requirements for enhanced security
- Wait 2-10 minutes for propagation
-
Configure Environment:
- Copy Consumer Key as
SFDC_CLIENT_ID
- Copy Consumer Secret as
SFDC_CLIENT_SECRET
- Set your org's instance URL as
SFDC_INSTANCE_URL
- Configure file paths for logging and token storage
- Copy Consumer Key as
-
Authentication Flow Details:
Initial Authentication:
- First tool use triggers OAuth2 PKCE flow
- Local HTTP server starts on
localhost:8080
- Browser opens to Salesforce login page
- User logs in and grants permissions
- Authorization code exchanged for access/refresh tokens
- Tokens encrypted with AES-256-GCM and stored locally
Subsequent Usage:
- Encrypted tokens loaded from local storage
- Access token used for API calls
- Automatic refresh when tokens expire
- No browser interaction required
-
Security Features:
- PKCE Flow: Protection against authorization code interception
- State Parameter: CSRF attack prevention
- Local Storage: No cloud storage of credentials
- Encryption: AES-256-GCM with random IV for each token
- Scope Limitation: Minimal required permissions only
-
Troubleshooting Authentication:
Browser Issues:
- If browser doesn't open: manually visit
http://localhost:8080/auth
- If callback fails: check firewall settings for port 8080
- If login loops: clear Salesforce cookies and try again
Token Issues:
- Delete token file to force re-authentication:
rm .salesforce-tokens.enc
- Check token file permissions (should be readable by user only)
- Verify instance URL matches your org exactly
Permission Errors:
- Ensure Connected App has all three required OAuth scopes
- Check user has API access enabled in Salesforce
- Verify profile permissions for object access
- If browser doesn't open: manually visit
Security Features
- PKCE (RFC 7636): Protection against authorization code interception
- AES-256-GCM Encryption: Secure local token storage
- State Parameter: CSRF protection
- Automatic Token Refresh: Seamless re-authentication
๐ Available Tools
โ Currently Implemented
describe_object
Get comprehensive metadata and schema information for any Salesforce object.
Input:
{
"objectName": "Account"
}
Returns:
- Object properties (name, label, key prefix, permissions)
- Complete field metadata (types, lengths, constraints, relationships)
- Field-level permissions and editability
- Record type information
- Standard vs custom object classification
Example Usage:
Can you describe the Account object structure?
Which fields are required when creating a new Contact?
What are the field types and constraints for the Opportunity object?
list_objects
List all available Salesforce objects with filtering and pagination support.
Input:
{
"objectType": "all", // "all", "standard", or "custom"
"limit": 100 // 1-500, default 100
}
Returns:
- Object names and labels
- Standard vs custom classification
- Paginated results with count information
- Filterable by object type
Example Usage:
What objects are available in this Salesforce org?
Show me all custom objects
List the first 50 standard objects
soql_query
Execute SOQL queries with comprehensive security validation and pagination support.
Input:
{
"query": "SELECT Id, Name FROM Account WHERE Type = 'Customer' LIMIT 10",
"limit": 200 // Optional: 1-2000, default 200
}
Features:
- Security: SOQL injection prevention with dangerous pattern detection
- Pagination: Configurable record limits (1-2000)
- Validation: Query syntax and structure validation
- Clean Output: Removes Salesforce metadata for readability
Example Usage:
Show me all Accounts where Type is 'Customer'
Query the last 5 Opportunities created this month
Find all Contacts with email addresses containing '@salesforce.com'
get_record
Retrieve specific Salesforce records by ID with optional field selection.
Input:
{
"objectName": "Account",
"recordId": "001000000001AAA",
"fields": ["Id", "Name", "Type", "CreatedDate"] // Optional
}
Features:
- ID Validation: Salesforce ID format validation (15 or 18 characters)
- Field Selection: Specify fields to retrieve (optional)
- Relationship Support: Handles relationship fields and nested objects
- Clean Formatting: Readable output with proper field organization
Example Usage:
Get the Account record with ID 001000000001AAA
Show me the Contact record 003000000001BBB with just Name and Email fields
Retrieve the full details for Opportunity 006000000001CCC
๐ง Planned Tools
The following tools are planned for future implementation:
Advanced Query Tools
search
: Perform SOSL searches across multiple objects
Discovery Tools
get_picklist_values
: Get picklist values for specified fields
Utility Tools
get_limits
: Retrieve org limits and usage statisticsget_user_info
: Get current user information
๐ Resources
MCP resources are planned for future implementation to expose Salesforce data:
- Objects:
salesforce://object/{objectType}
- Object metadata and schema - Records:
salesforce://record/{objectType}/{recordId}
- Individual record data - Reports:
salesforce://report/{reportId}
- Report definitions and results
Currently, all functionality is available through the tools interface.
๐งช Development
Setup
git clone https://github.com/your-org/salesforce-mcp-server.git
cd salesforce-mcp-server
npm install
Available Scripts
npm run dev # Start development server with auto-reload
npm run build # Build for production
npm run test # Run unit tests (335 tests)
npm run test:functional # Run functional E2E validation (12 tools)
npm run test:integration # Run integration tests
npm run test:all # Run all tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Generate coverage report
npm run type-check # Run TypeScript type checking
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint issues
npm run format # Format code with Prettier
npm run ci # Run full CI pipeline (includes functional tests)
Project Structure
src/
โโโ config.ts # Configuration management
โโโ errors.ts # Error handling and types
โโโ types.ts # TypeScript type definitions
โโโ tools.ts # MCP tool implementations
โโโ salesforce-client.ts # Salesforce API client
โโโ server.ts # Main MCP server implementation
โโโ stdio-server.ts # stdio transport server
โโโ http-server.ts # HTTP transport server
โโโ index.ts # Entry point
src/test/
โโโ setup.ts # Test environment setup
โโโ integration/ # Integration test files
๐งช Testing
Running Tests
# Run unit tests (335 tests)
npm test
# Run functional tests (all 12 tools validation)
npm run test:functional
# Run integration tests (with real Salesforce API)
npm run test:integration
# Run all tests with coverage
npm run test:coverage
# Run specific test file
npm test config.test.ts
# Run tests in watch mode
npm run test:watch
# Run complete CI pipeline
npm run ci
Test Environment
- Framework: Vitest for unit and integration tests
- Functional Testing: tsx-based E2E tool validation (75% success rate)
- Coverage: v8 coverage provider with 80%+ coverage
- Test Count: 335 unit tests + 12 functional tool validations
- Speed: Sub-second execution for functional tests
Functional Testing
The functional test suite validates all 12 MCP tools with realistic scenarios:
npm run test:functional
Test Results:
- โ 9/12 tools working (75% success rate)
- 4ms total execution time
- Validates both JSON and human-readable responses
- No external dependencies required
Working Tools:
- describe_object, list_objects, soql_query
- get_record, sosl_search, get_recent_items
- validate_soql, describe_layout, get_picklist_values
This provides rapid feedback during development and CI/CD integration.
Manual Testing
Test the server with Claude Desktop:
- Set up
.env
file with real Salesforce credentials - Configure Claude Desktop with the server
- Use natural language to test tools:
Can you describe the Account object in Salesforce? What fields are available on the Contact object?
๐ค Contributing
We welcome contributions! Please see our for details.
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes following our coding standards
- Add tests for new functionality
- Ensure all tests pass (
npm run ci
) - Commit with conventional commit format
- Push to your branch
- Open a Pull Request
Code Quality
- TypeScript strict mode enabled
- ESLint with TypeScript rules
- Prettier for code formatting
- Husky for pre-commit hooks
- Conventional commits required
๐ Status
Current Version: 0.6.0 (Development)
Phase 3: Core MCP Tools (โ COMPLETE)
- โ OAuth2 PKCE browser authentication flow
- โ Encrypted token storage with AES-256-GCM
- โ Automatic token refresh handling
- โ Claude Desktop integration via stdio transport
- โ
describe_object
tool implementation - โ
list_objects
tool with filtering and pagination - โ
soql_query
tool with injection prevention and pagination - โ
get_record
tool with field selection and relationship support - โ 175 tests passing, 80%+ coverage
- โ Production validated with real Salesforce data
Next Phase: MCP Resources and advanced features (Phase 4)
See for detailed roadmap.
๐ License
This project is licensed under the BSL License - see the file for details.
๐ Support
- ๐ Issue Tracker
๐ Acknowledgments
- Model Context Protocol for the MCP specification
- jsforce for Salesforce API integration
- Salesforce for their comprehensive APIs
Made with โค๏ธ + AI by realfast
Copyright (C) 2025 Ontic Pte. Ltd.