SFCC开发MCP服务器是一个基于Model Context Protocol(MCP)的服务器,它为Salesforce B2C Commerce Cloud开发功能提供全面访问。借助该服务器,AI代理能够协助处理SFCC开发任务,包括日志分析、调试、监控以及SFCC文档查询等。
若要将此MCP服务器与Claude Desktop或其他MCP客户端配合使用,请在MCP设置文件中添加以下内容:
{
"mcpServers": {
"sfcc-dev": {
"command": "npx",
"args": ["sfcc-dev-mcp"]
}
}
}
{
"mcpServers": {
"sfcc-dev": {
"command": "npx",
"args": ["sfcc-dev-mcp", "--dw-json", "/path/to/your/dw.json"]
}
}
}
dw.json 文件创建在完整模式下,你需要创建一个包含SFCC凭证的 dw.json 文件:
{
"hostname": "your-instance.sandbox.us01.dx.commercecloud.salesforce.com",
"username": "your-username",
"password": "your-password",
"client-id": "your-client-id",
"client-secret": "your-client-secret"
}
| 工具类别 | 仅文档模式 | 完整模式 |
|---|---|---|
| SFCC文档 (7个工具) | ✅ 可用 | ✅ 可用 |
| 最佳实践指南 (4个工具) | ✅ 可用 | ✅ 可用 |
| SFRA文档 (5个工具) | ✅ 可用 | ✅ 可用 |
| 日志分析 (6个工具) | ❌ 需要凭证 | ✅ 可用 |
| 系统对象定义 (6个工具) | ❌ 需要OAuth | ✅ 支持OAuth |
立即开始使用:该服务器无需任何凭证即可运行,只需使用 npx sfcc-dev-mcp 命令,你就能访问所有文档和最佳实践工具!
match_all_query。为了在处理SFCC项目时获得最佳的AI辅助,请将 文件复制到你的SFCC项目目录,并将其重命名为 copilot-instructions.md、claude.md 或类似名称。该文件为AI助手提供了以下方面的全面指导:
这将显著提高AI在处理SFCC开发任务时的辅助准确性,并减少幻觉现象。
git clone [仓库地址]
npm install
npm run build
服务器支持多个命令行参数来定制其行为:
--dw-json <路径>指定自定义的 dw.json 配置文件路径:
# 使用npm并指定自定义dw.json路径
npm start -- --dw-json /path/to/your/dw.json
# 使用npm并指定相对路径
npm start -- --dw-json ./config/dw.json
# 直接使用node
node dist/main.js --dw-json /path/to/your/dw.json
--debug 控制调试日志输出,以定制服务器日志的详细程度:
# 启用调试日志(显示详细的调试消息、方法进入/退出、计时信息)
npm start -- --debug true
npm start -- --debug # 简写为true
# 禁用调试日志(仅显示基本信息、警告和错误)
npm start -- --debug false
# 与其他选项结合使用
npm start -- --dw-json ./config/dw.json --debug false
# 基本启动(使用./dw.json或环境变量)
npm start
# 使用自定义dw.json文件启动
npm start -- --dw-json /path/to/custom/dw.json
# 或者直接使用node启动
node dist/main.js
# 或者使用自定义配置启动
node dist/main.js --dw-json ./config/production.json
你也可以直接使用npx运行服务器,而无需在本地安装:
# 使用npx运行(使用./dw.json或环境变量)
npx sfcc-dev-mcp
# 使用npx并指定自定义dw.json文件运行
npx sfcc-dev-mcp --dw-json /path/to/custom/dw.json
# 使用npx并指定相对路径运行
npx sfcc-dev-mcp --dw-json ./config/dw.json
将此服务器添加到你的MCP客户端配置中。例如,在Claude Desktop的配置中:
{
"mcpServers": {
"sfcc-dev": {
"command": "node",
"args": ["/path/to/sfcc-dev-mcp/dist/main.js"]
}
}
}
{
"mcpServers": {
"sfcc-dev": {
"type": "stdio",
"command": "npx",
"args": [
"sfcc-dev-mcp",
"--dw-json",
"/path/to/your/dw.json"
]
}
}
}
get_sfcc_class_info - 获取SFCC类的综合信息{
"className": "Catalog"
}
search_sfcc_classes - 按名称搜索类{
"query": "product"
}
get_available_best_practice_guides - 列出所有可用的最佳实践指南{}
get_best_practice_guide - 获取完整的最佳实践指南{
"guideName": "sfra_controllers"
}
get_available_sfra_documents - 列出所有可用的SFRA文档{}
get_sfra_document - 获取完整的SFRA类或模块文档{
"documentName": "server"
}
get_system_object_definitions - 获取所有系统对象定义{
"count": 50,
"select": "(**)"
}
get_system_object_definition - 获取特定系统对象定义{
"objectType": "Product"
}
get_latest_errors - 获取最近的错误消息get_latest_warnings - 获取最近的警告消息get_latest_info - 获取最近的信息消息summarize_logs - 获取日志摘要及计数search_logs - 在日志中搜索模式list_log_files - 列出可用的日志文件服务器使用当前工作目录(cwd)来定位文档文件。默认情况下,它期望在服务器启动的目录中找到一个 docs/ 文件夹。如果你需要使用不同位置的文档,可以采用以下几种方法:
方法一:从正确的目录启动服务器
cd /path/to/sfcc-dev-mcp
npx sfcc-dev-mcp
方法二:使用 --cwd 标志(如果你的MCP客户端支持)
{
"mcpServers": {
"sfcc-dev": {
"command": "npx",
"args": ["sfcc-dev-mcp"],
"cwd": "/path/to/sfcc-dev-mcp"
}
}
}
方法三:创建符号链接
# 在你期望的位置创建指向docs文件夹的符号链接
ln -s /path/to/sfcc-dev-mcp/docs /your/desired/location/docs
cd /your/desired/location
npx sfcc-dev-mcp
期望的目录结构 服务器期望的目录结构如下:
./docs/
├── best-practices/
│ ├── cartridge_creation.md
│ ├── ocapi_hooks.md
│ ├── scapi_hooks.md
│ └── ...
├── sfra/
│ ├── server.md
│ ├── request.md
│ ├── response.md
│ ├── querystring.md
│ └── render.md
├── dw_catalog/
├── dw_order/
└── ... (其他SFCC类文档文件夹)
dw.json(推荐)服务器支持Commerce Cloud开发工具使用的标准SFCC dw.json 配置格式。在项目根目录下创建一个 dw.json 文件:
{
"hostname": "your-instance.sandbox.us01.dx.commercecloud.salesforce.com",
"username": "your-username",
"password": "your-password",
"client-id": "your-client-id",
"client-secret": "your-client-secret",
"code-version": "version1"
}
必填字段:
hostname:你的SFCC实例主机名username:你的SFCC用户名password:你的SFCC密码可选字段:
client-id:OAuth客户端ID(用于API访问)client-secret:OAuth客户端密钥(用于API访问)code-version:要使用的代码版本你也可以使用环境变量来配置服务器:
export SFCC_HOSTNAME="your-instance.sandbox.us01.dx.commercecloud.salesforce.com"
export SFCC_USERNAME="your-username"
export SFCC_PASSWORD="your-password"
export SFCC_CLIENT_ID="your-client-id"
export SFCC_CLIENT_SECRET="your-client-secret"
export SFCC_SITE_ID="RefArch"
若要使用系统对象定义工具(get_system_object_definitions、get_system_object_definition、search_system_object_attribute_definitions、search_site_preferences、search_system_object_attribute_groups、search_custom_object_attribute_definitions),你需要在Business Manager中配置数据API访问:
SFCC Dev MCP Server(或任何描述性名称)客户端配置:
{
"_v": "23.2",
"clients": [
{
"client_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"resources": [
{
"resource_id": "/system_object_definitions",
"methods": [
"get"
],
"read_attributes": "(**)",
"write_attributes": "(**)"
},
{
"resource_id": "/system_object_definitions/*",
"methods": [
"get"
],
"read_attributes": "(**)",
"write_attributes": "(**)"
},
{
"resource_id": "/system_object_definition_search",
"methods": [
"post"
],
"read_attributes": "(**)",
"write_attributes": "(**)"
},
{
"resource_id": "/system_object_definitions/*/attribute_definition_search",
"methods": [
"post"
],
"read_attributes": "(**)",
"write_attributes": "(**)"
},
{
"resource_id": "/system_object_definitions/*/attribute_group_search",
"methods": [
"post"
],
"read_attributes": "(**)",
","write_attributes": "(**)"
},
{
"resource_id": "/custom_object_definitions/*/attribute_definition_search",
"methods": [
"post"
],
"read_attributes": "(**)",
"write_attributes": "(**)"
},
{
"resource_id": "/site_preferences/preference_groups/*/*/preference_search",
"methods": [
"post"
],
"read_attributes": "(**)",
"write_attributes": "(**)"
}
]
}
]
}
必填设置:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)/system_object_definitions/*(允许访问所有系统对象定义端点)/site_preferences/preference_groups/*/*/preference_search(允许访问站点首选项搜索)get 和 post(检索和搜索系统对象及首选项所需)(**)(允许读取所有属性)(**)(某些操作可能需要)将客户端凭证添加到你的 dw.json 文件中:
{
"hostname": "your-instance.sandbox.us01.dx.commercecloud.salesforce.com",
"username": "your-username",
"password": "your-password",
"client-id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"client-secret": "your-api-client-password",
"code-version": "version1"
}
常见问题:
/system_object_definitions/* 和 /site_preferences/preference_groups/*/*/preference_search 匹配。测试你的配置: 你可以使用MCP工具测试你的数据API访问:
{
"tool": "get_system_object_definitions",
"parameters": {
"count": 5,
"select": "(**)"
}
}
测试站点首选项工作流:
{
"tool": "search_system_object_attribute_groups",
"parameters": {
"objectType": "SitePreferences",
"searchRequest": {
"query": {
"match_all_query": {}
},
"select": "(**)"
}
}
}
服务器按以下优先级加载配置:
--dw-json 参数(最高优先级):允许你指定自定义的 dw.json 文件路径,适用于不同环境或项目配置。./dw.json 文件:如果工作目录中存在该文件,则会自动检测并使用,这是标准的SFCC开发工作流程。dw.json 文件,则会回退到使用环境变量。启用调试模式可获取详细的故障排除信息:
{
"mcpServers": {
"sfcc-dev": {
"command": "npx",
"args": ["sfcc-dev-mcp", "--dw-json", "/path/to/dw.json", "--debug", "true"]
}
}
}
调试模式提供以下信息:
日志文件会随着时间积累,你可以安全地删除旧的日志文件:
macOS/Linux:
# 删除所有日志文件
rm /tmp/sfcc-mcp-logs/*.log
# 删除7天以上的日志
find /tmp/sfcc-mcp-logs -name "*.log" -mtime +7 -delete
Windows:
# 删除所有日志文件
Remove-Item "$env:TEMP\sfcc-mcp-logs\*.log"
# 删除7天以上的日志
Get-ChildItem "$env:TEMP\sfcc-mcp-logs" -Filter "*.log" | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Remove-Item
SFCC文档是使用包含的抓取脚本从官方SFCC文档自动转换而来的。
注意:文档转换脚本需要额外的依赖项,这些依赖项未包含在主包中,以保持MCP服务器的轻量级:
# 安装文档转换所需的依赖项
npm install axios cheerio
# 转换SFCC文档(带速率限制)
node scripts/convert-docs.js
# 测试模式(有限转换)
node scripts/convert-docs.js --test
# 保守的速率限制
node scripts/convert-docs.js --slow
axios 和 cheerio 依赖项仅在从SFCC文档网站重新生成文档时需要,正常的MCP服务器操作不需要这些依赖项。
服务器包含了所有主要SFCC开发领域的全面最佳实践指南:
服务器包含了所有SFCC包的全面文档:
dw.campaign - 活动和促销管理dw.catalog - 产品和目录管理dw.content - 内容管理dw.customer - 客户管理dw.order - 订单处理dw.system - 系统实用程序dw.web - 网络框架dw.json 文件,切勿将其提交到版本控制系统。dw.json 添加到你的 .gitignore 文件中。npm run build
npm test
服务器会自动将所有日志写入文件,以避免干扰JSON-RPC协议,并确保一致的调试能力。这可以防止JSON解析错误,并为故障排除提供可靠的日志访问。
macOS:
/tmp/sfcc-mcp-logs/
├── sfcc-mcp-info.log # 一般信息和启动消息
├── sfcc-mcp-warn.log # 警告消息和弃用通知
├── sfcc-mcp-error.log # 错误消息和堆栈跟踪
└── sfcc-mcp-debug.log # 详细的调试信息(启用调试模式时)
Windows:
%TEMP%\sfcc-mcp-logs\
├── sfcc-mcp-info.log # 一般信息和启动消息
├── sfcc-mcp-warn.log # 警告消息和弃用通知
├── sfcc-mcp-error.log # 错误消息和堆栈跟踪
└── sfcc-mcp-debug.log # 详细的调试信息(启用调试模式时)
Linux:
/tmp/sfcc-mcp-logs/
├── sfcc-mcp-info.log # 一般信息和启动消息
├── sfcc-mcp-warn.log # 警告消息和弃用通知
├── sfcc-mcp-error.log # 错误消息和堆栈跟踪
└── sfcc-mcp-debug.log # 详细的调试信息(启用调试模式时)
macOS/Linux:
# 实时查看所有日志
tail -f /tmp/sfcc-mcp-logs/*.log
# 查看特定日志级别
tail -f /tmp/sfcc-mcp-logs/sfcc-mcp-error.log # 仅查看错误日志
tail -f /tmp/sfcc-mcp-logs/sfcc-mcp-debug.log # 查看调试信息(如果启用)
Windows (PowerShell):
# 实时查看错误日志
Get-Content "$env:TEMP\sfcc-mcp-logs\sfcc-mcp-error.log" -Wait
# 查看所有日志
Get-ChildItem "$env:TEMP\sfcc-mcp-logs" | ForEach-Object { Get-Content $_.FullName -Wait }
Expected ',' or ']' after array element in JSON at position Xnode),或者验证临时目录的写入权限。--debug true:{
"mcpServers": {
"sfcc-dev": {
"command": "npx",
"args": ["sfcc-dev-mcp", "--dw-json", "/path/to/dw.json", "--debug", "true"]
}
}
}
我们欢迎贡献!请参阅我们的 贡献指南 以了解以下详细信息:
无论你是修复错误、添加功能、改进文档还是增强最佳实践指南,你的贡献都有助于让每个人更轻松地进行SFCC开发。
本项目采用ISC许可证,请参阅 LICENSE 文件以获取详细信息。