使用说明
🚀 Salesforce MCP服务器
用于Salesforce开发的完整模型上下文协议(MCP)服务器 部署元数据、运行SOQL、管理多个组织以及自动化一切——所有这些都可以通过Claude Desktop完成。
由Sameer创建 | 报告问题
✨ 这是什么?
将克劳德桌面转换为 强大的Salesforce集成开发环境 使用元数据管理、测试、多组织操作等优化工具。没有手动API调用,没有上下文切换,只有自然语言命令。
v2.0: 工具整合减少了106个工具→ 57 工具(减少46%)可提高LLM性能!
v2.1: 添加了全面的调试工具-诊断和修复任何Salesforce缺陷!
v2.2: 添加 analyze_field_usage -通过CSV导出对所有元数据进行全面的字段使用分析!
v2.3: API-only身份验证-Claude Desktop可靠的用户名/密码登录!
v2.4: 添加 compare_page_layouts -使用完整的CSV差异报告比较组织之间的页面布局!
v2.5: 安全强化-所有工具的SOQL注入保护,实现批量升级,线程本地连接缓存过时修复!
v2.6: 增强 compare_profiles 和 compare_permission_sets -现在涵盖了对象、字段、选项卡、应用程序、Apex/VF页面和具有完整分页的系统权限!
主要特点
- 🔐 基于API的身份验证 -可靠的用户名/密码登录,在Claude Desktop中完美运行
- 🛠️ 57优化工具 -采用LLM友好型设计,全面覆盖Salesforce API
- 🔒 SOQL注入保护 -所有用户输入都通过以下方式逃逸
escape_soql_string()贯穿 - 🎯 智能基础设施 -缓存、连接池、分页和增强的错误处理
- 🔍 现场使用分析 -使用CSV导出分析所有元数据中使用500多个字段的位置
- 🐛 智能调试 -诊断并修复触发器、流、验证、字段、权限等
- 🌐 多组织管理 -同时与多个组织合作并比较元数据
- 📦 批量操作 -使用批量API 2.0处理数千条记录(插入/更新/删除/追加)
- 🧪 Apex测试 -运行测试、获取覆盖率、使用完整日志进行调试
- 🔍 模式分析 -分析依赖关系,查找未使用的字段,生成ERD
- 📊 健康监测 -检查组织限制、API使用情况和系统运行状况
- 🚦 生产就绪 -重试逻辑、输入验证、结构化日志记录
🎯 快速开始
先决条件
⚡ 快速身份验证(克劳德桌面版)
推荐: 使用用户名/密码身份验证(对MCP服务器最可靠)
Step 1: Get domain from your org URL
Use salesforce_get_domain_from_url with: https://your-org.salesforce.com
Step 2: Login
Use salesforce_login_username_password with:
- username: your.email@company.com
- password: YourPassword
- security_token: [Get from Salesforce Settings → Reset Security Token]
- domain: [from step 1]
Step 3: Start using tools!
Use soql_query to run: SELECT Id, Name FROM Account LIMIT 10
安装
Windows(推荐-一键安装)
# Clone repository
git clone https://github.com/AethereusSF/SF-MCP-Server
cd SF-MCP-Server
# Run setup script (creates venv, installs dependencies, tests installation)
.\setup.bat
就是这样! setup.bat 自动处理一切-创建虚拟环境,安装所有依赖项,并验证安装。
macOS/Linux(推荐-一键设置)
# Clone repository
git clone https://github.com/AethereusSF/SF-MCP-Server
cd SF-MCP-Server
# Make scripts executable
chmod +x setup.sh start_mcp.sh start_http.sh
# Run setup script (creates venv, installs dependencies, tests installation)
./setup.sh
配置Claude桌面
视窗
编辑 %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"salesforce-mcp-server": {
"command": "C:\\path\\to\\Salesforce-MCP-Server\\start_mcp.bat"
}
}
}
macOS/Linux
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"salesforce-mcp-server": {
"command": "/bin/bash",
"args": [
"-c",
"cd '/absolute/path/to/Salesforce-MCP-Server' && venv/bin/python -m app.main --mcp-stdio"
]
}
}
}
重要提示: 替换 /absolute/path/to/Salesforce-MCP-Server 用你真正的绝对路径!
首先使用
- 重新启动克劳德桌面
- 登录: 类型
"Login to Salesforce production"在新的克劳德聊天中 - 身份验证: 浏览器窗口打开→ 登录→ 允许访问
- 开始使用: 尝试
"Check my Salesforce org health"
🛠️ 工具类别(共57个)
⭐ 整合工具(核心运营)
取代许多专用工具的通用工具:
deploy_metadata-使用单个工具部署任何元数据类型(Apex、LWC、Fields等)fetch_metadata-获取具有一致接口的任何元数据类型list_metadata-使用通配符筛选列出任何类型的元数据bulk_operation-统一批量插入/更新/删除/ 更新插入 通过批量API 2.0export_data-以CSV、JSON或备份格式导出数据soql_query-使用可选分析构建和执行SOQL查询get_object_metadata-在一次调用中获取字段、关系和元数据manage_user_permissions-管理配置文件和权限集(set_profile/assign_permset/remove_permset/list)
🐛 调试与缺陷解决(1)
diagnose_and_fix_issue-对触发器、流、验证、字段、权限、公式、选择列表、查找、布局和报告进行全面调试
由26个真实世界的QA场景模式提供支持:
- 触发递归和SOQL限制问题
- 流空处理和决策逻辑
- 验证规则日期/必填字段错误
- 现场级安全和权限问题
- 公式字段计算和参考
- 页面布局分配问题
- 报告字段可见性问题
- 断开的查找关系
🔐 身份验证和会话(7)
salesforce_production_login-OAuth到生产组织salesforce_sandbox_login-OAuth到沙盒(test.sealesforce.com)salesforce_custom_login-OAuth到自定义域salesforce_login_username_password-使用用户名/密码/令牌登录 (推荐)salesforce_logout-清除所有会话salesforce_auth_status-检查身份验证状态salesforce_get_domain_from_url-从任何Salesforce URL中提取域参数
🌐 多组织管理(5)
list_connected_orgs-列出所有已连接的组织switch_active_org-在组织之间切换compare_metadata_between_orgs-比较不同组织的Apex、Flows等compare_object_schemas-跨组织比较字段模式get_org_differences_summary-高层组织比较
📝 元数据操作(3个统一工具)
一个工具可以处理所有16种元数据类型:
| 工具 | 支持的类型 |
|---|---|
deploy_metadata |
ApexClass、ApexTrigger、LWC、AuraComponent、CustomObject、CustomField、Flow、EmailTemplate、PermissionSet、StaticResource、CustomMetadataType、CustomLabel、RecordType、QuickAction、CustomTab (验证规则--仅手动) |
fetch_metadata |
以上16种类型 |
list_metadata |
ApexClass、ApexTrigger、自定义对象、流、权限集、静态资源 |
🧪 Apex测试与调试(3)
run_apex_tests-运行覆盖率测试get_apex_test_coverage-获取代码覆盖率详细信息list_apex_test_classes-列出所有测试类
📦 批量操作
bulk_operation-插入/更新/删除/ 更新插入 (批量API 2.0,与轮询完全异步)get_bulk_job_status-检查作业进度
💾 数据导出和备份(3)
export_data-导出为CSV/JSON/带时间戳的备份get_record_count-使用可选的WHERE过滤器快速计数记录export_schema_to_json-将对象模式导出为JSON
🔍 SOQL和查询助手(2)
soql_query-执行或自动构建SOQL;可选查询分析query_with_related_records-在一次通话中查询父+子记录
📊 模式分析(7)
analyze_object_dependencies-完全依赖性分析(查找、触发器、流、VR)find_unused_fields-识别没有Apex/触发器引用的字段generate_object_diagram-生成ERD数据export_object_relationships-出口关系图extract_metadata_relationships-交叉元数据关系分析analyze_field_usage-在CSV导出的所有元数据中使用字段compare_field_presence-比较对象之间的字段存在情况
🤖 过程自动化(8)
list_batch_jobs-列出批处理Apex作业get_batch_job_details-获取详细的工作信息list_scheduled_jobs-列出计划的Apexabort_batch_job-停止运行批处理delete_scheduled_job-删除计划作业execute_anonymous_apex-立即执行Apexget_debug_logs-检索调试日志get_debug_log_body-获取完整日志内容
🏥 组织健康与限制(6)
salesforce_health_check-全面健康检查get_org_limits-API/存储限制get_org_info-组织详细信息get_current_user_info-当前用户配置文件list_installed_packages-列出托管包get_api_usage_stats-API使用情况统计
🎯 核心业务(2)
execute_soql_query-低级SOQL执行get_metadata_deploy_status-检查部署状态
👥 用户管理(支持功能)
通过暴露 manage_user_permissions 整合工具:
- set_profile、assign_permset、remove_permset和列表
list_available_profiles-列出组织中的所有配置文件list_available_permission_sets-列出组织中的所有权限集
🔄 高级比较工具(6)
compare_profiles- 完整比较:对象、字段、选项卡、应用程序、Apex/VF页面和系统权限;sections目标查询的参数compare_permission_sets- 完整比较:覆盖范围与个人资料相同,完全分页(无限制上限);sections参数compare_object_field_counts-比较组织之间的字段计数/类型find_similar_fields_across_objects-查找具有相似名称/类型的字段compare_org_object_counts-比较组织之间的对象总数compare_page_layouts-比较组织之间的页面布局——字段、部分、相关列表与CSV导出不同
📄 文档工具(4)
generate_brd_document-生成业务需求文档generate_design_document-生成技术设计文档generate_test_document-生成测试计划文档generate_sf_object_documentation-生成对象文档
📚 用法示例
基本操作
# Authentication
"Login to Salesforce production"
"Login to Salesforce sandbox"
"Check my login status"
# Health Check
"Check my Salesforce org health"
"Show me my API limits"
# Run Query
"Run SOQL: SELECT Id, Name FROM Account WHERE Industry = 'Technology' LIMIT 10"
# Get Information
"Show me all custom fields on the Account object"
"List all Apex classes in the org"
元数据管理
# Create Apex Class
"Create an Apex class called AccountService with this code:
public class AccountService {
public static List<Account> getHighValueAccounts() {
return [SELECT Id, Name, AnnualRevenue FROM Account WHERE AnnualRevenue > 1000000];
}
}"
# Create Custom Field
"Create a text field called Customer_Code__c on Account with length 50"
# Create Validation Rule
"Create a validation rule on Opportunity that requires Amount when Stage is Closed Won"
# Deploy LWC Component
"Create an LWC component called accountCard"
测试与调试
# Run Tests
"Run all Apex tests and show me the code coverage"
"Run tests from AccountServiceTest class"
"Show me code coverage for AccountService"
# Debug
"Get my last 10 debug logs"
"Show me the full log for 07L4x000000AbcD"
"Execute this Apex: System.debug('Test message');"
多组织运营
# Connect Multiple Orgs
"Login to Salesforce production"
"Login to Salesforce sandbox"
# List & Switch
"List all my connected orgs"
"Switch to org 00D4x000000XyzE"
# Compare
"Compare Apex classes between production and sandbox"
"Compare Account schema between the two orgs"
"Get differences summary between my orgs"
批量操作
# Bulk Insert
"Bulk insert these Account records: [...]"
# Bulk Upsert (NEW - uses external ID field)
"Bulk upsert Contacts using Email__c as the external ID: [...]"
# Check Status
"Check status of bulk job 7504x000000AbcD"
数据导出
# Export to CSV
"Export all Opportunities from Q4 2024 to CSV"
# Backup
"Backup all Account records"
# Count Records
"How many Leads were created today?"
# Export Schema
"Export Account, Contact, and Opportunity schemas to JSON"
高级比较(v2.6)
# Full profile comparison (all sections)
"Compare System Administrator and Standard User profiles"
# Targeted comparison (faster)
"Compare object and field permissions between Sales User and Service User"
→ compare_profiles("Sales User", "Service User", sections="objects,fields")
# Permission set comparison
"Compare Marketing_Admin and Marketing_User permission sets"
# Cross-org profile comparison
"Compare System Administrator profile between production and sandbox"
→ compare_profiles("System Administrator", "System Administrator", org2_user_id="005xx...", sections="all")
# Compare object fields across orgs
"Compare Account object fields between my two connected orgs"
# Compare page layouts
"Compare Account page layout between production and sandbox"
→ compare_page_layouts(
layout_names="Account-Account Layout",
source_org_user_id="005xx...",
target_org_user_id="005yy..."
)
现场使用分析
# Analyze single field
"Where is the Case Status field used?"
# Analyze ALL fields on an object
"Analyze all Case fields and create a CSV report"
# Include reports
"Analyze Account.Customer_Type__c including reports"
# Custom output filename
"Analyze Opportunity fields and save to opp_field_audit.csv"
🎓 高级功能
🔄 高级配置文件和权限集比较(v2.6)
两者 compare_profiles 和 compare_permission_sets 现在提供 全面覆盖 在所有权限维度上:
| 第节 | 它检查什么 |
|---|---|
objects |
CRUD+查看全部+按对象修改全部 |
fields |
按字段读取+编辑(完全分页,无大写) |
tabs |
选项卡可见性(默认打开/默认关闭/隐藏) |
apps |
Apex类、VF页面、自定义权限访问 |
system |
所有~150个布尔用户权限(PermissionsApiEnabled、PermissionModifyAllData等) |
使用 sections 参数仅运行所需的检查:
# Only object + field permissions (fast)
compare_profiles("Admin", "Standard", sections="objects,fields")
# Only system permissions
compare_profiles("Admin", "Standard", sections="system")
# Everything (default)
compare_profiles("Admin", "Standard")
🔍 现场使用分析
这 analyze_field_usage 该工具提供全面的现场使用分析。非常适合现场审计、清理项目和影响分析。
检查以下方面的使用情况:Apex类、Apex触发器、流、验证规则、公式字段、工作流规则、页面布局、电子邮件模板、报告(可选)。
CSV输出保存到 Documents/{ObjectName}_field_usage_{timestamp}.csv.
配置
创建一个 .env 文件(复制自 .env.example):
# Server Configuration
SFMCP_MCP_SERVER_NAME=salesforce-mcp-server
SFMCP_LOG_LEVEL=INFO
SFMCP_DEBUG_MODE=false
# OAuth Configuration
SFMCP_OAUTH_CALLBACK_PORT=1717
SFMCP_OAUTH_TIMEOUT_SECONDS=300
# API Configuration
SFMCP_SALESFORCE_API_VERSION=62.0
SFMCP_MAX_RETRIES=3
SFMCP_REQUEST_TIMEOUT_SECONDS=120
# Deployment
SFMCP_DEPLOY_TIMEOUT_SECONDS=300
SFMCP_DEPLOY_POLL_INTERVAL_SECONDS=5
# HTTP/SSE mode (optional)
SFMCP_HTTP_HOST=0.0.0.0
SFMCP_HTTP_PORT=8000
SFMCP_API_KEY=change-this-before-deploying
📁 项目结构
SF-MCP-Server/
├── app/
│ ├── main.py # Entry point, tool imports
│ ├── config.py # Configuration management
│ │
│ ├── mcp/
│ │ ├── server.py # MCP server setup, tool registration
│ │ └── tools/ # All MCP tools
│ │ ├── consolidated_metadata.py # Unified deploy/fetch/list
│ │ ├── consolidated_operations.py # Bulk ops, export, queries, permissions
│ │ ├── oauth_auth.py # OAuth 2.0 + username/password auth
│ │ ├── debugging.py # Issue diagnosis (26 QA patterns)
│ │ ├── dynamic_tools.py # Low-level Metadata API helpers
│ │ ├── multi_org.py # Multi-org management
│ │ ├── advanced_comparison.py # Full profile/permset/schema comparison
│ │ ├── user_management.py # Backing user permission functions
│ │ ├── schema_analysis.py # Dependencies, unused fields, ERDs
│ │ ├── org_management.py # Health check, limits, org info
│ │ ├── automation.py # Batch jobs, scheduled jobs
│ │ ├── testing.py # Apex tests, coverage
│ │ ├── bulk_operations.py # Bulk API backing functions
│ │ ├── data_export.py # Export/backup backing functions
│ │ ├── query_helpers.py # Query builder backing functions
│ │ ├── documentation.py # BRD/TDD/Test document generation
│ │ ├── page_layout_comparison.py # Page layout diff tool
│ │ └── utils.py # Response formatting, error handling
│ │
│ ├── services/
│ │ └── salesforce.py # Connection management, token refresh
│ │
│ └── utils/
│ ├── validators.py # SOQL injection protection, SafeSOQLBuilder
│ ├── retry.py # Retry with exponential backoff
│ ├── logging.py # Structured logging
│ ├── cache.py # LRU caching system
│ ├── errors.py # Enhanced error handling
│ ├── pagination.py # Pagination utilities
│ └── connection_pool.py # Connection pooling
│
├── requirements.txt # Dependencies
├── .env.example # Example configuration
├── CLAUDE.md # Developer guide for Claude Code
├── README.md # This file
├── setup.bat / setup.sh # One-click setup scripts
├── start_mcp.bat / start_mcp.sh # stdio mode startup
└── start_http.bat / start_http.sh # HTTP/SSE mode startup
重试逻辑
所有API调用都会自动重试,并进行指数退避:
- 最大尝试次数:3(可通过配置
SFMCP_MAX_RETRIES) - 回退倍数:2.0
- 优雅地处理瞬态故障
安全
- SOQL注入保护 --所有用户提供的值都用
escape_soql_string()/escape_soql_like()查询插值前 - SafeSOQLBuilder 可用于程序化查询构造
- OAuth令牌 仅存储在内存中--在进程重新启动时清除
- 需要HTTPS 用于自定义域OAuth流
🔧 故障排除
“未找到活动的Salesforce会话”
先登录:
"Login to Salesforce production"
或使用用户名/密码: salesforce_login_username_password
“令牌已过期”
注销并重新登录:
"Logout from all Salesforce orgs"
"Login to Salesforce production"
“部署超时”
增加超时时间 .env:
SFMCP_DEPLOY_TIMEOUT_SECONDS=600
“超过API限制”
检查限制: "Get org limits"
“使用了错误的组织”
"List connected orgs"
"Switch to org [user_id]"
工具未在Claude中显示
- 检查Claude Desktop配置文件路径
- 验证绝对路径是否正确
- 重新启动克劳德桌面
- 检查日志:
%APPDATA%\Claude\logs\(Windows)
🤝 贡献
我们欢迎捐款!查看我们的 贡献指南 了解详情。
添加新工具
- 在相应的模块中创建工具功能
app/mcp/tools/ - 添加
@register_tool装饰器 - 写一个清晰的文档字符串——第一行是工具描述,然后
Args:部分 - 将模块导入
app/main.py - 使用以下命令返回JSON字符串
format_success_response()/format_error_response() - 始终忽略用户输入:
escape_soql_string(value)SOQL插值之前
测试要求
在提交PR之前:
- ✅ 所有现有测试必须通过
- ✅ 新工具必须包括测试场景
- ✅ 首先在沙盒环境中进行测试
- ✅ 记录任何API限值影响
⚖️ 许可证
MIT许可证-请参阅 许可证 详情
由Sameer创建 |内置于 模型上下文协议
🆘 支持
建于☕, Sameer的《代码与好奇心》
