modelcontextprotocol / modelcontextprotocol/python-sdk
Progress notifications cause server to hang on stdio transport
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 24.3k
- Forks
- 4k
- Merge medio
- 1 d 1 h
- PR fusionados (30 d)
- 31
Descripción
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la API de Server de bajo nivel y la implementación del transporte stdio en src/mcp/server/stdio.py:57. Ejecuta el ejemplo proporcionado de notificaciones de progreso con MCP 1.10.1 para confirmar dónde se bloquea la llamada a send y, después, inspecciona el comportamiento del búfer del stream. La tarea estará terminada cuando tanto las notificaciones de progreso como el CallToolResult final lleguen al cliente sin que el servidor se quede bloqueado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 48/100