[Capability] Describe nullable parameters with `anyOf` instead of a `type` array?
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in SchemaGenerator, where a nullable parameter currently produces a type array such as ["null", "string"]; find the branch that builds that array and the tests covering nullable scalars, enums, arrays and objects. The open question is a design one, so the first deliverable is a maintainer answer on whether anyOf should be default or opt-in before any patch. Done means every nullable parameter shape is covered and existing schema tests are updated alongside the new behaviour.
由索引模型根据 Issue 内容生成。
描述
For a nullable parameter, SchemaGenerator emits a type array. With mcp/sdk 0.9.0, the ?string $company = null parameter of a tool gets:
{"type": ["null", "string"], "description": "The company of the speaker", "default": null}
MCP Inspector 2 then reports "Schema portability: 0 errors, 1 warning" and suggests {"anyOf": [{"type": "null"}, {"type": "string"}]}. That rule is a warning on purpose (schemaLint.ts, modelcontextprotocol/inspector#2286). The array form is what OpenAI recommends. It only costs portability to clients that map tool schemas onto a dialect with a single type.
What the providers document:
- OpenAI: "it is possible to emulate an optional parameter by using a union type with
null", with"type": ["string", "null"]in the examples.anyOfworks too, except at the root. - Anthropic: strict tool use supports
anyOf, and countsanyOfand type arrays the same in its limit on union types. - Gemini: the
parametersof a function declaration use "a select subset of an OpenAPI 3.0 schema object". Itstypeis a single value, withanyOf,nullableand aNULLtype. So only theanyOfform maps onto it.parametersJsonSchematakes JSON Schema instead.
Switching to anyOf would change the schema of every nullable parameter, including enums, arrays and objects, and clients that read type wouldn't find it anymore. So I'd rather ask first. Would you take a PR that emits anyOf for nullable parameters, maybe as an option of SchemaGenerator?
Found with the submit_proposal tool of the MCP server of the Symfony showcase app.
- 主要语言
- PHP
- 星标
- 1.7k
- 派生
- 206
- 平均合并
- 1 天 17 小时
- 30 天内合并 PR
- 102
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/php-sdk 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 85/100
modelcontextprotocol/php-sdk#746 ·
维护者通常 1 天内回复
-
[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStan未关闭Server
难度 1/5 1 小时以内 新手友好度 78/100
modelcontextprotocol/php-sdk#468 · 3 条评论 ·
维护者通常 1 天内回复
-
enhancement P3
难度 4/5 3-5 天 新手友好度 48/100
modelcontextprotocol/php-sdk#733 · 2 条评论 ·
维护者通常 1 天内回复
-
[Server] Handle notifications/cancelled on the handshake era可能已有人在做 @ump45nose 于 5 天前认领。 未关闭help wanted improves spec compliance Server
难度 4/5 3-5 天 新手友好度 57/100
modelcontextprotocol/php-sdk#732 ·
维护者通常 1 天内回复
-
[Client][Server] Ship extension classes for the two authorization extensions可能已有人在做 @chr-hertel 于 6 天前认领。 未关闭auth Client Server
modelcontextprotocol/php-sdk#721 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/php-sdk 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 82/100
pluginsGLPI/carbon#396 ·
-
[BUG] Bundle products lose their price in RSS feeds: getPrices() was removed可能已有人在做 @pcvelz 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
OpenMage/magento-lts#5869 ·
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
OpenGIS/waymark-wp#82 ·
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
claude
难度 2/5 1-3 小时 新手友好度 76/100
sprain/sprainocchio#39 ·
维护者通常 1 天内回复