From 9655d471f7df25fc2c48e4c8a34bac864beb8347 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Mon, 14 Apr 2025 17:13:11 -0400 Subject: [PATCH] Add periodic stderr messages. In everything.ts - add a 10 second interval for sending 'notifications/stderr' messages to the client This was created in order to test the display and clearing of stderr messages in the client. - see https://github.com/modelcontextprotocol/inspector/pull/286 --- src/everything/everything.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/everything/everything.ts b/src/everything/everything.ts index cee1e731..d0a2ffb3 100644 --- a/src/everything/everything.ts +++ b/src/everything/everything.ts @@ -114,8 +114,9 @@ export const createServer = () => { let subscriptions: Set = new Set(); let subsUpdateInterval: NodeJS.Timeout | undefined; - // Set up update interval for subscribed resources + let stdErrUpdateInterval: NodeJS.Timeout | undefined; + // Set up update interval for subscribed resources subsUpdateInterval = setInterval(() => { for (const uri of subscriptions) { server.notification({ @@ -154,6 +155,19 @@ export const createServer = () => { server.notification(message); }, 15000); + + // Set up update interval for stderr messages + stdErrUpdateInterval = setInterval(() => { + const shortTimestamp = new Date().toLocaleTimeString([], { + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }); server.notification({ + method: "notifications/stderr", + params: { content: `${shortTimestamp}: A stderr message` }, + }); + }, 10000); + // Helper method to request sampling from client const requestSampling = async ( context: string, @@ -676,6 +690,7 @@ export const createServer = () => { const cleanup = async () => { if (subsUpdateInterval) clearInterval(subsUpdateInterval); if (logsUpdateInterval) clearInterval(logsUpdateInterval); + if (stdErrUpdateInterval) clearInterval(stdErrUpdateInterval); }; return { server, cleanup };