本页内容
Sommatic 文档
打开控制台

JSON-RPC Client

调用 JSON-RPC 2.0 方法。

以 Markdown 查看
在以下应用中打开
输入与输出 可用 io.jsonrpc 版本 1.0.0 执行方式: async

以 HTTP POST 发送一次 JSON-RPC 2.0 请求,返回 result 成员,或通过 error 端口返回 JSON-RPC error 成员。

工作原理

  1. 解析配置。connection_id、method、params 和 id 缺失时回退到输入 payload 中的同名键;connection_id 和 method 为必填。
  2. 解析凭据:URL 为 config.url(或 config.endpoint);若密钥含 username 和 password,则使用 HTTP Basic 认证。
  3. 构建 { jsonrpc: "2.0", method, params, id }:字符串形式的 params 会按 JSON 解析,缺失时为 [];id 默认为 1。
  4. POST 该请求。响应含 error 成员时从 error 输出;否则从 out 输出 { result }。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-get-balance",
  "label": "Get balance",
  "operator_slug": "io.jsonrpc",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "method": "account.getBalance",
    "params": "[\"{{ $json.account_id }}\"]",
    "id": "1"
  }
}

配置

connection_id string 必填

JSON-RPC 端点的凭据。接受 `api-key` 或 `basic-auth` 类型的凭据。

method string 必填

方法名称

params string 可选

参数(数组/对象,可为 JSON 字符串或数组)

id string 可选

请求 ID

默认值: 1

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

connection_id
密钥中只读取 username + password(basic-auth);api-key 凭据不会添加认证。以 http:// 或 https:// 开头的值会直接用作端点 URL,不带认证。
params
接受数组、对象或 JSON 字符串;字符串会在发送前解析。
id
按配置原样发送(在配置中设置时为字符串);为空时发送数字 1。

输出端口

out 默认

服务器返回 2xx 且无 error 成员。result 为 JSON-RPC 的 result。

数据
{
  "result": {
    "balance": "1250.40",
    "currency": "USD"
  }
}
error

响应包含 JSON-RPC error(数据为 { error: { code, message, data? } }),或请求失败(数据为 { error, response },其中 error 为消息字符串)。

数据
{
  "error": {
    "code": -32601,
    "message": "Method not found"
  }
}

在表达式中

后续节点可通过 $("JSON-RPC Client").item.json.<路径> 读取此节点输出中的内容(请把 JSON-RPC Client 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("JSON-RPC Client").item.json.resultobject= {…}JSON-RPC 结果
$("JSON-RPC Client").item.json.result.balancestring编辑器不提示= "1250.40"—
$("JSON-RPC Client").item.json.result.currencystring编辑器不提示= "USD"—

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
connection_id is required error 未选择凭据。
method is required error 配置和输入 payload 中的方法名均为空。
<JSON parse error> error params 是无效 JSON 字符串。请写成 JSON 数组或对象,例如 ["acc_001"]。
Request failed with status code <status> error HTTP 调用返回非 2xx 状态;response 中包含正文。

输入契约

connection_id string 必填
method string 必填
params string 可选
id string 可选

输出契约

result object 可选

JSON-RPC 结果

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "io.jsonrpc",
  "name": "JSON-RPC Client",
  "category": "io",
  "version": "1.0.0",
  "description": "Call JSON-RPC 2.0 Method.",
  "capabilities": [
    "jsonrpc",
    "api",
    "http"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "JSON-RPC Credential",
        "description": "Credential for the JSON-RPC endpoint. Accepts credentials of type `api-key` or `basic-auth`.",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "api-key",
            "basic-auth"
          ],
          "types": [
            "jsonrpc",
            "http"
          ]
        }
      },
      "method": {
        "type": "string",
        "description": "Method Name"
      },
      "params": {
        "type": "string",
        "description": "Parameters (Array/Object as JSON string or array)"
      },
      "id": {
        "type": "string",
        "default": "1",
        "description": "Request ID"
      }
    },
    "required": [
      "connection_id",
      "method"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "method": {
        "type": "string"
      },
      "params": {
        "type": "string"
      },
      "id": {
        "type": "string"
      }
    },
    "required": [
      "connection_id",
      "method"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "object",
        "description": "JSON-RPC Result"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Result",
      "description": "JSON-RPC Result",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "JSON-RPC Error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io"
  ],
  "tags": [
    "rpc",
    "api"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}

执行

执行方式
async
有状态
否
凭据
在服务器端根据 connection_id 解析,密钥不会进入工作流。
能力
jsonrpcapihttp
标签
rpcapi

说明与限制

  • 每次运行一个请求;不支持批量请求和通知(无 id 的请求)。无超时,也不重试。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

安装 Sommatic AI CLI,并为检测到的智能体配置合适的插件。

npx @sommatic/cli agent setup
智能体如何读取本文档