项目简介

Agentforce MCP Server 是一个基于 Model Context Protocol (MCP) 构建的服务器,旨在为 LLM 客户端提供与 Salesforce Agentforce API 交互的能力。通过此服务器,LLM 可以调用工具来认证 Salesforce、创建 Agentforce 会话、发送消息给 Agentforce 智能客服坐席并获取回复,从而实现与 Salesforce Agentforce 系统的集成。

主要功能点

  • 认证 (authenticate): 允许 LLM 客户端使用 Salesforce 凭据进行身份验证,为后续操作获取必要的访问令牌。
  • 创建会话 (create_agent_session): 在成功认证后,可以创建一个与 Agentforce 智能客服坐席的会话,为消息交互建立通道。
  • 发送消息 (send_message_to_agent): 允许 LLM 客户端向 Agentforce 坐席发送消息,并接收坐席的回复,实现对话功能。
  • 获取会话状态 (get_session_status): 查询当前会话的状态信息,包括认证状态、会话 ID 和消息序列 ID 等。
  • 完整对话流程 (complete_agentforce_conversation): 提供一个便捷工具,一次性完成认证、创建会话和发送消息的完整流程,简化操作。

安装步骤

  1. 安装 Python 依赖: 确保您的系统已安装 Python 3.10 或更高版本。克隆仓库到本地后,在项目根目录下运行以下命令安装所需的 Python 库:

    pip install -r requirements.txt
  2. 配置环境变量: 复制 '.env.example' 文件并重命名为 '.env',然后编辑 '.env' 文件,填入您的 Salesforce 组织 ID、Agent ID、客户端 ID、客户端密钥以及 Salesforce My Domain URL。这些凭据用于连接您的 Salesforce Agentforce 实例。

    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="your_server_url_here"
  3. 使服务器脚本可执行: 赋予服务器运行脚本 'agentforce_mcp_server.py' 执行权限:

    chmod +x agentforce_mcp_server.py

服务器配置

要将此 MCP 服务器配置到 MCP 客户端(例如 Claude for Desktop),您需要提供服务器的启动命令和参数。以下是配置信息,请根据您的实际情况修改脚本路径:

{
  "mcpServers": {
    "agentforce": {
      "command": "python",
      "args": [
        "/path/to/your/agentforce_mcp_server.py"  // 请替换为 agentforce_mcp_server.py 脚本的绝对路径
      ]
    }
  }
}

参数说明:

  • command: 启动服务器的命令,这里使用 'python' 解释器。
  • args: 传递给 'python' 命令的参数,这里是 'agentforce_mcp_server.py' 脚本的绝对路径。请务必将 '/path/to/your/agentforce_mcp_server.py' 替换为您机器上 'agentforce_mcp_server.py' 文件的实际绝对路径。 例如,在 macOS 上可能是 '/Users/yourusername/Projects/agentforce-mcp-xlengelle/agentforce_mcp_server.py',在 Windows 上可能是 'C:\Users\yourusername\Projects\agentforce-mcp-xlengelle\agentforce_mcp_server.py'。

基本使用方法

  1. 启动 MCP 服务器: 在项目根目录下运行以下命令启动 Agentforce MCP Server:

    python agentforce_mcp_server.py

    服务器默认使用 'stdio' 传输协议。

  2. 在 MCP 客户端中使用工具: 在您的 MCP 客户端中配置好服务器后,即可调用服务器提供的工具。通常的使用流程如下:

    • 调用 'authenticate' 工具: 首先使用 'authenticate' 工具进行身份验证,需要提供您的 Salesforce 客户端邮箱地址作为参数。
    • 调用 'create_agent_session' 工具: 成功认证后,调用 'create_agent_session' 工具创建与 Agentforce 坐席的会话。
    • 调用 'send_message_to_agent' 工具: 创建会话后,可以使用 'send_message_to_agent' 工具向 Agentforce 坐席发送消息,并获取回复。您可以多次调用此工具进行多轮对话。
    • 调用 'get_session_status' 工具: 您可以随时调用 'get_session_status' 工具来查看当前的会话状态。
    • 调用 'complete_agentforce_conversation' 工具: 如果您需要快速完成认证、会话创建和发送消息的流程,可以直接使用 'complete_agentforce_conversation' 工具,只需提供客户端邮箱和用户查询消息即可。

请参考仓库的 'README.md' 文件获取更详细的 Salesforce 配置步骤和故障排除信息。

信息

分类

商业系统