Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

ClientSessionGroup raises KeyError when connecting a server that exposes no components

オープン 初心者向け
#3,578 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

ClientSessionGroup クラス、特に _aggregate_components メソッドを確認してください。問題は、コンポーネントが公開されていない場合に _session_exit_stacks からセッションを削除する条件ブロックにあります。修正は、そのブロックを削除するか、セッションが辞書に存在しないケースを処理することです。connect_with_session メソッドと connect_to_server メソッドを確認してフローを理解してください。提供された最小限の再現手順を実行して修正を検証してください。

索引モデルが issue の本文から書いたものです。

説明

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)
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 16時間
マージ済み PR(30日)
25

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/python-sdk のほかの issue

modelcontextprotocol/python-sdk の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。