mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-24 06:45:21 +02:00
Let Everything's STDIO server use SDK's automatic log level handling (#2706)
- bump TS SDK to 1.18.0 * In src/everything/stdio.ts - remove logging related imports - remove custom log-level handling, now handled automatically by the SDK * In src/everything/everything.ts - remove console.log of sessionId
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -5818,7 +5818,7 @@
|
|||||||
"version": "0.6.2",
|
"version": "0.6.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.17.5",
|
"@modelcontextprotocol/sdk": "^1.18.0",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
"zod": "^3.23.8",
|
"zod": "^3.23.8",
|
||||||
"zod-to-json-schema": "^3.23.5"
|
"zod-to-json-schema": "^3.23.5"
|
||||||
@@ -5833,9 +5833,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"src/everything/node_modules/@modelcontextprotocol/sdk": {
|
"src/everything/node_modules/@modelcontextprotocol/sdk": {
|
||||||
"version": "1.17.5",
|
"version": "1.18.0",
|
||||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.17.5.tgz",
|
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.18.0.tgz",
|
||||||
"integrity": "sha512-QakrKIGniGuRVfWBdMsDea/dx1PNE739QJ7gCM41s9q+qaCYTHCdsIBXQVVXry3mfWAiaM9kT22Hyz53Uw8mfg==",
|
"integrity": "sha512-JvKyB6YwS3quM+88JPR0axeRgvdDu3Pv6mdZUy+w4qVkCzGgumb9bXG/TmtDRQv+671yaofVfXSQmFLlWU5qPQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^6.12.6",
|
"ajv": "^6.12.6",
|
||||||
|
|||||||
@@ -196,7 +196,6 @@ export const createServer = () => {
|
|||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(sessionId)
|
|
||||||
const maybeAppendSessionId = sessionId ? ` - SessionId ${sessionId}`: "";
|
const maybeAppendSessionId = sessionId ? ` - SessionId ${sessionId}`: "";
|
||||||
const messages: { level: LoggingLevel; data: string }[] = [
|
const messages: { level: LoggingLevel; data: string }[] = [
|
||||||
{ level: "debug", data: `Debug-level message${maybeAppendSessionId}` },
|
{ level: "debug", data: `Debug-level message${maybeAppendSessionId}` },
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
"start:streamableHttp": "node dist/streamableHttp.js"
|
"start:streamableHttp": "node dist/streamableHttp.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.17.5",
|
"@modelcontextprotocol/sdk": "^1.18.0",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
"zod": "^3.23.8",
|
"zod": "^3.23.8",
|
||||||
"zod-to-json-schema": "^3.23.5"
|
"zod-to-json-schema": "^3.23.5"
|
||||||
|
|||||||
@@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createServer } from "./everything.js";
|
import { createServer } from "./everything.js";
|
||||||
import {
|
|
||||||
LoggingLevel,
|
|
||||||
LoggingLevelSchema,
|
|
||||||
LoggingMessageNotification,
|
|
||||||
SetLevelRequestSchema
|
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
|
||||||
|
|
||||||
console.error('Starting default (STDIO) server...');
|
console.error('Starting default (STDIO) server...');
|
||||||
|
|
||||||
@@ -15,36 +9,6 @@ async function main() {
|
|||||||
const transport = new StdioServerTransport();
|
const transport = new StdioServerTransport();
|
||||||
const {server, cleanup, startNotificationIntervals} = createServer();
|
const {server, cleanup, startNotificationIntervals} = createServer();
|
||||||
|
|
||||||
// Currently, for STDIO servers, automatic log-level support is not available, as levels are tracked by sessionId.
|
|
||||||
// The listener will be set, so if the STDIO server advertises support for logging, and the client sends a setLevel
|
|
||||||
// request, it will be handled and thus not throw a "Method not found" error. However, the STDIO server will need to
|
|
||||||
// implement its own listener and level handling for now. This will be remediated in a future SDK version.
|
|
||||||
|
|
||||||
let logLevel: LoggingLevel = "debug";
|
|
||||||
server.setRequestHandler(SetLevelRequestSchema, async (request) => {
|
|
||||||
const { level } = request.params;
|
|
||||||
logLevel = level;
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
|
|
||||||
server.sendLoggingMessage = async (params: LoggingMessageNotification["params"], _: string|undefined): Promise<void> => {
|
|
||||||
const LOG_LEVEL_SEVERITY = new Map(
|
|
||||||
LoggingLevelSchema.options.map((level, index) => [level, index])
|
|
||||||
);
|
|
||||||
|
|
||||||
const isMessageIgnored = (level: LoggingLevel): boolean => {
|
|
||||||
const currentLevel = logLevel;
|
|
||||||
return (currentLevel)
|
|
||||||
? LOG_LEVEL_SEVERITY.get(level)! < LOG_LEVEL_SEVERITY.get(currentLevel)!
|
|
||||||
: false;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!isMessageIgnored(params.level)) {
|
|
||||||
return server.notification({method: "notifications/message", params})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
startNotificationIntervals();
|
startNotificationIntervals();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user