modelcontextprotocol / modelcontextprotocol/python-sdk

Prompt validation errors are logged with an unnecessary traceback

Đang mở Phù hợp với người mới
#3,342 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

v1 v2
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
Release line

2.x (current stable)

Description

Description

When a prompt is called without a required argument, the request is correctly rejected, but the Python SDK logs the validation error with a full traceback.

To Reproduce

Steps to reproduce the behavior:

  1. Create a prompt with a required argument:

    @mcp.prompt()
    def diagnose_cluster(problem: str) -> str:
        return f"Diagnose: {problem}"
    
  2. Call prompts/list and confirm that problem is marked as required.

  3. Call prompts/get without providing the required argument:

    {
      "method": "prompts/get",
      "params": {
        "name": "diagnose_cluster"
      }
    }
    
  4. The request is rejected, but the server logs a full traceback:

    Error getting prompt diagnose_cluster
    Traceback (most recent call last):
      ...
      File ".../mcp/server/mcpserver/server.py", line 1285, in get_prompt
        rendered = await prompt.render(arguments, context)
      File ".../mcp/server/mcpserver/prompts/base.py", line 160, in render
        raise ValueError(f"Missing required arguments: {missing}")
    ValueError: Missing required arguments: {'problem'}
    
    handler for 'prompts/get' raised
    
Example Code

Python & MCP Python SDK
## Environment

- MCP Python SDK: v2
- Python: 3.x
- Server: `MCPServer`
- Prompt transport: Streamable HTTP

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu tại get_prompt trong mcp/server/mcpserver/server.py và lần theo lệnh gọi render trong mcp/server/mcpserver/prompts/base.py. Tái hiện prompts/get cho diagnose_cluster mà không có đối số problem bắt buộc, sau đó kiểm tra cách lỗi xác thực được ghi log. Hoàn thành khi yêu cầu vẫn bị từ chối và lỗi xác thực mong đợi được ghi log mà không có traceback đầy đủ.

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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
72/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.