Add support for --header flags in MCP Inspector CLI
- Add --header option to both wrapper CLI (cli.ts) and main CLI (index.ts) - Support multiple headers with "HeaderName: Value" format validation - Pass headers to HTTP and SSE transports via requestInit.headers - Add parseHeaderPair function for proper header parsing - Fix output truncation issue by removing forced process.exit(0) - Update types to include headers in Args and TransportOptions Usage: --header "Authorization: Bearer token" --header "X-Custom: value"
This commit is contained in:
parent
16edf53794
commit
77d4963b8a
1 changed files with 112 additions and 9 deletions
|
|
@ -12,6 +12,7 @@ export type TransportOptions = {
|
|||
command?: string;
|
||||
args?: string[];
|
||||
url?: string;
|
||||
headers?: Record<string, string>;
|
||||
};
|
||||
|
||||
function createStdioTransport(options: TransportOptions): Transport {
|
||||
|
|
@ -64,11 +65,25 @@ export function createTransport(options: TransportOptions): Transport {
|
|||
const url = new URL(options.url);
|
||||
|
||||
if (transportType === "sse") {
|
||||
return new SSEClientTransport(url);
|
||||
const transportOptions = options.headers
|
||||
? {
|
||||
requestInit: {
|
||||
headers: options.headers,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
return new SSEClientTransport(url, transportOptions);
|
||||
}
|
||||
|
||||
if (transportType === "http") {
|
||||
return new StreamableHTTPClientTransport(url);
|
||||
const transportOptions = options.headers
|
||||
? {
|
||||
requestInit: {
|
||||
headers: options.headers,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
return new StreamableHTTPClientTransport(url, transportOptions);
|
||||
}
|
||||
|
||||
throw new Error(`Unsupported transport type: ${transportType}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue