@@ -120,6 +120,85 @@ try {
120120const invalidConfigPath = path . join ( TEMP_DIR , "invalid-config.json" ) ;
121121fs . writeFileSync ( invalidConfigPath , '{\n "mcpServers": {\n "invalid": {' ) ;
122122
123+ // Create config files with different transport types for testing
124+ const sseConfigPath = path . join ( TEMP_DIR , "sse-config.json" ) ;
125+ fs . writeFileSync (
126+ sseConfigPath ,
127+ JSON . stringify (
128+ {
129+ mcpServers : {
130+ "test-sse" : {
131+ type : "sse" ,
132+ url : "http://localhost:3000/sse" ,
133+ note : "Test SSE server" ,
134+ } ,
135+ } ,
136+ } ,
137+ null ,
138+ 2 ,
139+ ) ,
140+ ) ;
141+
142+ const httpConfigPath = path . join ( TEMP_DIR , "http-config.json" ) ;
143+ fs . writeFileSync (
144+ httpConfigPath ,
145+ JSON . stringify (
146+ {
147+ mcpServers : {
148+ "test-http" : {
149+ type : "streamable-http" ,
150+ url : "http://localhost:3000/mcp" ,
151+ note : "Test HTTP server" ,
152+ } ,
153+ } ,
154+ } ,
155+ null ,
156+ 2 ,
157+ ) ,
158+ ) ;
159+
160+ const stdioConfigPath = path . join ( TEMP_DIR , "stdio-config.json" ) ;
161+ fs . writeFileSync (
162+ stdioConfigPath ,
163+ JSON . stringify (
164+ {
165+ mcpServers : {
166+ "test-stdio" : {
167+ type : "stdio" ,
168+ command : "npx" ,
169+ args : [ "@modelcontextprotocol/server-everything" ] ,
170+ env : {
171+ TEST_ENV : "test-value" ,
172+ } ,
173+ } ,
174+ } ,
175+ } ,
176+ null ,
177+ 2 ,
178+ ) ,
179+ ) ;
180+
181+ // Config without type field (backward compatibility)
182+ const legacyConfigPath = path . join ( TEMP_DIR , "legacy-config.json" ) ;
183+ fs . writeFileSync (
184+ legacyConfigPath ,
185+ JSON . stringify (
186+ {
187+ mcpServers : {
188+ "test-legacy" : {
189+ command : "npx" ,
190+ args : [ "@modelcontextprotocol/server-everything" ] ,
191+ env : {
192+ LEGACY_ENV : "legacy-value" ,
193+ } ,
194+ } ,
195+ } ,
196+ } ,
197+ null ,
198+ 2 ,
199+ ) ,
200+ ) ;
201+
123202// Function to run a basic test
124203async function runBasicTest ( testName , ...args ) {
125204 const outputFile = path . join (
@@ -649,6 +728,160 @@ async function runTests() {
649728 "debug" ,
650729 ) ;
651730
731+ console . log (
732+ `\n${ colors . YELLOW } === Running Config Transport Type Tests ===${ colors . NC } ` ,
733+ ) ;
734+
735+ // Test 25: Config with stdio transport type
736+ await runBasicTest (
737+ "config_stdio_type" ,
738+ "--config" ,
739+ stdioConfigPath ,
740+ "--server" ,
741+ "test-stdio" ,
742+ "--cli" ,
743+ "--method" ,
744+ "tools/list" ,
745+ ) ;
746+
747+ // Test 26: Config with SSE transport type (CLI mode) - expects connection error
748+ await runErrorTest (
749+ "config_sse_type_cli" ,
750+ "--config" ,
751+ sseConfigPath ,
752+ "--server" ,
753+ "test-sse" ,
754+ "--cli" ,
755+ "--method" ,
756+ "tools/list" ,
757+ ) ;
758+
759+ // Test 27: Config with streamable-http transport type (CLI mode) - expects connection error
760+ await runErrorTest (
761+ "config_http_type_cli" ,
762+ "--config" ,
763+ httpConfigPath ,
764+ "--server" ,
765+ "test-http" ,
766+ "--cli" ,
767+ "--method" ,
768+ "tools/list" ,
769+ ) ;
770+
771+ // Test 28: Legacy config without type field (backward compatibility)
772+ await runBasicTest (
773+ "config_legacy_no_type" ,
774+ "--config" ,
775+ legacyConfigPath ,
776+ "--server" ,
777+ "test-legacy" ,
778+ "--cli" ,
779+ "--method" ,
780+ "tools/list" ,
781+ ) ;
782+
783+ console . log (
784+ `\n${ colors . YELLOW } === Running Default Server Tests ===${ colors . NC } ` ,
785+ ) ;
786+
787+ // Create config with single server for auto-selection
788+ const singleServerConfigPath = path . join (
789+ TEMP_DIR ,
790+ "single-server-config.json" ,
791+ ) ;
792+ fs . writeFileSync (
793+ singleServerConfigPath ,
794+ JSON . stringify (
795+ {
796+ mcpServers : {
797+ "only-server" : {
798+ command : "npx" ,
799+ args : [ "@modelcontextprotocol/server-everything" ] ,
800+ } ,
801+ } ,
802+ } ,
803+ null ,
804+ 2 ,
805+ ) ,
806+ ) ;
807+
808+ // Create config with default-server
809+ const defaultServerConfigPath = path . join (
810+ TEMP_DIR ,
811+ "default-server-config.json" ,
812+ ) ;
813+ fs . writeFileSync (
814+ defaultServerConfigPath ,
815+ JSON . stringify (
816+ {
817+ mcpServers : {
818+ "default-server" : {
819+ command : "npx" ,
820+ args : [ "@modelcontextprotocol/server-everything" ] ,
821+ } ,
822+ "other-server" : {
823+ command : "node" ,
824+ args : [ "other.js" ] ,
825+ } ,
826+ } ,
827+ } ,
828+ null ,
829+ 2 ,
830+ ) ,
831+ ) ;
832+
833+ // Create config with multiple servers (no default)
834+ const multiServerConfigPath = path . join ( TEMP_DIR , "multi-server-config.json" ) ;
835+ fs . writeFileSync (
836+ multiServerConfigPath ,
837+ JSON . stringify (
838+ {
839+ mcpServers : {
840+ server1 : {
841+ command : "npx" ,
842+ args : [ "@modelcontextprotocol/server-everything" ] ,
843+ } ,
844+ server2 : {
845+ command : "node" ,
846+ args : [ "other.js" ] ,
847+ } ,
848+ } ,
849+ } ,
850+ null ,
851+ 2 ,
852+ ) ,
853+ ) ;
854+
855+ // Test 29: Config with single server auto-selection
856+ await runBasicTest (
857+ "single_server_auto_select" ,
858+ "--config" ,
859+ singleServerConfigPath ,
860+ "--cli" ,
861+ "--method" ,
862+ "tools/list" ,
863+ ) ;
864+
865+ // Test 30: Config with default-server should now require explicit selection (multiple servers)
866+ await runErrorTest (
867+ "default_server_requires_explicit_selection" ,
868+ "--config" ,
869+ defaultServerConfigPath ,
870+ "--cli" ,
871+ "--method" ,
872+ "tools/list" ,
873+ ) ;
874+
875+ // Test 31: Config with multiple servers and no default (should fail)
876+ await runErrorTest (
877+ "multi_server_no_default" ,
878+ "--config" ,
879+ multiServerConfigPath ,
880+ "--cli" ,
881+ "--method" ,
882+ "tools/list" ,
883+ ) ;
884+
652885 console . log (
653886 `\n${ colors . YELLOW } === Running HTTP Transport Tests ===${ colors . NC } ` ,
654887 ) ;
@@ -668,7 +901,7 @@ async function runTests() {
668901
669902 await new Promise ( ( resolve ) => setTimeout ( resolve , 3000 ) ) ;
670903
671- // Test 25 : HTTP transport inferred from URL ending with /mcp
904+ // Test 32 : HTTP transport inferred from URL ending with /mcp
672905 await runBasicTest (
673906 "http_transport_inferred" ,
674907 "http://127.0.0.1:3001/mcp" ,
@@ -677,7 +910,7 @@ async function runTests() {
677910 "tools/list" ,
678911 ) ;
679912
680- // Test 26 : HTTP transport with explicit --transport http flag
913+ // Test 33 : HTTP transport with explicit --transport http flag
681914 await runBasicTest (
682915 "http_transport_with_explicit_flag" ,
683916 "http://127.0.0.1:3001/mcp" ,
@@ -688,7 +921,7 @@ async function runTests() {
688921 "tools/list" ,
689922 ) ;
690923
691- // Test 27 : HTTP transport with suffix and --transport http flag
924+ // Test 34 : HTTP transport with suffix and --transport http flag
692925 await runBasicTest (
693926 "http_transport_with_explicit_flag_and_suffix" ,
694927 "http://127.0.0.1:3001/mcp" ,
@@ -699,7 +932,7 @@ async function runTests() {
699932 "tools/list" ,
700933 ) ;
701934
702- // Test 28 : SSE transport given to HTTP server (should fail)
935+ // Test 35 : SSE transport given to HTTP server (should fail)
703936 await runErrorTest (
704937 "sse_transport_given_to_http_server" ,
705938 "http://127.0.0.1:3001" ,
@@ -710,7 +943,7 @@ async function runTests() {
710943 "tools/list" ,
711944 ) ;
712945
713- // Test 29 : HTTP transport without URL (should fail)
946+ // Test 36 : HTTP transport without URL (should fail)
714947 await runErrorTest (
715948 "http_transport_without_url" ,
716949 "--transport" ,
@@ -720,7 +953,7 @@ async function runTests() {
720953 "tools/list" ,
721954 ) ;
722955
723- // Test 30 : SSE transport without URL (should fail)
956+ // Test 37 : SSE transport without URL (should fail)
724957 await runErrorTest (
725958 "sse_transport_without_url" ,
726959 "--transport" ,
0 commit comments