Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions src/everything/everything.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,6 @@ export const createServer = () => {
let subsUpdateInterval: NodeJS.Timeout | undefined;
let stdErrUpdateInterval: NodeJS.Timeout | undefined;

// Set up update interval for subscribed resources
subsUpdateInterval = setInterval(() => {
for (const uri of subscriptions) {
server.notification({
method: "notifications/resources/updated",
params: { uri },
});
}
}, 10000);

let logLevel: LoggingLevel = "debug";
let logsUpdateInterval: NodeJS.Timeout | undefined;
const messages = [
Expand All @@ -198,15 +188,30 @@ export const createServer = () => {
return messageLevel < currentLevel;
};

// Set up update interval for random log messages
logsUpdateInterval = setInterval(() => {
let message = {
method: "notifications/message",
params: messages[Math.floor(Math.random() * messages.length)],
};
if (!isMessageIgnored(message.params.level as LoggingLevel))
server.notification(message);
}, 20000);
// Function to start notification intervals when a client connects
const startNotificationIntervals = () => {
if (!subsUpdateInterval) {
subsUpdateInterval = setInterval(() => {
for (const uri of subscriptions) {
server.notification({
method: "notifications/resources/updated",
params: { uri },
});
}
}, 10000);
}

if (!logsUpdateInterval) {
logsUpdateInterval = setInterval(() => {
let message = {
method: "notifications/message",
params: messages[Math.floor(Math.random() * messages.length)],
};
if (!isMessageIgnored(message.params.level as LoggingLevel))
server.notification(message);
}, 20000);
}
};



Expand Down Expand Up @@ -874,7 +879,7 @@ export const createServer = () => {
if (stdErrUpdateInterval) clearInterval(stdErrUpdateInterval);
};

return { server, cleanup };
return { server, cleanup, startNotificationIntervals };
};

const MCP_TINY_IMAGE =
Expand Down
5 changes: 4 additions & 1 deletion src/everything/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const transports: Map<string, SSEServerTransport> = new Map<string, SSEServerTra

app.get("/sse", async (req, res) => {
let transport: SSEServerTransport;
const { server, cleanup } = createServer();
const { server, cleanup, startNotificationIntervals } = createServer();

if (req?.query?.sessionId) {
const sessionId = (req?.query?.sessionId as string);
Expand All @@ -25,6 +25,9 @@ app.get("/sse", async (req, res) => {
await server.connect(transport);
console.error("Client Connected: ", transport.sessionId);

// Start notification intervals after client connects
startNotificationIntervals();

// Handle close of connection
server.onclose = async () => {
console.error("Client Disconnected: ", transport.sessionId);
Expand Down