v1.30.0: normal streamable-HTTP session close logs "Error in standalone SSE writer" (anyio.ClosedResourceError) at ERROR
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
Línea de trabajo
Empieza por mcp/server/streamable_http.py, especialmente por standalone_sse_writer() y StreamableHTTPServerTransport.terminate(), y luego sigue cómo la limpieza de DELETE cierra el flujo. Reproduce el problema con el ejemplo proporcionado de cliente y servidor y comprueba el registro del servidor al cerrar la sesión. El trabajo estará terminado cuando la terminación normal del cliente ya no produzca un traceback ERROR y haya una prueba de regresión que cubra el flujo cerrado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 1.x, 1.30.0)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
1.x (maintenance line, v1.x branch)
Description
With 1.30.0 on the server side, closing a stateful streamable-HTTP session the normal way logs an ERROR with a full traceback:
ERROR mcp.server.streamable_http: Error in standalone SSE writer
Traceback (most recent call last):
File ".../mcp/server/streamable_http.py", line 723, in standalone_sse_writer
async for event_message in standalone_stream_reader:
File ".../anyio/abc/_streams.py", line 37, in __anext__
return await self.receive()
File ".../anyio/streams/memory.py", line 141, in receive
raise ClosedResourceError from None
anyio.ClosedResourceError
Here, closing the normal way means the client's streamablehttp_client context exits and sends DELETE. Nothing actually fails: the calls succeed and the server keeps serving. But every session that ends puts an ERROR traceback in the server log, and that buries real errors.
Which side and which version: it depends only on the server's SDK version. I crossed the two versions:
| server SDK | client SDK | ERROR records on close |
|---|---|---|
| 1.29.1 | 1.29.1 | 0 |
| 1.30.0 | 1.30.0 | 1 |
| 1.30.0 | 1.29.1 | 1 |
| 1.29.1 | 1.30.0 | 0 |
What seems to happen (from reading the 1.30.0 source):
- The
DELETErunsStreamableHTTPServerTransport.terminate(). terminate()calls_clean_up_memory_streams(GET_STREAM_KEY).- That closes the receive stream
standalone_sse_writeris still iterating, so the iteration raisesClosedResourceErrorinstead of ending. - The writer's
except Exception: logger.exception("Error in standalone SSE writer")reports it.
1.30.0 moved the GET handler's stream cleanup into a finally, which looks like what changed the shutdown order.
Expected: a client-initiated session termination is not logged at ERROR. Either the writer stops cleanly when its stream is closed by terminate(), or ClosedResourceError during termination is treated as a normal end, logged at DEBUG at most.
We work around it in our server with a logging.Filter on mcp.server.streamable_http that demotes exactly this record (that message plus ClosedResourceError) to DEBUG.
Example Code
"""Prints 1 ERROR record on mcp 1.30.0, 0 on 1.29.1."""
import asyncio, logging, socket, threading, time
import uvicorn
from mcp.client.session import ClientSession
from mcp.client.streamable_http import streamablehttp_client
from mcp.server.fastmcp import FastMCP
errors = []
class Collect(logging.Handler):
def emit(self, record):
if record.levelno >= logging.ERROR:
errors.append(record)
logging.getLogger("mcp.server.streamable_http").addHandler(Collect())
server = FastMCP("repro")
@server.tool()
def echo(text: str) -> str:
return text
with socket.socket() as s:
s.bind(("127.0.0.1", 0))
port = s.getsockname()[1]
uv = uvicorn.Server(uvicorn.Config(server.streamable_http_app(),
host="127.0.0.1", port=port, log_level="warning"))
threading.Thread(target=uv.run, daemon=True).start()
while not uv.started:
time.sleep(0.05)
async def main():
async with streamablehttp_client(f"http://127.0.0.1:{port}/mcp") as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
await session.list_tools()
await asyncio.sleep(1) # let the server process the DELETE
asyncio.run(main())
uv.should_exit = True
print(len(errors), "ERROR record(s):",
[(r.getMessage(), type(r.exc_info[1]).__name__) for r in errors])
# 1.30.0: 1 ERROR record(s): [('Error in standalone SSE writer', 'ClosedResourceError')]
# 1.29.1: 0 ERROR record(s): []
Python & MCP Python SDK
Python 3.12.8, Linux
mcp 1.30.0 (server side; 1.29.1 does not show it)
anyio 4.16.0, starlette 1.10.0, sse-starlette 3.7.0, uvicorn 0.54.0
- Lenguaje dominante
- Python
- Estrellas
- 25k
- Forks
- 4.2k
- Merge medio
- 10 min
- PR fusionados (30 d)
- 1
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la 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.
Más de modelcontextprotocol/python-sdk
-
v2
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
modelcontextprotocol/python-sdk#3978 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Client serves cached tools after its context exits with an exceptionPosiblemente ocupada @jonxsong la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
modelcontextprotocol/python-sdk#3968 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
modelcontextprotocol/python-sdk#3957 ·
Los mantenedores suelen responder en 1 día
-
v2
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
modelcontextprotocol/python-sdk#3934 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug v1
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
modelcontextprotocol/python-sdk#3929 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/python-sdk
Issues similares
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwisePosiblemente ocupada @abdulwaarith0 la tomó hoy. Abiertoneeds-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
MakazhanAlpamys/Soup#3690 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug data-types native-format
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
ClickHouse/clickhouse-connect#1320 ·
Los mantenedores suelen responder en 1 día
-
Public benchmark import end-to-end test fails when the test stack's worker runs the parity jobAbiertoaccepted
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
future-agi/future-agi#6392 ·
Los mantenedores suelen responder en 1 día