@@ -44,7 +44,10 @@ console.log(`${colors.BLUE}- Resource-related options (--uri)${colors.NC}`);
4444console . log (
4545 `${ colors . BLUE } - Prompt-related options (--prompt-name, --prompt-args)${ colors . NC } ` ,
4646) ;
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` ) ;
4851
4952// Get directory paths
5053const SCRIPTS_DIR = __dirname ;
@@ -62,9 +65,11 @@ if (!fs.existsSync(OUTPUT_DIR)) {
6265}
6366
6467// 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 = [ ] ;
6873
6974process . on ( "exit" , ( ) => {
7075 try {
@@ -74,6 +79,23 @@ process.on("exit", () => {
7479 `${ colors . RED } Failed to remove temp directory: ${ err . message } ${ colors . NC } ` ,
7580 ) ;
7681 }
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 ) ;
7799} ) ;
78100
79101// Use the existing sample config file
@@ -121,6 +143,11 @@ async function runBasicTest(testName, ...args) {
121143 stdio : [ "ignore" , "pipe" , "pipe" ] ,
122144 } ) ;
123145
146+ const timeout = setTimeout ( ( ) => {
147+ console . log ( `${ colors . YELLOW } Test timed out: ${ testName } ${ colors . NC } ` ) ;
148+ child . kill ( ) ;
149+ } , 10000 ) ;
150+
124151 // Pipe stdout and stderr to the output file
125152 child . stdout . pipe ( outputStream ) ;
126153 child . stderr . pipe ( outputStream ) ;
@@ -135,6 +162,7 @@ async function runBasicTest(testName, ...args) {
135162 } ) ;
136163
137164 child . on ( "close" , ( code ) => {
165+ clearTimeout ( timeout ) ;
138166 outputStream . end ( ) ;
139167
140168 if ( code === 0 ) {
@@ -201,6 +229,11 @@ async function runErrorTest(testName, ...args) {
201229 stdio : [ "ignore" , "pipe" , "pipe" ] ,
202230 } ) ;
203231
232+ const timeout = setTimeout ( ( ) => {
233+ console . log ( `${ colors . YELLOW } Error test timed out: ${ testName } ${ colors . NC } ` ) ;
234+ child . kill ( ) ;
235+ } , 10000 ) ;
236+
204237 // Pipe stdout and stderr to the output file
205238 child . stdout . pipe ( outputStream ) ;
206239 child . stderr . pipe ( outputStream ) ;
@@ -215,6 +248,7 @@ async function runErrorTest(testName, ...args) {
215248 } ) ;
216249
217250 child . on ( "close" , ( code ) => {
251+ clearTimeout ( timeout ) ;
218252 outputStream . end ( ) ;
219253
220254 // For error tests, we expect a non-zero exit code
@@ -611,6 +645,69 @@ async function runTests() {
611645 "debug" ,
612646 ) ;
613647
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+
614711 // Print test summary
615712 console . log ( `\n${ colors . YELLOW } === Test Summary ===${ colors . NC } ` ) ;
616713 console . log ( `${ colors . GREEN } Passed: ${ PASSED_TESTS } ${ colors . NC } ` ) ;
0 commit comments