initalize logging for UI

This commit is contained in:
oleina 2025-07-11 11:18:01 -07:00
commit 925d11a91d
2 changed files with 8 additions and 0 deletions

View file

@ -204,6 +204,7 @@ const App = () => {
]); ]);
}, },
getRoots: () => rootsRef.current, getRoots: () => rootsRef.current,
defaultLoggingLevel: "debug"
}); });
useEffect(() => { useEffect(() => {

View file

@ -28,6 +28,7 @@ import {
ToolListChangedNotificationSchema, ToolListChangedNotificationSchema,
PromptListChangedNotificationSchema, PromptListChangedNotificationSchema,
Progress, Progress,
LoggingLevel,
} from "@modelcontextprotocol/sdk/types.js"; } from "@modelcontextprotocol/sdk/types.js";
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js"; import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
import { useState } from "react"; import { useState } from "react";
@ -63,6 +64,7 @@ interface UseConnectionOptions {
onPendingRequest?: (request: any, resolve: any, reject: any) => void; onPendingRequest?: (request: any, resolve: any, reject: any) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
getRoots?: () => any[]; getRoots?: () => any[];
defaultLoggingLevel?: LoggingLevel,
} }
export function useConnection({ export function useConnection({
@ -78,6 +80,7 @@ export function useConnection({
onStdErrNotification, onStdErrNotification,
onPendingRequest, onPendingRequest,
getRoots, getRoots,
defaultLoggingLevel,
}: UseConnectionOptions) { }: UseConnectionOptions) {
const [connectionStatus, setConnectionStatus] = const [connectionStatus, setConnectionStatus] =
useState<ConnectionStatus>("disconnected"); useState<ConnectionStatus>("disconnected");
@ -521,6 +524,10 @@ export function useConnection({
}); });
} }
if (capabilities?.logging && defaultLoggingLevel) {
await client.setLoggingLevel(defaultLoggingLevel);
}
setMcpClient(client); setMcpClient(client);
setConnectionStatus("connected"); setConnectionStatus("connected");
} catch (e) { } catch (e) {