Agentforce (Salesforce) MCP server

Provides a bridge to Salesforce's Agentforce API, enabling authentication, session management, and message exchange with Salesforce agents for accessing customer data and domain-specific knowledge.
Back to servers
Provider
Xavier Lengelle
Release date
Apr 09, 2025
Language
Python
Stats
8 stars

The Agentforce MCP Server enables interaction with the Salesforce Agentforce API, allowing you to authenticate, create sessions, and exchange messages with Salesforce agents through a Model Context Protocol interface.

Installation

Prerequisites

  • Python 3.10 or higher
  • Salesforce organization with Agentforce configured

Quick Setup

The easiest way to get started is using the interactive setup script:

chmod +x setup.sh
./setup.sh

This script will check your Python version, install dependencies, guide you through credential setup, test your connection, and offer to start the server.

Manual Setup

  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Create environment file:

    cp .env.example .env
    
  3. Edit the .env file with your Salesforce credentials:

    SALESFORCE_ORG_ID="your_org_id_here"
    SALESFORCE_AGENT_ID="your_agent_id_here"
    SALESFORCE_CLIENT_ID="your_client_id_here"
    SALESFORCE_CLIENT_SECRET="your_client_secret_here"
    SALESFORCE_SERVER_URL="example.my.salesforce.com"
    
  4. Make the server script executable:

    chmod +x agentforce_mcp_server.py
    

Running the Server

Start the MCP server with:

python agentforce_mcp_server.py

Collecting Salesforce Credentials

Finding Your Org ID

  1. Log in to Salesforce as an administrator
  2. Go to Setup
  3. Search for "Company Information"
  4. Look for the "Organization ID" field - an 18-character alphanumeric string

Creating a Connected App

  1. In Salesforce Setup, search for "App Manager"
  2. Click New Connected App
  3. Fill in the basics:
    • Name: "Agentforce MCP Integration" (or your preferred name)
    • Contact Email: Your email
  4. Enable OAuth Settings:
    • Check Enable OAuth Settings
    • Set Callback URL to https://localhost/oauth/callback
    • Add OAuth Scopes: "Manage user data via APIs (api)" and "Perform requests at any time (refresh_token, offline_access)"
  5. Save and note the Consumer Key and Consumer Secret

Finding Your Agent ID

  1. Navigate to Einstein Agent Builder in Salesforce
  2. Select your agent
  3. Look at the URL: https://your-salesforce-instance.lightning.force.com/lightning/r/Agent__c/0XxXXXXXXXXXXXXX/view
  4. Your Agent ID is the 18-character string in the URL

Getting Your My Domain URL

  1. In Salesforce Setup, search for "My Domain"
  2. Note your domain in the format DOMAIN-NAME.my.salesforce.com
  3. Use this URL without the "https://" prefix

Configuring Claude Desktop

Update your Claude Desktop configuration file to use this MCP server:

{
  "mcpServers": {
    "agentforce": {
      "command": "python",
      "args": [
        "/path/to/your/agentforce_mcp_server.py"
      ]
    }
  }
}

Configuration File Locations

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

Available Tools

The server provides the following tools:

authenticate

Authenticates with the Agentforce API.

  • Parameter: client_email - Email for authentication

create_agent_session

Creates a session with the configured agent.

  • Parameter: client_email - Email of the authenticated client

send_message_to_agent

Sends a message to the agent and returns the response.

  • Parameters:
    • client_email - Email of the authenticated client
    • message - Message to send to the agent

get_session_status

Gets the status of the current session.

  • Parameter: client_email - Email of the authenticated client

complete_agentforce_conversation

Handles the entire workflow in one call.

  • Parameters:
    • client_email - Email for authentication
    • user_query - Message to send to the agent

Troubleshooting

If you encounter issues:

  • Authentication failures: Verify your Connected App settings and credentials
  • Session creation errors: Double-check your Agent ID (ensure it's 18 characters)
  • Connection issues: Verify your Salesforce My Domain URL is correct
  • Permission errors: Ensure your Connected App has the proper OAuth scopes

To test your setup, run:

python test_agentforce.py

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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