Salesforce MCP Server

Salesforce MCP Server

Enables AI assistants to interact with Salesforce CRM by executing SOQL queries and performing CRUD operations on records such as Leads. It supports secure OAuth 2.0 authentication and provides management for both standard and custom Salesforce fields.

Category
访问服务器

README

Salesforce MCP Server

A Model Context Protocol (MCP) server that provides tools for interacting with Salesforce CRM through its REST API. This server enables AI assistants to query data using SOQL and perform CRUD operations on Salesforce objects like Leads.

Features

  • SOQL Query Execution: Run Salesforce Object Query Language (SOQL) queries to fetch data from your Salesforce org
  • Lead Management: Complete CRUD operations (Create, Read, Update, Delete) for Salesforce Lead objects
  • OAuth Authentication: Secure authentication using OAuth 2.0 password grant flow
  • Custom Field Support: Handle both standard and custom Salesforce fields

Prerequisites

  • Python >= 3.14
  • Salesforce account with API access
  • OAuth credentials (Client ID and Client Secret)

Installation

  1. Clone the repository:
git clone <repository-url>
cd salesforceMCP
  1. Install dependencies using uv (recommended) or pip:
uv sync
  1. Create a .env file in the root directory with your Salesforce credentials:
URL=your-instance.my.salesforce.com
CLIENT_ID=your_client_id
CLIENT_SECRET=your_client_secret
USERNAME=your_username
PASSWORD=your_password

Configuration

To use this MCP server with Claude Desktop or Cursor, you need to configure it in your MCP settings file.

Claude Desktop

Add the following to your Claude Desktop configuration file:

  • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "salesforce": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/salesforceMCP",
        "run",
        "main.py"
      ],
      "env": {
        "URL": "your-instance.my.salesforce.com",
        "CLIENT_ID": "your_client_id",
        "CLIENT_SECRET": "your_client_secret",
        "USERNAME": "your_username",
        "PASSWORD": "your_password"
      }
    }
  }
}

Cursor

Add the following to your Cursor MCP settings file (~/.cursor/mcp.json or similar):

{
  "mcpServers": {
    "salesforce": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/salesforceMCP",
        "run",
        "main.py"
      ],
      "env": {
        "URL": "your-instance.my.salesforce.com",
        "CLIENT_ID": "your_client_id",
        "CLIENT_SECRET": "your_client_secret",
        "USERNAME": "your_username",
        "PASSWORD": "your_password"
      }
    }
  }
}

Important: Replace /absolute/path/to/salesforceMCP with the actual absolute path to your project directory, and fill in your Salesforce credentials.

After adding the configuration, restart Claude Desktop or Cursor for the changes to take effect.

Available Tools

1. run_soql

Execute SOQL queries to fetch data from Salesforce.

Parameters:

  • query (str): The SOQL query to execute

Example:

query = "SELECT Id, Name, Email FROM Lead WHERE Status = 'Open' LIMIT 10"

Note: Custom objects and fields in Salesforce end with __c

2. run_lead_operation

Perform CRUD operations on Salesforce Lead objects.

Operations:

  • create: Create a new Lead (requires LastName and Company)
  • update: Update an existing Lead (requires lead_id)
  • delete: Delete a Lead (requires lead_id)
  • get: Fetch a Lead by ID (requires lead_id)

Standard Fields:

  • lead_id: Salesforce Lead ID (required for update, delete, get)
  • last_name: Lead's last name (required for create)
  • company: Lead's company (required for create)
  • first_name: Lead's first name
  • salutation: Salutation (e.g., 'Mr.', 'Ms.', 'Dr.')
  • title: Job title
  • email: Email address
  • phone: Phone number
  • mobile_phone: Mobile phone number
  • fax: Fax number
  • website: Website URL
  • lead_source: Lead source (e.g., 'Web', 'Phone Inquiry')
  • status: Lead status (e.g., 'Open', 'Contacted', 'Qualified')
  • rating: Lead rating (e.g., 'Hot', 'Warm', 'Cold')
  • industry: Industry
  • annual_revenue: Annual revenue (float)
  • number_of_employees: Number of employees (int)
  • street: Street address
  • city: City
  • state: State/Province
  • postal_code: Postal/ZIP code
  • country: Country
  • description: Notes about the lead
  • owner_id: Salesforce User ID of lead owner
  • is_converted: Whether the lead has been converted (bool)
  • custom_fields: Dictionary of custom fields (e.g., {"My_Field__c": "value"})

Project Structure

salesforceMCP/
├── main.py                          # Entry point for the MCP server
├── src/
│   └── salesforce_mcp/
│       ├── objects/                 # Salesforce object implementations
│       │   ├── SFObject.py         # Base object class
│       │   └── LeadObject.py       # Lead object operations
│       ├── services/                # Core services
│       │   └── SalesforceSession.py # Session and authentication handling
│       ├── types/                   # Type definitions
│       │   ├── SFRecord.py         # Base record type
│       │   └── LeadRecord.py       # Lead record type
│       └── utils/                   # Utility modules
│           ├── soql.py             # SOQL query execution
│           ├── credentials.py       # Credential management
│           └── dataClassMapper.py  # Data class mapping utilities
├── tests/                           # Test files
├── pyproject.toml                   # Project configuration
└── .env                            # Environment variables (not in repo)

Development

Running Tests

pytest

Test Coverage

pytest --cov=src --cov-report=html

Authentication

This server uses OAuth 2.0 password grant flow for authentication. Each request to Salesforce will:

  1. Authenticate using the credentials from your .env file
  2. Obtain an access token
  3. Use the token for API requests

Error Handling

The server includes comprehensive error logging. Errors are logged to stderr with timestamps and severity levels.

Dependencies

  • fastmcp>=2.14.1 - FastMCP framework for building MCP servers
  • mcp[cli]>=1.25.0 - Model Context Protocol implementation
  • requests>=2.32.5 - HTTP library for API requests
  • pytest>=9.0.2 - Testing framework
  • pytest-cov>=7.0.0 - Test coverage plugin
  • pytest-mock>=3.15.1 - Mocking plugin for pytest

Security Notes

  • Never commit your .env file to version control
  • Keep your OAuth credentials secure
  • Use environment variables for sensitive configuration
  • Validate domain names before making requests

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选