@@ -29,9 +29,13 @@ type Args = {
2929 logLevel ?: LogLevel ;
3030 toolName ?: string ;
3131 toolArg ?: Record < string , string > ;
32+ transport ?: "sse" | "stdio" | "http" ;
3233} ;
3334
34- function createTransportOptions ( target : string [ ] ) : TransportOptions {
35+ function createTransportOptions (
36+ target : string [ ] ,
37+ transport ?: "sse" | "stdio" | "http" ,
38+ ) : TransportOptions {
3539 if ( target . length === 0 ) {
3640 throw new Error (
3741 "Target is required. Specify a URL or a command to execute." ,
@@ -50,16 +54,38 @@ function createTransportOptions(target: string[]): TransportOptions {
5054 throw new Error ( "Arguments cannot be passed to a URL-based MCP server." ) ;
5155 }
5256
57+ let transportType : "sse" | "stdio" | "http" ;
58+ if ( transport ) {
59+ if ( ! isUrl && transport !== "stdio" ) {
60+ throw new Error ( "Only stdio transport can be used with local commands." ) ;
61+ }
62+ if ( isUrl && transport === "stdio" ) {
63+ throw new Error ( "stdio transport cannot be used with URLs." ) ;
64+ }
65+ transportType = transport ;
66+ } else if ( isUrl ) {
67+ const url = new URL ( command ) ;
68+ if ( url . pathname . endsWith ( "/mcp" ) ) {
69+ transportType = "http" ;
70+ } else if ( url . pathname . endsWith ( "/sse" ) ) {
71+ transportType = "sse" ;
72+ } else {
73+ transportType = "sse" ;
74+ }
75+ } else {
76+ transportType = "stdio" ;
77+ }
78+
5379 return {
54- transportType : isUrl ? "sse" : "stdio" ,
80+ transportType,
5581 command : isUrl ? undefined : command ,
5682 args : isUrl ? undefined : commandArgs ,
5783 url : isUrl ? command : undefined ,
5884 } ;
5985}
6086
6187async function callMethod ( args : Args ) : Promise < void > {
62- const transportOptions = createTransportOptions ( args . target ) ;
88+ const transportOptions = createTransportOptions ( args . target , args . transport ) ;
6389 const transport = createTransport ( transportOptions ) ;
6490 const client = new Client ( {
6591 name : "inspector-cli" ,
@@ -214,6 +240,22 @@ function parseArgs(): Args {
214240
215241 return value as LogLevel ;
216242 } ,
243+ )
244+ //
245+ // Transport options
246+ //
247+ . option (
248+ "--transport <type>" ,
249+ "Transport type (sse, http, or stdio). Auto-detected from URL: /mcp → http, /sse → sse, commands → stdio" ,
250+ ( value : string ) => {
251+ const validTransports = [ "sse" , "http" , "stdio" ] ;
252+ if ( ! validTransports . includes ( value ) ) {
253+ throw new Error (
254+ `Invalid transport type: ${ value } . Valid types are: ${ validTransports . join ( ", " ) } ` ,
255+ ) ;
256+ }
257+ return value as "sse" | "http" | "stdio" ;
258+ } ,
217259 ) ;
218260
219261 // Parse only the arguments before --
0 commit comments