From f93911607b165c1e0b0f0a68b6ab9647b62adece Mon Sep 17 00:00:00 2001 From: cliffhall Date: Mon, 5 May 2025 13:09:38 -0400 Subject: [PATCH 1/4] Update `server-everything` to allow choosing the transport on the command line. # Run the default (stdio) server ```npx @modelcontextprotocol/server-everything``` # Or specify stdio explicitly ```npx @modelcontextprotocol/server-everything stdio``` # Run the SSE server ```npx @modelcontextprotocol/server-everything sse``` # Run the streamable HTTP server ```npx @modelcontextprotocol/server-everything streamableHttp``` * In src/everything/index.ts - refactor/extracted contents to stdio.ts - replaced with code that - Gets the single argument from the commandline as scriptName - switches on scriptName - imports the appropriate server script or outputs usage options - scripts run on import * In src/everything/stdio.ts - added console log "Starting default (STDIO) server..." * In src/everything/sse.ts - added console log "Starting SSE server..." * In src/everything/streamableHttp.ts - added console log "Starting Streamable HTTP server..." * This fixes #1594 --- src/everything/index.ts | 50 ++++++++++++++++++++------------ src/everything/sse.ts | 2 ++ src/everything/stdio.ts | 26 +++++++++++++++++ src/everything/streamableHttp.ts | 2 ++ 4 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 src/everything/stdio.ts diff --git a/src/everything/index.ts b/src/everything/index.ts index c0ab77a2da..801fe72165 100644 --- a/src/everything/index.ts +++ b/src/everything/index.ts @@ -1,23 +1,37 @@ #!/usr/bin/env node -import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; -import { createServer } from "./everything.js"; +// Parse command line arguments first +const args = process.argv.slice(2); +const scriptName = args[0] || 'stdio'; -async function main() { - const transport = new StdioServerTransport(); - const { server, cleanup } = createServer(); - - await server.connect(transport); - - // Cleanup on exit - process.on("SIGINT", async () => { - await cleanup(); - await server.close(); - process.exit(0); - }); +async function run() { + try { + // Dynamically import only the requested module to prevent all modules from initializing + switch (scriptName) { + case 'stdio': + // Import and run the default server + await import('./stdio.js'); + break; + case 'sse': + // Import and run the SSE server + await import('./sse.js'); + break; + case 'streamableHttp': + // Import and run the streamable HTTP server + await import('./streamableHttp.js'); + break; + default: + console.error(`Unknown script: ${scriptName}`); + console.log('Available scripts:'); + console.log('- stdio'); + console.log('- sse'); + console.log('- streamableHttp'); + process.exit(1); + } + } catch (error) { + console.error('Error running script:', error); + process.exit(1); + } } -main().catch((error) => { - console.error("Server error:", error); - process.exit(1); -}); +run(); diff --git a/src/everything/sse.ts b/src/everything/sse.ts index 7a02eb53e5..08d44654b3 100644 --- a/src/everything/sse.ts +++ b/src/everything/sse.ts @@ -2,6 +2,8 @@ import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js"; import express from "express"; import { createServer } from "./everything.js"; +console.log('Starting SSE server...'); + const app = express(); const { server, cleanup } = createServer(); diff --git a/src/everything/stdio.ts b/src/everything/stdio.ts new file mode 100644 index 0000000000..2c94fa356e --- /dev/null +++ b/src/everything/stdio.ts @@ -0,0 +1,26 @@ +#!/usr/bin/env node + +import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; +import { createServer } from "./everything.js"; + +console.log('Starting default (STDIO) server...'); + +async function main() { + const transport = new StdioServerTransport(); + const {server, cleanup} = createServer(); + + await server.connect(transport); + + // 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); +}); + diff --git a/src/everything/streamableHttp.ts b/src/everything/streamableHttp.ts index 3a87bc8332..2e4d52deda 100644 --- a/src/everything/streamableHttp.ts +++ b/src/everything/streamableHttp.ts @@ -4,6 +4,8 @@ import express, { Request, Response } from "express"; import { createServer } from "./everything.js"; import { randomUUID } from 'node:crypto'; +console.log('Starting Streamable HTTP server...'); + const app = express(); const { server, cleanup } = createServer(); From f06dc654ff65bd4bd814bd9b4b4aacfa2a13aae6 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Mon, 5 May 2025 13:33:25 -0400 Subject: [PATCH 2/4] Update `server-everything` to allow choosing the transport on the command line. * Update README.md --- src/everything/README.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/everything/README.md b/src/everything/README.md index 4d51de51a3..261ce03374 100644 --- a/src/everything/README.md +++ b/src/everything/README.md @@ -173,7 +173,7 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace } ``` -## Run with [HTTP+SSE Transport](https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse) (deprecated as of [2025-03-26](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports)) +## Running from source with [HTTP+SSE Transport](https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse) (deprecated as of [2025-03-26](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports)) ```shell cd src/everything @@ -181,10 +181,37 @@ npm install npm run start:sse ``` -## Run with [Streamable HTTP Transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) +## Run from source with [Streamable HTTP Transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) ```shell cd src/everything npm install npm run start:streamableHttp ``` + +## Running as an installed package +### Install +```shell +npm install -g @modelcontextprotocol/server-everything@latest +```` + +### Run the default (stdio) server +```shell +npx @modelcontextprotocol/server-everything +``` + +### Or specify stdio explicitly +```shell +npx @modelcontextprotocol/server-everything stdio +``` + +### Run the SSE server +```shell +npx @modelcontextprotocol/server-everything sse +``` + +### Run the streamable HTTP server +```shell +npx @modelcontextprotocol/server-everything streamableHttp +``` + From 69549cc8445ab9f4189c2c867b7b8f6cca2f8d78 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Tue, 6 May 2025 10:26:47 -0400 Subject: [PATCH 3/4] Update `server-everything` to use the latest version of the SDK * In stdio.ts - change console.log to console.error --- src/everything/stdio.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/everything/stdio.ts b/src/everything/stdio.ts index 2c94fa356e..a98fbc5371 100644 --- a/src/everything/stdio.ts +++ b/src/everything/stdio.ts @@ -3,7 +3,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { createServer } from "./everything.js"; -console.log('Starting default (STDIO) server...'); +console.error('Starting default (STDIO) server...'); async function main() { const transport = new StdioServerTransport(); From e30f30868fb3b1ba488c5a6ae09f60c64ebe5bc7 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Tue, 6 May 2025 10:27:49 -0400 Subject: [PATCH 4/4] Update `server-everything` to use the latest version of the SDK * In sse.ts & streamableHttp.ts - change console.log to console.error --- src/everything/sse.ts | 2 +- src/everything/streamableHttp.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/everything/sse.ts b/src/everything/sse.ts index 08d44654b3..928916c754 100644 --- a/src/everything/sse.ts +++ b/src/everything/sse.ts @@ -2,7 +2,7 @@ import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js"; import express from "express"; import { createServer } from "./everything.js"; -console.log('Starting SSE server...'); +console.error('Starting SSE server...'); const app = express(); diff --git a/src/everything/streamableHttp.ts b/src/everything/streamableHttp.ts index 2e4d52deda..e6486dfa44 100644 --- a/src/everything/streamableHttp.ts +++ b/src/everything/streamableHttp.ts @@ -4,7 +4,7 @@ import express, { Request, Response } from "express"; import { createServer } from "./everything.js"; import { randomUUID } from 'node:crypto'; -console.log('Starting Streamable HTTP server...'); +console.error('Starting Streamable HTTP server...'); const app = express();