diff --git a/cli/src/client/connection.ts b/cli/src/client/connection.ts index 931f803d..dcbe8e51 100644 --- a/cli/src/client/connection.ts +++ b/cli/src/client/connection.ts @@ -18,6 +18,12 @@ export async function connect( ): Promise { try { await client.connect(transport); + + if (client.getServerCapabilities()?.logging) { + // default logging level is undefined in the spec, but the user of the + // inspector most likely wants debug. + await client.setLoggingLevel("debug"); + } } catch (error) { throw new Error( `Failed to connect to MCP server: ${error instanceof Error ? error.message : String(error)}`, diff --git a/client/src/App.tsx b/client/src/App.tsx index cff51b4f..c80cfd35 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -204,6 +204,7 @@ const App = () => { ]); }, getRoots: () => rootsRef.current, + defaultLoggingLevel: logLevel, }); useEffect(() => { diff --git a/client/src/lib/hooks/useConnection.ts b/client/src/lib/hooks/useConnection.ts index 9009e698..b32552f4 100644 --- a/client/src/lib/hooks/useConnection.ts +++ b/client/src/lib/hooks/useConnection.ts @@ -28,6 +28,7 @@ import { ToolListChangedNotificationSchema, PromptListChangedNotificationSchema, Progress, + LoggingLevel, } from "@modelcontextprotocol/sdk/types.js"; import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js"; import { useState } from "react"; @@ -63,6 +64,7 @@ interface UseConnectionOptions { onPendingRequest?: (request: any, resolve: any, reject: any) => void; // eslint-disable-next-line @typescript-eslint/no-explicit-any getRoots?: () => any[]; + defaultLoggingLevel?: LoggingLevel; } export function useConnection({ @@ -78,6 +80,7 @@ export function useConnection({ onStdErrNotification, onPendingRequest, getRoots, + defaultLoggingLevel, }: UseConnectionOptions) { const [connectionStatus, setConnectionStatus] = useState("disconnected"); @@ -521,6 +524,10 @@ export function useConnection({ }); } + if (capabilities?.logging && defaultLoggingLevel) { + await client.setLoggingLevel(defaultLoggingLevel); + } + setMcpClient(client); setConnectionStatus("connected"); } catch (e) {