@modelcontextprotocol/server-everything 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +37 -20
  2. package/dist/docs/architecture.md +6 -5
  3. package/dist/docs/extension.md +5 -3
  4. package/dist/docs/features.md +65 -71
  5. package/dist/docs/how-it-works.md +31 -16
  6. package/dist/docs/instructions.md +14 -7
  7. package/dist/docs/startup.md +28 -33
  8. package/dist/docs/structure.md +63 -29
  9. package/dist/prompts/args.js +2 -2
  10. package/dist/prompts/completions.js +3 -3
  11. package/dist/prompts/resource.js +3 -2
  12. package/dist/resources/files.js +9 -1
  13. package/dist/resources/index.js +7 -2
  14. package/dist/resources/minted.js +119 -0
  15. package/dist/resources/subscriptions.js +44 -122
  16. package/dist/resources/templates.js +5 -4
  17. package/dist/server/context.js +47 -0
  18. package/dist/server/index.js +113 -55
  19. package/dist/server/logging.js +39 -66
  20. package/dist/server/roots.js +41 -62
  21. package/dist/server/tasks.js +295 -0
  22. package/dist/tools/get-header-params.js +95 -0
  23. package/dist/tools/get-roots-list.js +49 -50
  24. package/dist/tools/gzip-file-as-resource.js +24 -5
  25. package/dist/tools/index.js +72 -14
  26. package/dist/tools/simulate-research-query.js +166 -201
  27. package/dist/tools/toggle-simulated-logging.js +33 -20
  28. package/dist/tools/toggle-subscriber-updates.js +33 -23
  29. package/dist/tools/trigger-elicitation-request-async.js +99 -204
  30. package/dist/tools/trigger-elicitation-request.js +197 -196
  31. package/dist/tools/trigger-list-changed.js +57 -0
  32. package/dist/tools/trigger-log-messages.js +60 -0
  33. package/dist/tools/trigger-long-running-operation.js +3 -3
  34. package/dist/tools/trigger-multi-step-elicitation.js +125 -0
  35. package/dist/tools/trigger-resource-update.js +52 -0
  36. package/dist/tools/trigger-sampling-request-async.js +79 -143
  37. package/dist/tools/trigger-sampling-request.js +51 -45
  38. package/dist/tools/trigger-url-elicitation.js +148 -111
  39. package/dist/transports/sse.js +26 -6
  40. package/dist/transports/stdio.js +42 -22
  41. package/dist/transports/streamableHttp.js +110 -14
  42. package/package.json +12 -5
@@ -1,9 +1,21 @@
1
- import { beginSimulatedResourceUpdates, stopSimulatedResourceUpdates, } from "../resources/subscriptions.js";
1
+ // The `toggle-subscriber-updates` tool: starts or stops a timer that sends
2
+ // `notifications/resources/updated` for each resource the client subscribed
3
+ // to with `resources/subscribe`.
4
+ //
5
+ // 2025-era only, and deprecated: the 2026-07-28 revision removes
6
+ // `resources/subscribe` and unsolicited notifications, so the server factory
7
+ // registers this tool only for a 2025-era client. A 2026-07-28 client asks
8
+ // for updates in its `subscriptions/listen` filter, and
9
+ // `trigger-resource-update` sends one on demand. The timer belongs to the
10
+ // server instance serving this client, so no session map is needed (#4852).
11
+ import { beginSimulatedResourceUpdates } from "../resources/subscriptions.js";
2
12
  // Tool configuration
3
13
  const name = "toggle-subscriber-updates";
4
14
  const config = {
5
15
  title: "Toggle Subscriber Updates",
6
- description: "Toggles simulated resource subscription updates on or off.",
16
+ description: "Toggles simulated resource subscription updates on or off. Deprecated: 2025-era clients only, " +
17
+ "since protocol version 2026-07-28 removes resources/subscribe; use trigger-resource-update with a " +
18
+ "subscriptions/listen stream instead.",
7
19
  inputSchema: {},
8
20
  annotations: {
9
21
  readOnlyHint: false,
@@ -12,39 +24,37 @@ const config = {
12
24
  openWorldHint: false,
13
25
  },
14
26
  };
15
- // Track enabled clients by session id
16
- const clients = new Set();
17
27
  /**
18
28
  * Registers the `toggle-subscriber-updates` tool.
19
29
  *
20
30
  * The registered tool enables or disables the sending of periodic, simulated resource
21
- * update messages the connected client for any subscriptions they have made.
22
- *
23
- * When invoked, it either starts or stops simulated resource updates based on the session's
24
- * current state. If simulated updates for the specified session is active, it will be stopped;
25
- * if it is inactive, simulated updates will be started.
26
- *
27
- * The response provides feedback indicating whether simulated updates were started or stopped,
28
- * including the session ID.
31
+ * update messages to the connected client for any subscriptions it has made.
32
+ * Each call flips the state: it starts the updates when they are off and stops
33
+ * them when they are on. The updates also stop when the connection ends.
29
34
  *
30
35
  * @param {McpServer} server - The McpServer instance where the tool will be registered.
36
+ * @param {ServerContext} context - The instance's subscriptions and cleanup registry.
31
37
  */
32
- export const registerToggleSubscriberUpdatesTool = (server) => {
33
- server.registerTool(name, config, async (_args, extra) => {
34
- const sessionId = extra?.sessionId;
38
+ export const registerToggleSubscriberUpdatesTool = (server, context) => {
39
+ let stop;
40
+ context.onCleanup(() => {
41
+ stop?.();
42
+ stop = undefined;
43
+ });
44
+ server.registerTool(name, config, async () => {
35
45
  let response;
36
- if (clients.has(sessionId)) {
37
- stopSimulatedResourceUpdates(sessionId);
38
- clients.delete(sessionId);
39
- response = `Stopped simulated resource updates for session ${sessionId}`;
46
+ if (stop) {
47
+ stop();
48
+ stop = undefined;
49
+ response = "Stopped simulated resource updates";
40
50
  }
41
51
  else {
42
- beginSimulatedResourceUpdates(server, sessionId);
43
- clients.add(sessionId);
44
- response = `Started simulated resource updated notifications for session ${sessionId} at a 5 second pace. Client will receive updates for any resources the it is subscribed to.`;
52
+ stop = beginSimulatedResourceUpdates(server, context.subscribed);
53
+ response =
54
+ "Started simulated resource updated notifications at a 5 second pace. Client will receive updates for any resources it is subscribed to.";
45
55
  }
46
56
  return {
47
- content: [{ type: "text", text: `${response}` }],
57
+ content: [{ type: "text", text: response }],
48
58
  };
49
59
  });
50
60
  };
@@ -1,11 +1,23 @@
1
+ // The `trigger-elicitation-request-async` tool: a task on the Tasks extension
2
+ // (`io.modelcontextprotocol/tasks`) that needs the user's input before it can
3
+ // finish, on protocol version 2026-07-28 (#4852).
4
+ //
5
+ // On 2025-11-25 this tool sent the client a task-augmented
6
+ // `elicitation/create` request and polled the client's own task. The
7
+ // 2026-07-28 revision has no server-to-client requests, so the roles turn
8
+ // around: the call returns a handle to a server task whose status is
9
+ // `input_required`, carrying the elicitation. The client shows it to the user
10
+ // and answers with `tasks/update`, and the task completes with a summary.
11
+ import { acceptedContent, inputRequired, inputResponse, } from "@modelcontextprotocol/server";
1
12
  import { z } from "zod";
13
+ import { createTask } from "../server/tasks.js";
2
14
  // Tool configuration
3
15
  const name = "trigger-elicitation-request-async";
4
16
  const config = {
5
17
  title: "Trigger Async Elicitation Request Tool",
6
- description: "Trigger an async elicitation request that the CLIENT executes as a background task. " +
7
- "Demonstrates bidirectional MCP tasks where the server sends an elicitation request and " +
8
- "the client handles user input asynchronously, allowing the server to poll for completion.",
18
+ description: "Runs as a task on the io.modelcontextprotocol/tasks extension (protocol version 2026-07-28) that needs " +
19
+ "the user's input: the task waits in status input_required, carrying an elicitation request, until the " +
20
+ "client answers it with tasks/update, then completes with a summary of the answer.",
9
21
  inputSchema: {},
10
22
  annotations: {
11
23
  readOnlyHint: false,
@@ -14,214 +26,97 @@ const config = {
14
26
  openWorldHint: false,
15
27
  },
16
28
  };
17
- // Poll interval in milliseconds
18
- const POLL_INTERVAL = 1000;
19
- // Time-to-live requested for the client's task (10 minutes for user input)
20
- const TASK_TTL = 600000;
21
- // Stop polling this long before the TTL runs out, so the last tasks/get
22
- // reaches the client while it still holds the task
23
- const TTL_SAFETY_MARGIN = 5000;
24
29
  /**
25
- * Registers the 'trigger-elicitation-request-async' tool.
30
+ * The form the task asks the user to fill in. The same schema is sent as the
31
+ * requested schema and checks the answer, since the client's answer is
32
+ * untrusted: an accepted answer that does not fit leaves the task waiting.
33
+ */
34
+ const FormSchema = z.object({
35
+ name: z
36
+ .string()
37
+ .min(1)
38
+ .meta({ title: "Your Name" })
39
+ .describe("Enter your name"),
40
+ favoriteColor: z
41
+ .enum(["red", "orange", "yellow", "green", "blue", "purple"])
42
+ .optional()
43
+ .meta({ title: "Favorite Color" })
44
+ .describe("What is your favorite color?"),
45
+ agreeToTerms: z
46
+ .boolean()
47
+ .optional()
48
+ .meta({ title: "Agree to Terms" })
49
+ .describe("Do you agree to the terms and conditions?"),
50
+ });
51
+ /** The completed task's summary of the user's answer. */
52
+ function summarize(action, content) {
53
+ const lines = [`Elicitation ${action}.`];
54
+ if (content) {
55
+ lines.push(`Name: ${content.name}`);
56
+ if (content.favoriteColor) {
57
+ lines.push(`Favorite color: ${content.favoriteColor}`);
58
+ }
59
+ if (content.agreeToTerms !== undefined) {
60
+ lines.push(`Agreed to terms: ${content.agreeToTerms}`);
61
+ }
62
+ }
63
+ return { content: [{ type: "text", text: lines.join("\n") }] };
64
+ }
65
+ /**
66
+ * Registers the 'trigger-elicitation-request-async' tool, for 2026-07-28
67
+ * clients.
26
68
  *
27
- * This tool demonstrates bidirectional MCP tasks for elicitation:
28
- * - Server sends elicitation request to client with task metadata
29
- * - Client creates a task and returns CreateTaskResult
30
- * - Client prompts user for input (task status: input_required)
31
- * - Server polls client's tasks/get endpoint for status
32
- * - Server fetches final result from client's tasks/result endpoint
69
+ * A client that does not declare both the tasks extension and form-mode
70
+ * elicitation is refused with -32021 before the tool runs (`guardTaskTools`).
33
71
  *
34
72
  * @param {McpServer} server - The McpServer instance where the tool will be registered.
35
73
  */
36
74
  export const registerTriggerElicitationRequestAsyncTool = (server) => {
37
- // Check client capabilities
38
- const clientCapabilities = server.server.getClientCapabilities() || {};
39
- // Client must support form-mode elicitation AND tasks.requests.elicitation.
40
- // The request is form mode, so a URL-only client cannot answer it (#4985):
41
- // form mode is `elicitation.form`, or `elicitation` with neither mode.
42
- const elicitation = clientCapabilities.elicitation;
43
- const clientSupportsElicitation = elicitation !== undefined &&
44
- (elicitation.form !== undefined || elicitation.url === undefined);
45
- const clientTasksCapability = clientCapabilities.tasks;
46
- const clientSupportsAsyncElicitation = clientTasksCapability?.requests?.elicitation?.create !== undefined;
47
- if (clientSupportsElicitation && clientSupportsAsyncElicitation) {
48
- server.registerTool(name, config, async (args, extra) => {
49
- // Polling must end before the client may expire the task. The client
50
- // starts the TTL when it creates the task, after this point, so a
51
- // deadline measured from here is conservative. performance.now() is
52
- // monotonic, so a wall-clock adjustment cannot stretch the deadline.
53
- const pollDeadline = performance.now() + TASK_TTL - TTL_SAFETY_MARGIN;
54
- // Create the elicitation request WITH task metadata
55
- // Using z.any() schema to avoid complex type matching with _meta
56
- const request = {
57
- method: "elicitation/create",
58
- params: {
59
- task: {
60
- ttl: TASK_TTL, // 10 minutes (user input may take a while)
61
- },
62
- message: "Please provide inputs for the following fields (async task demo):",
63
- requestedSchema: {
64
- type: "object",
65
- properties: {
66
- name: {
67
- title: "Your Name",
68
- type: "string",
69
- description: "Your full name",
70
- },
71
- favoriteColor: {
72
- title: "Favorite Color",
73
- type: "string",
74
- description: "What is your favorite color?",
75
- enum: ["Red", "Blue", "Green", "Yellow", "Purple"],
76
- },
77
- agreeToTerms: {
78
- title: "Terms Agreement",
79
- type: "boolean",
80
- description: "Do you agree to the terms and conditions?",
81
- },
82
- },
83
- required: ["name"],
75
+ server.registerTool(name, config, async () => {
76
+ const createdAt = Date.now();
77
+ let summary;
78
+ let answeredAt = createdAt;
79
+ // The key of the outstanding request. A key is never reused once
80
+ // answered, so a re-asked form gets the next one.
81
+ let attempt = 1;
82
+ const key = () => `form-${attempt}`;
83
+ return createTask({
84
+ stateAt: () => summary === undefined
85
+ ? {
86
+ // Waiting since the form, or the last re-ask, went out
87
+ since: answeredAt,
88
+ status: "input_required",
89
+ statusMessage: "Waiting for the user's input",
90
+ inputRequests: {
91
+ [key()]: inputRequired.elicit({
92
+ message: "Please provide inputs for the following fields (async task demo):",
93
+ requestedSchema: FormSchema,
94
+ }),
84
95
  },
85
- },
86
- };
87
- // Send the elicitation request
88
- // Client may return either:
89
- // - ElicitResult (synchronous execution)
90
- // - CreateTaskResult (task-based execution with { task } object)
91
- const elicitResponse = await extra.sendRequest(request, z.union([
92
- // CreateTaskResult - client created a task
93
- z.object({
94
- task: z.object({
95
- taskId: z.string(),
96
- status: z.string(),
97
- pollInterval: z.number().optional(),
98
- statusMessage: z.string().optional(),
99
- }),
100
- }),
101
- // ElicitResult - synchronous execution
102
- z.object({
103
- action: z.string(),
104
- content: z.any().optional(),
105
- }),
106
- ]));
107
- // Check if client returned CreateTaskResult (has task object)
108
- const isTaskResult = "task" in elicitResponse && elicitResponse.task;
109
- if (!isTaskResult) {
110
- // Client executed synchronously - return the direct response
111
- return {
112
- content: [
113
- {
114
- type: "text",
115
- text: `[SYNC] Client executed synchronously:\n${JSON.stringify(elicitResponse, null, 2)}`,
116
- },
117
- ],
118
- };
119
- }
120
- const taskId = elicitResponse.task.taskId;
121
- const statusMessages = [];
122
- statusMessages.push(`Task created: ${taskId}`);
123
- // Poll for task completion
124
- let attempts = 0;
125
- let taskStatus = elicitResponse.task.status;
126
- // A task that is already finished when created is never polled, so
127
- // its status message has to come from the CreateTaskResult
128
- let taskStatusMessage = elicitResponse.task.statusMessage;
129
- let timedOut = false;
130
- while (taskStatus !== "completed" &&
131
- taskStatus !== "failed" &&
132
- taskStatus !== "cancelled") {
133
- // Wait before polling
134
- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
135
- // Give up rather than poll past the TTL the task was created with.
136
- // Checked after the wait, so a timer that fires late cannot slip a
137
- // poll in after the deadline.
138
- if (performance.now() > pollDeadline) {
139
- timedOut = true;
140
- break;
141
96
  }
142
- attempts++;
143
- // Get task status from client
144
- const pollResult = await extra.sendRequest({
145
- method: "tasks/get",
146
- params: { taskId },
147
- }, z.looseObject({
148
- status: z.string(),
149
- statusMessage: z.string().optional(),
150
- }));
151
- taskStatus = pollResult.status;
152
- taskStatusMessage = pollResult.statusMessage;
153
- // Only log status changes or every 10 polls to avoid spam
154
- if (attempts === 1 ||
155
- attempts % 10 === 0 ||
156
- taskStatus !== "input_required") {
157
- statusMessages.push(`Poll ${attempts}: ${taskStatus}${taskStatusMessage ? ` - ${taskStatusMessage}` : ""}`);
97
+ : {
98
+ since: answeredAt,
99
+ status: "completed",
100
+ statusMessage: "Input received",
101
+ result: summary,
102
+ },
103
+ receive: (responses, now) => {
104
+ answeredAt = now;
105
+ const answer = inputResponse(responses, key());
106
+ if (answer.kind === "elicit" && answer.action !== "accept") {
107
+ summary = summarize(answer.action);
108
+ return;
158
109
  }
159
- }
160
- // Check for timeout
161
- if (timedOut) {
162
- return {
163
- content: [
164
- {
165
- type: "text",
166
- text: `[TIMEOUT] Task timed out after ${attempts} poll attempts, before its ${TASK_TTL / 60000}-minute TTL expired\n\nProgress:\n${statusMessages.join("\n")}`,
167
- },
168
- ],
169
- };
170
- }
171
- // Check for failure/cancellation
172
- if (taskStatus === "failed" || taskStatus === "cancelled") {
173
- return {
174
- content: [
175
- {
176
- type: "text",
177
- text: `[${taskStatus.toUpperCase()}] ${taskStatusMessage || "No message"}\n\nProgress:\n${statusMessages.join("\n")}`,
178
- },
179
- ],
180
- };
181
- }
182
- // Fetch the final result
183
- const result = await extra.sendRequest({
184
- method: "tasks/result",
185
- params: { taskId },
186
- }, z.any());
187
- // Format the elicitation result
188
- const content = [];
189
- if (result.action === "accept" && result.content) {
190
- content.push({
191
- type: "text",
192
- text: `[COMPLETED] User provided the requested information!`,
193
- });
194
- const userData = result.content;
195
- const lines = [];
196
- if (userData.name)
197
- lines.push(`- Name: ${userData.name}`);
198
- if (userData.favoriteColor)
199
- lines.push(`- Favorite Color: ${userData.favoriteColor}`);
200
- if (userData.agreeToTerms !== undefined)
201
- lines.push(`- Agreed to terms: ${userData.agreeToTerms}`);
202
- content.push({
203
- type: "text",
204
- text: `User inputs:\n${lines.join("\n")}`,
205
- });
206
- }
207
- else if (result.action === "decline") {
208
- content.push({
209
- type: "text",
210
- text: `[DECLINED] User declined to provide the requested information.`,
211
- });
212
- }
213
- else if (result.action === "cancel") {
214
- content.push({
215
- type: "text",
216
- text: `[CANCELLED] User cancelled the elicitation dialog.`,
217
- });
218
- }
219
- // Include progress and raw result for debugging
220
- content.push({
221
- type: "text",
222
- text: `\nProgress:\n${statusMessages.join("\n")}\n\nRaw result: ${JSON.stringify(result, null, 2)}`,
223
- });
224
- return { content };
225
- });
226
- }
110
+ const content = answer.kind === "elicit"
111
+ ? acceptedContent(responses, key(), FormSchema)
112
+ : undefined;
113
+ // An answer of another kind, or one that does not fit the form,
114
+ // spends the request: ask again under a new key.
115
+ if (content === undefined)
116
+ attempt++;
117
+ else
118
+ summary = summarize("accept", content);
119
+ },
120
+ }, { ttlMs: 10 * 60_000, pollIntervalMs: 1000 });
121
+ });
227
122
  };