modelcontextprotocol / modelcontextprotocol/python-sdk

Progress notifications cause server to hang on stdio transport

オープン
#1,141 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

bug P3 ready for work
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

Initial Checks
Description

When using the low-level Server API (mcp.server.lowlevel.Server) with stdio transport, sending progress notifications during request handling causes the server to hang indefinitely and never send the final response.

What I am seeing:

  • Server successfully sends progress notification via write_stream.send()
  • Server handler returns CallToolResult
  • The final response is never sent to the client
  • Client times out waiting for response
  • Server remains blocked and time out eventually
Example Code
import asyncio
from mcp.server.lowlevel import Server
from mcp.server.stdio import stdio_server
from mcp.types import *

server = Server("progress-bug-demo")

@server.list_tools()
async def handle_list_tools() -> list[Tool]:
    return [Tool(
        name="test_tool",
        description="Demonstrates the bug",
        inputSchema={"type": "object", "properties": {}}
    )]

@server.call_tool()
async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
    ctx = server.request_context
    progress_token = ctx.meta.progressToken if ctx.meta else None
    
    if progress_token:
        # This causes the server to hang
        await ctx.session.send_progress_notification(
            progress_token=progress_token,
            progress=0.5,
            total=1.0,
            message="Working..."
        )
    
    # This response is never sent due to the hang
    return [TextContent(type="text", text="Task completed!")]

async def main():
    async with stdio_server() as (read_stream, write_stream):
        await server.run(
            read_stream,
            write_stream,
            server.create_initialization_options()
        )

if __name__ == "__main__":
    asyncio.run(main())
Python & MCP Python SDK
MCP: 1.10.1
Python: 3.12.6

From deeper debugging looks like buffer size is the problem : https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/stdio.py#L57

Have to test locally if increasing it will most likely fix the issue and if its causing more problems than just fixing this.

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

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

はじめの一歩

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

調査の方向性

src/mcp/server/stdio.py:57 の低レベルな Server API と stdio トランスポートの実装から始めます。MCP 1.10.1 で提供されている進捗通知の例を実行して send がどこでブロックするかを確認し、その後ストリームバッファの動作を調べます。進捗通知と最終的な CallToolResult の両方が、サーバーがハングすることなくクライアントに届けば完了です。

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

評価

技術スタック
python
領域
api, backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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