modelcontextprotocol / modelcontextprotocol/python-sdk
Field alias is published in the tool schema but forwarded as an invalid Python keyword
未關閉
還沒有人認領這個 Issue。
bug
needs confirmation
P2
v1
v2
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先閱讀 Tool.from_function 和 Tool.run 進入點,並使用帶有別名的參數執行提供的重現程式。追蹤 schema 名稱 externalX 如何傳遞給函式,然後新增涵蓋範圍,顯示符合 schema 的輸入會以 x 呼叫 f 並成功返回。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- api, backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 活躍
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100