modelcontextprotocol / modelcontextprotocol/python-sdk

It is not possible to define a Resource that takes only the Context parameter as an argument.

Đang mở
#1,405 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.

bug improves spec compliance P2 ready for work
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
Description

Problem

Currently, it is not possible to define a Resource that takes only the Context parameter as an argument. When attempting to create such a resource, the registration logic incorrectly classifies it as a template resource instead of a regular resource.

Expected Behavior

Resources with only a Context parameter should be registered as regular resources, not template resources.

Current Behavior

Resources with only a Context parameter are incorrectly registered as template resources, causing them to not appear in the resource list and fail when accessed.

Root Cause

The parameter validation logic in the FastMCP.resource() decorator doesn't properly distinguish between effective function parameters and Context parameters. It treats any function with parameters as a potential template resource, even when the only parameter is a Context.

Solution

  1. Fix the parameter validation logic to exclude Context parameters when determining if a resource should be a template
  2. Update the Resource.read() method signature to accept an optional context parameter
  3. Update all resource implementations to support the new signature

This change maintains full backward compatibility while enabling context-only resources.

Example Code
@mcp.resource("resource://user_profile")
def get_user_profile(ctx: Context) -> str:
    # Something Code ...
Python & MCP Python SDK
Python 3.13.5
MCP Python SDK v1.15.0

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 với việc xác thực tham số của decorator FastMCP.resource() và kiểm tra cách các hàm Context-only được phân loại. Sau đó, lần theo Resource.read() và các triển khai resource hiện có để cập nhật nhất quán chữ ký lời gọi; được xem là hoàn thành khi các resource Context-only xuất hiện trong danh sách resource và có thể được truy cập mà không làm hỏng các resource hiện có.

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
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/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.