modelcontextprotocol / modelcontextprotocol/python-sdk
Field alias is published in the tool schema but forwarded as an invalid Python keyword
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 24.3k
- Fork
- 4k
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 31
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách đọc các entry point Tool.from_function và Tool.run, rồi chạy bản tái hiện được cung cấp với một tham số có alias. Theo dõi cách tên schema externalX được truyền vào hàm, sau đó bổ sung coverage cho thấy input hợp lệ theo schema sẽ gọi f với x và trả về thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- api, backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 68/100