Link Search Menu Expand Document Documentation Menu

MCP SSE 消息

3.0 版本引入

这是一个实验性功能,不建议在生产环境中使用。有关此功能进展的更新或如果您想提供反馈,请在 OpenSearch 论坛 上加入讨论。

此端点处理模型上下文协议 (MCP) 的标准消息交互。它通过服务器发送事件 (SSE) 实现与 OpenSearch 中 MCP 服务器的通信。

当使用标准 MCP 客户端时,大多数用户无需直接与此 API 交互。

端点

POST /_plugins/_ml/mcp/sse/message

请求正文字段

下表列出了可用的请求字段。

字段 数据类型 必需/可选 描述
jsonrpc 字符串   JSON-RPC 版本。
id 字符串   请求的唯一 ID。
method 字符串   要执行的操作,例如 tools/call
params 对象 必需 请求参数的顶级容器。
params.name 字符串 必需 要调用的工具的名称。
params.arguments 对象 必需 要传递给工具的参数。
params.arguments.input 对象 必需 工具的输入参数。这些参数取决于工具类型。有关特定工具类型的信息,请参阅 工具

请求示例

SSE 消息 API 使用 JSON-RPC(远程过程调用)协议结构,提供对工具的直接低级访问。这与代理框架方法不同,在代理框架方法中,工具是使用 parameters 在代理注册期间配置的。当直接使用此 API 时,您将根据 JSON-RPC 规范使用 paramsarguments 字段来构建请求,完全绕过代理框架。

POST /_plugins/_ml/mcp/sse/message
{
  "jsonrpc": "2.0",
  "id": "110",
  "method": "tools/call",
  "params": {
      "name": "ListIndexTool1",
      "arguments": {
          "indices": ["test"]
      }
  }
}

示例响应

OpenSearch 向客户端发送 SSE 数据流

event: message
data: {
  "jsonrpc": "2.0",
  "id": "100",
  "result": {
    "tools": [
      {
        "name": "ListIndexTool",
        "description": "This is my first list index tool",
        "inputSchema": {
          "type": "object",
          "properties": {
            "indices": {
              "type": "array",
              "items": { "type": "string" },
              "description": "A comma-separated list of OpenSearch index names. For example: [\"index1\", \"index2\"]. Use [] (an empty array) to list all indices in the cluster."
            }
          },
          "additionalProperties": false
        }
      }
    ]
  }
}
剩余 350 字符

有问题?

想贡献吗?