File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed
Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,13 @@ async function main() {
113113 }
114114 }
115115 }
116+ if ( ( server . type === "http" || server . type === "sse" ) && server . config . options ?. requestInit ?. headers ) {
117+ for ( const [ key , value ] of Object . entries ( server . config . options . requestInit . headers ) ) {
118+ if ( value . includes ( envSpecialValue ) ) {
119+ inputVars . add ( key ) ;
120+ }
121+ }
122+ }
116123 }
117124
118125 if ( inputVars . size === 0 ) {
@@ -156,6 +163,29 @@ async function main() {
156163 }
157164 }
158165 }
166+ if ( ( server . type === "http" || server . type === "sse" ) && server . config . options ?. requestInit ?. headers ) {
167+ for ( const [ key , value ] of Object . entries ( server . config . options . requestInit . headers ) ) {
168+ if ( value . includes ( envSpecialValue ) ) {
169+ if ( userInput ) {
170+ server . config . options . requestInit . headers [ key ] = value . replace ( envSpecialValue , userInput ) ;
171+ } else {
172+ const valueFromEnv = process . env [ key ] || "" ;
173+ server . config . options . requestInit . headers [ key ] = value . replace ( envSpecialValue , valueFromEnv ) ;
174+ if ( valueFromEnv ) {
175+ stdout . write ( ANSI . GREEN ) ;
176+ stdout . write ( `Value successfully loaded from '${ key } '` ) ;
177+ stdout . write ( ANSI . RESET ) ;
178+ stdout . write ( "\n" ) ;
179+ } else {
180+ stdout . write ( ANSI . YELLOW ) ;
181+ stdout . write ( `No value found for '${ key } ' in environment variables. Continuing.` ) ;
182+ stdout . write ( ANSI . RESET ) ;
183+ stdout . write ( "\n" ) ;
184+ }
185+ }
186+ }
187+ }
188+ }
159189 }
160190 }
161191
Original file line number Diff line number Diff line change @@ -21,6 +21,14 @@ export const ServerConfigSchema = z.discriminatedUnion("type", [
2121 url : z . union ( [ z . string ( ) , z . string ( ) . url ( ) ] ) ,
2222 options : z
2323 . object ( {
24+ /**
25+ * Customizes HTTP requests to the server.
26+ */
27+ requestInit : z
28+ . object ( {
29+ headers : z . record ( z . string ( ) ) . optional ( ) ,
30+ } )
31+ . optional ( ) ,
2432 /**
2533 * Session ID for the connection. This is used to identify the session on the server.
2634 * When not provided and connecting to a server that supports session IDs, the server will generate a new session ID.
@@ -34,7 +42,18 @@ export const ServerConfigSchema = z.discriminatedUnion("type", [
3442 type : z . literal ( "sse" ) ,
3543 config : z . object ( {
3644 url : z . union ( [ z . string ( ) , z . string ( ) . url ( ) ] ) ,
37- options : z . object ( { } ) . optional ( ) ,
45+ options : z
46+ . object ( {
47+ /**
48+ * Customizes HTTP requests to the server.
49+ */
50+ requestInit : z
51+ . object ( {
52+ headers : z . record ( z . string ( ) ) . optional ( ) ,
53+ } )
54+ . optional ( ) ,
55+ } )
56+ . optional ( ) ,
3857 } ) ,
3958 } ) ,
4059] ) ;
You can’t perform that action at this time.
0 commit comments