Skip to content

[Client] Support cancellation and per-call deadlines in Client::callTool() #517

Description

@ineersa

Client::callTool() does not accept a cancellation signal or a per-call timeout. Applications cannot abandon an individual tool call when a user cancels it without closing the connection or waiting for the configured request timeout.

Expected behavior

  • Accept an optional cancellation token and per-call timeout.
  • Check interruption before sending, after synchronous I/O returns, and after a suspended request resumes.
  • Discard interrupted results, clear pending state, and keep the connection usable.
  • Send notifications/cancelled over STDIO and legacy HTTP. For HTTP protocol 2026-07-28, use response-stream closure.
  • Log cancellation-notification failures without replacing the original interruption.

Async behavior and limitations

The client API remains synchronous. Cancellation is cooperative; this proposal does not add an async API, event loop, or framework-specific HTTP client.

  • STDIO: cancellation and deadlines are checked while polling for responses. An interrupted request sends notifications/cancelled.
  • HTTP: checks run when control returns from blocking PSR-18 requests or PSR-7 body reads. Cancellation cannot interrupt a wait for headers or the next body chunk.
  • Legacy HTTP: a best-effort cancellation POST can itself block. Delivery failures are logged without replacing the original interruption.
  • HTTP 2026-07-28: cancellation uses response-stream closure rather than a separate notification.

Per-call deadlines are not hard HTTP wall-clock limits. Applications still need network timeouts on their HTTP client. An async-capable underlying client does not change this when accessed through its synchronous PSR-18 interface.

Cancellation discards the result locally, but does not guarantee that server-side work stops or rolls back.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequest for a new feature that's not currently supported

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions