@modelcontextprotocol/server-everything 0.6.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +140 -76
  2. package/dist/docs/architecture.md +45 -0
  3. package/dist/docs/extension.md +25 -0
  4. package/dist/docs/features.md +99 -0
  5. package/dist/docs/how-it-works.md +60 -0
  6. package/dist/docs/instructions.md +44 -0
  7. package/dist/docs/startup.md +71 -0
  8. package/dist/docs/structure.md +246 -0
  9. package/dist/index.js +73 -16
  10. package/dist/prompts/args.js +34 -0
  11. package/dist/prompts/completions.js +52 -0
  12. package/dist/prompts/index.js +15 -0
  13. package/dist/prompts/resource.js +61 -0
  14. package/dist/prompts/simple.js +23 -0
  15. package/dist/resources/files.js +91 -0
  16. package/dist/resources/index.js +38 -0
  17. package/dist/resources/minted.js +119 -0
  18. package/dist/resources/session.js +62 -0
  19. package/dist/resources/subscriptions.js +66 -0
  20. package/dist/resources/templates.js +167 -0
  21. package/dist/server/context.js +47 -0
  22. package/dist/server/index.js +153 -0
  23. package/dist/server/logging.js +43 -0
  24. package/dist/server/roots.js +49 -0
  25. package/dist/server/tasks.js +295 -0
  26. package/dist/tools/echo.js +35 -0
  27. package/dist/tools/get-annotated-message.js +89 -0
  28. package/dist/tools/get-env.js +34 -0
  29. package/dist/tools/get-header-params.js +95 -0
  30. package/dist/tools/get-resource-links.js +68 -0
  31. package/dist/tools/get-resource-reference.js +81 -0
  32. package/dist/tools/get-roots-list.js +76 -0
  33. package/dist/tools/get-structured-content.js +78 -0
  34. package/dist/tools/get-sum.js +46 -0
  35. package/dist/tools/get-tiny-image.js +47 -0
  36. package/dist/tools/gzip-file-as-resource.js +213 -0
  37. package/dist/tools/index.js +110 -0
  38. package/dist/tools/simulate-research-query.js +216 -0
  39. package/dist/tools/toggle-simulated-logging.js +60 -0
  40. package/dist/tools/toggle-subscriber-updates.js +60 -0
  41. package/dist/tools/trigger-elicitation-request-async.js +122 -0
  42. package/dist/tools/trigger-elicitation-request.js +223 -0
  43. package/dist/tools/trigger-list-changed.js +57 -0
  44. package/dist/tools/trigger-log-messages.js +60 -0
  45. package/dist/tools/trigger-long-running-operation.js +65 -0
  46. package/dist/tools/trigger-multi-step-elicitation.js +125 -0
  47. package/dist/tools/trigger-resource-update.js +52 -0
  48. package/dist/tools/trigger-sampling-request-async.js +110 -0
  49. package/dist/tools/trigger-sampling-request.js +83 -0
  50. package/dist/tools/trigger-url-elicitation.js +206 -0
  51. package/dist/transports/in-memory-event-store.js +44 -0
  52. package/dist/transports/listen.js +36 -0
  53. package/dist/transports/sse.js +112 -0
  54. package/dist/transports/stdio.js +68 -0
  55. package/dist/transports/streamableHttp.js +326 -0
  56. package/dist/version.js +35 -0
  57. package/package.json +39 -13
  58. package/dist/everything.js +0 -361
  59. package/dist/sse.js +0 -24
@@ -0,0 +1,326 @@
1
+ // The Streamable HTTP transport manager: one `/mcp` endpoint serving both
2
+ // protocol eras (#4852).
3
+ //
4
+ // - 2026-07-28 traffic (a request carrying the per-request `_meta` envelope)
5
+ // goes to the SDK's `createMcpHandler`, which builds a fresh server per
6
+ // request: no sessions, `server/discover` instead of `initialize`, change
7
+ // notifications on `subscriptions/listen` streams published through the
8
+ // handler's bus, and input requests in-band (`input_required`).
9
+ // - 2025-era traffic keeps the sessionful wiring it had: one server per
10
+ // session, created on the initialize POST, with GET for the standalone SSE
11
+ // stream, DELETE to end the session, and an event store for resumability.
12
+ // The SDK's default 2025-era serving is stateless, which would leave no
13
+ // channel for server-to-client requests, so elicitation, sampling and roots
14
+ // would stop working for 2025-era HTTP clients; routing them here keeps them
15
+ // working, the pattern the SDK documents for an existing sessionful
16
+ // deployment.
17
+ //
18
+ // A request with an `Mcp-Session-Id`, a GET and a DELETE are 2025-era by
19
+ // definition, since 2026-07-28 has none of them. A session-less POST is
20
+ // classified by the SDK's own `isLegacyRequest`, from a body parsed once and
21
+ // handed to whichever side serves it.
22
+ //
23
+ // `createApp()` builds the Express app without binding a port or installing a
24
+ // signal handler (#4854), so a test can serve it on a free port, drive it with
25
+ // a real client, and call its shutdown handler directly; each app has its own
26
+ // session map and its own 2026-07-28 handler. `startStreamableHttpServer()` is
27
+ // what the launcher runs.
28
+ import { createMcpHandler, isJSONRPCRequest, isLegacyRequest, } from "@modelcontextprotocol/server";
29
+ import { NodeStreamableHTTPServerTransport, toNodeHandler, toWebRequest, } from "@modelcontextprotocol/node";
30
+ import express from "express";
31
+ import { createServer } from "../server/index.js";
32
+ import { randomUUID } from "node:crypto";
33
+ import cors from "cors";
34
+ import { listenOrExit } from "./listen.js";
35
+ import { InMemoryEventStore } from "./in-memory-event-store.js";
36
+ /** The most bytes of a refused POST's body read to find its request id. */
37
+ const MAX_ID_BODY_BYTES = 64 * 1024;
38
+ /**
39
+ * The JSON-RPC `id` of a POST's body, or `null` when the body is not a single
40
+ * JSON-RPC request (a notification, a response, a batch, any other JSON,
41
+ * malformed JSON, or larger than `MAX_ID_BODY_BYTES`). Used only for a POST that is refused before the SDK
42
+ * reads its body, so the error can still carry the request's id (#4982).
43
+ */
44
+ async function readRequestId(req) {
45
+ try {
46
+ const chunks = [];
47
+ let size = 0;
48
+ for await (const chunk of req) {
49
+ size += chunk.length;
50
+ if (size > MAX_ID_BODY_BYTES)
51
+ return null;
52
+ chunks.push(chunk);
53
+ }
54
+ const message = JSON.parse(Buffer.concat(chunks).toString("utf8"));
55
+ return isJSONRPCRequest(message) ? message.id : null;
56
+ }
57
+ catch {
58
+ return null;
59
+ }
60
+ }
61
+ /**
62
+ * Answer a request whose `Mcp-Session-Id` this app does not know, or has
63
+ * ended: `404 Not Found`, which the spec makes the client's signal to start a
64
+ * new session (#4982). Same shape as the SDK's own "Session not found".
65
+ */
66
+ function sessionNotFound(res, id = null) {
67
+ res.status(404).json({
68
+ jsonrpc: "2.0",
69
+ error: { code: -32001, message: "Session not found" },
70
+ id,
71
+ });
72
+ }
73
+ /** The most bytes of a session-less POST body parsed to classify it (4 MiB, the SDK's own bound). */
74
+ const MAX_BODY_BYTES = 4 * 1024 * 1024;
75
+ /** Parses a session-less POST's JSON body, to classify it and to serve it. */
76
+ const parseJson = express.json({
77
+ limit: MAX_BODY_BYTES,
78
+ type: () => true,
79
+ // Any JSON value parses, so a primitive body reaches the SDK, which answers
80
+ // it as an invalid request (-32600); -32700 is only for text that is not JSON.
81
+ strict: false,
82
+ });
83
+ /**
84
+ * Answer a session-less POST whose body could not be parsed the way the SDK
85
+ * answers one: a JSON-RPC error with a null id, as 400 (not JSON) or 413 (too
86
+ * large). Anything else goes on to Express's error handling.
87
+ */
88
+ function bodyError(error, _req, res, next) {
89
+ if (error.type === "entity.parse.failed") {
90
+ res.status(400).json({
91
+ jsonrpc: "2.0",
92
+ error: {
93
+ code: -32700,
94
+ message: "Parse error: the request body is not valid JSON",
95
+ },
96
+ id: null,
97
+ });
98
+ }
99
+ else if (error.type === "entity.too.large") {
100
+ res.status(413).json({
101
+ jsonrpc: "2.0",
102
+ error: { code: -32600, message: "Request body too large" },
103
+ id: null,
104
+ });
105
+ }
106
+ else {
107
+ next(error);
108
+ }
109
+ }
110
+ /**
111
+ * Build the Streamable HTTP transport's Express app: CORS, the `/mcp` POST,
112
+ * GET and DELETE routes, the map from session id to transport that they
113
+ * share, the 2026-07-28 handler, and the shutdown handler that closes them.
114
+ */
115
+ export function createApp() {
116
+ // Express app with permissive CORS for testing with Inspector direct connect mode
117
+ const app = express();
118
+ app.use(cors({
119
+ origin: "*", // use "*" with caution in production
120
+ methods: "GET,POST,DELETE",
121
+ preflightContinue: false,
122
+ optionsSuccessStatus: 204,
123
+ exposedHeaders: [
124
+ "mcp-session-id",
125
+ "last-event-id",
126
+ "mcp-protocol-version",
127
+ ],
128
+ }));
129
+ // The 2026-07-28 side: a fresh server per request, built for the modern
130
+ // era. Its change notifications go out on the handler's subscription bus,
131
+ // which reaches every open subscriptions/listen stream that asked for them.
132
+ // It refuses 2025-era traffic, which the routes below never send it.
133
+ const modern = createMcpHandler(() => createServer({
134
+ era: "modern",
135
+ publish: {
136
+ toolsChanged: () => modern.notify.toolsChanged(),
137
+ promptsChanged: () => modern.notify.promptsChanged(),
138
+ resourcesChanged: () => modern.notify.resourcesChanged(),
139
+ resourceUpdated: (uri) => modern.notify.resourceUpdated(uri),
140
+ },
141
+ }).server, {
142
+ legacy: "reject",
143
+ onerror: (error) => console.log("Error serving MCP request:", error),
144
+ });
145
+ const serveModern = toNodeHandler(modern);
146
+ // Map sessionId to server transport for each client
147
+ const transports = new Map();
148
+ // A session-less POST's body is parsed once, to classify it and serve it.
149
+ // A POST with a session id is a 2025-era session's, and its transport reads
150
+ // the body itself.
151
+ app.post("/mcp", (req, res, next) => req.headers["mcp-session-id"] ? next() : parseJson(req, res, next), bodyError);
152
+ // Handle POST requests for client messages
153
+ app.post("/mcp", async (req, res) => {
154
+ console.log("Received MCP POST request");
155
+ try {
156
+ // Check for existing session ID
157
+ const sessionId = req.headers["mcp-session-id"];
158
+ // A session-less POST that carries the 2026-07-28 envelope is served
159
+ // by the modern handler; everything else stays on the 2025-era path.
160
+ if (!sessionId &&
161
+ !(await isLegacyRequest(await toWebRequest(req, req.body)))) {
162
+ await serveModern(req, res, req.body);
163
+ return;
164
+ }
165
+ let transport;
166
+ if (sessionId && transports.has(sessionId)) {
167
+ // Reuse existing transport
168
+ transport = transports.get(sessionId);
169
+ }
170
+ else if (!sessionId) {
171
+ const { server, cleanup } = createServer();
172
+ // New initialization request
173
+ const eventStore = new InMemoryEventStore();
174
+ transport = new NodeStreamableHTTPServerTransport({
175
+ sessionIdGenerator: () => randomUUID(),
176
+ eventStore, // Enable resumability
177
+ onsessioninitialized: (sessionId) => {
178
+ // Store the transport by session ID when a session is initialized
179
+ // This avoids race conditions where requests might come in before the session is stored
180
+ console.log(`Session initialized with ID: ${sessionId}`);
181
+ transports.set(sessionId, transport);
182
+ },
183
+ });
184
+ // Set up onclose handler to clean up transport when closed
185
+ server.server.onclose = async () => {
186
+ const sid = transport.sessionId;
187
+ if (sid && transports.has(sid)) {
188
+ console.log(`Transport closed for session ${sid}, removing from transports map`);
189
+ transports.delete(sid);
190
+ cleanup();
191
+ }
192
+ };
193
+ // Connect the transport to the MCP server BEFORE handling the request
194
+ // so responses can flow back through the same transport
195
+ await server.connect(transport);
196
+ await transport.handleRequest(req, res, req.body);
197
+ return;
198
+ }
199
+ else {
200
+ // A session ID this app does not know, or has already ended
201
+ sessionNotFound(res, await readRequestId(req));
202
+ return;
203
+ }
204
+ // Handle the request with existing transport - no need to reconnect
205
+ // The existing transport is already connected to the server
206
+ await transport.handleRequest(req, res);
207
+ }
208
+ catch (error) {
209
+ console.log("Error handling MCP request:", error);
210
+ if (!res.headersSent) {
211
+ res.status(500).json({
212
+ jsonrpc: "2.0",
213
+ error: {
214
+ code: -32603,
215
+ message: "Internal server error",
216
+ },
217
+ id: req?.body?.id,
218
+ });
219
+ return;
220
+ }
221
+ }
222
+ });
223
+ // Handle GET requests for SSE streams
224
+ app.get("/mcp", async (req, res) => {
225
+ console.log("Received MCP GET request");
226
+ const sessionId = req.headers["mcp-session-id"];
227
+ if (!sessionId) {
228
+ res.status(400).json({
229
+ jsonrpc: "2.0",
230
+ error: {
231
+ code: -32000,
232
+ message: "Bad Request: No valid session ID provided",
233
+ },
234
+ id: req?.body?.id,
235
+ });
236
+ return;
237
+ }
238
+ if (!transports.has(sessionId)) {
239
+ sessionNotFound(res);
240
+ return;
241
+ }
242
+ // Check for Last-Event-ID header for resumability
243
+ const lastEventId = req.headers["last-event-id"];
244
+ if (lastEventId) {
245
+ console.log(`Client reconnecting with Last-Event-ID: ${lastEventId}`);
246
+ }
247
+ else {
248
+ console.log(`Establishing new SSE stream for session ${sessionId}`);
249
+ }
250
+ const transport = transports.get(sessionId);
251
+ await transport.handleRequest(req, res);
252
+ });
253
+ // Handle DELETE requests for session termination
254
+ app.delete("/mcp", async (req, res) => {
255
+ const sessionId = req.headers["mcp-session-id"];
256
+ if (!sessionId) {
257
+ res.status(400).json({
258
+ jsonrpc: "2.0",
259
+ error: {
260
+ code: -32000,
261
+ message: "Bad Request: No valid session ID provided",
262
+ },
263
+ id: req?.body?.id,
264
+ });
265
+ return;
266
+ }
267
+ if (!transports.has(sessionId)) {
268
+ sessionNotFound(res);
269
+ return;
270
+ }
271
+ console.log(`Received session termination request for session ${sessionId}`);
272
+ try {
273
+ const transport = transports.get(sessionId);
274
+ await transport.handleRequest(req, res);
275
+ }
276
+ catch (error) {
277
+ console.log("Error handling session termination:", error);
278
+ if (!res.headersSent) {
279
+ res.status(500).json({
280
+ jsonrpc: "2.0",
281
+ error: {
282
+ code: -32603,
283
+ message: "Error handling session termination",
284
+ },
285
+ id: req?.body?.id,
286
+ });
287
+ return;
288
+ }
289
+ }
290
+ });
291
+ // Handle server shutdown
292
+ const shutdown = async () => {
293
+ console.log("Shutting down server...");
294
+ // End the 2026-07-28 requests and subscription streams in flight
295
+ await modern.close();
296
+ // Close all active transports to properly clean up resources
297
+ // (a snapshot, since closing a transport removes it from the map)
298
+ for (const [sessionId, transport] of [...transports]) {
299
+ try {
300
+ console.log(`Closing transport for session ${sessionId}`);
301
+ await transport.close();
302
+ transports.delete(sessionId);
303
+ }
304
+ catch (error) {
305
+ console.log(`Error closing transport for session ${sessionId}:`, error);
306
+ }
307
+ }
308
+ console.log("Server shutdown complete");
309
+ process.exit(0);
310
+ };
311
+ return { app, shutdown };
312
+ }
313
+ /**
314
+ * Start the Streamable HTTP server as the launcher does: build the app, bind
315
+ * it to `PORT` (default 3001), and install its shutdown handler for SIGINT.
316
+ */
317
+ export function startStreamableHttpServer() {
318
+ console.log("Starting Streamable HTTP server...");
319
+ const { app, shutdown } = createApp();
320
+ // Start the server
321
+ const PORT = process.env.PORT || 3001;
322
+ const httpServer = listenOrExit(app, PORT, `MCP Streamable HTTP Server listening on port ${PORT}`);
323
+ // Handle server shutdown
324
+ process.on("SIGINT", shutdown);
325
+ return httpServer;
326
+ }
@@ -0,0 +1,35 @@
1
+ // The version this server reports in `serverInfo`, read from package.json so
2
+ // it cannot drift from the published version (#4472). The TypeScript servers
3
+ // are versioned by changesets, whose "Version Packages" PR edits only
4
+ // package.json and CHANGELOG.md: a version literal in the source would stay
5
+ // behind at the first bump. Same module as `memory` and `sequentialthinking`.
6
+ import { createRequire } from "node:module";
7
+ import path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ /**
10
+ * Resolve this package's version from package.json.
11
+ *
12
+ * Works both from source (`src/everything/`) and from the published layout
13
+ * (`dist/`), where package.json lives one directory up.
14
+ */
15
+ export function resolvePackageVersion() {
16
+ const require = createRequire(import.meta.url);
17
+ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
18
+ const candidates = [
19
+ path.join(moduleDir, "package.json"),
20
+ path.join(moduleDir, "..", "package.json"),
21
+ ];
22
+ for (const candidate of candidates) {
23
+ try {
24
+ const pkg = require(candidate);
25
+ if (pkg.version) {
26
+ return pkg.version;
27
+ }
28
+ }
29
+ catch {
30
+ // Try the next candidate when running from dist/ or source.
31
+ }
32
+ }
33
+ throw new Error("Could not locate package.json for server version");
34
+ }
35
+ export const SERVER_VERSION = resolvePackageVersion();
package/package.json CHANGED
@@ -1,12 +1,20 @@
1
1
  {
2
2
  "name": "@modelcontextprotocol/server-everything",
3
- "version": "0.6.2",
3
+ "version": "2.0.0",
4
4
  "description": "MCP server that exercises all the features of the MCP protocol",
5
- "license": "MIT",
6
- "author": "Anthropic, PBC (https://anthropic.com)",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "mcpName": "io.github.modelcontextprotocol/server-everything",
7
+ "author": "Model Context Protocol a Series of LF Projects, LLC.",
7
8
  "homepage": "https://modelcontextprotocol.io",
8
9
  "bugs": "https://github.com/modelcontextprotocol/servers/issues",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/modelcontextprotocol/servers.git"
13
+ },
9
14
  "type": "module",
15
+ "engines": {
16
+ "node": ">=24"
17
+ },
10
18
  "bin": {
11
19
  "mcp-server-everything": "dist/index.js"
12
20
  },
@@ -14,19 +22,37 @@
14
22
  "dist"
15
23
  ],
16
24
  "scripts": {
17
- "build": "tsc && shx chmod +x dist/*.js",
25
+ "build": "tsc && shx cp -r docs dist/ && shx chmod +x dist/*.js",
18
26
  "prepare": "npm run build",
19
- "watch": "tsc --watch"
27
+ "watch": "tsc --watch",
28
+ "start:stdio": "node dist/index.js stdio",
29
+ "start:sse": "node dist/index.js sse",
30
+ "start:streamableHttp": "node dist/index.js streamableHttp",
31
+ "test": "vitest run",
32
+ "format": "prettier --write \"**/*.{ts,mts,cts,js,mjs,cjs}\" --ignore-path ../../.prettierignore",
33
+ "format:check": "prettier --check \"**/*.{ts,mts,cts,js,mjs,cjs}\" --ignore-path ../../.prettierignore",
34
+ "lint": "eslint . --max-warnings 0",
35
+ "typecheck": "tsc -p tsconfig.test.json",
36
+ "coverage": "vitest run --coverage",
37
+ "validate": "npm run format:check && npm run lint && npm run typecheck && npm run build && npm run test"
20
38
  },
21
39
  "dependencies": {
22
- "@modelcontextprotocol/sdk": "1.0.1",
23
- "express": "^4.21.1",
24
- "zod": "^3.23.8",
25
- "zod-to-json-schema": "^3.23.5"
40
+ "@modelcontextprotocol/node": "^2.1.1",
41
+ "@modelcontextprotocol/server": "^2.3.1",
42
+ "@modelcontextprotocol/server-legacy": "^2.3.1",
43
+ "cors": "^2.8.5",
44
+ "express": "^5.2.1",
45
+ "jszip": "^3.10.1",
46
+ "zod": "^4.2.0"
26
47
  },
27
48
  "devDependencies": {
28
- "@types/express": "^5.0.0",
29
- "shx": "^0.3.4",
30
- "typescript": "^5.6.2"
49
+ "@modelcontextprotocol/client": "^2.3.1",
50
+ "@modelcontextprotocol/core": "^2.3.1",
51
+ "@types/cors": "^2.8.19",
52
+ "@types/express": "^5.0.6",
53
+ "@vitest/coverage-v8": "^4.1.11",
54
+ "shx": "^0.4.0",
55
+ "typescript": "^5.8.2",
56
+ "vitest": "^4.1.11"
31
57
  }
32
- }
58
+ }