使用说明
🚀 Salesforce MCP服务器
用于Salesforce开发的完整模型上下文协议(MCP)服务器 部署元数据、运行SOQL、管理多个组织以及自动化一切——所有这些都可以通过Claude Desktop完成。
✨ 这是什么?
将克劳德桌面转换为 强大的Salesforce集成开发环境 拥有60个用于元数据管理、测试、多组织操作等的优化工具。没有手动API调用,没有上下文切换,只有自然语言命令。
新版v2.0: 工具整合减少了106个工具→ 57 工具(减少46%)可提高LLM性能!
新v2.1: 添加了全面的调试工具-诊断和修复任何Salesforce缺陷!
新v2.2: 添加 analyze_field_usage -通过CSV导出对所有元数据进行全面的字段使用分析!
新v2.3: API-only身份验证-Claude Desktop可靠的用户名/密码登录!
主要特点
- 🔐 基于API的身份验证 -可靠的用户名/密码登录,在Claude Desktop中完美运行
- 🛠️ 60个优化工具 -采用LLM友好型设计,全面覆盖Salesforce API
- 🎯 智能基础设施 -缓存、连接池、分页和增强的错误处理
- 🔍 现场使用分析 -使用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 execute_soql_query to run: SELECT Id, Name FROM Account LIMIT 10
📖 完整的身份验证指南 -带示例的详细说明
安装
视窗
# Clone repository
git clone https://github.com/UltralegendSam-Fs/Salesforce-MCP-Server
cd Salesforce-MCP-Server
# Create virtual environment
python -m venv venv
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Test server (optional)
python -m app.main --mcp-stdio
macOS/Linux
# Clone repository
git clone https://github.com/UltralegendSam-Fs/Salesforce-MCP-Server
cd Salesforce-MCP-Server
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Test server (optional)
python -m app.main --mcp-stdio
配置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": [
"-lc",
"cd '/absolute/path/to/Salesforce-MCP-Server' && source venv/bin/activate && python -m app.main --mcp-stdio"
]
}
}
}
重要提示: 替换为您实际的绝对路径!
首先使用
- 重新启动克劳德桌面
- 登录: 类型
"Login to Salesforce production"在新的克劳德聊天中 - 身份验证: 浏览器窗口打开→ 登录→ 允许访问
- 开始使用: 尝试
"Check my Salesforce org health"
🛠️ 工具类别(共57个-针对LLM进行了优化!)
⭐ 新增:整合工具(核心运营)
通用工具可替代59种专用工具:
deploy_metadata-使用单个工具部署任何元数据类型(Apex、LWC、Fields等)fetch_metadata-获取具有一致接口的任何元数据类型list_metadata-列出任何类型的元数据并进行过滤bulk_operation-统一的批量插入/更新/删除操作export_data-以CSV、JSON或备份格式导出数据soql_query-使用可选分析构建和执行查询get_object_metadata-在一次调用中获取字段、关系和元数据manage_user_permissions-管理配置文件和权限集
优点: LLM更容易选择,更一致的API,灵活的参数
🐛 调试与缺陷解决(1)
diagnose_and_fix_issue-对触发器、流、验证、字段、权限、公式、选择列表、查找、布局和报告进行全面调试
由25个真实世界的QA场景模式提供支持:
- 触发递归和SOQL限制问题
- 流空处理和决策逻辑
- 验证规则日期/必填字段错误
- 现场级安全和权限问题
- 公式字段计算和参考
- 页面布局分配问题
- 报告字段可见性问题
- 断开的查找关系
通过智能诊断、根本原因分析和可操作的修复建议处理10多种问题类型。看 调试指南 了解完整细节。
🔐 身份验证和会话(6)
salesforce_production_login-OAuth到生产组织salesforce_sandbox_login-OAuth到沙盒(test.sealesforce.com)salesforce_custom_login-OAuth到自定义域salesforce_login_username_password-使用用户名/密码/令牌登录salesforce_logout-清除所有会话salesforce_auth_status-检查身份验证状态
🌐 多组织管理(5)
list_connected_orgs-列出所有已连接的组织switch_active_org-在组织之间切换compare_metadata_between_orgs-比较顶点、流量等。compare_object_schemas-比较字段模式get_org_differences_summary-高层组织比较
📝 元数据操作(60)
16元数据类型 ×3操作(获取、创建、追加销售):
- Apex类 -完整的CRUD操作
- 顶点触发器 -创建和管理触发器
- 验证规则 -部署验证逻辑
- LWC(闪电网络组件) -完整的捆绑管理
- 自定义对象 -创建和配置对象
- 自定义字段 -向任何对象添加字段
- 流动 -管理流定义
- 电子邮件模板 -创建电子邮件模板
- 权限集 -配置权限
- 静态资源 -上传JavaScript、CSS等。
- 自定义元数据类型 -配置管理
- 光环组件 -传统Lightning组件
- 自定义标签 -翻译标签
- 记录类型 -对象记录类型
- 快捷操作 -创建快速操作
- 自定义选项卡 -配置自定义选项卡
🧪 Apex测试与调试(3)
run_apex_tests-运行覆盖率测试get_apex_test_coverage-获取代码覆盖率详细信息list_apex_test_classes-列出所有测试类
📦 批量操作(4)
bulk_insert_records-通过批量API 2.0插入数千bulk_update_records-更新数千条记录bulk_delete_records-删除数千条记录get_bulk_job_status-检查作业进度
💾 数据导出和备份(5)
export_data_to_csv-将SOQL结果导出到CSVexport_object_data-导出整个对象backup_object_records-创建带时间戳的备份get_record_count-快速记录计数export_schema_to_json-导出对象架构
🔍 查询助手(5)
build_soql_query-从组件构建查询get_object_fields-获取字段元数据get_field_relationships-获取所有关系explain_soql_query-分析和优化查询query_with_related_records-查询父子记录
📊 模式分析(6)
analyze_object_dependencies-完全依赖性分析find_unused_fields-识别未使用的字段generate_object_diagram-生成ERD数据list_all_objects-列出所有对象(自定义/标准)get_field_usage_stats-实地人口统计analyze_field_usage- 新 全面的字段使用分析-通过CSV导出找到所有元数据(顶点、触发器、流、验证规则、公式、页面布局、报告)中字段的使用位置
🤖 过程自动化(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-检查部署状态
👥 用户管理和权限(6)
change_user_profile-更改用户的个人资料assign_permission_set-为用户分配权限集remove_permission_set-从用户中删除权限集list_user_permissions-列出用户的权限集和配置文件list_available_profiles-列出组织中的所有配置文件list_available_permission_sets-列出组织中的所有权限集
🔄 高级比较工具(5)
compare_profiles-并排比较两个配置文件compare_permission_sets-比较两个权限集compare_object_field_counts-比较组织之间的字段计数find_similar_fields_across_objects-查找具有相似名称/类型的字段compare_org_object_counts-比较组织之间的对象总数
📚 使用示例
基本操作
# 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 1000 Account records with this CSV data: [...]"
# Bulk Update
"Bulk update all Contacts where State is null to set State = 'Unknown'"
# 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"
现场使用分析(基于API)
# Analyze single field (fast - excludes reports by default)
"Where is the Case Status field used?"
"Analyze usage of Account.Customer_Type__c field"
# Analyze with reports included (slower but comprehensive)
"Check if Case Status field is used in any reports"
"Analyze Case.Priority including reports"
# Analyze ALL fields on an object (handles 500+ fields)
"Analyze all Case fields and show me where they are used"
"Create a field usage report for all Account fields"
# Analyze all fields including reports
"Analyze all Case fields and check reports too"
# Custom CSV output
"Analyze all Opportunity fields and export to opportunity_audit.csv"
# Results include usage in:
# - Apex Classes (with class names) ✅ Always checked
# - Apex Triggers (with trigger names) ✅ Always checked
# - Flows (with flow names) ✅ Always checked
# - Validation Rules (with rule names) ✅ Always checked
# - Formula Fields (with field names) ✅ Always checked
# - Workflow Rules ✅ Always checked
# - Page Layouts ✅ Always checked
# - Email Templates ✅ Always checked
# - Reports ⚡ Optional (only if you say "include reports" or "check reports")
自动化与就业
# Batch Jobs
"Show all running batch jobs"
"Get details for batch job 7074x000000AbcD"
"Abort batch job 7074x000000AbcD"
# Scheduled Jobs
"List all scheduled Apex jobs"
"Delete scheduled job 0884x000000XyzA"
用户管理
# Change User Profiles
"Change profile for user john.doe@example.com to System Administrator"
"Assign Standard User profile to jane.smith@example.com"
# Manage Permission Sets
"Assign Sales_User permission set to john.doe@example.com"
"Remove Marketing_Access permission set from jane.smith@example.com"
"List all permission sets for user john.doe@example.com"
# Query Profiles and Permission Sets
"List all available profiles in the org"
"Show me all permission sets"
高级比较
# Profile Comparison
"Compare System Administrator and Standard User profiles"
"What are the differences between Sales User and Service User profiles?"
# Permission Set Comparison
"Compare Marketing_Admin and Marketing_User permission sets"
# Cross-Org Comparison
"Compare Account object fields between my two connected orgs"
"Find similar fields across Account and Contact objects"
"Compare total object counts between production and sandbox"
🎓 高级功能
🔍 字段使用分析(v2.2中的新功能!)
这 analyze_field_usage 该工具为整个Salesforce组织提供了全面的现场使用分析。非常适合在进行更改之前进行现场审计、清理项目和影响分析。
它做什么
分析字段的使用位置 所有元数据类型:
- ✅ Apex类 -显示哪些类引用该字段
- ✅ 顶点触发器 -识别触发器依赖关系
- ✅ 流动 -使用字段查找流(包括Process Builder)
- ✅ 验证规则 -检查验证规则公式
- ✅ 公式字段 -标识公式字段依赖关系
- ✅ 工作流规则 -查找工作流字段条件
- ✅ 页面布局 -显示布局字段位置
- ✅ 报告 -使用该字段标识报告
用例
- 现场清理 -归档前查找未使用的字段
- 影响分析 -在更改之前了解依赖关系
- 合规性审计 -审计员的文档字段使用情况
- 迁移规划 -跨组织映射字段使用情况
- 文档 -生成全面的现场参考
如何使用
# Analyze a single field
"Where is the Case Status field used?"
# Analyze ALL fields on an object (handles 500+ fields efficiently)
"Analyze all Case fields and create a CSV report"
# Custom output filename
"Analyze Account fields and save to account_field_audit.csv"
csv输出
该工具会自动生成保存在 Documents/ 包含以下列的文件夹:
- 字段名称、标签、类型
- 是自定义的,是必需的
- Apex类计数+名称
- 触发器计数+名称
- 流量计数+名称
- 验证规则计数+名称
- 公式字段计数+名称
- 工作流规则计数+名称
- 页面布局计数+名称
- 报告计数+名称
- 总使用计数
- 是否被引用(是/否)
存储位置: Documents/{ObjectName}_field_usage_{timestamp}.csv
演出
v2.2中的新功能-大幅改进:
- 速度快5-6倍 智能批量处理
- 在5-10分钟内分析了500个字段 (30-45分钟!)
- API调用减少99% -任何字段计数仅需~15-20个调用
- 智能缓存 -一次获取所有元数据,并对照它检查所有字段
- 进度跟踪 -每50个字段更新一次
- 内存效率高 -处理无限字段
它是如何工作的:
- 一次性获取所有Apex、触发器、流、验证、工作流、布局和报告
- 将所有内容缓存在内存中
- 根据缓存数据检查所有字段(即时!)
- 结果:在5-10分钟内完成500个字段,而不是45分钟!
配置
创建一个 .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=59.0
SFMCP_MAX_RETRIES=3
SFMCP_REQUEST_TIMEOUT_SECONDS=120
# Deployment
SFMCP_DEPLOY_TIMEOUT_SECONDS=300
SFMCP_DEPLOY_POLL_INTERVAL_SECONDS=5
📁 项目结构
Salesforce-MCP-Server/
├── app/
│ ├── main.py # Entry point, tool imports
│ ├── config.py # Configuration management
│ │
│ ├── mcp/
│ │ ├── server.py # MCP server setup, tool registration
│ │ └── tools/ # All 57 MCP tools
│ │ ├── __init__.py
│ │ ├── consolidated_metadata.py # Unified metadata deploy/fetch/list
│ │ ├── consolidated_operations.py # Bulk ops, export, queries, permissions
│ │ ├── oauth_auth.py # OAuth 2.0 authentication
│ │ ├── debugging.py # NEW: Issue diagnosis (25 QA patterns)
│ │ ├── dynamic_tools.py # Apex, triggers, flows, etc.
│ │ ├── multi_org.py # Multi-org management
│ │ ├── advanced_comparison.py # Profile/permset/schema comparison
│ │ ├── user_management.py # User profile/permission management
│ │ ├── 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 operations
│ │ ├── data_export.py # Export/backup tools
│ │ ├── query_helpers.py # Query builders
│ │ └── utils.py # Response formatting, error handling
│ │
│ ├── services/
│ │ └── salesforce.py # Salesforce connection management
│ │
│ └── utils/ # Production-grade utilities
│ ├── __init__.py # Utility exports
│ ├── validators.py # SOQL injection protection, input validation
│ ├── retry.py # Retry logic with exponential backoff
│ ├── logging.py # Structured logging
│ ├── cache.py # NEW: Caching system (LRU, metadata cache)
│ ├── errors.py # NEW: Enhanced error handling
│ ├── pagination.py # NEW: Pagination utilities
│ └── connection_pool.py # NEW: Connection pooling
│
├── requirements.txt # Dependencies
├── .env.example # Example configuration
├── README.md # Main documentation
├── test_all_mcp_tools.py # Comprehensive testing suite
├── start_mcp.bat # Windows startup script
└── Documents/ # CSV exports and reports stored here
├── README.md # Documents folder info
└── *.csv # Field usage reports, data exports
总大小: 12500+行Python代码(仅限工具)
重试逻辑
所有API调用都会自动重试,并进行指数退避:
- 最大尝试次数:3次(可配置)
- 回退倍数:2.0
- 优雅地处理瞬态故障
输入验证
内置保护功能,防止:
- SOQL注入
- 元数据名称无效
- API请求格式不正确
- 不安全操作
结构化日志记录
使用关联ID跟踪所有操作:
- 请求跟踪
- 调试错误
- 性能监控
- 审核跟踪
先进的基础设施
内置生产级公用设施,实现最佳性能:
缓存系统
- LRU缓存 用于元数据和字段定义
- 自动缓存失效 带TTL
- 验证规则缓存 用于更快的查找
- 重复查询的性能显著提高
增强的错误处理
- 自定义
SalesforceError例外 带有错误类别 - 错误类别: 身份验证、查询、部署、批量操作
- 故障排除提示 嵌入错误消息中
- 结构化错误响应 提出可行的建议
分页支持
- 基于光标的分页 对于大型结果集
- SOQL分页助手 自动配料
- 列表分页 API响应
- 高效处理任何大小的数据集
连接池
- 多组织连接池 与国家管理
- 线程本地存储 用于连接隔离
- 池统计 监测
- 自动清理 过时的连接
🔧 故障排除
“未找到活动的Salesforce会话”
解决方案: 先登录: "Login to Salesforce production"
“令牌已过期”
解决方案: 注销并重新登录:
"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\
🤝 贡献
我们欢迎捐款!查看我们的 贡献指南 了解详情。
添加新工具
- 创建工具功能 在适当的模块下
app/mcp/tools/ - 添加
@register_tool装饰器 - 写入docstring 举例说明
- 添加归因:
"Added by Sameer"在docstring中 - 彻底测试 提交PR之前
- 更新文档 在
COMPLETE_GUIDE.md
测试要求
在提交PR之前:
- ✅ 所有现有测试必须通过
- ✅ 新工具必须包括测试场景
- ✅ 首先在沙盒环境中进行测试
- ✅ 记录任何API限值影响
📖 文档
- 完整指南 -全面的2000+线路指南,包含所有工具
- 调试指南 新诊断并修复任何Salesforce缺陷
- 更新摘要 -最新v2.1调试功能
- 能力概述 -功能摘要
- 测试报告 -最新测试结果
- 贡献 -贡献指南
🎯 路线图
完成✅
- ✅ 多组织管理(已完成)
- ✅ 批量操作(已完成)
- ✅ 模式分析工具(已完成)
- ✅ Apex测试套件(已完成)
- ✅ 用户管理工具(已完成)
- ✅ 配置文件和权限集分析(已完成)
- ✅ 高级比较工具(已完成)
- ✅ 全面调试和缺陷解决(Complete v2.1)
计划的🔄
- 🔄 增强的流构建器功能
- 🔄 数据质量检查
- 🔄 自动备份计划
- 🔄 CI/CD集成助手
- 🔄 加密令牌持久性
社区请求
- 📊 仪表板创建工具
- 🔐 增强的安全扫描
- 📈 性能评测
- 🌍 多语言支持
🏆 成功案例
“仅使用自然语言命令,在10分钟内部署了5个Apex类、3个触发器和10个字段的完整功能。” --开发团队负责人
“多组织比较为我们节省了部署前验证的时间。” --DevOps工程师
“健康检查和监测工具帮助我们在API限制问题变得关键之前发现这些问题。” --Salesforce管理员
⚖️ 许可证
MIT许可证-请参阅 许可证 详情
由Sameer创建 |内置于 模型上下文协议
🆘 支持
🌟 明星历史
如果这个项目为您节省了时间,请在存储库中加星! ⭐
由以下材料制成❤️ 作者Sameer |技术支持: 安thropic克劳德
