Skip to content

Commit 21bb004

Browse files
authored
Merge pull request #611 from antholeole/oleina/logging
initalize logging after connection
2 parents aba186c + eec20ff commit 21bb004

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

cli/src/client/connection.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export async function connect(
1818
): Promise<void> {
1919
try {
2020
await client.connect(transport);
21+
22+
if (client.getServerCapabilities()?.logging) {
23+
// default logging level is undefined in the spec, but the user of the
24+
// inspector most likely wants debug.
25+
await client.setLoggingLevel("debug");
26+
}
2127
} catch (error) {
2228
throw new Error(
2329
`Failed to connect to MCP server: ${error instanceof Error ? error.message : String(error)}`,

client/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ const App = () => {
260260
window.location.hash = "elicitations";
261261
},
262262
getRoots: () => rootsRef.current,
263+
defaultLoggingLevel: logLevel,
263264
});
264265

265266
useEffect(() => {

client/src/lib/hooks/useConnection.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ToolListChangedNotificationSchema,
2929
PromptListChangedNotificationSchema,
3030
Progress,
31+
LoggingLevel,
3132
ElicitRequestSchema,
3233
} from "@modelcontextprotocol/sdk/types.js";
3334
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
@@ -72,6 +73,7 @@ interface UseConnectionOptions {
7273
onElicitationRequest?: (request: any, resolve: any) => void;
7374
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7475
getRoots?: () => any[];
76+
defaultLoggingLevel?: LoggingLevel;
7577
}
7678

7779
export function useConnection({
@@ -90,6 +92,7 @@ export function useConnection({
9092
onPendingRequest,
9193
onElicitationRequest,
9294
getRoots,
95+
defaultLoggingLevel,
9396
}: UseConnectionOptions) {
9497
const [connectionStatus, setConnectionStatus] =
9598
useState<ConnectionStatus>("disconnected");
@@ -560,6 +563,10 @@ export function useConnection({
560563
});
561564
}
562565

566+
if (capabilities?.logging && defaultLoggingLevel) {
567+
await client.setLoggingLevel(defaultLoggingLevel);
568+
}
569+
563570
if (onElicitationRequest) {
564571
client.setRequestHandler(ElicitRequestSchema, async (request) => {
565572
return new Promise((resolve) => {

0 commit comments

Comments
 (0)