Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

ClientSessionGroup raises KeyError when connecting a server that exposes no components

Đang mở Phù hợp với người mới
#3,578 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.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Xem xét lớp ClientSessionGroup, cụ thể là phương thức _aggregate_components. Vấn đề nằm trong khối điều kiện xóa một phiên khỏi _session_exit_stacks khi không có thành phần nào được hiển thị. Cách sửa là xóa khối đó hoặc xử lý trường hợp phiên không có trong từ điển. Kiểm tra các phương thức connect_with_session và connect_to_server để hiểu luồng hoạt động. Chạy bản tái tạo tối thiểu được cung cấp để xác minh bản sửa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

v1 v2
Initial Checks
Release line

2.x (current stable)

Description
What I ran into

ClientSessionGroup._aggregate_components deletes the session from
_session_exit_stacks whenever a connected server exposes no prompts, resources,
or tools:

if not any((prompts_temp, resources_temp, tools_temp)):
    del self._session_exit_stacks[session]

Via connect_with_session(server_info, session) the caller supplies a session
that was never registered in _session_exit_stacks, so this raises KeyError.
Via connect_to_server it drops the freshly-registered exit stack, so a later
disconnect_from_server can't close that session's transport.

Why it matters

A valid MCP server can legitimately register zero tools/resources/prompts (e.g.
one that only does sampling/roots), and list_* failures are swallowed into
empty dicts too. In both cases connecting an otherwise-fine server either crashes
or leaks a transport until group teardown.

Minimal reproduction
group = ClientSessionGroup()
# server_info + an in-memory session whose list_tools/resources/prompts are empty
await group.connect_with_session(server_info, session)  # -> KeyError
Suggested fix

Remove the empty-server cleanup block so an empty server is aggregated like any
other. Happy to open a PR (branch already prepared).

Example Code

Python & MCP Python SDK
Python 3.13.2
MCP Python SDK: main @ f1b6589 (dev build 0.0.1.dev1063)
Ngôn ngữ chính
Python
Star
24.3k
Fork
4k
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
25

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.

Issue khác của modelcontextprotocol/python-sdk

Tất cả issue của modelcontextprotocol/python-sdk

Issue tương tự

Thêm issue về Python

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.