MCP: pass protocol cancellation through to Sentry API requests

Open
#2,275 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
tooling

Research direction

Start at handleToolCall in packages/mcp-core/src/server.ts (around line 410) and trace how the tool context is built, then follow how the API client is constructed from it. The reference behavior is the shared transport in @sentry/api (transport.ts, test/cancellation.test.ts), which already honors per-request signals and stops retry backoff. Thread extra.signal through the context and every API call including polling and retry waits, recognizing cancellation by signal.aborted/abort reason. Done when a new test cancels an in-flight call, asserts no further API requests, and concurrent calls still complete.

Written by the indexing model from the issue text.

Description

When an MCP client cancels a tool call, the work keeps running. handleToolCall in packages/mcp-core/src/server.ts only takes params, so the SDK's extra.signal never reaches the tool context, the API client or its polling and retry waits.

The transport side is already done in @sentry/api. Its shared transport, which MCP uses since getsentry/toolkit#1722, honors per-request signals and stops retry backoff on abort (transport.ts, covered by test/cancellation.test.ts, from getsentry/sentry-api-schema#105).

What's left:

  • Thread extra.signal from the tool handler into the invocation context and every API call the tool makes, including polling and retry waits.
  • Keep cancellation scoped to the one invocation, so concurrent calls on the same server keep running.
  • Recognize cancellation by signal.aborted and the abort reason, not only error.name === "AbortError", since MCP reasons can be strings.
  • Add a test that cancels an in-flight tool call and checks that no further API requests go out.

Split out of getsentry/sentry-api-schema#95.

via @BYK.

--

View Session [Sentry]

Dominant language
TypeScript
Stars
961
Forks
179
Avg merge
15h 33m
Merged PRs (30d)
476

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from getsentry/toolkit

All issues in getsentry/toolkit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.