mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-22 16:55:40 +02:00
- add .idea/ for Jetbrains IDEs
* in everything.ts
- remove import of SetLevelRequestSchema
- remove logLevel var
- add sessionId var
- in startNotificationIntervals function
- add optional sid argument
- set sessionId to sid
- define messages to be sent, adding sessionId if present
- remove setRequestHandler call for SetLevelRequestSchema
- replace server.notification calls that sent "notifications/message" objects with calls to server.sendLoggingMessage, passing just the parameters and sessionId.
* In package.json & package-lock.json
- bump TS SDK version to 1.17.5
* In sse.ts, pass transport.sessionId to startNotificationIntervals call
* In stdio.ts
- destructure startNotificationIntervals from createServer call
- implement custom logging request handler and server.sendLoggingMessage implementation, as a
workaround for the fact that the SDK's automatic log level handling currently only tracks requested log level by session id. This will be fixed in a followup PR for the SDK
- call the startNotificationIntervals function after connecting the transport to the server
* In streamableHttp.ts
- destructure startNotificationIntervals from createServer call
- call startNotificationIntervals passing the transport.sessionId after connecting the transport to the server
64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
import { createServer } from "./everything.js";
|
|
import {
|
|
LoggingLevel,
|
|
LoggingLevelSchema,
|
|
LoggingMessageNotification,
|
|
SetLevelRequestSchema
|
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
|
|
console.error('Starting default (STDIO) server...');
|
|
|
|
async function main() {
|
|
const transport = new StdioServerTransport();
|
|
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);
|
|
startNotificationIntervals();
|
|
|
|
// Cleanup on exit
|
|
process.on("SIGINT", async () => {
|
|
await cleanup();
|
|
await server.close();
|
|
process.exit(0);
|
|
});
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error("Server error:", error);
|
|
process.exit(1);
|
|
});
|
|
|