Skip to content

Commit 2ba960c

Browse files
committed
In the Inspector, log messages from the server were not being displayed.
modelcontextprotocol/inspector#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
1 parent f09e674 commit 2ba960c

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/everything/everything.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ export const createServer = () => {
9999
);
100100

101101
let subscriptions: Set<string> = new Set();
102-
let updateInterval: NodeJS.Timeout | undefined;
102+
let subsUpdateInterval: NodeJS.Timeout | undefined;
103+
let logsUpdateInterval: NodeJS.Timeout | undefined;
103104

104105
// Set up update interval for subscribed resources
105-
updateInterval = setInterval(() => {
106+
subsUpdateInterval = setInterval(() => {
106107
for (const uri of subscriptions) {
107108
server.notification({
108109
method: "notifications/resources/updated",
@@ -111,6 +112,21 @@ export const createServer = () => {
111112
}
112113
}, 5000);
113114

115+
// Set up update interval for random log messages
116+
logsUpdateInterval = setInterval(() => {
117+
const messages = [
118+
{level: "info", data: "Information is good"},
119+
{level: "warning", data: "Warning is scary"},
120+
{level: "error", data: "Error is bad"},
121+
]
122+
server.notification({
123+
method: "notifications/message",
124+
params: messages[Math.floor(Math.random()*3)],
125+
});
126+
}, 15000);
127+
128+
129+
114130
// Helper method to request sampling from client
115131
const requestSampling = async (
116132
context: string,
@@ -451,7 +467,7 @@ export const createServer = () => {
451467

452468
if (name === ToolName.ANNOTATED_MESSAGE) {
453469
const { messageType, includeImage } = AnnotatedMessageSchema.parse(args);
454-
470+
455471
const content = [];
456472

457473
// Main message with different priorities/audiences based on type
@@ -511,7 +527,7 @@ export const createServer = () => {
511527
if (!resourceId) return { completion: { values: [] } };
512528

513529
// Filter resource IDs that start with the input value
514-
const values = EXAMPLE_COMPLETIONS.resourceId.filter(id =>
530+
const values = EXAMPLE_COMPLETIONS.resourceId.filter(id =>
515531
id.startsWith(argument.value)
516532
);
517533
return { completion: { values, hasMore: false, total: values.length } };
@@ -522,7 +538,7 @@ export const createServer = () => {
522538
const completions = EXAMPLE_COMPLETIONS[argument.name as keyof typeof EXAMPLE_COMPLETIONS];
523539
if (!completions) return { completion: { values: [] } };
524540

525-
const values = completions.filter(value =>
541+
const values = completions.filter(value =>
526542
value.startsWith(argument.value)
527543
);
528544
return { completion: { values, hasMore: false, total: values.length } };
@@ -548,9 +564,8 @@ export const createServer = () => {
548564
});
549565

550566
const cleanup = async () => {
551-
if (updateInterval) {
552-
clearInterval(updateInterval);
553-
}
567+
if (subsUpdateInterval) clearInterval(subsUpdateInterval);
568+
if (logsUpdateInterval) clearInterval(logsUpdateInterval);
554569
};
555570

556571
return { server, cleanup };

0 commit comments

Comments
 (0)