dsh-gemini-tool-schema:在请求前规范化工具 Schema,避免 Gemini functionDeclarations 400

前言

在 DeepSeek Harness(DSH)里接 MCP、内置工具或其他插件注册的工具时,发往模型的 tools 往往带着「别处合法」的 JSON Schema。走 Google Gemini 一类严格校验的 functionDeclarations[].parameters 路由时,整包请求可能被直接拒掉(HTTP 400),错误信息却指向某个字段的 schema 细节,排查成本高。

在 MCP 代理层单独改 schema 只能覆盖该代理背后的服务;内置工具和不经过 MCP 传输的工具进不了那条链路。因此在 Harness 组装工具集、发出模型请求之前做统一规范化,才能一次覆盖所有来源。下面介绍社区插件 dsh-gemini-tool-schema(维护者 ChenXu233,分类:模型推理)的用途与接入方式。

这是什么

dsh-gemini-tool-schema 是 DSH 的 TypeScript 插件:在模型请求发出前,把工具 schema 规整为 Gemini function declarations 可接受的严格 OpenAPI 3.0 子集。README 中的定位是修复来自任意 MCP 或内置工具触发的 Gemini functionDeclarations 400,而不是替换某一家的 MCP 实现。

典型会踩到的 400

资料里列了三类「在其他环境合法、在 Gemini 路由上会整请求失败」的例子:

实际报错 问题 schema 来源
schema didn't specify the schema type field { anyOf: [{type:'string',…}, {type:'null'}] },顶层无 type Playwright MCP browser_emulate_media.colorScheme(z.string().nullable())
properties[v_types].items: missing field { type: 'array' },缺 items Lingshu MCP lingshu_cg / lingshu_stg(19 个参数)
properties[permission].enum[3]: cannot be empty enum 中含空字符串 DSH 内置 task_board_update.permission

这类问题往往只在 Gemini 风味路由上暴露,容易误以为是某个 MCP 单独坏了。

为什么在 Harness 里做 Hook

MCP 代理只能处理它包装到的服务端;内置工具和其他插件注册的工具不会经过 MCP 传输。在 Harness 组装阶段规范化,是资料中给出的、能 同时覆盖全部工具 的做法。

核心能力与规整规则

插件在装配工具集时按配置决定是否改写 schema。README 概括的规整规则包括:

  • 每个节点补上 type;每个 array 补上 items。
  • enum 条目不为空;const 不能重新引入空枚举。
  • $ref / $defs 在避免循环的前提下内联;不支持的关键字剥离,其余标量走允许列表。
  • required 收窄到真实存在的 properties。

此外支持诊断与审计:dryRun 可只报告与 lint 而不改写发往模型的 schema;logFile / logLevel、dumpDir / dumpSchemas 用于离线核对模型侧看到的工具集。

安装与启用

有两种方式,均来自仓库 README。

方式一:本地构建后挂载 dist

git clone https://github.com/ChenXu233/dsh-gemini-tool-schema.git
cd dsh-gemini-tool-schema && npm install && npm run build

在 <DSH home>/profiles/<profile>/cordis.patch.yml 追加:

- insert:
    - id: gemini-tool-schema
      name: '/absolute/path/to/dsh-gemini-tool-schema/dist/index.js'
      config:
        mode: list
        apis: ['gemini', 'google', 'vertex']

将 name 换成你机器上 dist/index.js 的绝对路径。

方式二:npm 包

npm install dsh-gemini-tool-schema

按包名挂载(包内提供 cordis.patch.yml 片段,见 npm 包说明)。

运行环境:package.json 要求 Node >=20;开发测试在 Node ≥22.6 下可直接跑 TypeScript 测试(README 写明 36 个测试)。

配置项

字段 默认值 含义
mode list all 每条请求都处理 · list 仅匹配 apis · off 关闭
apis ['gemini','google','vertex'] API 匹配模式,按正则编译
unknownApi apply 无法读取路由时:apply 或 skip
itemsFallback {type:'string'} 缺 items 的数组使用的元素 schema
nullable true 对 null 联合类型输出 nullable: true
dryRun false 只报告与 lint,仍发送原始 schema
logFile / logLevel 无 / info 每次装配一行诊断
dumpDir / dumpSchemas 无 / true 导出模型侧工具集供离线审计

apis 针对 provider/model 字符串匹配(例如 gemini-lumiya/gemini-4-argon),支持子串、正则以及 /pattern/flags;无法编译的条目会退化为不区分大小写的子串匹配。'*' 匹配全部,或设置 mode: all。

适用场景与注意

适合:在 DSH 里使用 Gemini、Google 或 Vertex 等路由做 function calling,且工具来自多个 MCP、内置能力或其他插件,需要避免 schema 子集差异导致整请求 400。

注意:

  • 插件随当前 DSH 进程权限运行,安装或挂载前请自行审阅 GitHub 源码 与 MIT 许可证。
  • 社区目录 SkillHub 插件页 与 GitHub 仓库由维护者发布,与 DeepSeek / 幻方无官方从属关系;DSH 生态强调「一切皆插件」,目录站是社区索引,不是官方应用商店。
  • 若需验证规整逻辑而不改线上请求,可先开 dryRun: true,再结合 dumpSchemas 对比前后工具定义。

结尾

dsh-gemini-tool-schema 把「Gemini 能吃的 OpenAPI 3.0 子集」这一约束前移到 Harness 装配阶段,用同一套规则处理 MCP 与内置工具,减少 functionDeclarations 400 带来的断链。接入与配置以 README 为准:

  • 目录页:https://www.skillhub.cn/plugins/ChenXu233/dsh-gemini-tool-schema
  • 仓库:https://github.com/ChenXu233/dsh-gemini-tool-schema
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜