@modelcontextprotocol/server-everything 2.0.1 → 2.2.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 +45 -0
- package/dist/docs/features.md +9 -4
- package/dist/docs/instructions.md +2 -1
- package/dist/docs/structure.md +9 -2
- package/dist/prompts/args.js +2 -0
- package/dist/prompts/completions.js +2 -0
- package/dist/prompts/resource.js +2 -0
- package/dist/prompts/simple.js +2 -0
- package/dist/resources/collections.js +108 -0
- package/dist/resources/files.js +7 -1
- package/dist/resources/index.js +2 -0
- package/dist/resources/minted.js +4 -0
- package/dist/resources/templates.js +12 -2
- package/dist/server/icons.js +51 -0
- package/dist/server/index.js +2 -0
- package/dist/tools/echo.js +2 -0
- package/dist/tools/get-annotated-message.js +2 -0
- package/dist/tools/get-env.js +60 -4
- package/dist/tools/get-header-params.js +2 -0
- package/dist/tools/get-resource-links.js +9 -7
- package/dist/tools/get-resource-reference.js +2 -0
- package/dist/tools/get-roots-list.js +2 -0
- package/dist/tools/get-structured-content.js +2 -0
- package/dist/tools/get-sum.js +2 -0
- package/dist/tools/get-tiny-image.js +3 -1
- package/dist/tools/gzip-file-as-resource.js +184 -33
- package/dist/tools/simulate-research-query.js +2 -0
- package/dist/tools/toggle-simulated-logging.js +2 -0
- package/dist/tools/toggle-subscriber-updates.js +2 -0
- package/dist/tools/trigger-elicitation-request-async.js +2 -0
- package/dist/tools/trigger-elicitation-request.js +140 -123
- package/dist/tools/trigger-list-changed.js +2 -0
- package/dist/tools/trigger-log-messages.js +2 -0
- package/dist/tools/trigger-long-running-operation.js +26 -2
- package/dist/tools/trigger-multi-step-elicitation.js +2 -0
- package/dist/tools/trigger-resource-update.js +2 -0
- package/dist/tools/trigger-sampling-request-async.js +2 -0
- package/dist/tools/trigger-sampling-request.js +2 -0
- package/dist/tools/trigger-url-elicitation.js +2 -0
- package/package.json +1 -1
package/dist/tools/get-env.js
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
2
|
+
/** The placeholder that replaces a masked value. */
|
|
3
|
+
export const REDACTED = "<redacted>";
|
|
4
|
+
/** The opt-in that returns every value unmasked. */
|
|
5
|
+
export const INCLUDE_SECRETS_VAR = "GET_ENV_INCLUDE_SECRETS";
|
|
6
|
+
/** Name segments that mark a variable as holding a credential. */
|
|
7
|
+
const CREDENTIAL_SEGMENTS = new Set([
|
|
8
|
+
"KEY",
|
|
9
|
+
"TOKEN",
|
|
10
|
+
"SECRET",
|
|
11
|
+
"PASSWORD",
|
|
12
|
+
"PASSWD",
|
|
13
|
+
"CREDENTIAL",
|
|
14
|
+
"AUTH",
|
|
15
|
+
"COOKIE",
|
|
16
|
+
]);
|
|
17
|
+
/** Values of `GET_ENV_INCLUDE_SECRETS` that turn the opt-in on. */
|
|
18
|
+
const TRUTHY = new Set(["1", "true", "yes", "on"]);
|
|
1
19
|
// Tool configuration
|
|
2
20
|
const name = "get-env";
|
|
3
21
|
const config = {
|
|
4
22
|
title: "Print Environment Tool",
|
|
5
|
-
description: "Returns all environment variables, helpful for debugging MCP server configuration"
|
|
23
|
+
description: "Returns all environment variables, helpful for debugging MCP server configuration. " +
|
|
24
|
+
`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
25
|
inputSchema: {},
|
|
26
|
+
icons: TOOL_ICONS,
|
|
7
27
|
annotations: {
|
|
8
28
|
readOnlyHint: true,
|
|
9
29
|
destructiveHint: false,
|
|
@@ -11,11 +31,47 @@ const config = {
|
|
|
11
31
|
openWorldHint: false,
|
|
12
32
|
},
|
|
13
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Whether an environment variable name looks like it holds a credential:
|
|
36
|
+
* one of its underscore-separated segments, compared case-insensitively, is
|
|
37
|
+
* a credential word.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} key - The environment variable name.
|
|
40
|
+
* @returns {boolean} True when the value should be masked.
|
|
41
|
+
*/
|
|
42
|
+
export const isCredentialName = (key) => key
|
|
43
|
+
.toUpperCase()
|
|
44
|
+
.split("_")
|
|
45
|
+
.some((segment) => CREDENTIAL_SEGMENTS.has(segment));
|
|
46
|
+
/**
|
|
47
|
+
* Whether `GET_ENV_INCLUDE_SECRETS` is set to a truthy value
|
|
48
|
+
* (`1`, `true`, `yes` or `on`, case-insensitively).
|
|
49
|
+
*
|
|
50
|
+
* @param {NodeJS.ProcessEnv} env - The environment to read the opt-in from.
|
|
51
|
+
* @returns {boolean} True when values should be returned unmasked.
|
|
52
|
+
*/
|
|
53
|
+
export const includeSecrets = (env) => TRUTHY.has((env[INCLUDE_SECRETS_VAR] ?? "").trim().toLowerCase());
|
|
54
|
+
/**
|
|
55
|
+
* The environment as the tool returns it: every name, with the value of each
|
|
56
|
+
* credential-like name masked unless the opt-in is set.
|
|
57
|
+
*
|
|
58
|
+
* @param {NodeJS.ProcessEnv} env - The environment to render.
|
|
59
|
+
* @returns {Record<string, string | undefined>} The (possibly masked) copy.
|
|
60
|
+
*/
|
|
61
|
+
export const maskEnv = (env) => {
|
|
62
|
+
if (includeSecrets(env))
|
|
63
|
+
return { ...env };
|
|
64
|
+
return Object.fromEntries(Object.entries(env).map(([key, value]) => [
|
|
65
|
+
key,
|
|
66
|
+
isCredentialName(key) ? REDACTED : value,
|
|
67
|
+
]));
|
|
68
|
+
};
|
|
14
69
|
/**
|
|
15
70
|
* Registers the 'get-env' tool.
|
|
16
71
|
*
|
|
17
|
-
* The registered tool
|
|
18
|
-
*
|
|
72
|
+
* The registered tool returns the environment variables of the current
|
|
73
|
+
* process as a JSON-formatted string in a text response, with the values of
|
|
74
|
+
* credential-like names masked unless `GET_ENV_INCLUDE_SECRETS` is set.
|
|
19
75
|
*
|
|
20
76
|
* @param {McpServer} server - The McpServer instance where the tool will be registered.
|
|
21
77
|
* @returns {void}
|
|
@@ -26,7 +82,7 @@ export const registerGetEnvTool = (server) => {
|
|
|
26
82
|
content: [
|
|
27
83
|
{
|
|
28
84
|
type: "text",
|
|
29
|
-
text: JSON.stringify(process.env, null, 2),
|
|
85
|
+
text: JSON.stringify(maskEnv(process.env), null, 2),
|
|
30
86
|
},
|
|
31
87
|
],
|
|
32
88
|
};
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// with the body (-32020). The tool reports the header it was sent, which is
|
|
13
13
|
// null on stdio and for a 2025-era client, which mirrors nothing.
|
|
14
14
|
import { fromJsonSchema, } from "@modelcontextprotocol/server";
|
|
15
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
15
16
|
/**
|
|
16
17
|
* The keyword that asks a 2026-07-28 client to mirror an argument into the
|
|
17
18
|
* `Mcp-Param-<value>` header (SEP-2243). It is an extension keyword, so the
|
|
@@ -67,6 +68,7 @@ const config = {
|
|
|
67
68
|
"JSON Schema 2020-12 input and output schemas.",
|
|
68
69
|
inputSchema: fromJsonSchema(inputSchema),
|
|
69
70
|
outputSchema: fromJsonSchema(outputSchema),
|
|
71
|
+
icons: TOOL_ICONS,
|
|
70
72
|
annotations: {
|
|
71
73
|
readOnlyHint: true,
|
|
72
74
|
destructiveHint: false,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { textResource, textResourceUri, blobResourceUri, blobResource, } from "../resources/templates.js";
|
|
3
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
3
4
|
// Tool input schema
|
|
4
5
|
const GetResourceLinksSchema = z.object({
|
|
5
6
|
count: z
|
|
@@ -15,6 +16,7 @@ const config = {
|
|
|
15
16
|
title: "Get Resource Links Tool",
|
|
16
17
|
description: "Returns up to ten resource links that reference different types of resources",
|
|
17
18
|
inputSchema: GetResourceLinksSchema,
|
|
19
|
+
icons: TOOL_ICONS,
|
|
18
20
|
annotations: {
|
|
19
21
|
readOnlyHint: true,
|
|
20
22
|
destructiveHint: false,
|
|
@@ -23,11 +25,11 @@ const config = {
|
|
|
23
25
|
},
|
|
24
26
|
};
|
|
25
27
|
/**
|
|
26
|
-
* Registers the 'get-resource-
|
|
28
|
+
* Registers the 'get-resource-links' tool.
|
|
27
29
|
*
|
|
28
30
|
* The registered tool retrieves a specified number of resource links and their metadata.
|
|
29
31
|
* Resource links are dynamically generated as either text or binary blob resources,
|
|
30
|
-
* based on their ID
|
|
32
|
+
* based on their ID: even IDs are text resources, odd IDs are blob resources.
|
|
31
33
|
|
|
32
34
|
* The response contains a "text" introductory block and multiple "resource_link" blocks.
|
|
33
35
|
*
|
|
@@ -44,19 +46,19 @@ export const registerGetResourceLinksTool = (server) => {
|
|
|
44
46
|
});
|
|
45
47
|
// Create resource link content blocks
|
|
46
48
|
for (let resourceId = 1; resourceId <= count; resourceId++) {
|
|
47
|
-
//
|
|
48
|
-
const
|
|
49
|
-
const uri =
|
|
49
|
+
// Even resourceIds are text resources, odd ones are blob resources
|
|
50
|
+
const isText = resourceId % 2 === 0;
|
|
51
|
+
const uri = isText
|
|
50
52
|
? textResourceUri(resourceId)
|
|
51
53
|
: blobResourceUri(resourceId);
|
|
52
54
|
// Get resource based on the resource type
|
|
53
|
-
const resource =
|
|
55
|
+
const resource = isText
|
|
54
56
|
? textResource(uri, resourceId)
|
|
55
57
|
: blobResource(uri, resourceId);
|
|
56
58
|
content.push({
|
|
57
59
|
type: "resource_link",
|
|
58
60
|
uri: resource.uri,
|
|
59
|
-
name: `${
|
|
61
|
+
name: `${isText ? "Text" : "Blob"} Resource ${resourceId}`,
|
|
60
62
|
description: `Resource ${resourceId}: ${resource.mimeType === "text/plain"
|
|
61
63
|
? "plaintext resource"
|
|
62
64
|
: "binary blob resource"}`,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { textResource, textResourceUri, blobResourceUri, blobResource, RESOURCE_TYPE_BLOB, RESOURCE_TYPE_TEXT, RESOURCE_TYPES, } from "../resources/templates.js";
|
|
3
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
3
4
|
// Tool input schema
|
|
4
5
|
const GetResourceReferenceSchema = z.object({
|
|
5
6
|
resourceType: z
|
|
@@ -16,6 +17,7 @@ const config = {
|
|
|
16
17
|
title: "Get Resource Reference Tool",
|
|
17
18
|
description: "Returns a resource reference that can be used by MCP clients",
|
|
18
19
|
inputSchema: GetResourceReferenceSchema,
|
|
20
|
+
icons: TOOL_ICONS,
|
|
19
21
|
annotations: {
|
|
20
22
|
readOnlyHint: true,
|
|
21
23
|
destructiveHint: false,
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// SDK's legacy shim sends a real `roots/list` request and re-enters the
|
|
8
8
|
// handler with the answer. Roots is deprecated as of 2026-07-28 (SEP-2577).
|
|
9
9
|
import { inputRequired, inputResponse, } from "@modelcontextprotocol/server";
|
|
10
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
10
11
|
// Tool configuration
|
|
11
12
|
const name = "get-roots-list";
|
|
12
13
|
const config = {
|
|
@@ -14,6 +15,7 @@ const config = {
|
|
|
14
15
|
description: "Lists the current MCP roots provided by the client. Demonstrates the roots protocol capability even though this server doesn't access files. " +
|
|
15
16
|
"Deprecated: Roots is deprecated as of protocol version 2026-07-28. The server asks for the roots with a multi-round-trip request on every protocol version.",
|
|
16
17
|
inputSchema: {},
|
|
18
|
+
icons: TOOL_ICONS,
|
|
17
19
|
annotations: {
|
|
18
20
|
readOnlyHint: true,
|
|
19
21
|
destructiveHint: false,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
2
3
|
// Tool input schema
|
|
3
4
|
const GetStructuredContentInputSchema = {
|
|
4
5
|
location: z
|
|
@@ -18,6 +19,7 @@ const config = {
|
|
|
18
19
|
description: "Returns structured content along with an output schema for client data validation",
|
|
19
20
|
inputSchema: GetStructuredContentInputSchema,
|
|
20
21
|
outputSchema: GetStructuredContentOutputSchema,
|
|
22
|
+
icons: TOOL_ICONS,
|
|
21
23
|
annotations: {
|
|
22
24
|
readOnlyHint: true,
|
|
23
25
|
destructiveHint: false,
|
package/dist/tools/get-sum.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
2
3
|
// Tool input schema
|
|
3
4
|
const GetSumSchema = z.object({
|
|
4
5
|
a: z.number().describe("First number"),
|
|
@@ -10,6 +11,7 @@ const config = {
|
|
|
10
11
|
title: "Get Sum Tool",
|
|
11
12
|
description: "Returns the sum of two numbers",
|
|
12
13
|
inputSchema: GetSumSchema,
|
|
14
|
+
icons: TOOL_ICONS,
|
|
13
15
|
annotations: {
|
|
14
16
|
readOnlyHint: true,
|
|
15
17
|
destructiveHint: false,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
1
2
|
// A tiny encoded MCP logo image
|
|
2
|
-
export const MCP_TINY_IMAGE = "
|
|
3
|
+
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
4
|
// Tool configuration
|
|
4
5
|
const name = "get-tiny-image";
|
|
5
6
|
const config = {
|
|
6
7
|
title: "Get Tiny Image Tool",
|
|
7
8
|
description: "Returns a tiny MCP logo image.",
|
|
8
9
|
inputSchema: {},
|
|
10
|
+
icons: TOOL_ICONS,
|
|
9
11
|
annotations: {
|
|
10
12
|
readOnlyHint: true,
|
|
11
13
|
destructiveHint: false,
|
|
@@ -9,19 +9,119 @@
|
|
|
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";
|
|
27
|
+
import { RESOURCE_ICONS, TOOL_ICONS } from "../server/icons.js";
|
|
16
28
|
// Maximum input file size - 10 MB default
|
|
17
29
|
const GZIP_MAX_FETCH_SIZE = Number(process.env.GZIP_MAX_FETCH_SIZE ?? String(10 * 1024 * 1024));
|
|
18
30
|
// Maximum fetch time - 30 seconds default.
|
|
19
31
|
const GZIP_MAX_FETCH_TIME_MILLIS = Number(process.env.GZIP_MAX_FETCH_TIME_MILLIS ?? String(30 * 1000));
|
|
20
|
-
// Comma-separated list of allowed domains
|
|
32
|
+
// Comma-separated list of allowed domains, matched by name on every request
|
|
33
|
+
// (redirect hops included). Empty means any name is allowed. It filters names,
|
|
34
|
+
// not addresses: a listed name that resolves to a private address is still
|
|
35
|
+
// refused unless GZIP_ALLOW_PRIVATE_IPS is set.
|
|
21
36
|
const GZIP_ALLOWED_DOMAINS = (process.env.GZIP_ALLOWED_DOMAINS ?? "")
|
|
22
37
|
.split(",")
|
|
23
38
|
.map((d) => d.trim().toLowerCase())
|
|
24
39
|
.filter((d) => d.length > 0);
|
|
40
|
+
// Opt in to fetching from loopback, private, link-local and other non-public
|
|
41
|
+
// addresses (1, true, yes or on). Off by default.
|
|
42
|
+
const GZIP_ALLOW_PRIVATE_IPS = /^(1|true|yes|on)$/i.test((process.env.GZIP_ALLOW_PRIVATE_IPS ?? "").trim());
|
|
43
|
+
// Redirects followed before a fetch is abandoned.
|
|
44
|
+
const MAX_REDIRECTS = 5;
|
|
45
|
+
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
46
|
+
// Addresses that are not public destinations: the IANA special-purpose ranges
|
|
47
|
+
// the fetch server refuses (src/fetch's _NON_PUBLIC_NETWORKS), plus
|
|
48
|
+
// multicast. BlockList judges an IPv4-mapped IPv6 address (::ffff:a.b.c.d) by
|
|
49
|
+
// the IPv4 rules, so those need no ranges of their own. The well-known NAT64
|
|
50
|
+
// prefix (64:ff9b::/96) is not unwrapped and so passes as public.
|
|
51
|
+
const NON_PUBLIC_ADDRESSES = new BlockList();
|
|
52
|
+
for (const [network, prefix] of [
|
|
53
|
+
["0.0.0.0", 8], // "this network", including the unspecified address
|
|
54
|
+
["10.0.0.0", 8], // RFC 1918
|
|
55
|
+
["100.64.0.0", 10], // CGNAT shared space (Alibaba Cloud metadata)
|
|
56
|
+
["127.0.0.0", 8], // loopback
|
|
57
|
+
["169.254.0.0", 16], // link-local (most cloud metadata endpoints)
|
|
58
|
+
["172.16.0.0", 12], // RFC 1918
|
|
59
|
+
["192.0.0.0", 24], // IETF protocol assignments
|
|
60
|
+
["192.0.2.0", 24], // documentation
|
|
61
|
+
["192.88.99.0", 24], // 6to4 relay anycast
|
|
62
|
+
["192.168.0.0", 16], // RFC 1918
|
|
63
|
+
["198.18.0.0", 15], // benchmarking
|
|
64
|
+
["198.51.100.0", 24], // documentation
|
|
65
|
+
["203.0.113.0", 24], // documentation
|
|
66
|
+
["224.0.0.0", 4], // multicast
|
|
67
|
+
["240.0.0.0", 4], // reserved, and broadcast
|
|
68
|
+
]) {
|
|
69
|
+
NON_PUBLIC_ADDRESSES.addSubnet(network, prefix, "ipv4");
|
|
70
|
+
}
|
|
71
|
+
for (const [network, prefix] of [
|
|
72
|
+
["::", 128], // unspecified
|
|
73
|
+
["::1", 128], // loopback
|
|
74
|
+
["64:ff9b:1::", 48], // local-use NAT64
|
|
75
|
+
["100::", 64], // discard-only
|
|
76
|
+
["2001::", 23], // IETF protocol assignments (Teredo among them)
|
|
77
|
+
["2001:db8::", 32], // documentation
|
|
78
|
+
["2002::", 16], // 6to4
|
|
79
|
+
["fc00::", 7], // unique local (AWS's fd00:ec2::254)
|
|
80
|
+
["fe80::", 10], // link-local
|
|
81
|
+
["ff00::", 8], // multicast
|
|
82
|
+
]) {
|
|
83
|
+
NON_PUBLIC_ADDRESSES.addSubnet(network, prefix, "ipv6");
|
|
84
|
+
}
|
|
85
|
+
// Globally reachable assignments inside those ranges (anycast services and
|
|
86
|
+
// the like), allowed as the fetch server allows its _PUBLIC_EXCEPTIONS.
|
|
87
|
+
const PUBLIC_EXCEPTIONS = new BlockList();
|
|
88
|
+
PUBLIC_EXCEPTIONS.addAddress("192.0.0.9", "ipv4");
|
|
89
|
+
PUBLIC_EXCEPTIONS.addAddress("192.0.0.10", "ipv4");
|
|
90
|
+
for (const [network, prefix] of [
|
|
91
|
+
["2001:1::1", 128],
|
|
92
|
+
["2001:1::2", 128],
|
|
93
|
+
["2001:3::", 32],
|
|
94
|
+
["2001:4:112::", 48],
|
|
95
|
+
["2001:20::", 28],
|
|
96
|
+
["2001:30::", 28],
|
|
97
|
+
]) {
|
|
98
|
+
PUBLIC_EXCEPTIONS.addSubnet(network, prefix, "ipv6");
|
|
99
|
+
}
|
|
100
|
+
/** True when `address` is not a public destination. */
|
|
101
|
+
function isNonPublic(address, family) {
|
|
102
|
+
const type = family === 6 ? "ipv6" : "ipv4";
|
|
103
|
+
return (!PUBLIC_EXCEPTIONS.check(address, type) &&
|
|
104
|
+
NON_PUBLIC_ADDRESSES.check(address, type));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Settles as `promise` does, or rejects with the signal's reason as soon as it
|
|
108
|
+
* aborts, so that the fetch deadline also bounds work that takes no signal
|
|
109
|
+
* (the DNS lookup).
|
|
110
|
+
*/
|
|
111
|
+
async function raceAbort(promise, signal) {
|
|
112
|
+
signal.throwIfAborted();
|
|
113
|
+
let onAbort = () => { };
|
|
114
|
+
const aborted = new Promise((_, reject) => {
|
|
115
|
+
onAbort = () => reject(signal.reason);
|
|
116
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
return await Promise.race([promise, aborted]);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
signal.removeEventListener("abort", onAbort);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
25
125
|
// Tool input schema
|
|
26
126
|
const GZipFileAsResourceSchema = z.object({
|
|
27
127
|
name: z
|
|
@@ -44,6 +144,7 @@ const config = {
|
|
|
44
144
|
title: "GZip File as Resource Tool",
|
|
45
145
|
description: "Compresses a single file using gzip compression. Depending upon the selected output type, returns either the compressed data as a gzipped resource or a resource link, allowing it to be downloaded in a subsequent request: during the current session for a 2025-era client, or for ten minutes at a minted URI on protocol version 2026-07-28.",
|
|
46
146
|
inputSchema: GZipFileAsResourceSchema,
|
|
147
|
+
icons: TOOL_ICONS,
|
|
47
148
|
annotations: {
|
|
48
149
|
readOnlyHint: false,
|
|
49
150
|
destructiveHint: false,
|
|
@@ -70,10 +171,8 @@ const config = {
|
|
|
70
171
|
export const registerGZipFileAsResourceTool = (server, context) => {
|
|
71
172
|
server.registerTool(name, config, async (args) => {
|
|
72
173
|
const { name, data: dataUri, outputType, } = GZipFileAsResourceSchema.parse(args);
|
|
73
|
-
//
|
|
74
|
-
const
|
|
75
|
-
// Fetch the data
|
|
76
|
-
const response = await fetchSafely(url, {
|
|
174
|
+
// Fetch the data; each request it makes is checked first
|
|
175
|
+
const response = await fetchSafely(new URL(dataUri), {
|
|
77
176
|
maxBytes: GZIP_MAX_FETCH_SIZE,
|
|
78
177
|
timeoutMillis: GZIP_MAX_FETCH_TIME_MILLIS,
|
|
79
178
|
});
|
|
@@ -84,7 +183,9 @@ export const registerGZipFileAsResourceTool = (server, context) => {
|
|
|
84
183
|
const uri = getSessionResourceURI(name);
|
|
85
184
|
const blob = compressedBuffer.toString("base64");
|
|
86
185
|
const mimeType = "application/gzip";
|
|
87
|
-
|
|
186
|
+
// #5434: the session resource is listed like any other, so it carries
|
|
187
|
+
// the resource icons (#3131) in resources/list and in its link.
|
|
188
|
+
const resource = { uri, name, mimeType, icons: RESOURCE_ICONS };
|
|
88
189
|
// Return the resource or a resource link that can be used to access this resource later
|
|
89
190
|
if (outputType === "resource") {
|
|
90
191
|
return {
|
|
@@ -112,36 +213,74 @@ export const registerGZipFileAsResourceTool = (server, context) => {
|
|
|
112
213
|
});
|
|
113
214
|
};
|
|
114
215
|
/**
|
|
115
|
-
*
|
|
216
|
+
* Refuses a request the server should not make: a protocol other than http,
|
|
217
|
+
* https or data; a host not in GZIP_ALLOWED_DOMAINS, when that is set; or,
|
|
218
|
+
* unless GZIP_ALLOW_PRIVATE_IPS is set, a host that resolves to any address
|
|
219
|
+
* that is not public. Called before every request, redirect hops included.
|
|
116
220
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
221
|
+
* This is a check, then a fetch: `fetch` resolves the name again to connect,
|
|
222
|
+
* so a name whose DNS answer changes between the two (DNS rebinding) can
|
|
223
|
+
* still reach a private address. Closing that window means pinning the
|
|
224
|
+
* checked address for the connection, which this demo server does not do.
|
|
225
|
+
*
|
|
226
|
+
* @param {URL} url The URL about to be requested.
|
|
227
|
+
* @param {AbortSignal} signal The fetch's deadline, which bounds the lookup too.
|
|
228
|
+
* @throws {Error} If the request is refused, or the host cannot be resolved.
|
|
120
229
|
*/
|
|
121
|
-
function
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
230
|
+
async function assertPermittedTarget(url, signal) {
|
|
231
|
+
const refuse = (reason) => new Error(`Error processing file ${url}: ${reason}`);
|
|
232
|
+
if (url.protocol === "data:")
|
|
233
|
+
return; // carries its own bytes
|
|
234
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
235
|
+
throw refuse(`Unsupported URL protocol for ${url}. Only http, https, and data URLs are supported.`);
|
|
236
|
+
}
|
|
237
|
+
// Names are matched as the URL spells them, an IPv6 literal with its
|
|
238
|
+
// brackets ([::1]), as they always have been
|
|
239
|
+
const domain = url.hostname;
|
|
240
|
+
if (GZIP_ALLOWED_DOMAINS.length > 0 &&
|
|
241
|
+
!GZIP_ALLOWED_DOMAINS.some((d) => domain === d || domain.endsWith(`.${d}`))) {
|
|
242
|
+
throw refuse(`Domain ${domain} is not in the allowed domains list.`);
|
|
243
|
+
}
|
|
244
|
+
if (GZIP_ALLOW_PRIVATE_IPS)
|
|
245
|
+
return;
|
|
246
|
+
// The resolver takes an IPv6 literal without its brackets
|
|
247
|
+
const host = domain.replace(/^\[(.*)\]$/, "$1");
|
|
248
|
+
const addresses = await raceAbort(lookup(host, { all: true }), signal);
|
|
249
|
+
for (const { address, family } of addresses) {
|
|
250
|
+
if (isNonPublic(address, family)) {
|
|
251
|
+
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
252
|
}
|
|
140
253
|
}
|
|
141
|
-
|
|
142
|
-
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Requests `url`, following redirects by hand so that every hop passes
|
|
257
|
+
* `assertPermittedTarget` first, and returns the first response that is not a
|
|
258
|
+
* redirect.
|
|
259
|
+
*
|
|
260
|
+
* @param {URL} url The URL the caller asked for.
|
|
261
|
+
* @param {AbortSignal} signal Aborts the request in flight.
|
|
262
|
+
* @return {Promise<Response>} The final response.
|
|
263
|
+
* @throws {Error} If a hop is refused, or there are more than MAX_REDIRECTS.
|
|
264
|
+
*/
|
|
265
|
+
async function fetchPermitted(url, signal) {
|
|
266
|
+
let target = url;
|
|
267
|
+
for (let redirects = 0;; redirects++) {
|
|
268
|
+
await assertPermittedTarget(target, signal);
|
|
269
|
+
const response = await fetch(target, { signal, redirect: "manual" });
|
|
270
|
+
const location = response.headers.get("location");
|
|
271
|
+
if (!REDIRECT_STATUSES.has(response.status) || location === null) {
|
|
272
|
+
return response;
|
|
273
|
+
}
|
|
274
|
+
// Discard the redirect's own body before moving on. Not awaited, as in
|
|
275
|
+
// fetchSafely: cancel() may never settle, and only the next hop matters.
|
|
276
|
+
response.body?.cancel().catch(
|
|
277
|
+
/* v8 ignore next -- only runs if cancelling the source fails, which nothing here can provoke */
|
|
278
|
+
() => { });
|
|
279
|
+
if (redirects === MAX_REDIRECTS) {
|
|
280
|
+
throw new Error(`Fetching ${url} followed more than ${MAX_REDIRECTS} redirects and was abandoned.`);
|
|
281
|
+
}
|
|
282
|
+
target = new URL(location, target);
|
|
143
283
|
}
|
|
144
|
-
return url;
|
|
145
284
|
}
|
|
146
285
|
/**
|
|
147
286
|
* Fetches data safely from a given URL while ensuring constraints on maximum byte size and timeout duration.
|
|
@@ -157,8 +296,20 @@ async function fetchSafely(url, { maxBytes, timeoutMillis }) {
|
|
|
157
296
|
const controller = new AbortController();
|
|
158
297
|
const timeout = setTimeout(() => controller.abort(`Fetching ${url} took more than ${timeoutMillis} ms and was aborted.`), timeoutMillis);
|
|
159
298
|
try {
|
|
160
|
-
// Fetch the data
|
|
161
|
-
|
|
299
|
+
// Fetch the data, following only redirects that pass the same checks.
|
|
300
|
+
// The response is the final, non-redirect one, so a redirect is never
|
|
301
|
+
// mistaken for an error status here.
|
|
302
|
+
const response = await fetchPermitted(url, controller.signal);
|
|
303
|
+
if (!response.ok) {
|
|
304
|
+
// An error page is not the requested file (#5207). Release the
|
|
305
|
+
// connection without reading the body; as with the size check below,
|
|
306
|
+
// the cancel is not awaited and its rejection is swallowed, since the
|
|
307
|
+
// thrown status error is the failure this path reports.
|
|
308
|
+
response.body?.cancel().catch(
|
|
309
|
+
/* v8 ignore next -- only runs if cancelling the source fails, which nothing here can provoke */
|
|
310
|
+
() => { });
|
|
311
|
+
throw new Error(`Fetching ${url} failed with HTTP ${response.status} ${response.statusText}`);
|
|
312
|
+
}
|
|
162
313
|
if (!response.body) {
|
|
163
314
|
throw new Error("No response body");
|
|
164
315
|
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { acceptedContent, inputRequired, inputResponse, } from "@modelcontextprotocol/server";
|
|
17
17
|
import { z } from "zod";
|
|
18
18
|
import { clientSupportsFormElicitation, createTask, } from "../server/tasks.js";
|
|
19
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
19
20
|
// Tool input schema
|
|
20
21
|
const SimulateResearchQuerySchema = z.object({
|
|
21
22
|
topic: z
|
|
@@ -48,6 +49,7 @@ const config = {
|
|
|
48
49
|
"If 'ambiguous' is true and the client supports elicitation, the task pauses with status " +
|
|
49
50
|
"input_required until the client answers its clarification request with tasks/update.",
|
|
50
51
|
inputSchema: SimulateResearchQuerySchema,
|
|
52
|
+
icons: TOOL_ICONS,
|
|
51
53
|
annotations: {
|
|
52
54
|
// Each call creates a task in the process-wide task store.
|
|
53
55
|
readOnlyHint: false,
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// per request. The timer belongs to the server instance serving this client,
|
|
10
10
|
// so no session map is needed (#4852).
|
|
11
11
|
import { beginSimulatedLogging } from "../server/logging.js";
|
|
12
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
12
13
|
// Tool configuration
|
|
13
14
|
const name = "toggle-simulated-logging";
|
|
14
15
|
const config = {
|
|
@@ -17,6 +18,7 @@ const config = {
|
|
|
17
18
|
"protocol version 2026-07-28 removes logging/setLevel; use trigger-log-messages with a per-request " +
|
|
18
19
|
"log level instead.",
|
|
19
20
|
inputSchema: {},
|
|
21
|
+
icons: TOOL_ICONS,
|
|
20
22
|
annotations: {
|
|
21
23
|
readOnlyHint: false,
|
|
22
24
|
destructiveHint: false,
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// `trigger-resource-update` sends one on demand. The timer belongs to the
|
|
10
10
|
// server instance serving this client, so no session map is needed (#4852).
|
|
11
11
|
import { beginSimulatedResourceUpdates } from "../resources/subscriptions.js";
|
|
12
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
12
13
|
// Tool configuration
|
|
13
14
|
const name = "toggle-subscriber-updates";
|
|
14
15
|
const config = {
|
|
@@ -17,6 +18,7 @@ const config = {
|
|
|
17
18
|
"since protocol version 2026-07-28 removes resources/subscribe; use trigger-resource-update with a " +
|
|
18
19
|
"subscriptions/listen stream instead.",
|
|
19
20
|
inputSchema: {},
|
|
21
|
+
icons: TOOL_ICONS,
|
|
20
22
|
annotations: {
|
|
21
23
|
readOnlyHint: false,
|
|
22
24
|
destructiveHint: false,
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { acceptedContent, inputRequired, inputResponse, } from "@modelcontextprotocol/server";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { createTask } from "../server/tasks.js";
|
|
14
|
+
import { TOOL_ICONS } from "../server/icons.js";
|
|
14
15
|
// Tool configuration
|
|
15
16
|
const name = "trigger-elicitation-request-async";
|
|
16
17
|
const config = {
|
|
@@ -19,6 +20,7 @@ const config = {
|
|
|
19
20
|
"the user's input: the task waits in status input_required, carrying an elicitation request, until the " +
|
|
20
21
|
"client answers it with tasks/update, then completes with a summary of the answer.",
|
|
21
22
|
inputSchema: {},
|
|
23
|
+
icons: TOOL_ICONS,
|
|
22
24
|
annotations: {
|
|
23
25
|
readOnlyHint: false,
|
|
24
26
|
destructiveHint: false,
|