@modelcontextprotocol/server-everything 2.0.0 → 2.0.1

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.
package/README.md CHANGED
@@ -108,6 +108,8 @@ npm run start:streamableHttp
108
108
 
109
109
  The endpoint is `http://localhost:3001/mcp` (`PORT` overrides the port). It serves 2026-07-28 clients statelessly and 2025-era clients with sessions, from the same URL.
110
110
 
111
+ Both HTTP transports (Streamable HTTP and HTTP+SSE) accept browser requests only from a localhost origin: an `Origin` header whose host is `localhost`, `127.0.0.1` or `[::1]`, on any port, such as the MCP Inspector's. A request carrying any other `Origin` is refused with `403 Forbidden`. Clients that send no `Origin` header, which is every non-browser client, are unaffected.
112
+
111
113
  ## 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))
112
114
 
113
115
  ```shell
@@ -12,6 +12,7 @@
12
12
  // test can serve it on a free port and drive it with a real client, and each
13
13
  // app has its own session map. `startSseServer()` is what the launcher runs.
14
14
  import { SSEServerTransport } from "@modelcontextprotocol/server-legacy/sse";
15
+ import { localhostOriginValidation } from "@modelcontextprotocol/node";
15
16
  import express from "express";
16
17
  import { createServer } from "../server/index.js";
17
18
  import cors from "cors";
@@ -28,14 +29,24 @@ function sendError(res, status, message) {
28
29
  });
29
30
  }
30
31
  /**
31
- * Build the SSE transport's Express app: CORS, `GET /sse` and `POST /message`,
32
- * and the map from session id to transport that they share.
32
+ * Build the SSE transport's Express app: Origin validation, CORS, `GET /sse`
33
+ * and `POST /message`, and the map from session id to transport that they
34
+ * share.
33
35
  */
34
36
  export function createApp() {
35
- // Express app with permissive CORS for testing with Inspector direct connect mode
36
37
  const app = express();
38
+ // A browser page may reach this server only from a localhost origin. The
39
+ // SDK's guard answers any other Origin with a 403 before a route or the
40
+ // CORS middleware sees it, preflights included; a request with no Origin
41
+ // (a non-browser client) passes. CORS then grants the origin that passed,
42
+ // so the Inspector's direct connect mode keeps working from localhost.
43
+ const allowOrigin = localhostOriginValidation();
44
+ app.use((req, res, next) => {
45
+ if (allowOrigin(req, res))
46
+ next();
47
+ });
37
48
  app.use(cors({
38
- origin: "*", // use "*" with caution in production
49
+ origin: true,
39
50
  methods: "GET,POST",
40
51
  preflightContinue: false,
41
52
  optionsSuccessStatus: 204,
@@ -26,7 +26,7 @@
26
26
  // session map and its own 2026-07-28 handler. `startStreamableHttpServer()` is
27
27
  // what the launcher runs.
28
28
  import { createMcpHandler, isJSONRPCRequest, isLegacyRequest, } from "@modelcontextprotocol/server";
29
- import { NodeStreamableHTTPServerTransport, toNodeHandler, toWebRequest, } from "@modelcontextprotocol/node";
29
+ import { localhostOriginValidation, NodeStreamableHTTPServerTransport, toNodeHandler, toWebRequest, } from "@modelcontextprotocol/node";
30
30
  import express from "express";
31
31
  import { createServer } from "../server/index.js";
32
32
  import { randomUUID } from "node:crypto";
@@ -108,15 +108,25 @@ function bodyError(error, _req, res, next) {
108
108
  }
109
109
  }
110
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.
111
+ * Build the Streamable HTTP transport's Express app: Origin validation, CORS,
112
+ * the `/mcp` POST, GET and DELETE routes, the map from session id to
113
+ * transport that they share, the 2026-07-28 handler, and the shutdown handler
114
+ * that closes them.
114
115
  */
115
116
  export function createApp() {
116
- // Express app with permissive CORS for testing with Inspector direct connect mode
117
117
  const app = express();
118
+ // A browser page may reach this server only from a localhost origin. The
119
+ // SDK's guard answers any other Origin with a 403 before a route or the
120
+ // CORS middleware sees it, preflights included; a request with no Origin
121
+ // (a non-browser client) passes. CORS then grants the origin that passed,
122
+ // so the Inspector's direct connect mode keeps working from localhost.
123
+ const allowOrigin = localhostOriginValidation();
124
+ app.use((req, res, next) => {
125
+ if (allowOrigin(req, res))
126
+ next();
127
+ });
118
128
  app.use(cors({
119
- origin: "*", // use "*" with caution in production
129
+ origin: true,
120
130
  methods: "GET,POST,DELETE",
121
131
  preflightContinue: false,
122
132
  optionsSuccessStatus: 204,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelcontextprotocol/server-everything",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "MCP server that exercises all the features of the MCP protocol",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "mcpName": "io.github.modelcontextprotocol/server-everything",
@@ -50,9 +50,9 @@
50
50
  "@modelcontextprotocol/core": "^2.3.1",
51
51
  "@types/cors": "^2.8.19",
52
52
  "@types/express": "^5.0.6",
53
- "@vitest/coverage-v8": "^4.1.11",
53
+ "@vitest/coverage-v8": "^4.1.12",
54
54
  "shx": "^0.4.0",
55
55
  "typescript": "^5.8.2",
56
- "vitest": "^4.1.11"
56
+ "vitest": "^4.1.12"
57
57
  }
58
58
  }