In the Inspector, log messages from the server were not being displayed.

https://github.com/modelcontextprotocol/inspector/issues/184

The user who created the issue provided a python test server to send dummy messages, but I expected that the 'everything server' would be exercising this capability, but it wasn't. So I decided to add that functionality at the same time as fixing the inspector.

In src/everything/everything.ts
 - add logsUpdateInterval
 - use setInterval to send a random-leveled log message every 15 seconds
This commit is contained in:
cliffhall 2025-03-13 15:23:52 -04:00
commit 2ba960ca13

View file

@ -99,10 +99,11 @@ export const createServer = () => {
);
let subscriptions: Set<string> = new Set();
let updateInterval: NodeJS.Timeout | undefined;
let subsUpdateInterval: NodeJS.Timeout | undefined;
let logsUpdateInterval: NodeJS.Timeout | undefined;
// Set up update interval for subscribed resources
updateInterval = setInterval(() => {
subsUpdateInterval = setInterval(() => {
for (const uri of subscriptions) {
server.notification({
method: "notifications/resources/updated",
@ -111,6 +112,21 @@ export const createServer = () => {
}
}, 5000);
// Set up update interval for random log messages
logsUpdateInterval = setInterval(() => {
const messages = [
{level: "info", data: "Information is good"},
{level: "warning", data: "Warning is scary"},
{level: "error", data: "Error is bad"},
]
server.notification({
method: "notifications/message",
params: messages[Math.floor(Math.random()*3)],
});
}, 15000);
// Helper method to request sampling from client
const requestSampling = async (
context: string,
@ -548,9 +564,8 @@ export const createServer = () => {
});
const cleanup = async () => {
if (updateInterval) {
clearInterval(updateInterval);
}
if (subsUpdateInterval) clearInterval(subsUpdateInterval);
if (logsUpdateInterval) clearInterval(logsUpdateInterval);
};
return { server, cleanup };