@@ -117,6 +117,85 @@ try {
117117const invalidConfigPath = path . join ( TEMP_DIR , "invalid-config.json" ) ;
118118fs . writeFileSync ( invalidConfigPath , '{\n "mcpServers": {\n "invalid": {' ) ;
119119
120+ // Create config files with different transport types for testing
121+ const sseConfigPath = path . join ( TEMP_DIR , "sse-config.json" ) ;
122+ fs . writeFileSync (
123+ sseConfigPath ,
124+ JSON . stringify (
125+ {
126+ mcpServers : {
127+ "test-sse" : {
128+ type : "sse" ,
129+ url : "http://localhost:3000/sse" ,
130+ note : "Test SSE server" ,
131+ } ,
132+ } ,
133+ } ,
134+ null ,
135+ 2 ,
136+ ) ,
137+ ) ;
138+
139+ const httpConfigPath = path . join ( TEMP_DIR , "http-config.json" ) ;
140+ fs . writeFileSync (
141+ httpConfigPath ,
142+ JSON . stringify (
143+ {
144+ mcpServers : {
145+ "test-http" : {
146+ type : "streamable-http" ,
147+ url : "http://localhost:3000/mcp" ,
148+ note : "Test HTTP server" ,
149+ } ,
150+ } ,
151+ } ,
152+ null ,
153+ 2 ,
154+ ) ,
155+ ) ;
156+
157+ const stdioConfigPath = path . join ( TEMP_DIR , "stdio-config.json" ) ;
158+ fs . writeFileSync (
159+ stdioConfigPath ,
160+ JSON . stringify (
161+ {
162+ mcpServers : {
163+ "test-stdio" : {
164+ type : "stdio" ,
165+ command : "npx" ,
166+ args : [ "@modelcontextprotocol/server-everything" ] ,
167+ env : {
168+ TEST_ENV : "test-value" ,
169+ } ,
170+ } ,
171+ } ,
172+ } ,
173+ null ,
174+ 2 ,
175+ ) ,
176+ ) ;
177+
178+ // Config without type field (backward compatibility)
179+ const legacyConfigPath = path . join ( TEMP_DIR , "legacy-config.json" ) ;
180+ fs . writeFileSync (
181+ legacyConfigPath ,
182+ JSON . stringify (
183+ {
184+ mcpServers : {
185+ "test-legacy" : {
186+ command : "npx" ,
187+ args : [ "@modelcontextprotocol/server-everything" ] ,
188+ env : {
189+ LEGACY_ENV : "legacy-value" ,
190+ } ,
191+ } ,
192+ } ,
193+ } ,
194+ null ,
195+ 2 ,
196+ ) ,
197+ ) ;
198+
120199// Function to run a basic test
121200async function runBasicTest ( testName , ...args ) {
122201 const outputFile = path . join (
@@ -587,6 +666,160 @@ async function runTests() {
587666 "debug" ,
588667 ) ;
589668
669+ console . log (
670+ `\n${ colors . YELLOW } === Running Config Transport Type Tests ===${ colors . NC } ` ,
671+ ) ;
672+
673+ // Test 25: Config with stdio transport type
674+ await runBasicTest (
675+ "config_stdio_type" ,
676+ "--config" ,
677+ stdioConfigPath ,
678+ "--server" ,
679+ "test-stdio" ,
680+ "--cli" ,
681+ "--method" ,
682+ "tools/list" ,
683+ ) ;
684+
685+ // Test 26: Config with SSE transport type (CLI mode) - expects connection error
686+ await runErrorTest (
687+ "config_sse_type_cli" ,
688+ "--config" ,
689+ sseConfigPath ,
690+ "--server" ,
691+ "test-sse" ,
692+ "--cli" ,
693+ "--method" ,
694+ "tools/list" ,
695+ ) ;
696+
697+ // Test 27: Config with streamable-http transport type (CLI mode) - expects connection error
698+ await runErrorTest (
699+ "config_http_type_cli" ,
700+ "--config" ,
701+ httpConfigPath ,
702+ "--server" ,
703+ "test-http" ,
704+ "--cli" ,
705+ "--method" ,
706+ "tools/list" ,
707+ ) ;
708+
709+ // Test 28: Legacy config without type field (backward compatibility)
710+ await runBasicTest (
711+ "config_legacy_no_type" ,
712+ "--config" ,
713+ legacyConfigPath ,
714+ "--server" ,
715+ "test-legacy" ,
716+ "--cli" ,
717+ "--method" ,
718+ "tools/list" ,
719+ ) ;
720+
721+ console . log (
722+ `\n${ colors . YELLOW } === Running Default Server Tests ===${ colors . NC } ` ,
723+ ) ;
724+
725+ // Create config with single server for auto-selection
726+ const singleServerConfigPath = path . join (
727+ TEMP_DIR ,
728+ "single-server-config.json" ,
729+ ) ;
730+ fs . writeFileSync (
731+ singleServerConfigPath ,
732+ JSON . stringify (
733+ {
734+ mcpServers : {
735+ "only-server" : {
736+ command : "npx" ,
737+ args : [ "@modelcontextprotocol/server-everything" ] ,
738+ } ,
739+ } ,
740+ } ,
741+ null ,
742+ 2 ,
743+ ) ,
744+ ) ;
745+
746+ // Create config with default-server
747+ const defaultServerConfigPath = path . join (
748+ TEMP_DIR ,
749+ "default-server-config.json" ,
750+ ) ;
751+ fs . writeFileSync (
752+ defaultServerConfigPath ,
753+ JSON . stringify (
754+ {
755+ mcpServers : {
756+ "default-server" : {
757+ command : "npx" ,
758+ args : [ "@modelcontextprotocol/server-everything" ] ,
759+ } ,
760+ "other-server" : {
761+ command : "node" ,
762+ args : [ "other.js" ] ,
763+ } ,
764+ } ,
765+ } ,
766+ null ,
767+ 2 ,
768+ ) ,
769+ ) ;
770+
771+ // Create config with multiple servers (no default)
772+ const multiServerConfigPath = path . join ( TEMP_DIR , "multi-server-config.json" ) ;
773+ fs . writeFileSync (
774+ multiServerConfigPath ,
775+ JSON . stringify (
776+ {
777+ mcpServers : {
778+ server1 : {
779+ command : "npx" ,
780+ args : [ "@modelcontextprotocol/server-everything" ] ,
781+ } ,
782+ server2 : {
783+ command : "node" ,
784+ args : [ "other.js" ] ,
785+ } ,
786+ } ,
787+ } ,
788+ null ,
789+ 2 ,
790+ ) ,
791+ ) ;
792+
793+ // Test 29: Config with single server auto-selection
794+ await runBasicTest (
795+ "single_server_auto_select" ,
796+ "--config" ,
797+ singleServerConfigPath ,
798+ "--cli" ,
799+ "--method" ,
800+ "tools/list" ,
801+ ) ;
802+
803+ // Test 30: Config with default-server should now require explicit selection (multiple servers)
804+ await runErrorTest (
805+ "default_server_requires_explicit_selection" ,
806+ "--config" ,
807+ defaultServerConfigPath ,
808+ "--cli" ,
809+ "--method" ,
810+ "tools/list" ,
811+ ) ;
812+
813+ // Test 31: Config with multiple servers and no default (should fail)
814+ await runErrorTest (
815+ "multi_server_no_default" ,
816+ "--config" ,
817+ multiServerConfigPath ,
818+ "--cli" ,
819+ "--method" ,
820+ "tools/list" ,
821+ ) ;
822+
590823 console . log (
591824 `\n${ colors . YELLOW } === Running HTTP Transport Tests ===${ colors . NC } ` ,
592825 ) ;
@@ -606,7 +839,7 @@ async function runTests() {
606839
607840 await new Promise ( ( resolve ) => setTimeout ( resolve , 3000 ) ) ;
608841
609- // Test 25 : HTTP transport inferred from URL ending with /mcp
842+ // Test 32 : HTTP transport inferred from URL ending with /mcp
610843 await runBasicTest (
611844 "http_transport_inferred" ,
612845 "http://127.0.0.1:3001/mcp" ,
@@ -615,7 +848,7 @@ async function runTests() {
615848 "tools/list" ,
616849 ) ;
617850
618- // Test 26 : HTTP transport with explicit --transport http flag
851+ // Test 33 : HTTP transport with explicit --transport http flag
619852 await runBasicTest (
620853 "http_transport_with_explicit_flag" ,
621854 "http://127.0.0.1:3001/mcp" ,
@@ -626,7 +859,7 @@ async function runTests() {
626859 "tools/list" ,
627860 ) ;
628861
629- // Test 27 : HTTP transport with suffix and --transport http flag
862+ // Test 34 : HTTP transport with suffix and --transport http flag
630863 await runBasicTest (
631864 "http_transport_with_explicit_flag_and_suffix" ,
632865 "http://127.0.0.1:3001/mcp" ,
@@ -637,7 +870,7 @@ async function runTests() {
637870 "tools/list" ,
638871 ) ;
639872
640- // Test 28 : SSE transport given to HTTP server (should fail)
873+ // Test 35 : SSE transport given to HTTP server (should fail)
641874 await runErrorTest (
642875 "sse_transport_given_to_http_server" ,
643876 "http://127.0.0.1:3001" ,
@@ -648,7 +881,7 @@ async function runTests() {
648881 "tools/list" ,
649882 ) ;
650883
651- // Test 29 : HTTP transport without URL (should fail)
884+ // Test 36 : HTTP transport without URL (should fail)
652885 await runErrorTest (
653886 "http_transport_without_url" ,
654887 "--transport" ,
@@ -658,7 +891,7 @@ async function runTests() {
658891 "tools/list" ,
659892 ) ;
660893
661- // Test 30 : SSE transport without URL (should fail)
894+ // Test 37 : SSE transport without URL (should fail)
662895 await runErrorTest (
663896 "sse_transport_without_url" ,
664897 "--transport" ,
0 commit comments