modelcontextprotocol / modelcontextprotocol/python-sdk
A tool with a *args or **kwargs parameter is registered with a schema it can never satisfy
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 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.
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 từ quá trình đăng ký MCPServer.tool, nơi các chữ ký hàm được chuyển thành các lược đồ công cụ, và so sánh cách xử lý này với các template tài nguyên vốn hợp lệ khi chấp nhận **kwargs. Xác nhận đường dẫn InvalidSignature cho cả *args và **kwargs, sau đó kiểm tra rằng các tham số biến thiên của công cụ bị từ chối khi đăng ký, trong khi các template tài nguyên vẫn được hỗ trợ.
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
- backend-api-design
- 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
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 68/100