@@ -44,7 +44,10 @@ console.log(`${colors.BLUE}- Resource-related options (--uri)${colors.NC}`);
44
44
console . log (
45
45
`${ colors . BLUE } - Prompt-related options (--prompt-name, --prompt-args)${ colors . NC } ` ,
46
46
) ;
47
- console . log ( `${ colors . BLUE } - Logging options (--log-level)${ colors . NC } \n` ) ;
47
+ console . log ( `${ colors . BLUE } - Logging options (--log-level)${ colors . NC } ` ) ;
48
+ console . log ( `${ colors . BLUE } - Transport types (--transport http/sse/stdio)${ colors . NC } ` ) ;
49
+ console . log ( `${ colors . BLUE } - Transport inference from URL suffixes (/mcp, /sse)${ colors . NC } ` ) ;
50
+ console . log ( `\n` ) ;
48
51
49
52
// Get directory paths
50
53
const SCRIPTS_DIR = __dirname ;
@@ -62,9 +65,11 @@ if (!fs.existsSync(OUTPUT_DIR)) {
62
65
}
63
66
64
67
// Create a temporary directory for test files
65
- const TEMP_DIR = fs . mkdirSync ( path . join ( os . tmpdir ( ) , "mcp-inspector-tests" ) , {
66
- recursive : true ,
67
- } ) ;
68
+ const TEMP_DIR = path . join ( os . tmpdir ( ) , "mcp-inspector-tests" ) ;
69
+ fs . mkdirSync ( TEMP_DIR , { recursive : true } ) ;
70
+
71
+ // Track servers for cleanup
72
+ let runningServers = [ ] ;
68
73
69
74
process . on ( "exit" , ( ) => {
70
75
try {
@@ -74,6 +79,23 @@ process.on("exit", () => {
74
79
`${ colors . RED } Failed to remove temp directory: ${ err . message } ${ colors . NC } ` ,
75
80
) ;
76
81
}
82
+
83
+ runningServers . forEach ( server => {
84
+ try {
85
+ process . kill ( - server . pid ) ;
86
+ } catch ( e ) {
87
+ }
88
+ } ) ;
89
+ } ) ;
90
+
91
+ process . on ( "SIGINT" , ( ) => {
92
+ runningServers . forEach ( server => {
93
+ try {
94
+ process . kill ( - server . pid ) ;
95
+ } catch ( e ) {
96
+ }
97
+ } ) ;
98
+ process . exit ( 1 ) ;
77
99
} ) ;
78
100
79
101
// Use the existing sample config file
@@ -121,6 +143,11 @@ async function runBasicTest(testName, ...args) {
121
143
stdio : [ "ignore" , "pipe" , "pipe" ] ,
122
144
} ) ;
123
145
146
+ const timeout = setTimeout ( ( ) => {
147
+ console . log ( `${ colors . YELLOW } Test timed out: ${ testName } ${ colors . NC } ` ) ;
148
+ child . kill ( ) ;
149
+ } , 10000 ) ;
150
+
124
151
// Pipe stdout and stderr to the output file
125
152
child . stdout . pipe ( outputStream ) ;
126
153
child . stderr . pipe ( outputStream ) ;
@@ -135,6 +162,7 @@ async function runBasicTest(testName, ...args) {
135
162
} ) ;
136
163
137
164
child . on ( "close" , ( code ) => {
165
+ clearTimeout ( timeout ) ;
138
166
outputStream . end ( ) ;
139
167
140
168
if ( code === 0 ) {
@@ -201,6 +229,11 @@ async function runErrorTest(testName, ...args) {
201
229
stdio : [ "ignore" , "pipe" , "pipe" ] ,
202
230
} ) ;
203
231
232
+ const timeout = setTimeout ( ( ) => {
233
+ console . log ( `${ colors . YELLOW } Error test timed out: ${ testName } ${ colors . NC } ` ) ;
234
+ child . kill ( ) ;
235
+ } , 10000 ) ;
236
+
204
237
// Pipe stdout and stderr to the output file
205
238
child . stdout . pipe ( outputStream ) ;
206
239
child . stderr . pipe ( outputStream ) ;
@@ -215,6 +248,7 @@ async function runErrorTest(testName, ...args) {
215
248
} ) ;
216
249
217
250
child . on ( "close" , ( code ) => {
251
+ clearTimeout ( timeout ) ;
218
252
outputStream . end ( ) ;
219
253
220
254
// For error tests, we expect a non-zero exit code
@@ -611,6 +645,69 @@ async function runTests() {
611
645
"debug" ,
612
646
) ;
613
647
648
+ console . log (
649
+ `\n${ colors . YELLOW } === Running HTTP Transport Tests ===${ colors . NC } ` ,
650
+ ) ;
651
+
652
+ console . log ( `${ colors . BLUE } Starting server-everything in streamableHttp mode.${ colors . NC } ` ) ;
653
+ const httpServer = spawn ( "npx" , [ "@modelcontextprotocol/server-everything" , "streamableHttp" ] , {
654
+ detached : true ,
655
+ stdio : "ignore"
656
+ } ) ;
657
+ runningServers . push ( httpServer ) ;
658
+
659
+ await new Promise ( resolve => setTimeout ( resolve , 3000 ) ) ;
660
+
661
+ // Test 25: HTTP transport inferred from URL ending with /mcp
662
+ await runBasicTest (
663
+ "http_transport_inferred" ,
664
+ "http://127.0.0.1:3001/mcp" ,
665
+ "--cli" ,
666
+ "--method" ,
667
+ "tools/list" ,
668
+ ) ;
669
+
670
+ // Test 26: HTTP transport with explicit --transport http flag
671
+ await runBasicTest (
672
+ "http_transport_with_explicit_flag" ,
673
+ "http://127.0.0.1:3001" ,
674
+ "--transport" ,
675
+ "http" ,
676
+ "--cli" ,
677
+ "--method" ,
678
+ "tools/list" ,
679
+ ) ;
680
+
681
+ // Test 27: HTTP transport with suffix and --transport http flag
682
+ await runBasicTest (
683
+ "http_transport_with_explicit_flag_and_suffix" ,
684
+ "http://127.0.0.1:3001/mcp" ,
685
+ "--transport" ,
686
+ "http" ,
687
+ "--cli" ,
688
+ "--method" ,
689
+ "tools/list" ,
690
+ ) ;
691
+
692
+ // Test 28: SSE transport given to HTTP server (should fail)
693
+ await runErrorTest (
694
+ "sse_transport_given_to_http_server" ,
695
+ "http://127.0.0.1:3001" ,
696
+ "--transport" ,
697
+ "sse" ,
698
+ "--cli" ,
699
+ "--method" ,
700
+ "tools/list" ,
701
+ ) ;
702
+
703
+ // Kill HTTP server
704
+ try {
705
+ process . kill ( - httpServer . pid ) ;
706
+ console . log ( `${ colors . BLUE } HTTP server killed, waiting for port to be released...${ colors . NC } ` ) ;
707
+ } catch ( e ) {
708
+ console . log ( `${ colors . RED } Error killing HTTP server: ${ e . message } ${ colors . NC } ` ) ;
709
+ }
710
+
614
711
// Print test summary
615
712
console . log ( `\n${ colors . YELLOW } === Test Summary ===${ colors . NC } ` ) ;
616
713
console . log ( `${ colors . GREEN } Passed: ${ PASSED_TESTS } ${ colors . NC } ` ) ;
0 commit comments