modelcontextprotocol / modelcontextprotocol/python-sdk

Refactor handler context to be transport- and handler-type-aware

Đang mở
#2,021 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

P1 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ả

The current RequestContext / ServerRequestContext design has a few rough edges that warrant a dedicated refactor:

  1. Request vs notification context — Request handlers have request_id and meta, notification handlers do not. Currently request_id is optional (RequestId | None) on a single shared type, which loses type safety. Ideally these would be distinct types so request handlers get a context where request_id is always present, and notification handlers get one where it does not exist.

  2. Transport-specific context — The request_context field on ServerMessageMetadata is typed as Any because the server layer is transport-agnostic (e.g. it is a Starlette Request for HTTP transports, None for stdio). A better design would let transports provide their own typed context that handlers can access without casting.

These two concerns are related — both point toward making the context type more precise depending on how and where a handler is invoked.

AI Disclaimer

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 bằng cách lần theo RequestContext và ServerRequestContext qua các điểm vào của handler, sau đó kiểm tra ServerMessageMetadata.request_context và các trường hợp transport được đề cập cho Starlette Request và stdio. So sánh cách các handler request và notification nhận context cũng như cách truy cập các giá trị riêng của transport. Hoàn tất khi các ranh giới kiểu dự kiến và hành vi của transport được xác định mà không phụ thuộc vào Any hoặc các request ID tùy chọn.

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
Tái cấu trúc
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/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.