@@ -29,9 +29,13 @@ type Args = {
29
29
logLevel ?: LogLevel ;
30
30
toolName ?: string ;
31
31
toolArg ?: Record < string , string > ;
32
+ transport ?: "sse" | "stdio" | "http" ;
32
33
} ;
33
34
34
- function createTransportOptions ( target : string [ ] ) : TransportOptions {
35
+ function createTransportOptions (
36
+ target : string [ ] ,
37
+ transport ?: "sse" | "stdio" | "http" ,
38
+ ) : TransportOptions {
35
39
if ( target . length === 0 ) {
36
40
throw new Error (
37
41
"Target is required. Specify a URL or a command to execute." ,
@@ -50,16 +54,38 @@ function createTransportOptions(target: string[]): TransportOptions {
50
54
throw new Error ( "Arguments cannot be passed to a URL-based MCP server." ) ;
51
55
}
52
56
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
+
53
79
return {
54
- transportType : isUrl ? "sse" : "stdio" ,
80
+ transportType,
55
81
command : isUrl ? undefined : command ,
56
82
args : isUrl ? undefined : commandArgs ,
57
83
url : isUrl ? command : undefined ,
58
84
} ;
59
85
}
60
86
61
87
async function callMethod ( args : Args ) : Promise < void > {
62
- const transportOptions = createTransportOptions ( args . target ) ;
88
+ const transportOptions = createTransportOptions ( args . target , args . transport ) ;
63
89
const transport = createTransport ( transportOptions ) ;
64
90
const client = new Client ( {
65
91
name : "inspector-cli" ,
@@ -214,6 +240,22 @@ function parseArgs(): Args {
214
240
215
241
return value as LogLevel ;
216
242
} ,
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
+ } ,
217
259
) ;
218
260
219
261
// Parse only the arguments before --
0 commit comments