modelcontextprotocol / modelcontextprotocol/python-sdk

Field alias is published in the tool schema but forwarded as an invalid Python keyword

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

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

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

説明

Initial Checks
  • I confirm that I'm using the latest version of MCP Python SDK.
  • I confirm that I searched the issue tracker before opening this issue.
Description

For a function parameter annotated with Field(alias="externalX"), the generated tool schema correctly requires externalX. At runtime, however, that wire name is forwarded directly to the original function, so the call fails with:

ToolError: Error executing tool f: f() got an unexpected keyword argument 'externalX'

I expected the schema-valid input to be mapped back to the Python parameter x before invocation.

Example Code
import asyncio
from typing import Annotated

try:
    from mcp.server.mcpserver.tools.base import Tool
except ImportError:  # MCP Python SDK 1.x
    from mcp.server.fastmcp.tools.base import Tool

from pydantic import Field


AliasInt = Annotated[int, Field(alias="externalX", ge=1)]


def f(x: AliasInt) -> int:
    return x


async def main() -> None:
    tool = Tool.from_function(f)
    print(tool.parameters)
    print(await tool.run({"externalX": 1}, None))


asyncio.run(main())

The printed schema requires externalX, then the call fails with the error above.

Python & MCP Python SDK
Stable reproduction:
- Python 3.13.13
- mcp 1.28.1
- pydantic 2.13.4

Current main reproduction:
- modelcontextprotocol/python-sdk commit 2713b53b127afc094dc97d6067df9f69b647661c
- mcp 2.0.0b2
- mcp-types 2.0.0b2
- Python 3.13.13

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

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

はじめの一歩

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

調査の方向性

まず Tool.from_function と Tool.run のエントリポイントを読み、エイリアス付きのパラメータで提供された再現コードを実行します。スキーマ名 externalX がどのように関数に渡されるかを追跡し、スキーマに有効な入力が x を指定して f を呼び出し、正常に返ることを示すカバレッジを追加します。

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

評価

技術スタック
python
領域
api, backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
68/100

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

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