File tree Expand file tree Collapse file tree 2 files changed +10
-14
lines changed Expand file tree Collapse file tree 2 files changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ export abstract class McpAgent<
8080 }
8181
8282 /** Get the unique WebSocket. SSE transport only. */
83- private getWebSocket ( ) {
83+ getWebSocket ( ) {
8484 const websockets = Array . from ( this . getConnections ( ) ) ;
8585 if ( websockets . length === 0 ) {
8686 return null ;
@@ -110,10 +110,7 @@ export abstract class McpAgent<
110110 private initTransport ( ) {
111111 switch ( this . getTransportType ( ) ) {
112112 case "sse" : {
113- return new McpSSETransport ( {
114- getWebSocket : ( ) => this . getWebSocket ( ) ,
115- sessionId : this . getSessionId ( )
116- } ) ;
113+ return new McpSSETransport ( ) ;
117114 }
118115 case "streamable-http" : {
119116 return new StreamableHTTPServerTransport ( { } ) ;
Original file line number Diff line number Diff line change @@ -15,23 +15,22 @@ import type { McpAgent } from ".";
1515import { MessageType } from "../ai-types" ;
1616import { MCP_HTTP_METHOD_HEADER , MCP_MESSAGE_HEADER } from "./utils" ;
1717
18- export interface McpSSETransportOptions {
19- getWebSocket : ( ) => WebSocket | null ;
20- sessionId ?: string ;
21- }
22-
2318export class McpSSETransport implements Transport {
24- sessionId ? : string ;
19+ sessionId : string ;
2520 // Set by the server in `server.connect(transport)`
2621 onclose ?: ( ) => void ;
2722 onerror ?: ( error : Error ) => void ;
2823 onmessage ?: ( message : JSONRPCMessage , extra ?: MessageExtraInfo ) => void ;
2924
3025 private _getWebSocket : ( ) => WebSocket | null ;
3126 private _started = false ;
32- constructor ( options : McpSSETransportOptions ) {
33- this . _getWebSocket = options . getWebSocket ;
34- this . sessionId = options . sessionId ;
27+ constructor ( ) {
28+ const { agent } = getCurrentAgent < McpAgent > ( ) ;
29+ if ( ! agent )
30+ throw new Error ( "McpAgent was not found in Transport constructor" ) ;
31+
32+ this . sessionId = agent . getSessionId ( ) ;
33+ this . _getWebSocket = ( ) => agent . getWebSocket ( ) ;
3534 }
3635
3736 async start ( ) {
You can’t perform that action at this time.
0 commit comments