[Capability] Describe nullable parameters with `anyOf` instead of a `type` array?

オープン
#631 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
json, php
領域
api, backend

調査の方向性

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. anyOf works too, except at the root.
  • Anthropic: strict tool use supports anyOf, and counts anyOf and type arrays the same in its limit on union types.
  • Gemini: the parameters of a function declaration use "a select subset of an OpenAPI 3.0 schema object". Its type is a single value, with anyOf, nullable and a NULL type. So only the anyOf form maps onto it. parametersJsonSchema takes 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時間
マージ済み PR(30日)
102

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/php-sdk のほかの issue

modelcontextprotocol/php-sdk の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。