modelcontextprotocol / modelcontextprotocol/python-sdk

A tool with a *args or **kwargs parameter is registered with a schema it can never satisfy

オープン
#3,514 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

v1 v2
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

Initial Checks

  • I confirm that I'm using the newest release of my line (2.x, main at 6affe5c)
  • I confirm that I searched for my issue in the issue tracker before opening this issue

Release line

2.x (current stable)

Description

Registering a tool whose function signature has a *args or **kwargs
parameter succeeds, and the tool shows up in list_tools, but it can never
actually be called: the generated JSON schema lists args/kwargs as a
required parameter of a plain scalar type, which doesn't match how the
function actually receives those values.

Expected: either the decorator rejects a signature it can't turn into a
schema (it already does this for a leading underscore in a parameter name),
or the schema reflects what the function accepts.

Actual: the tool is silently registered and permanently uncallable. Calling
it with only the named parameters filled in fails schema validation because
args/kwargs is "missing"; there's no way to actually supply it, since a
JSON object has no way to express "and then also a variable number of
positional values" for a single scalar field.

Example Code

from mcp.server.mcpserver import MCPServer

server = MCPServer("demo")


@server.tool()
def with_kwargs(x: int, **kwargs: str) -> str:
    return f"{x} {kwargs}"

Listing tools shows:

{'type': 'object', 'properties': {'x': {'title': 'X', 'type': 'integer'}, 'kwargs': {'title': 'Kwargs', 'type': 'string'}}, 'required': ['x', 'kwargs'], 'title': 'with_kwargsArguments'}

Calling it with {"x": 1} (the only arguments a caller could reasonably
guess) fails:

Error executing tool with_kwargs: 1 validation error for with_kwargsArguments
kwargs
  Field required [type=missing, input_value={'x': 1}, input_type=dict]

Same shape with *args instead of **kwargs.

Python & MCP Python SDK

Python 3.14.7, mcp-python-sdk main @ 6affe5c0d3588fd1705713b3703dc68015cfe3eb

I have a patch that raises InvalidSignature for a *args/**kwargs tool
parameter at registration time, scoped so it doesn't affect resource
templates (which legitimately use **kwargs for runtime-determined URI
variables); happy to open a PR against this issue if that's the direction
you'd want.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

関数シグネチャがツールスキーマになる MCPServer.tool の登録処理から始め、正当に **kwargs を受け入れるリソーステンプレートの処理と比較してください。*args と **kwargs の両方について InvalidSignature の経路を確認し、ツールの可変長パラメーターが登録時に拒否される一方で、リソーステンプレートは引き続きサポートされることを検証してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend-api-design
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
68/100

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

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