First pass at pulling the v1.5 CLI, TUI, and Launcher clients into v2.
This commit is contained in:
parent
d5f12b2a82
commit
467b01edd6
5 changed files with 24043 additions and 203 deletions
|
|
@ -1 +1 @@
|
|||
export { silentLogger } from "./logger.js";
|
||||
export { silentLogger, type InspectorLogger } from "./logger.js";
|
||||
|
|
|
|||
|
|
@ -1,7 +1,39 @@
|
|||
import pino from "pino";
|
||||
import type { Bindings, LevelWithSilentOrString, LogFn } from "pino";
|
||||
|
||||
/**
|
||||
* Silent logger for use when no logger is injected. Satisfies pino.Logger,
|
||||
* does not output anything. InspectorClient uses this as the default.
|
||||
* Logging surface InspectorClient uses. Real pino loggers satisfy this;
|
||||
* the default silent logger implements it without opening a stream.
|
||||
*/
|
||||
export const silentLogger = pino({ level: "silent" });
|
||||
export interface InspectorLogger {
|
||||
level: LevelWithSilentOrString;
|
||||
fatal: LogFn;
|
||||
error: LogFn;
|
||||
warn: LogFn;
|
||||
info: LogFn;
|
||||
debug: LogFn;
|
||||
trace: LogFn;
|
||||
silent: LogFn;
|
||||
child(bindings?: Bindings): InspectorLogger;
|
||||
}
|
||||
|
||||
const noop: LogFn = () => {};
|
||||
|
||||
function createSilentLogger(): InspectorLogger {
|
||||
const logger: InspectorLogger = {
|
||||
level: "silent",
|
||||
fatal: noop,
|
||||
error: noop,
|
||||
warn: noop,
|
||||
info: noop,
|
||||
debug: noop,
|
||||
trace: noop,
|
||||
silent: noop,
|
||||
child: () => logger,
|
||||
};
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default logger when none is injected. No-op at all levels; no SonicBoom stream.
|
||||
*/
|
||||
export const silentLogger: InspectorLogger = createSilentLogger();
|
||||
|
|
|
|||
|
|
@ -119,8 +119,7 @@ import {
|
|||
} from "./urlElicitation.js";
|
||||
import type { AuthGuidedState, OAuthStep } from "../auth/types.js";
|
||||
import type { OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||
import type pino from "pino";
|
||||
import { silentLogger } from "../logging/logger.js";
|
||||
import { silentLogger, type InspectorLogger } from "../logging/logger.js";
|
||||
import { createFetchTracker } from "./fetchTracking.js";
|
||||
import { OAuthManager, type OAuthManagerConfig } from "./oauthManager.js";
|
||||
|
||||
|
|
@ -197,7 +196,7 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
private receiverTaskRecords: Map<string, ReceiverTaskRecord> = new Map();
|
||||
// OAuth support (config owned by oauthManager; client delegates and uses !!oauthManager for "is OAuth configured")
|
||||
private oauthManager: OAuthManager | null = null;
|
||||
private logger: pino.Logger;
|
||||
private logger: InspectorLogger;
|
||||
private transportClientFactory: CreateTransport;
|
||||
private fetchFn?: typeof fetch;
|
||||
private effectiveAuthFetch: typeof fetch;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { existsSync, readFileSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
import { getDefaultMcpConfigPath } from "../../storage/store-io.js";
|
||||
import type {
|
||||
MCPConfig,
|
||||
MCPServerConfig,
|
||||
|
|
@ -211,6 +212,24 @@ function applyOverrides(
|
|||
|
||||
export type ResolveServerConfigsMode = "single" | "multi";
|
||||
|
||||
export function hasAdHocServerOptions(options: ServerConfigOptions): boolean {
|
||||
return (
|
||||
(options.target != null && options.target.length > 0) ||
|
||||
Boolean(options.transport) ||
|
||||
Boolean(options.serverUrl?.trim())
|
||||
);
|
||||
}
|
||||
|
||||
/** When no --config and no ad-hoc target, use ~/.mcp-inspector/mcp.json (same as web). */
|
||||
export function withDefaultConfigPath(
|
||||
options: ServerConfigOptions,
|
||||
): ServerConfigOptions {
|
||||
if (options.configPath?.trim() || hasAdHocServerOptions(options)) {
|
||||
return options;
|
||||
}
|
||||
return { ...options, configPath: getDefaultMcpConfigPath() };
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves server config(s) from options and mode. Used by all runners.
|
||||
* Single mode: one config (from file + overrides, or from args).
|
||||
|
|
@ -220,11 +239,9 @@ export function resolveServerConfigs(
|
|||
options: ServerConfigOptions,
|
||||
mode: ResolveServerConfigsMode,
|
||||
): MCPServerConfig[] {
|
||||
options = withDefaultConfigPath(options);
|
||||
const hasConfigPath = Boolean(options.configPath?.trim());
|
||||
const hasAdHoc =
|
||||
(options.target && options.target.length > 0) ||
|
||||
Boolean(options.transport) ||
|
||||
Boolean(options.serverUrl);
|
||||
const hasAdHoc = hasAdHocServerOptions(options);
|
||||
|
||||
if (mode === "single") {
|
||||
if (hasConfigPath && options.serverName) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import type {
|
|||
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
||||
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
||||
import type pino from "pino";
|
||||
import type { InspectorLogger } from "../logging/logger.js";
|
||||
import type { JsonValue } from "../json/jsonUtils.js";
|
||||
import type {
|
||||
OAuthNavigation,
|
||||
|
|
@ -524,7 +524,7 @@ export interface InspectorClientEnvironment {
|
|||
* - Node: pino file logger
|
||||
* - Browser: createRemoteLogger
|
||||
*/
|
||||
logger?: pino.Logger;
|
||||
logger?: InspectorLogger;
|
||||
|
||||
/**
|
||||
* OAuth environment components
|
||||
|
|
|
|||
Loading…
Reference in a new issue