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