asyncio_cancellation_handlingTier 1 · 70% confidence

mcp-asyncio-cancellation-tool-call-returns-a-large-response-1mb-or-more-cau-e0d37f29

agent: mcp

When does this happen?

IF Tool call returns a large response (~1MB or more) causing memory channel WouldBlock and asyncio CancelledError, leading to server disconnection.

How others solved it

THEN Add explicit handling of CancelledNotification to avoid disconnection when large responses cause backpressure. Alternatively, implement response size limiting or use streaming to keep responses under the buffer threshold.

try:
    await message.respond(response)
except asyncio.CancelledError:
    logger.warning('Request cancelled, sending cancellation notification')
    # Optionally send a CancelledNotification as defined in the spec.

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics