Client serves cached tools after its context exits with an exception
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 65/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
issue では src/mcp/client/client.py、具体的には 480~496 行の Client.__aexit__ が示されています。このメソッドと既存の接続ガードを読み、キャッシュされた tools/list の応答と、コンテキスト内での例外を使って例を再現してください。通常終了時と例外終了時のどちらでも、その後の呼び出しでクローズ済みのクライアントが拒否され、元の例外が引き続き伝播すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Initial Checks
- Reproduced on the latest 2.x release.
- Searched existing issues and pull requests for this behavior.
Release line
2.x (current stable)
Description
After an exception leaves an async with Client(...) block, client.list_tools() can still return a cached tool list even though the connection has closed. The same call after a normal exit raises RuntimeError: Client must be used within an async context manager. Both exits should make subsequent calls reject the closed client.
Client.aexit clears _session after awaiting the exit stack. If the stack propagates an exception, the assignment is skipped and the cache's connection check still passes.
The example prints ['echo'] on both versions below. Remove the line that raises ApplicationError and the final call raises RuntimeError as expected.
Example Code
import anyio
from mcp import Client
from mcp.server import CacheHint, MCPServer
class ApplicationError(Exception):
pass
async def main() -> None:
server = MCPServer("repro", cache_hints={"tools/list": CacheHint(ttl_ms=60_000)})
@server.tool()
def echo() -> str:
return "echo"
client = Client(server, mode="2026-07-28")
try:
async with client:
await client.list_tools()
raise ApplicationError
except* ApplicationError:
pass
print([tool.name for tool in (await client.list_tools()).tools])
anyio.run(main)
Python & MCP Python SDK
Windows, CPython 3.12.4, MCP 2.3.0 and main at 77001c96.
I'd like to work on the fix if maintainers are open to an outside PR. Clearing the session reference even when the exit stack raises would preserve the original exception and let the existing connection guard reject later calls.
Codex helped with implementation. Report written and reviewed by Jon Zhang.
- 主要言語
- Python
- スター
- 25k
- フォーク
- 4.2k
- 平均マージ
- 10分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/python-sdk のほかの issue
-
v2
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
modelcontextprotocol/python-sdk#3978 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
modelcontextprotocol/python-sdk#3957 ·
メンテナーはふだん 1 日以内に返信
-
v2
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
modelcontextprotocol/python-sdk#3934 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
bug v1
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
modelcontextprotocol/python-sdk#3929 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
DCR `RegistrationHandler` accepts `{"redirect_uris": null}` and returns `201 Created` for `authorization_code` clients再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンbug v1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/python-sdk#3885 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/python-sdk の issue をすべて見る
似ている issue
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwise対応中かも @abdulwaarith0 が今日担当しました。 オープンneeds-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
MakazhanAlpamys/Soup#3690 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug data-types native-format
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
ClickHouse/clickhouse-connect#1320 ·
メンテナーはふだん 1 日以内に返信
-
accepted
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
future-agi/future-agi#6392 ·
メンテナーはふだん 1 日以内に返信