@modelcontextprotocol/server-everything 2.0.0 → 2.1.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.
- package/README.md +17 -0
- package/dist/docs/features.md +2 -2
- package/dist/docs/instructions.md +2 -1
- package/dist/docs/structure.md +3 -2
- package/dist/tools/get-env.js +58 -4
- package/dist/tools/get-resource-links.js +7 -7
- package/dist/tools/get-tiny-image.js +1 -1
- package/dist/tools/gzip-file-as-resource.js +179 -32
- package/dist/tools/trigger-elicitation-request.js +138 -123
- package/dist/tools/trigger-long-running-operation.js +1 -1
- package/dist/transports/sse.js +15 -4
- package/dist/transports/streamableHttp.js +16 -6
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ This MCP server attempts to exercise all the features of the MCP protocol. It is
|
|
|
13
13
|
|
|
14
14
|
A complete list of the registered MCP primitives and other protocol features demonstrated can be found in the [Server Features](docs/features.md) document.
|
|
15
15
|
|
|
16
|
+
The `get-env` tool returns the server's environment variables, but masks the value of any credential-like name (a `KEY`, `TOKEN`, `SECRET`, `PASSWORD`, `PASSWD`, `CREDENTIAL`, `AUTH` or `COOKIE` segment, such as `OPENAI_API_KEY`) as `"<redacted>"`. To see every value unmasked while debugging, start the server with `GET_ENV_INCLUDE_SECRETS=1` (or `true`). Leave it unset otherwise: with it set, every credential in the server's environment reaches the model's context.
|
|
17
|
+
|
|
16
18
|
## Protocol versions
|
|
17
19
|
|
|
18
20
|
The server serves both protocol eras, over stdio and Streamable HTTP, from one process:
|
|
@@ -22,6 +24,19 @@ The server serves both protocol eras, over stdio and Streamable HTTP, from one p
|
|
|
22
24
|
|
|
23
25
|
Roots, sampling and logging are deprecated as of 2026-07-28 and stay available, labelled deprecated. [Server Features](docs/features.md) marks which era each feature belongs to.
|
|
24
26
|
|
|
27
|
+
## Configuring `gzip-file-as-resource`
|
|
28
|
+
|
|
29
|
+
The `gzip-file-as-resource` tool fetches the URL it is given, so these environment variables limit what it will fetch:
|
|
30
|
+
|
|
31
|
+
| Variable | Default | Effect |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| `GZIP_MAX_FETCH_SIZE` | 10 MiB | The largest response, in bytes, it reads |
|
|
34
|
+
| `GZIP_MAX_FETCH_TIME_MILLIS` | 30000 | How long a fetch may take, redirects included |
|
|
35
|
+
| `GZIP_ALLOWED_DOMAINS` | empty (any name) | Comma-separated host names; a host must be one of them or a subdomain of one. Checked on the caller's URL and on every redirect hop |
|
|
36
|
+
| `GZIP_ALLOW_PRIVATE_IPS` | off | Set to `1` or `true` to allow loopback, private (RFC 1918), CGNAT, link-local (cloud metadata) and other non-public addresses |
|
|
37
|
+
|
|
38
|
+
By default the tool refuses a URL whose host resolves to a non-public address, and follows at most five redirects, checking each hop the same way. `GZIP_ALLOWED_DOMAINS` filters names, not addresses: a listed name that resolves to a private address is still refused unless `GZIP_ALLOW_PRIVATE_IPS` is set. The address is checked before the request and resolved again when it is made, so a DNS answer that changes in between (DNS rebinding) is not caught. `data:` URLs are not fetched, so neither check applies to them.
|
|
39
|
+
|
|
25
40
|
## Requirements
|
|
26
41
|
|
|
27
42
|
Node.js 24 or later, when the server runs through `npx` or from source.
|
|
@@ -108,6 +123,8 @@ npm run start:streamableHttp
|
|
|
108
123
|
|
|
109
124
|
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
125
|
|
|
126
|
+
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.
|
|
127
|
+
|
|
111
128
|
## 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
129
|
|
|
113
130
|
```shell
|
package/dist/docs/features.md
CHANGED
|
@@ -31,9 +31,9 @@ Each feature below is marked **both**, **2026-07-28** or **2025-era**. Roots, sa
|
|
|
31
31
|
|
|
32
32
|
- `echo` (tools/echo.ts), **both**: Echoes the provided `message: string`. Uses Zod to validate inputs.
|
|
33
33
|
- `get-annotated-message` (tools/get-annotated-message.ts), **both**: Returns a `text` message annotated with `priority` and `audience` based on `messageType` (`error`, `success`, or `debug`); can optionally include an annotated `image`.
|
|
34
|
-
- `get-env` (tools/get-env.ts), **both**: Returns all environment variables from the running process as pretty-printed JSON text.
|
|
34
|
+
- `get-env` (tools/get-env.ts), **both**: Returns all environment variables from the running process as pretty-printed JSON text. Every name is returned, but the value of a credential-like name (one with a `KEY`, `TOKEN`, `SECRET`, `PASSWORD`, `PASSWD`, `CREDENTIAL`, `AUTH` or `COOKIE` segment between underscores, in any case) is replaced with `"<redacted>"`. Set `GET_ENV_INCLUDE_SECRETS=1` (or `true`) in the server's environment to return every value unmasked, for debugging.
|
|
35
35
|
- `get-header-params` (tools/get-header-params.ts), **both**: Returns its `region` argument and the `Mcp-Param-Region` HTTP header it arrived in. Its input and output schemas are plain JSON Schema 2020-12, and `region` carries `x-mcp-header: "Region"`, so a 2026-07-28 Streamable HTTP client mirrors it into that header and the server refuses a call whose header disagrees with the body (`-32020`). The header is `null` on stdio and for a 2025-era client.
|
|
36
|
-
- `get-resource-links` (tools/get-resource-links.ts), **both**: Returns an intro `text` block followed by multiple `resource_link` items. For a requested `count` (1–10), alternates between dynamic Text and Blob resources using URIs from `resources/templates.ts`.
|
|
36
|
+
- `get-resource-links` (tools/get-resource-links.ts), **both**: Returns an intro `text` block followed by multiple `resource_link` items. For a requested `count` (1–10), alternates between dynamic Text resources (even IDs) and Blob resources (odd IDs), using URIs from `resources/templates.ts`.
|
|
37
37
|
- `get-resource-reference` (tools/get-resource-reference.ts), **both**: Accepts `resourceType` (`text` or `blob`) and `resourceId` (positive integer). Returns a concrete `resource` content block (with its `uri`, `mimeType`, and data) with surrounding explanatory `text`.
|
|
38
38
|
- `get-roots-list` (tools/get-roots-list.ts), **both**, deprecated: Asks the client for its roots with a multi-round-trip request (`inputRequired.listRoots()`) and lists them. Needs client capability `roots`.
|
|
39
39
|
- `gzip-file-as-resource` (tools/gzip-file-as-resource.ts), **both**: Accepts a `name` and `data` (URL or data URI), fetches the data subject to size/time/domain constraints, compresses it, and returns either a `resource_link` (default) or an inline `resource` depending on `outputType`, with `mimeType: application/gzip`. The linked resource is registered as a session resource at `demo://resource/session/<name>` for a 2025-era client, and stored for ten minutes at a minted `demo://resource/minted/<id>/<name>` for a 2026-07-28 client.
|
|
@@ -19,7 +19,8 @@ The server serves two protocol eras. A client on protocol version 2026-07-28 con
|
|
|
19
19
|
|
|
20
20
|
## Constraints & Limitations
|
|
21
21
|
|
|
22
|
-
- `gzip-file-as-resource`: Max fetch size controlled by `GZIP_MAX_FETCH_SIZE` (default 10MB), timeout by `GZIP_MAX_FETCH_TIME_MILLIS` (default 30s), allowed domains by `GZIP_ALLOWED_DOMAINS`
|
|
22
|
+
- `gzip-file-as-resource`: Max fetch size controlled by `GZIP_MAX_FETCH_SIZE` (default 10MB), timeout by `GZIP_MAX_FETCH_TIME_MILLIS` (default 30s), allowed domains by `GZIP_ALLOWED_DOMAINS` (checked on every redirect hop). It refuses URLs whose host resolves to a loopback, private or link-local address, unless the server was started with `GZIP_ALLOW_PRIVATE_IPS=1`
|
|
23
|
+
- `get-env`: Values of credential-like variable names (`*_KEY`, `*_TOKEN`, `*_SECRET`, `*_PASSWORD` and the like) come back as `"<redacted>"`; the server operator can set `GET_ENV_INCLUDE_SECRETS=1` to return them unmasked
|
|
23
24
|
- Session resources are ephemeral and lost when the session ends; minted resources expire after ten minutes
|
|
24
25
|
- Roots, sampling and logging are deprecated as of protocol version 2026-07-28, as is the HTTP+SSE transport
|
|
25
26
|
|
package/dist/docs/structure.md
CHANGED
|
@@ -168,7 +168,7 @@ src/everything
|
|
|
168
168
|
- `get-annotated-message.ts`
|
|
169
169
|
- Registers a `get-annotated-message` tool which demonstrates content-level annotations. Emits a primary `text` message with content `annotations` (`priority`, `audience`) that vary by `messageType` (`"error" | "success" | "debug"`), and optionally includes an annotated `image` (tiny PNG) when `includeImage` is true. All tools in this server include tool-level annotations (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`).
|
|
170
170
|
- `get-env.ts`
|
|
171
|
-
- Registers a `get-env` tool that returns the current process environment variables as formatted JSON text; useful for debugging configuration.
|
|
171
|
+
- Registers a `get-env` tool that returns the current process environment variables as formatted JSON text; useful for debugging configuration. Values of credential-like names are masked as `"<redacted>"` unless `GET_ENV_INCLUDE_SECRETS` is set to a truthy value.
|
|
172
172
|
- `get-header-params.ts`
|
|
173
173
|
- Registers a `get-header-params` tool with JSON Schema 2020-12 input and output schemas whose `region` argument carries `x-mcp-header`; returns the argument and the `Mcp-Param-Region` header it arrived in.
|
|
174
174
|
- `get-resource-links.ts`
|
|
@@ -185,7 +185,8 @@ src/everything
|
|
|
185
185
|
- Environment controls:
|
|
186
186
|
- `GZIP_MAX_FETCH_SIZE` (bytes, default 10 MiB)
|
|
187
187
|
- `GZIP_MAX_FETCH_TIME_MILLIS` (ms, default 30000)
|
|
188
|
-
- `GZIP_ALLOWED_DOMAINS` (comma-separated allowlist; empty means
|
|
188
|
+
- `GZIP_ALLOWED_DOMAINS` (comma-separated name allowlist, checked on the caller's URL and on every redirect hop; empty means any name is allowed)
|
|
189
|
+
- `GZIP_ALLOW_PRIVATE_IPS` (`1`/`true` to allow loopback, private, link-local and other non-public addresses; by default a host that resolves to one is refused, on every hop)
|
|
189
190
|
- `simulate-research-query.ts`
|
|
190
191
|
- 2026-07-28: registers a `simulate-research-query` tool that runs as a task on the tasks extension, through four timed stages, pausing at `input_required` for a clarification on an ambiguous topic.
|
|
191
192
|
- `trigger-elicitation-request.ts`
|
package/dist/tools/get-env.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
+
/** The placeholder that replaces a masked value. */
|
|
2
|
+
export const REDACTED = "<redacted>";
|
|
3
|
+
/** The opt-in that returns every value unmasked. */
|
|
4
|
+
export const INCLUDE_SECRETS_VAR = "GET_ENV_INCLUDE_SECRETS";
|
|
5
|
+
/** Name segments that mark a variable as holding a credential. */
|
|
6
|
+
const CREDENTIAL_SEGMENTS = new Set([
|
|
7
|
+
"KEY",
|
|
8
|
+
"TOKEN",
|
|
9
|
+
"SECRET",
|
|
10
|
+
"PASSWORD",
|
|
11
|
+
"PASSWD",
|
|
12
|
+
"CREDENTIAL",
|
|
13
|
+
"AUTH",
|
|
14
|
+
"COOKIE",
|
|
15
|
+
]);
|
|
16
|
+
/** Values of `GET_ENV_INCLUDE_SECRETS` that turn the opt-in on. */
|
|
17
|
+
const TRUTHY = new Set(["1", "true", "yes", "on"]);
|
|
1
18
|
// Tool configuration
|
|
2
19
|
const name = "get-env";
|
|
3
20
|
const config = {
|
|
4
21
|
title: "Print Environment Tool",
|
|
5
|
-
description: "Returns all environment variables, helpful for debugging MCP server configuration"
|
|
22
|
+
description: "Returns all environment variables, helpful for debugging MCP server configuration. " +
|
|
23
|
+
`Values of credential-like names (a KEY, TOKEN, SECRET, PASSWORD, PASSWD, CREDENTIAL, AUTH or COOKIE name segment) are masked as "${REDACTED}" unless ${INCLUDE_SECRETS_VAR} is set to 1 or true in the server's environment.`,
|
|
6
24
|
inputSchema: {},
|
|
7
25
|
annotations: {
|
|
8
26
|
readOnlyHint: true,
|
|
@@ -11,11 +29,47 @@ const config = {
|
|
|
11
29
|
openWorldHint: false,
|
|
12
30
|
},
|
|
13
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Whether an environment variable name looks like it holds a credential:
|
|
34
|
+
* one of its underscore-separated segments, compared case-insensitively, is
|
|
35
|
+
* a credential word.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} key - The environment variable name.
|
|
38
|
+
* @returns {boolean} True when the value should be masked.
|
|
39
|
+
*/
|
|
40
|
+
export const isCredentialName = (key) => key
|
|
41
|
+
.toUpperCase()
|
|
42
|
+
.split("_")
|
|
43
|
+
.some((segment) => CREDENTIAL_SEGMENTS.has(segment));
|
|
44
|
+
/**
|
|
45
|
+
* Whether `GET_ENV_INCLUDE_SECRETS` is set to a truthy value
|
|
46
|
+
* (`1`, `true`, `yes` or `on`, case-insensitively).
|
|
47
|
+
*
|
|
48
|
+
* @param {NodeJS.ProcessEnv} env - The environment to read the opt-in from.
|
|
49
|
+
* @returns {boolean} True when values should be returned unmasked.
|
|
50
|
+
*/
|
|
51
|
+
export const includeSecrets = (env) => TRUTHY.has((env[INCLUDE_SECRETS_VAR] ?? "").trim().toLowerCase());
|
|
52
|
+
/**
|
|
53
|
+
* The environment as the tool returns it: every name, with the value of each
|
|
54
|
+
* credential-like name masked unless the opt-in is set.
|
|
55
|
+
*
|
|
56
|
+
* @param {NodeJS.ProcessEnv} env - The environment to render.
|
|
57
|
+
* @returns {Record<string, string | undefined>} The (possibly masked) copy.
|
|
58
|
+
*/
|
|
59
|
+
export const maskEnv = (env) => {
|
|
60
|
+
if (includeSecrets(env))
|
|
61
|
+
return { ...env };
|
|
62
|
+
return Object.fromEntries(Object.entries(env).map(([key, value]) => [
|
|
63
|
+
key,
|
|
64
|
+
isCredentialName(key) ? REDACTED : value,
|
|
65
|
+
]));
|
|
66
|
+
};
|
|
14
67
|
/**
|
|
15
68
|
* Registers the 'get-env' tool.
|
|
16
69
|
*
|
|
17
|
-
* The registered tool
|
|
18
|
-
*
|
|
70
|
+
* The registered tool returns the environment variables of the current
|
|
71
|
+
* process as a JSON-formatted string in a text response, with the values of
|
|
72
|
+
* credential-like names masked unless `GET_ENV_INCLUDE_SECRETS` is set.
|
|
19
73
|
*
|
|
20
74
|
* @param {McpServer} server - The McpServer instance where the tool will be registered.
|
|
21
75
|
* @returns {void}
|
|
@@ -26,7 +80,7 @@ export const registerGetEnvTool = (server) => {
|
|
|
26
80
|
content: [
|
|
27
81
|
{
|
|
28
82
|
type: "text",
|
|
29
|
-
text: JSON.stringify(process.env, null, 2),
|
|
83
|
+
text: JSON.stringify(maskEnv(process.env), null, 2),
|
|
30
84
|
},
|
|
31
85
|
],
|
|
32
86
|
};
|
|
@@ -23,11 +23,11 @@ const config = {
|
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
* Registers the 'get-resource-
|
|
26
|
+
* Registers the 'get-resource-links' tool.
|
|
27
27
|
*
|
|
28
28
|
* The registered tool retrieves a specified number of resource links and their metadata.
|
|
29
29
|
* Resource links are dynamically generated as either text or binary blob resources,
|
|
30
|
-
* based on their ID
|
|
30
|
+
* based on their ID: even IDs are text resources, odd IDs are blob resources.
|
|
31
31
|
|
|
32
32
|
* The response contains a "text" introductory block and multiple "resource_link" blocks.
|
|
33
33
|
*
|
|
@@ -44,19 +44,19 @@ export const registerGetResourceLinksTool = (server) => {
|
|
|
44
44
|
});
|
|
45
45
|
// Create resource link content blocks
|
|
46
46
|
for (let resourceId = 1; resourceId <= count; resourceId++) {
|
|
47
|
-
//
|
|
48
|
-
const
|
|
49
|
-
const uri =
|
|
47
|
+
// Even resourceIds are text resources, odd ones are blob resources
|
|
48
|
+
const isText = resourceId % 2 === 0;
|
|
49
|
+
const uri = isText
|
|
50
50
|
? textResourceUri(resourceId)
|
|
51
51
|
: blobResourceUri(resourceId);
|
|
52
52
|
// Get resource based on the resource type
|
|
53
|
-
const resource =
|
|
53
|
+
const resource = isText
|
|
54
54
|
? textResource(uri, resourceId)
|
|
55
55
|
: blobResource(uri, resourceId);
|
|
56
56
|
content.push({
|
|
57
57
|
type: "resource_link",
|
|
58
58
|
uri: resource.uri,
|
|
59
|
-
name: `${
|
|
59
|
+
name: `${isText ? "Text" : "Blob"} Resource ${resourceId}`,
|
|
60
60
|
description: `Resource ${resourceId}: ${resource.mimeType === "text/plain"
|
|
61
61
|
? "plaintext resource"
|
|
62
62
|
: "binary blob resource"}`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// A tiny encoded MCP logo image
|
|
2
|
-
export const MCP_TINY_IMAGE = "
|
|
2
|
+
export const MCP_TINY_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAeGVYSWZNTQAqAAAACAAFARIAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSASgAAwAAAAEAAgAAh2kABAAAAAEAAABaAAAAAAAAAJAAAAABAAAAkAAAAAEAAqACAAQAAAABAAAAFKADAAQAAAABAAAAFAAAAAAXNii1AAAACXBIWXMAABYlAAAWJQFJUiTwAAAB82lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOllSZXNvbHV0aW9uPjE0NDwvdGlmZjpZUmVzb2x1dGlvbj4KICAgICAgICAgPHRpZmY6T3JpZW50YXRpb24+MTwvdGlmZjpPcmllbnRhdGlvbj4KICAgICAgICAgPHRpZmY6WFJlc29sdXRpb24+MTQ0PC90aWZmOlhSZXNvbHV0aW9uPgogICAgICAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KReh49gAAAjRJREFUOBGFlD2vMUEUx2clvoNCcW8hCqFAo1dKhEQpvsF9KrWEBh/ALbQ0KkInBI3SWyGPCCJEQliXgsTLefaca/bBWjvJzs6cOf/fnDkzOQJIjWm06/XKBEGgD8c6nU5VIWgBtQDPZPWtJE8O63a7LBgMMo/Hw0ql0jPjcY4RvmqXy4XMjUYDUwLtdhtmsxnYbDbI5/O0djqdFFKmsEiGZ9jP9gem0yn0ej2Yz+fg9XpfycimAD7DttstQTDKfr8Po9GIIg6Hw1Cr1RTgB+A72GAwgMPhQLBMJgNSXsFqtUI2myUo18pA6QJogefsPrLBX4QdCVatViklw+EQRFGEj88P2O12pEUGATmsXq+TaLPZ0AXgMRF2vMEqlQoJTSYTpNNpApvNZliv1/+BHDaZTAi2Wq1A3Ig0xmMej7+RcZjdbodUKkWAaDQK+GHjHPnImB88JrZIJAKFQgH2+z2BOczhcMiwRCIBgUAA+NN5BP6mj2DYff35gk6nA61WCzBn2JxO5wPM7/fLz4vD0E+OECfn8xl/0Gw2KbLxeAyLxQIsFgt8p75pDSO7h/HbpUWpewCike9WLpfB7XaDy+WCYrFI/slk8i0MnRRAUt46hPMI4vE4+Hw+ec7t9/44VgWigEeby+UgFArJWjUYOqhWG6x50rpcSfR6PVUfNOgEVRlTX0HhrZBKz4MZjUYWi8VoA+lc9H/VaRZYjBKrtXR8tlwumcFgeMWRbZpA9ORQWfVm8A/FsrLaxebd5wAAAABJRU5ErkJggg==";
|
|
3
3
|
// Tool configuration
|
|
4
4
|
const name = "get-tiny-image";
|
|
5
5
|
const config = {
|
|
@@ -9,7 +9,18 @@
|
|
|
9
9
|
// each request gets a fresh instance, so for a 2026-07-28 client the resource
|
|
10
10
|
// is stored under a URI with a server-minted id that every instance can serve
|
|
11
11
|
// (resources/minted.ts), and expires after ten minutes.
|
|
12
|
+
//
|
|
13
|
+
// The tool fetches whatever URL a model hands it, so it refuses non-public
|
|
14
|
+
// destinations by default (#5130), as the fetch server does: before every
|
|
15
|
+
// request, the caller's URL and each redirect hop alike, the host is checked
|
|
16
|
+
// against GZIP_ALLOWED_DOMAINS (a name filter, when set) and then resolved,
|
|
17
|
+
// and the request is refused if any address it resolves to is loopback,
|
|
18
|
+
// private, link-local (cloud metadata) or otherwise not public, unless
|
|
19
|
+
// GZIP_ALLOW_PRIVATE_IPS opts in. Redirects are followed by hand, so that each
|
|
20
|
+
// hop passes the same check, up to MAX_REDIRECTS of them.
|
|
12
21
|
import { z } from "zod";
|
|
22
|
+
import { lookup } from "node:dns/promises";
|
|
23
|
+
import { BlockList } from "node:net";
|
|
13
24
|
import { gzipSync } from "node:zlib";
|
|
14
25
|
import { mintBlobResource } from "../resources/minted.js";
|
|
15
26
|
import { getSessionResourceURI, registerSessionResource, } from "../resources/session.js";
|
|
@@ -17,11 +28,99 @@ import { getSessionResourceURI, registerSessionResource, } from "../resources/se
|
|
|
17
28
|
const GZIP_MAX_FETCH_SIZE = Number(process.env.GZIP_MAX_FETCH_SIZE ?? String(10 * 1024 * 1024));
|
|
18
29
|
// Maximum fetch time - 30 seconds default.
|
|
19
30
|
const GZIP_MAX_FETCH_TIME_MILLIS = Number(process.env.GZIP_MAX_FETCH_TIME_MILLIS ?? String(30 * 1000));
|
|
20
|
-
// Comma-separated list of allowed domains
|
|
31
|
+
// Comma-separated list of allowed domains, matched by name on every request
|
|
32
|
+
// (redirect hops included). Empty means any name is allowed. It filters names,
|
|
33
|
+
// not addresses: a listed name that resolves to a private address is still
|
|
34
|
+
// refused unless GZIP_ALLOW_PRIVATE_IPS is set.
|
|
21
35
|
const GZIP_ALLOWED_DOMAINS = (process.env.GZIP_ALLOWED_DOMAINS ?? "")
|
|
22
36
|
.split(",")
|
|
23
37
|
.map((d) => d.trim().toLowerCase())
|
|
24
38
|
.filter((d) => d.length > 0);
|
|
39
|
+
// Opt in to fetching from loopback, private, link-local and other non-public
|
|
40
|
+
// addresses (1, true, yes or on). Off by default.
|
|
41
|
+
const GZIP_ALLOW_PRIVATE_IPS = /^(1|true|yes|on)$/i.test((process.env.GZIP_ALLOW_PRIVATE_IPS ?? "").trim());
|
|
42
|
+
// Redirects followed before a fetch is abandoned.
|
|
43
|
+
const MAX_REDIRECTS = 5;
|
|
44
|
+
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
45
|
+
// Addresses that are not public destinations: the IANA special-purpose ranges
|
|
46
|
+
// the fetch server refuses (src/fetch's _NON_PUBLIC_NETWORKS), plus
|
|
47
|
+
// multicast. BlockList judges an IPv4-mapped IPv6 address (::ffff:a.b.c.d) by
|
|
48
|
+
// the IPv4 rules, so those need no ranges of their own. The well-known NAT64
|
|
49
|
+
// prefix (64:ff9b::/96) is not unwrapped and so passes as public.
|
|
50
|
+
const NON_PUBLIC_ADDRESSES = new BlockList();
|
|
51
|
+
for (const [network, prefix] of [
|
|
52
|
+
["0.0.0.0", 8], // "this network", including the unspecified address
|
|
53
|
+
["10.0.0.0", 8], // RFC 1918
|
|
54
|
+
["100.64.0.0", 10], // CGNAT shared space (Alibaba Cloud metadata)
|
|
55
|
+
["127.0.0.0", 8], // loopback
|
|
56
|
+
["169.254.0.0", 16], // link-local (most cloud metadata endpoints)
|
|
57
|
+
["172.16.0.0", 12], // RFC 1918
|
|
58
|
+
["192.0.0.0", 24], // IETF protocol assignments
|
|
59
|
+
["192.0.2.0", 24], // documentation
|
|
60
|
+
["192.88.99.0", 24], // 6to4 relay anycast
|
|
61
|
+
["192.168.0.0", 16], // RFC 1918
|
|
62
|
+
["198.18.0.0", 15], // benchmarking
|
|
63
|
+
["198.51.100.0", 24], // documentation
|
|
64
|
+
["203.0.113.0", 24], // documentation
|
|
65
|
+
["224.0.0.0", 4], // multicast
|
|
66
|
+
["240.0.0.0", 4], // reserved, and broadcast
|
|
67
|
+
]) {
|
|
68
|
+
NON_PUBLIC_ADDRESSES.addSubnet(network, prefix, "ipv4");
|
|
69
|
+
}
|
|
70
|
+
for (const [network, prefix] of [
|
|
71
|
+
["::", 128], // unspecified
|
|
72
|
+
["::1", 128], // loopback
|
|
73
|
+
["64:ff9b:1::", 48], // local-use NAT64
|
|
74
|
+
["100::", 64], // discard-only
|
|
75
|
+
["2001::", 23], // IETF protocol assignments (Teredo among them)
|
|
76
|
+
["2001:db8::", 32], // documentation
|
|
77
|
+
["2002::", 16], // 6to4
|
|
78
|
+
["fc00::", 7], // unique local (AWS's fd00:ec2::254)
|
|
79
|
+
["fe80::", 10], // link-local
|
|
80
|
+
["ff00::", 8], // multicast
|
|
81
|
+
]) {
|
|
82
|
+
NON_PUBLIC_ADDRESSES.addSubnet(network, prefix, "ipv6");
|
|
83
|
+
}
|
|
84
|
+
// Globally reachable assignments inside those ranges (anycast services and
|
|
85
|
+
// the like), allowed as the fetch server allows its _PUBLIC_EXCEPTIONS.
|
|
86
|
+
const PUBLIC_EXCEPTIONS = new BlockList();
|
|
87
|
+
PUBLIC_EXCEPTIONS.addAddress("192.0.0.9", "ipv4");
|
|
88
|
+
PUBLIC_EXCEPTIONS.addAddress("192.0.0.10", "ipv4");
|
|
89
|
+
for (const [network, prefix] of [
|
|
90
|
+
["2001:1::1", 128],
|
|
91
|
+
["2001:1::2", 128],
|
|
92
|
+
["2001:3::", 32],
|
|
93
|
+
["2001:4:112::", 48],
|
|
94
|
+
["2001:20::", 28],
|
|
95
|
+
["2001:30::", 28],
|
|
96
|
+
]) {
|
|
97
|
+
PUBLIC_EXCEPTIONS.addSubnet(network, prefix, "ipv6");
|
|
98
|
+
}
|
|
99
|
+
/** True when `address` is not a public destination. */
|
|
100
|
+
function isNonPublic(address, family) {
|
|
101
|
+
const type = family === 6 ? "ipv6" : "ipv4";
|
|
102
|
+
return (!PUBLIC_EXCEPTIONS.check(address, type) &&
|
|
103
|
+
NON_PUBLIC_ADDRESSES.check(address, type));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Settles as `promise` does, or rejects with the signal's reason as soon as it
|
|
107
|
+
* aborts, so that the fetch deadline also bounds work that takes no signal
|
|
108
|
+
* (the DNS lookup).
|
|
109
|
+
*/
|
|
110
|
+
async function raceAbort(promise, signal) {
|
|
111
|
+
signal.throwIfAborted();
|
|
112
|
+
let onAbort = () => { };
|
|
113
|
+
const aborted = new Promise((_, reject) => {
|
|
114
|
+
onAbort = () => reject(signal.reason);
|
|
115
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
116
|
+
});
|
|
117
|
+
try {
|
|
118
|
+
return await Promise.race([promise, aborted]);
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
signal.removeEventListener("abort", onAbort);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
25
124
|
// Tool input schema
|
|
26
125
|
const GZipFileAsResourceSchema = z.object({
|
|
27
126
|
name: z
|
|
@@ -70,10 +169,8 @@ const config = {
|
|
|
70
169
|
export const registerGZipFileAsResourceTool = (server, context) => {
|
|
71
170
|
server.registerTool(name, config, async (args) => {
|
|
72
171
|
const { name, data: dataUri, outputType, } = GZipFileAsResourceSchema.parse(args);
|
|
73
|
-
//
|
|
74
|
-
const
|
|
75
|
-
// Fetch the data
|
|
76
|
-
const response = await fetchSafely(url, {
|
|
172
|
+
// Fetch the data; each request it makes is checked first
|
|
173
|
+
const response = await fetchSafely(new URL(dataUri), {
|
|
77
174
|
maxBytes: GZIP_MAX_FETCH_SIZE,
|
|
78
175
|
timeoutMillis: GZIP_MAX_FETCH_TIME_MILLIS,
|
|
79
176
|
});
|
|
@@ -112,36 +209,74 @@ export const registerGZipFileAsResourceTool = (server, context) => {
|
|
|
112
209
|
});
|
|
113
210
|
};
|
|
114
211
|
/**
|
|
115
|
-
*
|
|
212
|
+
* Refuses a request the server should not make: a protocol other than http,
|
|
213
|
+
* https or data; a host not in GZIP_ALLOWED_DOMAINS, when that is set; or,
|
|
214
|
+
* unless GZIP_ALLOW_PRIVATE_IPS is set, a host that resolves to any address
|
|
215
|
+
* that is not public. Called before every request, redirect hops included.
|
|
116
216
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
217
|
+
* This is a check, then a fetch: `fetch` resolves the name again to connect,
|
|
218
|
+
* so a name whose DNS answer changes between the two (DNS rebinding) can
|
|
219
|
+
* still reach a private address. Closing that window means pinning the
|
|
220
|
+
* checked address for the connection, which this demo server does not do.
|
|
221
|
+
*
|
|
222
|
+
* @param {URL} url The URL about to be requested.
|
|
223
|
+
* @param {AbortSignal} signal The fetch's deadline, which bounds the lookup too.
|
|
224
|
+
* @throws {Error} If the request is refused, or the host cannot be resolved.
|
|
120
225
|
*/
|
|
121
|
-
function
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
226
|
+
async function assertPermittedTarget(url, signal) {
|
|
227
|
+
const refuse = (reason) => new Error(`Error processing file ${url}: ${reason}`);
|
|
228
|
+
if (url.protocol === "data:")
|
|
229
|
+
return; // carries its own bytes
|
|
230
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
231
|
+
throw refuse(`Unsupported URL protocol for ${url}. Only http, https, and data URLs are supported.`);
|
|
232
|
+
}
|
|
233
|
+
// Names are matched as the URL spells them, an IPv6 literal with its
|
|
234
|
+
// brackets ([::1]), as they always have been
|
|
235
|
+
const domain = url.hostname;
|
|
236
|
+
if (GZIP_ALLOWED_DOMAINS.length > 0 &&
|
|
237
|
+
!GZIP_ALLOWED_DOMAINS.some((d) => domain === d || domain.endsWith(`.${d}`))) {
|
|
238
|
+
throw refuse(`Domain ${domain} is not in the allowed domains list.`);
|
|
239
|
+
}
|
|
240
|
+
if (GZIP_ALLOW_PRIVATE_IPS)
|
|
241
|
+
return;
|
|
242
|
+
// The resolver takes an IPv6 literal without its brackets
|
|
243
|
+
const host = domain.replace(/^\[(.*)\]$/, "$1");
|
|
244
|
+
const addresses = await raceAbort(lookup(host, { all: true }), signal);
|
|
245
|
+
for (const { address, family } of addresses) {
|
|
246
|
+
if (isNonPublic(address, family)) {
|
|
247
|
+
throw refuse(`${host} resolves to ${address}, which is not a public address. Set GZIP_ALLOW_PRIVATE_IPS=1 to allow private, loopback and link-local addresses.`);
|
|
139
248
|
}
|
|
140
249
|
}
|
|
141
|
-
|
|
142
|
-
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Requests `url`, following redirects by hand so that every hop passes
|
|
253
|
+
* `assertPermittedTarget` first, and returns the first response that is not a
|
|
254
|
+
* redirect.
|
|
255
|
+
*
|
|
256
|
+
* @param {URL} url The URL the caller asked for.
|
|
257
|
+
* @param {AbortSignal} signal Aborts the request in flight.
|
|
258
|
+
* @return {Promise<Response>} The final response.
|
|
259
|
+
* @throws {Error} If a hop is refused, or there are more than MAX_REDIRECTS.
|
|
260
|
+
*/
|
|
261
|
+
async function fetchPermitted(url, signal) {
|
|
262
|
+
let target = url;
|
|
263
|
+
for (let redirects = 0;; redirects++) {
|
|
264
|
+
await assertPermittedTarget(target, signal);
|
|
265
|
+
const response = await fetch(target, { signal, redirect: "manual" });
|
|
266
|
+
const location = response.headers.get("location");
|
|
267
|
+
if (!REDIRECT_STATUSES.has(response.status) || location === null) {
|
|
268
|
+
return response;
|
|
269
|
+
}
|
|
270
|
+
// Discard the redirect's own body before moving on. Not awaited, as in
|
|
271
|
+
// fetchSafely: cancel() may never settle, and only the next hop matters.
|
|
272
|
+
response.body?.cancel().catch(
|
|
273
|
+
/* v8 ignore next -- only runs if cancelling the source fails, which nothing here can provoke */
|
|
274
|
+
() => { });
|
|
275
|
+
if (redirects === MAX_REDIRECTS) {
|
|
276
|
+
throw new Error(`Fetching ${url} followed more than ${MAX_REDIRECTS} redirects and was abandoned.`);
|
|
277
|
+
}
|
|
278
|
+
target = new URL(location, target);
|
|
143
279
|
}
|
|
144
|
-
return url;
|
|
145
280
|
}
|
|
146
281
|
/**
|
|
147
282
|
* Fetches data safely from a given URL while ensuring constraints on maximum byte size and timeout duration.
|
|
@@ -157,8 +292,20 @@ async function fetchSafely(url, { maxBytes, timeoutMillis }) {
|
|
|
157
292
|
const controller = new AbortController();
|
|
158
293
|
const timeout = setTimeout(() => controller.abort(`Fetching ${url} took more than ${timeoutMillis} ms and was aborted.`), timeoutMillis);
|
|
159
294
|
try {
|
|
160
|
-
// Fetch the data
|
|
161
|
-
|
|
295
|
+
// Fetch the data, following only redirects that pass the same checks.
|
|
296
|
+
// The response is the final, non-redirect one, so a redirect is never
|
|
297
|
+
// mistaken for an error status here.
|
|
298
|
+
const response = await fetchPermitted(url, controller.signal);
|
|
299
|
+
if (!response.ok) {
|
|
300
|
+
// An error page is not the requested file (#5207). Release the
|
|
301
|
+
// connection without reading the body; as with the size check below,
|
|
302
|
+
// the cancel is not awaited and its rejection is swallowed, since the
|
|
303
|
+
// thrown status error is the failure this path reports.
|
|
304
|
+
response.body?.cancel().catch(
|
|
305
|
+
/* v8 ignore next -- only runs if cancelling the source fails, which nothing here can provoke */
|
|
306
|
+
() => { });
|
|
307
|
+
throw new Error(`Fetching ${url} failed with HTTP ${response.status} ${response.statusText}`);
|
|
308
|
+
}
|
|
162
309
|
if (!response.body) {
|
|
163
310
|
throw new Error("No response body");
|
|
164
311
|
}
|
|
@@ -22,116 +22,150 @@ const config = {
|
|
|
22
22
|
openWorldHint: false,
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
|
-
/** The form: one
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
25
|
+
/** The form's fields: one of each type form-mode elicitation supports. */
|
|
26
|
+
const properties = {
|
|
27
|
+
name: {
|
|
28
|
+
title: "String",
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Your full, legal name",
|
|
31
|
+
},
|
|
32
|
+
check: {
|
|
33
|
+
title: "Boolean",
|
|
34
|
+
type: "boolean",
|
|
35
|
+
description: "Agree to the terms and conditions",
|
|
36
|
+
},
|
|
37
|
+
firstLine: {
|
|
38
|
+
title: "String with default",
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Favorite first line of a story",
|
|
41
|
+
default: "It was a dark and stormy night.",
|
|
42
|
+
},
|
|
43
|
+
email: {
|
|
44
|
+
title: "String with email format",
|
|
45
|
+
type: "string",
|
|
46
|
+
format: "email",
|
|
47
|
+
description: "Your email address (will be verified, and never shared with anyone else)",
|
|
48
|
+
},
|
|
49
|
+
homepage: {
|
|
50
|
+
type: "string",
|
|
51
|
+
format: "uri",
|
|
52
|
+
title: "String with uri format",
|
|
53
|
+
description: "Portfolio / personal website",
|
|
54
|
+
},
|
|
55
|
+
birthdate: {
|
|
56
|
+
title: "String with date format",
|
|
57
|
+
type: "string",
|
|
58
|
+
format: "date",
|
|
59
|
+
description: "Your date of birth",
|
|
60
|
+
},
|
|
61
|
+
integer: {
|
|
62
|
+
title: "Integer",
|
|
63
|
+
type: "integer",
|
|
64
|
+
description: "Your favorite integer (do not give us your phone number, pin, or other sensitive info)",
|
|
65
|
+
minimum: 1,
|
|
66
|
+
maximum: 100,
|
|
67
|
+
default: 42,
|
|
68
|
+
},
|
|
69
|
+
number: {
|
|
70
|
+
title: "Number in range 1-1000",
|
|
71
|
+
type: "number",
|
|
72
|
+
description: "Favorite number (there are no wrong answers)",
|
|
73
|
+
minimum: 0,
|
|
74
|
+
maximum: 1000,
|
|
75
|
+
default: 3.14,
|
|
76
|
+
},
|
|
77
|
+
untitledSingleSelectEnum: {
|
|
78
|
+
type: "string",
|
|
79
|
+
title: "Untitled Single Select Enum",
|
|
80
|
+
description: "Choose your favorite friend",
|
|
81
|
+
enum: ["Monica", "Rachel", "Joey", "Chandler", "Ross", "Phoebe"],
|
|
82
|
+
default: "Monica",
|
|
83
|
+
},
|
|
84
|
+
untitledMultipleSelectEnum: {
|
|
85
|
+
type: "array",
|
|
86
|
+
title: "Untitled Multiple Select Enum",
|
|
87
|
+
description: "Choose your favorite instruments",
|
|
88
|
+
minItems: 1,
|
|
89
|
+
maxItems: 3,
|
|
90
|
+
items: {
|
|
80
91
|
type: "string",
|
|
81
|
-
|
|
82
|
-
description: "Choose your favorite friend",
|
|
83
|
-
enum: ["Monica", "Rachel", "Joey", "Chandler", "Ross", "Phoebe"],
|
|
84
|
-
default: "Monica",
|
|
85
|
-
},
|
|
86
|
-
untitledMultipleSelectEnum: {
|
|
87
|
-
type: "array",
|
|
88
|
-
title: "Untitled Multiple Select Enum",
|
|
89
|
-
description: "Choose your favorite instruments",
|
|
90
|
-
minItems: 1,
|
|
91
|
-
maxItems: 3,
|
|
92
|
-
items: {
|
|
93
|
-
type: "string",
|
|
94
|
-
enum: ["Guitar", "Piano", "Violin", "Drums", "Bass"],
|
|
95
|
-
},
|
|
96
|
-
default: ["Guitar"],
|
|
92
|
+
enum: ["Guitar", "Piano", "Violin", "Drums", "Bass"],
|
|
97
93
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
default: ["Guitar"],
|
|
95
|
+
},
|
|
96
|
+
titledSingleSelectEnum: {
|
|
97
|
+
type: "string",
|
|
98
|
+
title: "Titled Single Select Enum",
|
|
99
|
+
description: "Choose your favorite hero",
|
|
100
|
+
oneOf: [
|
|
101
|
+
{ const: "hero-1", title: "Superman" },
|
|
102
|
+
{ const: "hero-2", title: "Green Lantern" },
|
|
103
|
+
{ const: "hero-3", title: "Wonder Woman" },
|
|
104
|
+
],
|
|
105
|
+
default: "hero-1",
|
|
106
|
+
},
|
|
107
|
+
titledMultipleSelectEnum: {
|
|
108
|
+
type: "array",
|
|
109
|
+
title: "Titled Multiple Select Enum",
|
|
110
|
+
description: "Choose your favorite types of fish",
|
|
111
|
+
minItems: 1,
|
|
112
|
+
maxItems: 3,
|
|
113
|
+
items: {
|
|
114
|
+
anyOf: [
|
|
115
|
+
{ const: "fish-1", title: "Tuna" },
|
|
116
|
+
{ const: "fish-2", title: "Salmon" },
|
|
117
|
+
{ const: "fish-3", title: "Trout" },
|
|
106
118
|
],
|
|
107
|
-
default: "hero-1",
|
|
108
|
-
},
|
|
109
|
-
titledMultipleSelectEnum: {
|
|
110
|
-
type: "array",
|
|
111
|
-
title: "Titled Multiple Select Enum",
|
|
112
|
-
description: "Choose your favorite types of fish",
|
|
113
|
-
minItems: 1,
|
|
114
|
-
maxItems: 3,
|
|
115
|
-
items: {
|
|
116
|
-
anyOf: [
|
|
117
|
-
{ const: "fish-1", title: "Tuna" },
|
|
118
|
-
{ const: "fish-2", title: "Salmon" },
|
|
119
|
-
{ const: "fish-3", title: "Trout" },
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
default: ["fish-1"],
|
|
123
|
-
},
|
|
124
|
-
legacyTitledEnum: {
|
|
125
|
-
type: "string",
|
|
126
|
-
title: "Legacy Titled Single Select Enum",
|
|
127
|
-
description: "Choose your favorite type of pet",
|
|
128
|
-
enum: ["pet-1", "pet-2", "pet-3", "pet-4", "pet-5"],
|
|
129
|
-
enumNames: ["Cats", "Dogs", "Birds", "Fish", "Reptiles"],
|
|
130
|
-
default: "pet-1",
|
|
131
119
|
},
|
|
120
|
+
default: ["fish-1"],
|
|
121
|
+
},
|
|
122
|
+
legacyTitledEnum: {
|
|
123
|
+
type: "string",
|
|
124
|
+
title: "Legacy Titled Single Select Enum",
|
|
125
|
+
description: "Choose your favorite type of pet",
|
|
126
|
+
enum: ["pet-1", "pet-2", "pet-3", "pet-4", "pet-5"],
|
|
127
|
+
enumNames: ["Cats", "Dogs", "Birds", "Fish", "Reptiles"],
|
|
128
|
+
default: "pet-1",
|
|
132
129
|
},
|
|
130
|
+
};
|
|
131
|
+
/** The form, as the elicitation request carries it. */
|
|
132
|
+
const requestedSchema = {
|
|
133
|
+
type: "object",
|
|
134
|
+
properties,
|
|
133
135
|
required: ["name"],
|
|
134
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* The label each field gets in the summary of an accepted form. Keyed by the
|
|
139
|
+
* form's own field names, so a field added to or removed from the form fails
|
|
140
|
+
* to compile until its label follows, and the summary cannot drift from the
|
|
141
|
+
* form again (#5209).
|
|
142
|
+
*/
|
|
143
|
+
const summaryLabels = {
|
|
144
|
+
name: "Name",
|
|
145
|
+
check: "Agreed to terms",
|
|
146
|
+
firstLine: "Favorite first line",
|
|
147
|
+
email: "Email",
|
|
148
|
+
homepage: "Homepage",
|
|
149
|
+
birthdate: "Birthdate",
|
|
150
|
+
integer: "Favorite integer",
|
|
151
|
+
number: "Favorite number",
|
|
152
|
+
untitledSingleSelectEnum: "Favorite friend",
|
|
153
|
+
untitledMultipleSelectEnum: "Favorite instruments",
|
|
154
|
+
titledSingleSelectEnum: "Favorite hero",
|
|
155
|
+
titledMultipleSelectEnum: "Favorite fish",
|
|
156
|
+
legacyTitledEnum: "Favorite pet",
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* One summary line per form field the user answered, in the form's order.
|
|
160
|
+
* A field the form does not define is left out, whatever the client sent.
|
|
161
|
+
*/
|
|
162
|
+
const summarize = (userData) => Object.keys(properties)
|
|
163
|
+
.filter((field) => userData[field] !== undefined)
|
|
164
|
+
.map((field) => {
|
|
165
|
+
const value = userData[field];
|
|
166
|
+
const shown = Array.isArray(value) ? value.join(", ") : String(value);
|
|
167
|
+
return `- ${summaryLabels[field]}: ${shown}`;
|
|
168
|
+
});
|
|
135
169
|
/**
|
|
136
170
|
* Registers the 'trigger-elicitation-request' tool.
|
|
137
171
|
*
|
|
@@ -176,26 +210,7 @@ export const registerTriggerElicitationRequestTool = (server) => {
|
|
|
176
210
|
text: `✅ User provided the requested information!`,
|
|
177
211
|
});
|
|
178
212
|
// Only access answer.content when action is accept
|
|
179
|
-
const
|
|
180
|
-
const lines = [];
|
|
181
|
-
if (userData.name)
|
|
182
|
-
lines.push(`- Name: ${userData.name}`);
|
|
183
|
-
if (userData.check !== undefined)
|
|
184
|
-
lines.push(`- Agreed to terms: ${userData.check}`);
|
|
185
|
-
if (userData.color)
|
|
186
|
-
lines.push(`- Favorite Color: ${userData.color}`);
|
|
187
|
-
if (userData.email)
|
|
188
|
-
lines.push(`- Email: ${userData.email}`);
|
|
189
|
-
if (userData.homepage)
|
|
190
|
-
lines.push(`- Homepage: ${userData.homepage}`);
|
|
191
|
-
if (userData.birthdate)
|
|
192
|
-
lines.push(`- Birthdate: ${userData.birthdate}`);
|
|
193
|
-
if (userData.integer !== undefined)
|
|
194
|
-
lines.push(`- Favorite Integer: ${userData.integer}`);
|
|
195
|
-
if (userData.number !== undefined)
|
|
196
|
-
lines.push(`- Favorite Number: ${userData.number}`);
|
|
197
|
-
if (userData.petType)
|
|
198
|
-
lines.push(`- Pet Type: ${userData.petType}`);
|
|
213
|
+
const lines = summarize(answer.content);
|
|
199
214
|
content.push({
|
|
200
215
|
type: "text",
|
|
201
216
|
text: `User inputs:\n${lines.join("\n")}`,
|
|
@@ -21,7 +21,7 @@ const config = {
|
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* Registers the 'trigger-
|
|
24
|
+
* Registers the 'trigger-long-running-operation' tool.
|
|
25
25
|
*
|
|
26
26
|
* The registered tool starts a long-running operation defined by a specific duration and
|
|
27
27
|
* number of steps.
|
package/dist/transports/sse.js
CHANGED
|
@@ -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`
|
|
32
|
-
* and the map from session id to transport that they
|
|
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:
|
|
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:
|
|
112
|
-
* GET and DELETE routes, the map from session id to
|
|
113
|
-
* share, the 2026-07-28 handler, and the shutdown handler
|
|
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:
|
|
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.
|
|
3
|
+
"version": "2.1.0",
|
|
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.
|
|
53
|
+
"@vitest/coverage-v8": "^4.1.12",
|
|
54
54
|
"shx": "^0.4.0",
|
|
55
55
|
"typescript": "^5.8.2",
|
|
56
|
-
"vitest": "^4.1.
|
|
56
|
+
"vitest": "^4.1.12"
|
|
57
57
|
}
|
|
58
58
|
}
|