@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,81 @@
1
+ import { z } from "zod";
2
+ import { textResource, textResourceUri, blobResourceUri, blobResource, RESOURCE_TYPE_BLOB, RESOURCE_TYPE_TEXT, RESOURCE_TYPES, } from "../resources/templates.js";
3
+ // Tool input schema
4
+ const GetResourceReferenceSchema = z.object({
5
+ resourceType: z
6
+ .enum([RESOURCE_TYPE_TEXT, RESOURCE_TYPE_BLOB])
7
+ .default(RESOURCE_TYPE_TEXT),
8
+ resourceId: z
9
+ .number()
10
+ .default(1)
11
+ .describe("ID of the text resource to fetch"),
12
+ });
13
+ // Tool configuration
14
+ const name = "get-resource-reference";
15
+ const config = {
16
+ title: "Get Resource Reference Tool",
17
+ description: "Returns a resource reference that can be used by MCP clients",
18
+ inputSchema: GetResourceReferenceSchema,
19
+ annotations: {
20
+ readOnlyHint: true,
21
+ destructiveHint: false,
22
+ idempotentHint: true,
23
+ openWorldHint: false,
24
+ },
25
+ };
26
+ /**
27
+ * Registers the 'get-resource-reference' tool.
28
+ *
29
+ * The registered tool validates and processes arguments for retrieving a resource
30
+ * reference. Supported resource types include predefined `RESOURCE_TYPE_TEXT` and
31
+ * `RESOURCE_TYPE_BLOB`. The retrieved resource's reference will include the resource
32
+ * ID, type, and its associated URI.
33
+ *
34
+ * The tool performs the following operations:
35
+ * 1. Validates the `resourceType` argument to ensure it matches a supported type.
36
+ * 2. Validates the `resourceId` argument to ensure it is a finite positive integer.
37
+ * 3. Constructs a URI for the resource based on its type (text or blob).
38
+ * 4. Retrieves the resource and returns it in a content block.
39
+ *
40
+ * @param {McpServer} server - The McpServer instance where the tool will be registered.
41
+ */
42
+ export const registerGetResourceReferenceTool = (server) => {
43
+ server.registerTool(name, config, async (args) => {
44
+ // Validate resource type argument
45
+ const { resourceType } = args;
46
+ /* v8 ignore next -- unreachable: the input schema's enum rejects any other resourceType before the handler runs */
47
+ if (!RESOURCE_TYPES.includes(resourceType)) {
48
+ throw new Error(`Invalid resourceType: ${args?.resourceType}. Must be ${RESOURCE_TYPE_TEXT} or ${RESOURCE_TYPE_BLOB}.`);
49
+ }
50
+ // Validate resourceId argument
51
+ const resourceId = Number(args?.resourceId);
52
+ if (!Number.isFinite(resourceId) ||
53
+ !Number.isInteger(resourceId) ||
54
+ resourceId < 1) {
55
+ throw new Error(`Invalid resourceId: ${args?.resourceId}. Must be a finite positive integer.`);
56
+ }
57
+ // Get resource based on the resource type
58
+ const uri = resourceType === RESOURCE_TYPE_TEXT
59
+ ? textResourceUri(resourceId)
60
+ : blobResourceUri(resourceId);
61
+ const resource = resourceType === RESOURCE_TYPE_TEXT
62
+ ? textResource(uri, resourceId)
63
+ : blobResource(uri, resourceId);
64
+ return {
65
+ content: [
66
+ {
67
+ type: "text",
68
+ text: `Returning resource reference for Resource ${resourceId}:`,
69
+ },
70
+ {
71
+ type: "resource",
72
+ resource: resource,
73
+ },
74
+ {
75
+ type: "text",
76
+ text: `You can access this resource using the URI: ${resource.uri}`,
77
+ },
78
+ ],
79
+ };
80
+ });
81
+ };
@@ -0,0 +1,76 @@
1
+ // The `get-roots-list` tool: asks the client for its roots and lists them.
2
+ //
3
+ // Written once for both protocol eras with a multi-round-trip request
4
+ // (#4852): the first call returns `input_required` carrying a `roots/list`
5
+ // request, the client answers it and retries, and the retry lists the
6
+ // answer. A 2026-07-28 client does that in-band; for a 2025-era client the
7
+ // SDK's legacy shim sends a real `roots/list` request and re-enters the
8
+ // handler with the answer. Roots is deprecated as of 2026-07-28 (SEP-2577).
9
+ import { inputRequired, inputResponse, } from "@modelcontextprotocol/server";
10
+ // Tool configuration
11
+ const name = "get-roots-list";
12
+ const config = {
13
+ title: "Get Roots List Tool",
14
+ description: "Lists the current MCP roots provided by the client. Demonstrates the roots protocol capability even though this server doesn't access files. " +
15
+ "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
+ inputSchema: {},
17
+ annotations: {
18
+ readOnlyHint: true,
19
+ destructiveHint: false,
20
+ idempotentHint: true,
21
+ openWorldHint: false,
22
+ },
23
+ };
24
+ /**
25
+ * Registers the 'get-roots-list' tool.
26
+ *
27
+ * The tool needs a client that supports Roots: on a 2025-era connection the
28
+ * server factory registers it only for one that declared the capability, and
29
+ * on 2026-07-28 the SDK refuses the embedded request (-32021) of a client
30
+ * whose request did not declare it.
31
+ *
32
+ * @param {McpServer} server - The McpServer instance where the tool will be registered.
33
+ */
34
+ export const registerGetRootsListTool = (server) => {
35
+ server.registerTool(name, config, async (_args, ctx) => {
36
+ const answer = inputResponse(ctx.mcpReq.inputResponses, "roots");
37
+ // First round: ask the client for its roots
38
+ if (answer.kind !== "roots") {
39
+ return inputRequired({
40
+ inputRequests: { roots: inputRequired.listRoots() },
41
+ });
42
+ }
43
+ const currentRoots = answer.roots;
44
+ // Respond if client supports roots but doesn't have any configured
45
+ if (currentRoots.length === 0) {
46
+ return {
47
+ content: [
48
+ {
49
+ type: "text",
50
+ text: "The client supports roots but no roots are currently configured.\n\n" +
51
+ "This could mean:\n" +
52
+ "1. The client hasn't provided any roots yet\n" +
53
+ "2. The client provided an empty roots list\n" +
54
+ "3. The roots configuration is still being loaded",
55
+ },
56
+ ],
57
+ };
58
+ }
59
+ // Create formatted response if there is a list of roots
60
+ const rootsList = currentRoots
61
+ .map((root, index) => {
62
+ return `${index + 1}. ${root.name || "Unnamed Root"}\n URI: ${root.uri}`;
63
+ })
64
+ .join("\n\n");
65
+ return {
66
+ content: [
67
+ {
68
+ type: "text",
69
+ text: `Current MCP Roots (${currentRoots.length} total):\n\n${rootsList}\n\n` +
70
+ "Note: This server demonstrates the roots protocol capability but doesn't actually access files. " +
71
+ "The roots are provided by the MCP client and can be used by servers that need file system access.",
72
+ },
73
+ ],
74
+ };
75
+ });
76
+ };
@@ -0,0 +1,78 @@
1
+ import { z } from "zod";
2
+ // Tool input schema
3
+ const GetStructuredContentInputSchema = {
4
+ location: z
5
+ .enum(["New York", "Chicago", "Los Angeles"])
6
+ .describe("Choose city"),
7
+ };
8
+ // Tool output schema
9
+ const GetStructuredContentOutputSchema = z.object({
10
+ temperature: z.number().describe("Temperature in celsius"),
11
+ conditions: z.string().describe("Weather conditions description"),
12
+ humidity: z.number().describe("Humidity percentage"),
13
+ });
14
+ // Tool configuration
15
+ const name = "get-structured-content";
16
+ const config = {
17
+ title: "Get Structured Content Tool",
18
+ description: "Returns structured content along with an output schema for client data validation",
19
+ inputSchema: GetStructuredContentInputSchema,
20
+ outputSchema: GetStructuredContentOutputSchema,
21
+ annotations: {
22
+ readOnlyHint: true,
23
+ destructiveHint: false,
24
+ idempotentHint: true,
25
+ openWorldHint: false,
26
+ },
27
+ };
28
+ /**
29
+ * Registers the 'get-structured-content' tool.
30
+ *
31
+ * The registered tool processes incoming arguments using a predefined input schema,
32
+ * generates structured content with weather information including temperature,
33
+ * conditions, and humidity, and returns both backward-compatible content blocks
34
+ * and structured content in the response.
35
+ *
36
+ * The response contains:
37
+ * - `content`: An array of content blocks, presented as JSON stringified objects.
38
+ * - `structuredContent`: A JSON structured representation of the weather data.
39
+ *
40
+ * @param {McpServer} server - The McpServer instance where the tool will be registered.
41
+ */
42
+ export const registerGetStructuredContentTool = (server) => {
43
+ server.registerTool(name, config, async (args) => {
44
+ // Get simulated weather for the chosen city
45
+ let weather;
46
+ switch (args.location) {
47
+ case "New York":
48
+ weather = {
49
+ temperature: 33,
50
+ conditions: "Cloudy",
51
+ humidity: 82,
52
+ };
53
+ break;
54
+ case "Chicago":
55
+ weather = {
56
+ temperature: 36,
57
+ conditions: "Light rain / drizzle",
58
+ humidity: 82,
59
+ };
60
+ break;
61
+ case "Los Angeles":
62
+ weather = {
63
+ temperature: 73,
64
+ conditions: "Sunny / Clear",
65
+ humidity: 48,
66
+ };
67
+ break;
68
+ }
69
+ const backwardCompatibleContentBlock = {
70
+ type: "text",
71
+ text: JSON.stringify(weather),
72
+ };
73
+ return {
74
+ content: [backwardCompatibleContentBlock],
75
+ structuredContent: weather,
76
+ };
77
+ });
78
+ };
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ // Tool input schema
3
+ const GetSumSchema = z.object({
4
+ a: z.number().describe("First number"),
5
+ b: z.number().describe("Second number"),
6
+ });
7
+ // Tool configuration
8
+ const name = "get-sum";
9
+ const config = {
10
+ title: "Get Sum Tool",
11
+ description: "Returns the sum of two numbers",
12
+ inputSchema: GetSumSchema,
13
+ annotations: {
14
+ readOnlyHint: true,
15
+ destructiveHint: false,
16
+ idempotentHint: true,
17
+ openWorldHint: false,
18
+ },
19
+ };
20
+ /**
21
+ * Registers the 'get-sum' tool.
22
+ **
23
+ * The registered tool processes input arguments, validates them using a predefined schema,
24
+ * calculates the sum of two numeric values, and returns the result in a content block.
25
+ *
26
+ * Expects input arguments to conform to a specific schema that includes two numeric properties, `a` and `b`.
27
+ * Validation is performed to ensure the input adheres to the expected structure before calculating the sum.
28
+ *
29
+ * The result is returned as a Promise resolving to an object containing the computed sum in a text format.
30
+ *
31
+ * @param {McpServer} server - The McpServer instance where the tool will be registered.
32
+ */
33
+ export const registerGetSumTool = (server) => {
34
+ server.registerTool(name, config, async (args) => {
35
+ const validatedArgs = GetSumSchema.parse(args);
36
+ const sum = validatedArgs.a + validatedArgs.b;
37
+ return {
38
+ content: [
39
+ {
40
+ type: "text",
41
+ text: `The sum of ${validatedArgs.a} and ${validatedArgs.b} is ${sum}.`,
42
+ },
43
+ ],
44
+ };
45
+ });
46
+ };
@@ -0,0 +1,47 @@
1
+ // A tiny encoded MCP logo image
2
+ export const MCP_TINY_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAKsGlDQ1BJQ0MgUHJvZmlsZQAASImVlwdUU+kSgOfe9JDQEiIgJfQmSCeAlBBaAAXpYCMkAUKJMRBU7MriClZURLCs6KqIgo0idizYFsWC3QVZBNR1sWDDlXeBQ9jdd9575805c+a7c+efmf+e/z9nLgCdKZDJMlF1gCxpjjwyyI8dn5DIJvUABRiY0kBdIMyWcSMiwgCTUft3+dgGyJC9YzuU69/f/1fREImzhQBIBMbJomxhFsbHMe0TyuQ5ALg9mN9kbo5siK9gzJRjDWL8ZIhTR7hviJOHGY8fjomO5GGsDUCmCQTyVACaKeZn5wpTsTw0f4ztpSKJFGPsGbyzsmaLMMbqgiUWI8N4KD8n+S95Uv+WM1mZUyBIVfLIXoaF7C/JlmUK5v+fn+N/S1amYrSGOaa0NHlwJGaxvpAHGbNDlSxNnhI+yhLRcPwwpymCY0ZZmM1LHGWRwD9UuTZzStgop0gC+co8OfzoURZnB0SNsnx2pLJWipzHHWWBfKyuIiNG6U8T85X589Ki40Y5VxI7ZZSzM6JCx2J4Sr9cEansXywN8hurG6jce1b2X/Yr4SvX5qRFByv3LhjrXyzljuXMjlf2JhL7B4zFxCjjZTl+ylqyzAhlvDgzSOnPzo1Srs3BDuTY2gjlN0wXhESMMoRBELAhBjIhB+QggECQgBTEOeJ5Q2cUeLNl8+WS1LQcNhe7ZWI2Xyq0m8B2tHd0Bhi6syNH4j1r+C4irGtjvhWVAF4nBgcHT475Qm4BHEkCoNaO+SxnAKh3A1w5JVTIc0d8Q9cJCEAFNWCCDhiACViCLTiCK3iC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ec7t9/44VgWigEeby+UgFArJWjUYOqhWG6x50rpcSfR6PVUfNOgEVRlTX0HhrZBKz4MZjUYWi8VoA+lc9H/VaRZYjBKrtXR8tlwumcFgeMWRbZpA9ORQWfVm8A/FsrLaxebd5wAAAABJRU5ErkJggg==";
3
+ // Tool configuration
4
+ const name = "get-tiny-image";
5
+ const config = {
6
+ title: "Get Tiny Image Tool",
7
+ description: "Returns a tiny MCP logo image.",
8
+ inputSchema: {},
9
+ annotations: {
10
+ readOnlyHint: true,
11
+ destructiveHint: false,
12
+ idempotentHint: true,
13
+ openWorldHint: false,
14
+ },
15
+ };
16
+ /**
17
+ * Registers the "get-tiny-image" tool.
18
+ *
19
+ * The registered tool returns a response containing a small image alongside some
20
+ * descriptive text.
21
+ *
22
+ * The response structure includes textual content before and after the image.
23
+ * The image is served as a PNG data type and represents the default MCP tiny image.
24
+ *
25
+ * @param server - The McpServer instance where the tool will be registered.
26
+ */
27
+ export const registerGetTinyImageTool = (server) => {
28
+ server.registerTool(name, config, async () => {
29
+ return {
30
+ content: [
31
+ {
32
+ type: "text",
33
+ text: "Here's the image you requested:",
34
+ },
35
+ {
36
+ type: "image",
37
+ data: MCP_TINY_IMAGE,
38
+ mimeType: "image/png",
39
+ },
40
+ {
41
+ type: "text",
42
+ text: "The image above is the MCP logo.",
43
+ },
44
+ ],
45
+ };
46
+ });
47
+ };
@@ -0,0 +1,213 @@
1
+ // The `gzip-file-as-resource` tool: fetches a file, gzips it, and returns the
2
+ // result as an embedded resource or as a link to a resource the client can
3
+ // read later.
4
+ //
5
+ // Where that later resource lives depends on the protocol era (#4852). For a
6
+ // 2025-era client it is registered on the server instance serving the
7
+ // client's connection or session (resources/session.ts), and lasts as long as
8
+ // that does. The 2026-07-28 revision has no sessions, and on its HTTP path
9
+ // each request gets a fresh instance, so for a 2026-07-28 client the resource
10
+ // is stored under a URI with a server-minted id that every instance can serve
11
+ // (resources/minted.ts), and expires after ten minutes.
12
+ import { z } from "zod";
13
+ import { gzipSync } from "node:zlib";
14
+ import { mintBlobResource } from "../resources/minted.js";
15
+ import { getSessionResourceURI, registerSessionResource, } from "../resources/session.js";
16
+ // Maximum input file size - 10 MB default
17
+ const GZIP_MAX_FETCH_SIZE = Number(process.env.GZIP_MAX_FETCH_SIZE ?? String(10 * 1024 * 1024));
18
+ // Maximum fetch time - 30 seconds default.
19
+ const GZIP_MAX_FETCH_TIME_MILLIS = Number(process.env.GZIP_MAX_FETCH_TIME_MILLIS ?? String(30 * 1000));
20
+ // Comma-separated list of allowed domains. Empty means all domains are allowed.
21
+ const GZIP_ALLOWED_DOMAINS = (process.env.GZIP_ALLOWED_DOMAINS ?? "")
22
+ .split(",")
23
+ .map((d) => d.trim().toLowerCase())
24
+ .filter((d) => d.length > 0);
25
+ // Tool input schema
26
+ const GZipFileAsResourceSchema = z.object({
27
+ name: z
28
+ .string()
29
+ .max(255)
30
+ .describe("Name of the output file (at most 255 characters)")
31
+ .default("README.md.gz"),
32
+ data: z
33
+ .url()
34
+ .describe("URL or data URI of the file content to compress")
35
+ .default("https://raw.githubusercontent.com/modelcontextprotocol/servers/refs/heads/main/README.md"),
36
+ outputType: z
37
+ .enum(["resourceLink", "resource"])
38
+ .default("resourceLink")
39
+ .describe("How the resulting gzipped file should be returned. 'resourceLink' returns a link to a resource that can be read later, 'resource' returns a full resource object."),
40
+ });
41
+ // Tool configuration
42
+ const name = "gzip-file-as-resource";
43
+ const config = {
44
+ title: "GZip File as Resource Tool",
45
+ 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
+ inputSchema: GZipFileAsResourceSchema,
47
+ annotations: {
48
+ readOnlyHint: false,
49
+ destructiveHint: false,
50
+ idempotentHint: true,
51
+ openWorldHint: true,
52
+ },
53
+ };
54
+ /**
55
+ * Registers the `gzip-file-as-resource` tool.
56
+ *
57
+ * The registered tool compresses input data using gzip, and makes the resulting file accessible
58
+ * as a resource for the duration of the session.
59
+ *
60
+ * The tool supports two output types:
61
+ * - "resource": Returns the resource directly, including its URI, MIME type, and base64-encoded content.
62
+ * - "resourceLink": Returns a link to access the resource later.
63
+ *
64
+ * If an unrecognized `outputType` is provided, the tool throws an error.
65
+ *
66
+ * @param {McpServer} server - The McpServer instance where the tool will be registered.
67
+ * @param {ServerContext} context - The protocol era the instance serves.
68
+ * @throws {Error} Throws an error if an unknown output type is specified.
69
+ */
70
+ export const registerGZipFileAsResourceTool = (server, context) => {
71
+ server.registerTool(name, config, async (args) => {
72
+ const { name, data: dataUri, outputType, } = GZipFileAsResourceSchema.parse(args);
73
+ // Validate data uri
74
+ const url = validateDataURI(dataUri);
75
+ // Fetch the data
76
+ const response = await fetchSafely(url, {
77
+ maxBytes: GZIP_MAX_FETCH_SIZE,
78
+ timeoutMillis: GZIP_MAX_FETCH_TIME_MILLIS,
79
+ });
80
+ // Compress the data using gzip
81
+ const inputBuffer = Buffer.from(response);
82
+ const compressedBuffer = gzipSync(inputBuffer);
83
+ // Create resource
84
+ const uri = getSessionResourceURI(name);
85
+ const blob = compressedBuffer.toString("base64");
86
+ const mimeType = "application/gzip";
87
+ const resource = { uri, name, mimeType };
88
+ // Return the resource or a resource link that can be used to access this resource later
89
+ if (outputType === "resource") {
90
+ return {
91
+ content: [
92
+ {
93
+ type: "resource",
94
+ resource: { uri, mimeType, blob },
95
+ },
96
+ ],
97
+ };
98
+ }
99
+ else if (outputType === "resourceLink") {
100
+ // Make the resource readable later, where this era can reach it
101
+ const resourceLink = context.era === "modern"
102
+ ? mintBlobResource(name, mimeType, blob)
103
+ : registerSessionResource(server, resource, "blob", blob);
104
+ return {
105
+ content: [resourceLink],
106
+ };
107
+ }
108
+ else {
109
+ /* v8 ignore next -- unreachable: the input schema's enum admits only resource and resourceLink */
110
+ throw new Error(`Unknown outputType: ${outputType}`);
111
+ }
112
+ });
113
+ };
114
+ /**
115
+ * Validates a given data URI to ensure it follows the appropriate protocols and rules.
116
+ *
117
+ * @param {string} dataUri - The data URI to validate. Must be an HTTP, HTTPS, or data protocol URL. If a domain is provided, it must match the allowed domains list if applicable.
118
+ * @return {URL} The validated and parsed URL object.
119
+ * @throws {Error} If the data URI does not use a supported protocol or does not meet allowed domains criteria.
120
+ */
121
+ function validateDataURI(dataUri) {
122
+ // Validate Inputs
123
+ const url = new URL(dataUri);
124
+ try {
125
+ if (url.protocol !== "http:" &&
126
+ url.protocol !== "https:" &&
127
+ url.protocol !== "data:") {
128
+ throw new Error(`Unsupported URL protocol for ${dataUri}. Only http, https, and data URLs are supported.`);
129
+ }
130
+ if (GZIP_ALLOWED_DOMAINS.length > 0 &&
131
+ (url.protocol === "http:" || url.protocol === "https:")) {
132
+ const domain = url.hostname;
133
+ const domainAllowed = GZIP_ALLOWED_DOMAINS.some((allowedDomain) => {
134
+ return domain === allowedDomain || domain.endsWith(`.${allowedDomain}`);
135
+ });
136
+ if (!domainAllowed) {
137
+ throw new Error(`Domain ${domain} is not in the allowed domains list.`);
138
+ }
139
+ }
140
+ }
141
+ catch (error) {
142
+ throw new Error(`Error processing file ${dataUri}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
143
+ }
144
+ return url;
145
+ }
146
+ /**
147
+ * Fetches data safely from a given URL while ensuring constraints on maximum byte size and timeout duration.
148
+ *
149
+ * @param {URL} url The URL to fetch data from.
150
+ * @param {Object} options An object containing options for the fetch operation.
151
+ * @param {number} options.maxBytes The maximum allowed size (in bytes) of the response. If the response exceeds this size, the operation will be aborted.
152
+ * @param {number} options.timeoutMillis The timeout duration (in milliseconds) for the fetch operation. If the fetch takes longer, it will be aborted.
153
+ * @return {Promise<ArrayBuffer>} A promise that resolves with the response as an ArrayBuffer if successful.
154
+ * @throws {Error} Throws an error if the response size exceeds the defined limit, the fetch times out, or the response is otherwise invalid.
155
+ */
156
+ async function fetchSafely(url, { maxBytes, timeoutMillis }) {
157
+ const controller = new AbortController();
158
+ const timeout = setTimeout(() => controller.abort(`Fetching ${url} took more than ${timeoutMillis} ms and was aborted.`), timeoutMillis);
159
+ try {
160
+ // Fetch the data
161
+ const response = await fetch(url, { signal: controller.signal });
162
+ if (!response.body) {
163
+ throw new Error("No response body");
164
+ }
165
+ // Note: we can't trust the Content-Length header: a malicious or clumsy server could return much more data than advertised.
166
+ // We check it here for early bail-out, but we still need to monitor actual bytes read below.
167
+ const contentLengthHeader = response.headers.get("content-length");
168
+ if (contentLengthHeader != null) {
169
+ const contentLength = parseInt(contentLengthHeader, 10);
170
+ if (contentLength > maxBytes) {
171
+ throw new Error(`Content-Length for ${url} exceeds max of ${maxBytes}: ${contentLength}`);
172
+ }
173
+ }
174
+ // Read the fetched data from the response body
175
+ const reader = response.body.getReader();
176
+ const chunks = [];
177
+ let totalSize = 0;
178
+ // Read chunks until done
179
+ try {
180
+ while (true) {
181
+ const { done, value } = await reader.read();
182
+ if (done)
183
+ break;
184
+ totalSize += value.length;
185
+ if (totalSize > maxBytes) {
186
+ // Not awaited: cancel() adopts the source's promise and may never
187
+ // settle, and we are about to throw anyway. Swallow its rejection so
188
+ // it cannot surface as an unhandled one; the thrown size error is
189
+ // the failure this path reports.
190
+ reader.cancel().catch(
191
+ /* v8 ignore next -- only runs if cancelling the source fails, which nothing here can provoke */
192
+ () => { });
193
+ throw new Error(`Response from ${url} exceeds ${maxBytes} bytes`);
194
+ }
195
+ chunks.push(value);
196
+ }
197
+ }
198
+ finally {
199
+ reader.releaseLock();
200
+ }
201
+ // Combine chunks into a single buffer
202
+ const buffer = new Uint8Array(totalSize);
203
+ let offset = 0;
204
+ for (const chunk of chunks) {
205
+ buffer.set(chunk, offset);
206
+ offset += chunk.length;
207
+ }
208
+ return buffer.buffer;
209
+ }
210
+ finally {
211
+ clearTimeout(timeout);
212
+ }
213
+ }
@@ -0,0 +1,110 @@
1
+ // Registers the everything server's tools, grouped by the protocol era that
2
+ // gets them (#4852):
3
+ // - `registerTools`: every client, on either era.
4
+ // - `registerLegacyTools`: 2025-era clients only, for the deprecated features
5
+ // the 2026-07-28 revision removes (`logging/setLevel`, `resources/subscribe`).
6
+ // - `registerConditionalTools`: 2025-era clients that declared the capability
7
+ // a tool needs; called once `initialize` has told the server what the client
8
+ // supports.
9
+ // - `registerModernTools`: 2026-07-28 clients. Their capabilities arrive with
10
+ // each request, so the capability-gated tools are registered up front and the
11
+ // SDK refuses an embedded request the client did not declare (-32021); the
12
+ // task tools are served only here, on the tasks extension.
13
+ import { registerGetAnnotatedMessageTool } from "./get-annotated-message.js";
14
+ import { registerEchoTool } from "./echo.js";
15
+ import { registerGetEnvTool } from "./get-env.js";
16
+ import { registerGetHeaderParamsTool } from "./get-header-params.js";
17
+ import { registerGetResourceLinksTool } from "./get-resource-links.js";
18
+ import { registerGetResourceReferenceTool } from "./get-resource-reference.js";
19
+ import { registerGetRootsListTool } from "./get-roots-list.js";
20
+ import { registerGetStructuredContentTool } from "./get-structured-content.js";
21
+ import { registerGetSumTool } from "./get-sum.js";
22
+ import { registerGetTinyImageTool } from "./get-tiny-image.js";
23
+ import { registerGZipFileAsResourceTool } from "./gzip-file-as-resource.js";
24
+ import { registerSimulateResearchQueryTool } from "./simulate-research-query.js";
25
+ import { registerToggleSimulatedLoggingTool } from "./toggle-simulated-logging.js";
26
+ import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates.js";
27
+ import { registerTriggerElicitationRequestAsyncTool } from "./trigger-elicitation-request-async.js";
28
+ import { registerTriggerElicitationRequestTool } from "./trigger-elicitation-request.js";
29
+ import { registerTriggerListChangedTool } from "./trigger-list-changed.js";
30
+ import { registerTriggerLogMessagesTool } from "./trigger-log-messages.js";
31
+ import { registerTriggerLongRunningOperationTool } from "./trigger-long-running-operation.js";
32
+ import { registerTriggerMultiStepElicitationTool } from "./trigger-multi-step-elicitation.js";
33
+ import { registerTriggerResourceUpdateTool } from "./trigger-resource-update.js";
34
+ import { registerTriggerSamplingRequestAsyncTool } from "./trigger-sampling-request-async.js";
35
+ import { registerTriggerSamplingRequestTool } from "./trigger-sampling-request.js";
36
+ import { registerTriggerUrlElicitationTool } from "./trigger-url-elicitation.js";
37
+ /**
38
+ * Register the tools every client gets, on either protocol era.
39
+ * @param server
40
+ * @param context
41
+ */
42
+ export const registerTools = (server, context) => {
43
+ registerEchoTool(server);
44
+ registerGetAnnotatedMessageTool(server);
45
+ registerGetEnvTool(server);
46
+ registerGetHeaderParamsTool(server);
47
+ registerGetResourceLinksTool(server);
48
+ registerGetResourceReferenceTool(server);
49
+ registerGetStructuredContentTool(server);
50
+ registerGetSumTool(server);
51
+ registerGetTinyImageTool(server);
52
+ registerGZipFileAsResourceTool(server, context);
53
+ registerTriggerListChangedTool(server, context);
54
+ registerTriggerLogMessagesTool(server);
55
+ registerTriggerLongRunningOperationTool(server);
56
+ registerTriggerResourceUpdateTool(server, context);
57
+ };
58
+ /**
59
+ * Register the deprecated tools that only a 2025-era client gets, because
60
+ * they rely on methods the 2026-07-28 revision removes.
61
+ * @param server
62
+ * @param context
63
+ */
64
+ export const registerLegacyTools = (server, context) => {
65
+ registerToggleSimulatedLoggingTool(server, context);
66
+ registerToggleSubscriberUpdatesTool(server, context);
67
+ };
68
+ /**
69
+ * Register the tools that need a client capability, for a 2025-era client
70
+ * that declared it. These must be registered after initialization, when the
71
+ * client's capabilities are known.
72
+ * @param server
73
+ * @param context
74
+ */
75
+ export const registerConditionalTools = (server, context) => {
76
+ const capabilities = server.server.getClientCapabilities() || {};
77
+ const elicitation = capabilities.elicitation;
78
+ // Form mode is `elicitation.form`, or `elicitation` with neither mode,
79
+ // which the spec treats as form mode for backwards compatibility (#4985).
80
+ const supportsFormElicitation = elicitation !== undefined &&
81
+ (elicitation.form !== undefined || elicitation.url === undefined);
82
+ if (capabilities.roots !== undefined)
83
+ registerGetRootsListTool(server);
84
+ if (supportsFormElicitation) {
85
+ registerTriggerElicitationRequestTool(server);
86
+ registerTriggerMultiStepElicitationTool(server);
87
+ }
88
+ if (elicitation?.url !== undefined) {
89
+ registerTriggerUrlElicitationTool(server, context);
90
+ }
91
+ if (capabilities.sampling !== undefined) {
92
+ registerTriggerSamplingRequestTool(server);
93
+ }
94
+ };
95
+ /**
96
+ * Register the tools a 2026-07-28 client gets beyond the common ones: the
97
+ * capability-gated tools, registered up front, and the task tools.
98
+ * @param server
99
+ * @param context
100
+ */
101
+ export const registerModernTools = (server, context) => {
102
+ registerGetRootsListTool(server);
103
+ registerTriggerElicitationRequestTool(server);
104
+ registerTriggerMultiStepElicitationTool(server);
105
+ registerTriggerUrlElicitationTool(server, context);
106
+ registerTriggerSamplingRequestTool(server);
107
+ registerSimulateResearchQueryTool(server);
108
+ registerTriggerSamplingRequestAsyncTool(server);
109
+ registerTriggerElicitationRequestAsyncTool(server);
110
+ };