switch to optional Transport.setProtocolVersion
This commit is contained in:
parent
4aaa26d900
commit
33257f14d4
7 changed files with 22 additions and 17 deletions
|
|
@ -166,7 +166,9 @@ export class Client<
|
|||
this._serverCapabilities = result.capabilities;
|
||||
this._serverVersion = result.serverInfo;
|
||||
// HTTP transports must set the protocol version in each header after initialization.
|
||||
transport.protocolVersion = result.protocolVersion;
|
||||
if (transport.setProtocolVersion) {
|
||||
transport.setProtocolVersion(result.protocolVersion);
|
||||
}
|
||||
|
||||
this._instructions = result.instructions;
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ export class SSEClientTransport implements Transport {
|
|||
private _eventSourceInit?: EventSourceInit;
|
||||
private _requestInit?: RequestInit;
|
||||
private _authProvider?: OAuthClientProvider;
|
||||
protocolVersion?: string;
|
||||
private _protocolVersion?: string;
|
||||
|
||||
onclose?: () => void;
|
||||
onerror?: (error: Error) => void;
|
||||
|
|
@ -109,8 +109,8 @@ export class SSEClientTransport implements Transport {
|
|||
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
||||
}
|
||||
}
|
||||
if (this.protocolVersion) {
|
||||
headers["mcp-protocol-version"] = this.protocolVersion;
|
||||
if (this._protocolVersion) {
|
||||
headers["mcp-protocol-version"] = this._protocolVersion;
|
||||
}
|
||||
|
||||
return headers;
|
||||
|
|
@ -255,4 +255,8 @@ export class SSEClientTransport implements Transport {
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
setProtocolVersion(version: string): void {
|
||||
this._protocolVersion = version;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ export class StreamableHTTPClientTransport implements Transport {
|
|||
private _authProvider?: OAuthClientProvider;
|
||||
private _sessionId?: string;
|
||||
private _reconnectionOptions: StreamableHTTPReconnectionOptions;
|
||||
protocolVersion?: string;
|
||||
private _protocolVersion?: string;
|
||||
|
||||
onclose?: () => void;
|
||||
onerror?: (error: Error) => void;
|
||||
|
|
@ -174,8 +174,8 @@ export class StreamableHTTPClientTransport implements Transport {
|
|||
if (this._sessionId) {
|
||||
headers["mcp-session-id"] = this._sessionId;
|
||||
}
|
||||
if (this.protocolVersion) {
|
||||
headers["mcp-protocol-version"] = this.protocolVersion;
|
||||
if (this._protocolVersion) {
|
||||
headers["mcp-protocol-version"] = this._protocolVersion;
|
||||
}
|
||||
|
||||
return new Headers(
|
||||
|
|
@ -520,4 +520,11 @@ export class StreamableHTTPClientTransport implements Transport {
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
setProtocolVersion(version: string): void {
|
||||
this._protocolVersion = version;
|
||||
}
|
||||
get protocolVersion(): string | undefined {
|
||||
return this._protocolVersion;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -254,9 +254,6 @@ export class Server<
|
|||
const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion)
|
||||
? requestedVersion
|
||||
: LATEST_PROTOCOL_VERSION;
|
||||
if (this.transport) {
|
||||
this.transport.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
return {
|
||||
protocolVersion,
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ const MAXIMUM_MESSAGE_SIZE = "4mb";
|
|||
export class SSEServerTransport implements Transport {
|
||||
private _sseResponse?: ServerResponse;
|
||||
private _sessionId: string;
|
||||
|
||||
protocolVersion?: string;
|
||||
onclose?: () => void;
|
||||
onerror?: (error: Error) => void;
|
||||
onmessage?: (message: JSONRPCMessage, extra?: { authInfo?: AuthInfo }) => void;
|
||||
|
|
|
|||
|
|
@ -111,7 +111,6 @@ export class StreamableHTTPServerTransport implements Transport {
|
|||
private _onsessioninitialized?: (sessionId: string) => void;
|
||||
|
||||
sessionId?: string;
|
||||
protocolVersion?: string;
|
||||
onclose?: () => void;
|
||||
onerror?: (error: Error) => void;
|
||||
onmessage?: (message: JSONRPCMessage, extra?: { authInfo?: AuthInfo }) => void;
|
||||
|
|
|
|||
|
|
@ -77,9 +77,7 @@ export interface Transport {
|
|||
sessionId?: string;
|
||||
|
||||
/**
|
||||
* The protocol version used for the connection.
|
||||
*
|
||||
* Only set after the initialize response was received.
|
||||
* Sets the protocol version used for the connection (called when the initialize response is received).
|
||||
*/
|
||||
protocolVersion?: string;
|
||||
setProtocolVersion?: (version: string) => void;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue