Claude Skills Guide

Salesforce MCP Server Data Integration Guide

The Model Context Protocol (MCP) provides a standardized way to connect Claude Code with external data sources, and Salesforce integration is one of the most powerful use cases for enterprise workflows. This guide walks you through setting up a Salesforce MCP server, configuring authentication, and building practical data integration pipelines that sync records, automate data entry, and query complex relationships.

Setting Up Your Salesforce MCP Server

Before you can integrate Salesforce with Claude Code, you need an MCP server that speaks the Salesforce API. The most common approach uses the salesforce-mcp package, which wraps the Salesforce REST API and Bulk API into MCP-compliant tools.

First, install the required dependencies:

npm install -g @modelcontextprotocol/server-salesforce

Configure your MCP settings in ~/.claude/mcp-servers.json:

{
  "mcpServers": {
    "salesforce": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-salesforce"],
      "env": {
        "SF_LOGIN_URL": "https://login.salesforce.com",
        "SF_CLIENT_ID": "your_connected_app_client_id",
        "SF_CLIENT_SECRET": "your_connected_app_client_secret",
        "SF_USERNAME": "your_salesforce_username",
        "SF_PASSWORD": "your_salesforce_password",
        "SF_SECURITY_TOKEN": "your_security_token"
      }
    }
  }
}

This configuration uses a Connected App in Salesforce, which is the recommended authentication method for production integrations. Create a Connected App in Salesforce Setup, enable OAuth Settings, and select the appropriate scopes for your use case.

Querying Salesforce Data

Once your MCP server is running, you can query Salesforce objects directly from Claude Code. The server exposes standard CRUD operations mapped to MCP tools.

To fetch a list of accounts with specific fields:

Use the salesforce_query tool to retrieve all accounts where Industry equals 'Technology'. Return the Id, Name, AnnualRevenue, and NumberOfEmployees fields.

The MCP server translates this into a SOQL query and returns structured results. For more complex queries involving relationships, you can chain multiple queries or use the raw SOQL execution tool:

Execute this SOQL query: SELECT Id, Name, Account.Name, Contact.Email FROM Opportunity WHERE StageName = 'Closed Won' AND CloseDate = THIS_YEAR

This approach works well for reporting and data analysis tasks. If you’re building a dashboard, combine the results with the frontend-design skill to create visualization components that display Salesforce metrics in your application.

Syncing Data Between Systems

One of the most common integration patterns involves bidirectional sync between Salesforce and other systems. Here’s a practical workflow for keeping a custom PostgreSQL database in sync with Salesforce contacts:

# sync_contacts.py - called by Claude Code via Bash tool
import psycopg2
from simple_salesforce import Salesforce
import os

sf = Salesforce(
    username=os.environ['SF_USERNAME'],
    password=os.environ['SF_PASSWORD'],
    security_token=os.environ['SF_SECURITY_TOKEN']
)
postgres_client = psycopg2.connect(os.environ['DATABASE_URL'])

def sync_contacts(last_sync_time):
    # Fetch modified contacts from Salesforce
    soql = f"""
        SELECT Id, FirstName, LastName, Email, Phone,
               LastModifiedDate FROM Contact
        WHERE LastModifiedDate > {last_sync_time}
    """
    sf_contacts = sf.query(soql)['records']

    # Upsert into local database
    for contact in sf_contacts:
        upsert_contact(postgres_client, contact)

    # Update sync checkpoint
    update_sync_time(postgres_client, get_current_time())

This pattern scales well for millions of records when you switch to the Bulk API for batch processing. The MCP server handles rate limiting and retry logic automatically, but you should implement your own checkpoint system to handle failures gracefully.

Automating Data Entry

Beyond querying, you can use the MCP server to create and update Salesforce records programmatically. This is useful for automating data entry from external sources like web forms, email imports, or IoT devices.

For example, when a new lead comes through your web application:

Use salesforce_create to add a new Lead object with the following fields: FirstName from form_first_name, LastName from form_last_name, Company from form_company, Email from form_email, LeadSource from 'Web Form'. Then use salesforce_update to set the Status to 'Open - Not Contacted'.

You can wrap these operations in a skill for repeated use. Create a custom skill file that encapsulates your lead creation workflow:

# Skill: salesforce-lead-creator

## Instructions
When a user provides lead information, use the salesforce_create tool to create a new Lead object. Map the input fields: first_name → FirstName, last_name → LastName, company → Company, email → Email. Set LeadSource to 'Web Form' and Status to 'Open - Not Contacted'. After creation, confirm the Lead ID and provide a link to the Salesforce record.

Save this as ~/.claude/skills/salesforce-lead-creator.md and invoke it with /salesforce-lead-creator in your Claude session.

Handling Complex Data Transformations

For ETL-style workflows involving data transformation, combine the Salesforce MCP server with Claude Code’s built-in skills. The tdd skill helps you write test cases for your transformation logic before implementing the pipeline:

Use /tdd to create test cases for a contact deduplication function. The function should accept a list of contacts with potential duplicates (matching on Email or Phone), merge their fields preferring non-null values, and return a deduplicated list.

After the skill generates your tests, implement the deduplication logic and verify all tests pass. This approach ensures your data pipeline handles edge cases like null values, conflicting data, and large datasets correctly.

For document generation based on Salesforce data, pair the pdf skill with your integration. Query opportunity details, then use the PDF skill to generate customized proposals or contracts:

Query the Opportunity and Account data for opp_id '0065e000002ABC', then use the pdf skill to generate a proposal document using the template 'proposal-v2.html'.

Best Practices for Production Integrations

When deploying Salesforce MCP integrations to production, consider these recommendations:

Security First: Never store credentials in configuration files. Use environment variables or a secrets manager. Rotate API keys and security tokens regularly. The supermemory skill can help you track which systems have access to which credentials without exposing sensitive data.

Rate Limiting: Salesforce API calls are subject to rate limits. The MCP server implements exponential backoff, but you should monitor your API usage in Salesforce Setup → API Usage. For high-volume integrations, request a higher API limit from Salesforce support.

Error Handling: Implement comprehensive error handling that logs failures, sends alerts, and supports manual retry. The MCP server returns detailed error messages that help you identify whether failures are due to validation errors, permission issues, or network problems.

Testing: Use Salesforce Sandboxes for all development and testing. The tdd skill integrates well with sandbox environments where you can create test data without affecting production.

Conclusion

Salesforce MCP server integration opens up powerful automation possibilities for developers building enterprise workflows. From simple query operations to complex multi-system syncs, the MCP approach provides a consistent, AI-friendly interface to your Salesforce data. Start with basic queries, then layer in automation and transformation logic as your integration matures. For patterns on combining MCP servers with skill workflows, see building stateful agents with Claude skills.

Built by theluckystrike — More at zovo.one