modelcontextprotocol / modelcontextprotocol/python-sdk

Progress notifications cause server to hang on stdio transport

Offen
#1,141 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P3 ready for work
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit der Low-Level-Server-API und der stdio-Transportimplementierung in src/mcp/server/stdio.py:57. Führen Sie das bereitgestellte Beispiel für Progress-Benachrichtigungen mit MCP 1.10.1 aus, um zu bestätigen, an welcher Stelle der send-Aufruf blockiert, und untersuchen Sie anschließend das Verhalten des Stream-Puffers. Als erledigt gilt die Aufgabe, wenn sowohl die Progress-Benachrichtigungen als auch das abschließende CallToolResult den Client erreichen, ohne dass der Server hängen bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
api, backend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.