mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-18 08:03:26 +02:00
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
This commit is contained in:
@@ -114,8 +114,9 @@ export const createServer = () => {
|
|||||||
|
|
||||||
let subscriptions: Set<string> = new Set();
|
let subscriptions: Set<string> = new Set();
|
||||||
let subsUpdateInterval: NodeJS.Timeout | undefined;
|
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(() => {
|
subsUpdateInterval = setInterval(() => {
|
||||||
for (const uri of subscriptions) {
|
for (const uri of subscriptions) {
|
||||||
server.notification({
|
server.notification({
|
||||||
@@ -154,6 +155,19 @@ export const createServer = () => {
|
|||||||
server.notification(message);
|
server.notification(message);
|
||||||
}, 15000);
|
}, 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
|
// Helper method to request sampling from client
|
||||||
const requestSampling = async (
|
const requestSampling = async (
|
||||||
context: string,
|
context: string,
|
||||||
@@ -676,6 +690,7 @@ export const createServer = () => {
|
|||||||
const cleanup = async () => {
|
const cleanup = async () => {
|
||||||
if (subsUpdateInterval) clearInterval(subsUpdateInterval);
|
if (subsUpdateInterval) clearInterval(subsUpdateInterval);
|
||||||
if (logsUpdateInterval) clearInterval(logsUpdateInterval);
|
if (logsUpdateInterval) clearInterval(logsUpdateInterval);
|
||||||
|
if (stdErrUpdateInterval) clearInterval(stdErrUpdateInterval);
|
||||||
};
|
};
|
||||||
|
|
||||||
return { server, cleanup };
|
return { server, cleanup };
|
||||||
|
|||||||
Reference in New Issue
Block a user