Merge pull request #611 from antholeole/oleina/logging
initalize logging after connection
This commit is contained in:
commit
21bb00499f
3 changed files with 14 additions and 0 deletions
|
|
@ -18,6 +18,12 @@ export async function connect(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await client.connect(transport);
|
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) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to connect to MCP server: ${error instanceof Error ? error.message : String(error)}`,
|
`Failed to connect to MCP server: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,7 @@ const App = () => {
|
||||||
window.location.hash = "elicitations";
|
window.location.hash = "elicitations";
|
||||||
},
|
},
|
||||||
getRoots: () => rootsRef.current,
|
getRoots: () => rootsRef.current,
|
||||||
|
defaultLoggingLevel: logLevel,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import {
|
||||||
ToolListChangedNotificationSchema,
|
ToolListChangedNotificationSchema,
|
||||||
PromptListChangedNotificationSchema,
|
PromptListChangedNotificationSchema,
|
||||||
Progress,
|
Progress,
|
||||||
|
LoggingLevel,
|
||||||
ElicitRequestSchema,
|
ElicitRequestSchema,
|
||||||
} 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";
|
||||||
|
|
@ -72,6 +73,7 @@ interface UseConnectionOptions {
|
||||||
onElicitationRequest?: (request: any, resolve: any) => void;
|
onElicitationRequest?: (request: any, resolve: 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({
|
||||||
|
|
@ -90,6 +92,7 @@ export function useConnection({
|
||||||
onPendingRequest,
|
onPendingRequest,
|
||||||
onElicitationRequest,
|
onElicitationRequest,
|
||||||
getRoots,
|
getRoots,
|
||||||
|
defaultLoggingLevel,
|
||||||
}: UseConnectionOptions) {
|
}: UseConnectionOptions) {
|
||||||
const [connectionStatus, setConnectionStatus] =
|
const [connectionStatus, setConnectionStatus] =
|
||||||
useState<ConnectionStatus>("disconnected");
|
useState<ConnectionStatus>("disconnected");
|
||||||
|
|
@ -560,6 +563,10 @@ export function useConnection({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (capabilities?.logging && defaultLoggingLevel) {
|
||||||
|
await client.setLoggingLevel(defaultLoggingLevel);
|
||||||
|
}
|
||||||
|
|
||||||
if (onElicitationRequest) {
|
if (onElicitationRequest) {
|
||||||
client.setRequestHandler(ElicitRequestSchema, async (request) => {
|
client.setRequestHandler(ElicitRequestSchema, async (request) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue