File tree 3 files changed +37
-1
lines changed
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,27 @@ describe("MCPConnection", () => {
55
55
expect ( conn . status ) . toBe ( "not-connected" ) ;
56
56
} ) ;
57
57
58
+ it ( "should create instance with SSE transport and custom headers" , ( ) => {
59
+ const options = {
60
+ name : "test-mcp" ,
61
+ id : "test-id" ,
62
+ transport : {
63
+ type : "sse" as const ,
64
+ url : "http://test.com/events" ,
65
+ requestOptions : {
66
+ headers : {
67
+ "Authorization" : "Bearer token123" ,
68
+ "X-Custom-Header" : "custom-value"
69
+ }
70
+ }
71
+ } ,
72
+ } ;
73
+
74
+ const conn = new MCPConnection ( options ) ;
75
+ expect ( conn ) . toBeInstanceOf ( MCPConnection ) ;
76
+ expect ( conn . status ) . toBe ( "not-connected" ) ;
77
+ } ) ;
78
+
58
79
it ( "should throw on invalid transport type" , ( ) => {
59
80
const options = {
60
81
name : "test-mcp" ,
Original file line number Diff line number Diff line change @@ -69,7 +69,19 @@ class MCPConnection {
69
69
case "websocket" :
70
70
return new WebSocketClientTransport ( new URL ( options . transport . url ) ) ;
71
71
case "sse" :
72
- return new SSEClientTransport ( new URL ( options . transport . url ) ) ;
72
+ return new SSEClientTransport ( new URL ( options . transport . url ) , {
73
+ eventSourceInit : {
74
+ fetch : ( input , init ) =>
75
+ fetch ( input , {
76
+ ...init ,
77
+ headers : {
78
+ ...init ?. headers ,
79
+ ...( options . transport . requestOptions ?. headers as Record < string , string > | undefined ) ,
80
+ }
81
+ } ) ,
82
+ } ,
83
+ requestInit : { headers : options . transport . requestOptions ?. headers }
84
+ } ) ;
73
85
default :
74
86
throw new Error (
75
87
`Unsupported transport type: ${ ( options . transport as any ) . type } ` ,
Original file line number Diff line number Diff line change @@ -1115,16 +1115,19 @@ export interface StdioOptions {
1115
1115
command : string ;
1116
1116
args : string [ ] ;
1117
1117
env ?: Record < string , string > ;
1118
+ requestOptions ?: RequestOptions ;
1118
1119
}
1119
1120
1120
1121
export interface WebSocketOptions {
1121
1122
type : "websocket" ;
1122
1123
url : string ;
1124
+ requestOptions ?: RequestOptions ;
1123
1125
}
1124
1126
1125
1127
export interface SSEOptions {
1126
1128
type : "sse" ;
1127
1129
url : string ;
1130
+ requestOptions ?: RequestOptions ;
1128
1131
}
1129
1132
1130
1133
export type TransportOptions = StdioOptions | WebSocketOptions | SSEOptions ;
You can’t perform that action at this time.
0 commit comments