`_onprogress` raises a protocol error for a race servers cannot avoid (progress notification arriving with the response)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- api
Research direction
Start in src/shared/protocol.ts by reading _onresponse and _onprogress, then reproduce the race with the callTool example and adjacent progress and response messages. Done means a late progress notification for a completed request is discarded without triggering _onerror, while normal progress delivery remains unchanged; consider whether the terminal-notification behavior needs documentation.
Written by the indexing model from the issue text.
Description
Summary
When a request completes, Protocol._onresponse deletes that request's progress handler. Any progress notification for the token that is processed afterwards falls into _onprogress, finds no handler, and is reported through _onerror:
Received a progress notification for an unknown token: {...}
Discarding the notification is reasonable — once the request is done, progress for it is moot. Raising a protocol error for it is not, because a server has no way to avoid producing that condition.
Why a server cannot avoid it
A server that reports progress for a batch operation naturally emits a terminal progress === total notification just before returning the result. Those two writes are adjacent by construction. Whether the client processes the notification before or after the response is a timing race the server does not control — and on a loaded machine it loses.
Concretely, in src/shared/protocol.ts:
// _onresponse
if (!isTaskResponse) {
this._progressHandlers.delete(messageId);
}
// _onprogress
const handler = this._progressHandlers.get(messageId);
if (!handler) {
this._onerror(new Error(`Received a progress notification for an unknown token: ...`));
return;
}
So any server emitting a terminal progress notification will intermittently cause onerror to fire in every client. For hosts that log or surface protocol errors, a well-behaved server ends up manufacturing spurious error noise on a successful operation.
Attempting to fix it server-side does not work. Awaiting the notification sends before returning the result orders the writes correctly, but cannot prevent the client from tearing down its handler before it dispatches them.
Reproduction
Server emits N progress notifications then the result, with no artificial spacing between them. Client:
const progress: unknown[] = [];
const errors: string[] = [];
client.onerror = (e) => errors.push(e.message);
await client.callTool({ name: "export", arguments: { /* 3 items */ } },
CallToolResultSchema, { onprogress: (p) => progress.push(p) });
Observed (server sent 4 notifications, all before the result):
received=1
errors=[
'Received a progress notification for an unknown token: {"method":"notifications/progress","params":{"progress":1,"total":3,...,"progressToken":1}}',
'...{"progress":2,...}',
'...{"progress":3,...}'
]
One delivered, three discarded with an error each. With ~100ms spacing between notifications the same code delivers all four — i.e. it is purely a timing race, not a protocol violation by either side.
Observed with @modelcontextprotocol/sdk 1.29.0 over stdio.
Suggested change
Treat "progress notification for a request that has just completed" as an expected, benign race rather than an error:
- don't route it to
_onerror; ignore it silently, or log at debug level; or - keep a short grace period after response for recently-completed tokens and drop matching notifications quietly.
Either removes the false error without changing the (sensible) decision not to deliver late progress.
Secondary question
Is there any supported way for a server to deliver a terminal progress notification reliably? If not, that is worth stating in the spec/docs, so server authors know the final progress === total frame is inherently best-effort and clients know not to build completion UI on it. Right now it looks reliable, and fails only under load.
- Dominant language
- TypeScript
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 32
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/typescript-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelcontextprotocol/typescript-sdk#2920 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelcontextprotocol/typescript-sdk#2919 · 1 comment ·
Maintainers usually reply within 1 day
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelcontextprotocol/typescript-sdk#2916 · 1 comment ·
Maintainers usually reply within 1 day
-
v1 v2
Difficulty 1/5 Under an hour Newbie friendliness 90/100
modelcontextprotocol/typescript-sdk#2867 · 1 comment ·
Maintainers usually reply within 1 day
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
modelcontextprotocol/typescript-sdk#2854 · 1 comment ·
Maintainers usually reply within 1 day
All issues in modelcontextprotocol/typescript-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
external-issue to-triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
diegosouzapw/OmniRoute#15401 ·
Maintainers usually reply within 2 days
-
Sign the pledgeOpen
Difficulty 1/5 Under an hour Newbie friendliness 95/100
input-output-hk/devx-updates#163 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
code-yeongyu/oh-my-openagent#9454 ·
Maintainers usually reply within 1 day