-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(client): preserve Streamable HTTP request provenance #2667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edenbuilds
wants to merge
8
commits into
modelcontextprotocol:main
Choose a base branch
from
edenbuilds:codex/fix-stream-provenance-2659
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d1584c4
fix(client): preserve Streamable HTTP request provenance (#2659)
edenbuilds d363e64
Merge upstream/main into codex/fix-stream-provenance-2659
edenbuilds d0f8ca2
chore(client): refresh stream provenance branch onto upstream main
edenbuilds 5d42a7f
fix(client): keep request provenance across a resumed SSE stream
KKonstantinov d237eda
chore(client): refresh provenance branch onto upstream main
edenbuilds fb4110c
fix(client): expose Streamable HTTP request provenance across resumes
edenbuilds e7c7e36
Merge upstream/main into the Streamable HTTP provenance fix
edenbuilds 913689e
test(client): document and cover resumed stream provenance
edenbuilds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@modelcontextprotocol/client": patch | ||
| --- | ||
|
|
||
| Expose the originating client request ID for server-initiated requests received on a Streamable HTTP response stream. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/client/test/client/streamProvenanceContext.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import type { JSONRPCMessage, MessageExtraInfo, Transport } from '@modelcontextprotocol/core-internal'; | ||
| import { isJSONRPCRequest } from '@modelcontextprotocol/core-internal'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { Client } from '../../src/client/client'; | ||
|
|
||
| class ScriptedTransport implements Transport { | ||
| onclose?: () => void; | ||
| onerror?: (error: Error) => void; | ||
| onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void; | ||
| sent: JSONRPCMessage[] = []; | ||
|
|
||
| async start(): Promise<void> {} | ||
|
|
||
| async close(): Promise<void> { | ||
| this.onclose?.(); | ||
| } | ||
|
|
||
| async send(message: JSONRPCMessage): Promise<void> { | ||
| this.sent.push(message); | ||
| if (isJSONRPCRequest(message) && message.method === 'initialize') { | ||
| queueMicrotask(() => | ||
| this.onmessage?.({ | ||
| jsonrpc: '2.0', | ||
| id: message.id, | ||
| result: { | ||
| protocolVersion: '2025-11-25', | ||
| capabilities: {}, | ||
| serverInfo: { name: 'scripted-server', version: '1.0.0' } | ||
| } | ||
| }) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| emit(message: JSONRPCMessage, extra?: MessageExtraInfo): void { | ||
| this.onmessage?.(message, extra); | ||
| } | ||
| } | ||
|
|
||
| describe('Streamable HTTP provenance in client request context', () => { | ||
| it('exposes relatedRequestId to the client request handler', async () => { | ||
| const transport = new ScriptedTransport(); | ||
| const client = new Client({ name: 'provenance-client', version: '1.0.0' }, { capabilities: { roots: { listChanged: false } } }); | ||
| let relatedRequestId: string | number | undefined; | ||
|
|
||
| client.setRequestHandler('roots/list', async (_request, context) => { | ||
| relatedRequestId = context.mcpReq.relatedRequestId; | ||
| return { roots: [] }; | ||
| }); | ||
|
|
||
| await client.connect(transport); | ||
| transport.emit({ jsonrpc: '2.0', id: 'server-request-1', method: 'roots/list', params: {} }, { relatedRequestId: 'tool-call-1' }); | ||
| await new Promise(resolve => setTimeout(resolve, 0)); | ||
|
|
||
| expect(relatedRequestId).toBe('tool-call-1'); | ||
| await client.close(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.