server: skip duplicate response on CancelledError (#1153)

Co-authored-by: ihrpr <inna@anthropic.com>
This commit is contained in:
lukacf 2025-07-25 11:16:13 +02:00 • committed by GitHub
commit b34e7207ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -647,6 +647,12 @@ class Server(Generic[LifespanResultT, RequestT]):
response = await handler(req)
except McpError as err:
response = err.error
except anyio.get_cancelled_exc_class():
logger.info(
"Request %s cancelled - duplicate response suppressed",
message.request_id,
)
return
except Exception as err:
if raise_exceptions:
raise err