@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.
- package/README.md +37 -20
- package/dist/docs/architecture.md +6 -5
- package/dist/docs/extension.md +5 -3
- package/dist/docs/features.md +65 -71
- package/dist/docs/how-it-works.md +31 -16
- package/dist/docs/instructions.md +14 -7
- package/dist/docs/startup.md +28 -33
- package/dist/docs/structure.md +63 -29
- package/dist/prompts/args.js +2 -2
- package/dist/prompts/completions.js +3 -3
- package/dist/prompts/resource.js +3 -2
- package/dist/resources/files.js +9 -1
- package/dist/resources/index.js +7 -2
- package/dist/resources/minted.js +119 -0
- package/dist/resources/subscriptions.js +44 -122
- package/dist/resources/templates.js +5 -4
- package/dist/server/context.js +47 -0
- package/dist/server/index.js +113 -55
- package/dist/server/logging.js +39 -66
- package/dist/server/roots.js +41 -62
- package/dist/server/tasks.js +295 -0
- package/dist/tools/get-header-params.js +95 -0
- package/dist/tools/get-roots-list.js +49 -50
- package/dist/tools/gzip-file-as-resource.js +24 -5
- package/dist/tools/index.js +72 -14
- package/dist/tools/simulate-research-query.js +166 -201
- package/dist/tools/toggle-simulated-logging.js +33 -20
- package/dist/tools/toggle-subscriber-updates.js +33 -23
- package/dist/tools/trigger-elicitation-request-async.js +99 -204
- package/dist/tools/trigger-elicitation-request.js +197 -196
- package/dist/tools/trigger-list-changed.js +57 -0
- package/dist/tools/trigger-log-messages.js +60 -0
- package/dist/tools/trigger-long-running-operation.js +3 -3
- package/dist/tools/trigger-multi-step-elicitation.js +125 -0
- package/dist/tools/trigger-resource-update.js +52 -0
- package/dist/tools/trigger-sampling-request-async.js +79 -143
- package/dist/tools/trigger-sampling-request.js +51 -45
- package/dist/tools/trigger-url-elicitation.js +148 -111
- package/dist/transports/sse.js +26 -6
- package/dist/transports/stdio.js +42 -22
- package/dist/transports/streamableHttp.js +110 -14
- package/package.json +12 -5
package/dist/tools/index.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
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.
|
|
1
13
|
import { registerGetAnnotatedMessageTool } from "./get-annotated-message.js";
|
|
2
14
|
import { registerEchoTool } from "./echo.js";
|
|
3
15
|
import { registerGetEnvTool } from "./get-env.js";
|
|
16
|
+
import { registerGetHeaderParamsTool } from "./get-header-params.js";
|
|
4
17
|
import { registerGetResourceLinksTool } from "./get-resource-links.js";
|
|
5
18
|
import { registerGetResourceReferenceTool } from "./get-resource-reference.js";
|
|
6
19
|
import { registerGetRootsListTool } from "./get-roots-list.js";
|
|
@@ -8,45 +21,90 @@ import { registerGetStructuredContentTool } from "./get-structured-content.js";
|
|
|
8
21
|
import { registerGetSumTool } from "./get-sum.js";
|
|
9
22
|
import { registerGetTinyImageTool } from "./get-tiny-image.js";
|
|
10
23
|
import { registerGZipFileAsResourceTool } from "./gzip-file-as-resource.js";
|
|
24
|
+
import { registerSimulateResearchQueryTool } from "./simulate-research-query.js";
|
|
11
25
|
import { registerToggleSimulatedLoggingTool } from "./toggle-simulated-logging.js";
|
|
12
26
|
import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates.js";
|
|
27
|
+
import { registerTriggerElicitationRequestAsyncTool } from "./trigger-elicitation-request-async.js";
|
|
13
28
|
import { registerTriggerElicitationRequestTool } from "./trigger-elicitation-request.js";
|
|
29
|
+
import { registerTriggerListChangedTool } from "./trigger-list-changed.js";
|
|
30
|
+
import { registerTriggerLogMessagesTool } from "./trigger-log-messages.js";
|
|
14
31
|
import { registerTriggerLongRunningOperationTool } from "./trigger-long-running-operation.js";
|
|
15
|
-
import {
|
|
32
|
+
import { registerTriggerMultiStepElicitationTool } from "./trigger-multi-step-elicitation.js";
|
|
33
|
+
import { registerTriggerResourceUpdateTool } from "./trigger-resource-update.js";
|
|
16
34
|
import { registerTriggerSamplingRequestAsyncTool } from "./trigger-sampling-request-async.js";
|
|
17
|
-
import {
|
|
18
|
-
import { registerSimulateResearchQueryTool } from "./simulate-research-query.js";
|
|
35
|
+
import { registerTriggerSamplingRequestTool } from "./trigger-sampling-request.js";
|
|
19
36
|
import { registerTriggerUrlElicitationTool } from "./trigger-url-elicitation.js";
|
|
20
37
|
/**
|
|
21
|
-
* Register the tools
|
|
38
|
+
* Register the tools every client gets, on either protocol era.
|
|
22
39
|
* @param server
|
|
40
|
+
* @param context
|
|
23
41
|
*/
|
|
24
|
-
export const registerTools = (server) => {
|
|
42
|
+
export const registerTools = (server, context) => {
|
|
25
43
|
registerEchoTool(server);
|
|
26
44
|
registerGetAnnotatedMessageTool(server);
|
|
27
45
|
registerGetEnvTool(server);
|
|
46
|
+
registerGetHeaderParamsTool(server);
|
|
28
47
|
registerGetResourceLinksTool(server);
|
|
29
48
|
registerGetResourceReferenceTool(server);
|
|
30
49
|
registerGetStructuredContentTool(server);
|
|
31
50
|
registerGetSumTool(server);
|
|
32
51
|
registerGetTinyImageTool(server);
|
|
33
|
-
registerGZipFileAsResourceTool(server);
|
|
34
|
-
|
|
35
|
-
|
|
52
|
+
registerGZipFileAsResourceTool(server, context);
|
|
53
|
+
registerTriggerListChangedTool(server, context);
|
|
54
|
+
registerTriggerLogMessagesTool(server);
|
|
36
55
|
registerTriggerLongRunningOperationTool(server);
|
|
56
|
+
registerTriggerResourceUpdateTool(server, context);
|
|
37
57
|
};
|
|
38
58
|
/**
|
|
39
|
-
* Register the tools that
|
|
40
|
-
*
|
|
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
|
|
41
100
|
*/
|
|
42
|
-
export const
|
|
101
|
+
export const registerModernTools = (server, context) => {
|
|
43
102
|
registerGetRootsListTool(server);
|
|
44
103
|
registerTriggerElicitationRequestTool(server);
|
|
45
|
-
|
|
104
|
+
registerTriggerMultiStepElicitationTool(server);
|
|
105
|
+
registerTriggerUrlElicitationTool(server, context);
|
|
46
106
|
registerTriggerSamplingRequestTool(server);
|
|
47
|
-
// Task-based research tool (uses experimental tasks API)
|
|
48
107
|
registerSimulateResearchQueryTool(server);
|
|
49
|
-
// Bidirectional task tools - server sends requests that client executes as tasks
|
|
50
108
|
registerTriggerSamplingRequestAsyncTool(server);
|
|
51
109
|
registerTriggerElicitationRequestAsyncTool(server);
|
|
52
110
|
};
|
|
@@ -1,114 +1,110 @@
|
|
|
1
|
+
// The `simulate-research-query` tool: a simulated deep-research job that runs
|
|
2
|
+
// as a task on the Tasks extension (`io.modelcontextprotocol/tasks`), on
|
|
3
|
+
// protocol version 2026-07-28 (#4852).
|
|
4
|
+
//
|
|
5
|
+
// The call returns a task handle at once. The task works through four
|
|
6
|
+
// stages, one a second, and the client follows it with `tasks/get`. For an
|
|
7
|
+
// ambiguous topic it stops at the third stage with status `input_required`,
|
|
8
|
+
// carrying an elicitation that asks which interpretation the user means; the
|
|
9
|
+
// client answers it with `tasks/update` and the task carries on. The final
|
|
10
|
+
// report arrives inside the `completed` status. The task's progress is worked
|
|
11
|
+
// out from the clock when it is read (server/tasks.ts), so nothing runs in
|
|
12
|
+
// the background.
|
|
13
|
+
//
|
|
14
|
+
// SDK v2 removed the experimental 2025-11-25 tasks layer this tool was first
|
|
15
|
+
// built on (SEP-1686), so it is registered for 2026-07-28 clients only.
|
|
16
|
+
import { acceptedContent, inputRequired, inputResponse, } from "@modelcontextprotocol/server";
|
|
1
17
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
18
|
+
import { clientSupportsFormElicitation, createTask, } from "../server/tasks.js";
|
|
3
19
|
// Tool input schema
|
|
4
20
|
const SimulateResearchQuerySchema = z.object({
|
|
5
|
-
topic: z
|
|
21
|
+
topic: z
|
|
22
|
+
.string()
|
|
23
|
+
.max(1000)
|
|
24
|
+
.describe("The research topic to investigate (at most 1,000 characters; the task keeps it until it expires)"),
|
|
6
25
|
ambiguous: z
|
|
7
26
|
.boolean()
|
|
8
27
|
.default(false)
|
|
9
28
|
.describe("Simulate an ambiguous query that requires clarification (triggers input_required status)"),
|
|
10
29
|
});
|
|
11
|
-
|
|
12
|
-
const STAGES = [
|
|
30
|
+
/** The stages a research task works through, in order. */
|
|
31
|
+
export const STAGES = [
|
|
13
32
|
"Gathering sources",
|
|
14
33
|
"Analyzing content",
|
|
15
34
|
"Synthesizing findings",
|
|
16
35
|
"Generating report",
|
|
17
36
|
];
|
|
18
|
-
|
|
19
|
-
const STAGE_DURATION = 1000;
|
|
20
|
-
|
|
21
|
-
const
|
|
37
|
+
/** How long each stage takes, in milliseconds. */
|
|
38
|
+
export const STAGE_DURATION = 1000;
|
|
39
|
+
/** The stage an ambiguous query stops before, to ask for a clarification. */
|
|
40
|
+
const CLARIFY_AT = 2;
|
|
41
|
+
// Tool configuration
|
|
42
|
+
const name = "simulate-research-query";
|
|
43
|
+
const config = {
|
|
44
|
+
title: "Simulate Research Query",
|
|
45
|
+
description: "Simulates a deep research operation that gathers, analyzes, and synthesizes information. " +
|
|
46
|
+
"Runs as a task on the io.modelcontextprotocol/tasks extension (protocol version 2026-07-28): " +
|
|
47
|
+
"the call returns a task handle, and the client polls tasks/get as the task moves through four stages. " +
|
|
48
|
+
"If 'ambiguous' is true and the client supports elicitation, the task pauses with status " +
|
|
49
|
+
"input_required until the client answers its clarification request with tasks/update.",
|
|
50
|
+
inputSchema: SimulateResearchQuerySchema,
|
|
51
|
+
annotations: {
|
|
52
|
+
// Each call creates a task in the process-wide task store.
|
|
53
|
+
readOnlyHint: false,
|
|
54
|
+
destructiveHint: false,
|
|
55
|
+
idempotentHint: false,
|
|
56
|
+
openWorldHint: false,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
22
59
|
/**
|
|
23
|
-
*
|
|
24
|
-
* Updates task status as it progresses through stages.
|
|
25
|
-
* If clarification is needed, sends elicitation via sendRequest with relatedTask,
|
|
26
|
-
* which queues the request in the task message queue. The SDK delivers it through
|
|
27
|
-
* the tasks/result stream when the client calls tasks/result (per spec input_required flow).
|
|
28
|
-
* This works on all transports (STDIO, SSE, Streamable HTTP).
|
|
60
|
+
* Returns contextual interpretation options based on the topic.
|
|
29
61
|
*/
|
|
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
|
-
required: ["interpretation"],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
}, ElicitResultSchema, { relatedTask: { taskId } });
|
|
69
|
-
// Process elicitation response
|
|
70
|
-
if (elicitResult.action === "accept" && elicitResult.content) {
|
|
71
|
-
state.clarification =
|
|
72
|
-
elicitResult.content
|
|
73
|
-
.interpretation || "User accepted without selection";
|
|
74
|
-
}
|
|
75
|
-
else if (elicitResult.action === "decline") {
|
|
76
|
-
state.clarification = "User declined - using default interpretation";
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
state.clarification = "User cancelled - using default interpretation";
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
// Elicitation failed - use default interpretation and continue
|
|
84
|
-
console.warn(`Elicitation failed for task ${taskId}:`, error instanceof Error ? error.message : String(error));
|
|
85
|
-
state.clarification = "technical (default - elicitation unavailable)";
|
|
86
|
-
}
|
|
87
|
-
// Resume with working status (spec SHOULD)
|
|
88
|
-
await taskStore.updateTaskStatus(taskId, "working", `Continuing with interpretation: "${state.clarification}"...`);
|
|
89
|
-
// Continue processing (no return - just keep going through the loop)
|
|
90
|
-
}
|
|
91
|
-
// Simulate work for this stage
|
|
92
|
-
await new Promise((resolve) => setTimeout(resolve, STAGE_DURATION));
|
|
62
|
+
function getInterpretationsForTopic(topic) {
|
|
63
|
+
const lowerTopic = topic.toLowerCase();
|
|
64
|
+
if (lowerTopic.includes("python")) {
|
|
65
|
+
return [
|
|
66
|
+
{ const: "programming", title: "Python programming language" },
|
|
67
|
+
{ const: "snake", title: "Python snake species" },
|
|
68
|
+
{ const: "comedy", title: "Monty Python comedy group" },
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
return [
|
|
72
|
+
{ const: "technical", title: "Technical/scientific perspective" },
|
|
73
|
+
{ const: "historical", title: "Historical perspective" },
|
|
74
|
+
{ const: "current", title: "Current events/news perspective" },
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* What the user's answer to the clarification request means. An accepted
|
|
79
|
+
* answer counts only if it is one of the interpretations offered for `topic`.
|
|
80
|
+
*/
|
|
81
|
+
function clarificationFrom(responses, topic) {
|
|
82
|
+
const offered = getInterpretationsForTopic(topic).map((o) => o.const);
|
|
83
|
+
const ClarificationSchema = z.object({
|
|
84
|
+
interpretation: z.string().refine((value) => offered.includes(value)),
|
|
85
|
+
});
|
|
86
|
+
const view = inputResponse(responses, "clarification");
|
|
87
|
+
const accepted = acceptedContent(responses, "clarification", ClarificationSchema);
|
|
88
|
+
if (accepted)
|
|
89
|
+
return accepted.interpretation;
|
|
90
|
+
if (view.kind === "elicit" && view.action === "decline") {
|
|
91
|
+
return "User declined - using default interpretation";
|
|
92
|
+
}
|
|
93
|
+
if (view.kind === "elicit" && view.action === "cancel") {
|
|
94
|
+
return "User cancelled - using default interpretation";
|
|
93
95
|
}
|
|
94
|
-
|
|
95
|
-
state.completed = true;
|
|
96
|
-
const result = generateResearchReport(state);
|
|
97
|
-
state.result = result;
|
|
98
|
-
await taskStore.storeTaskResult(taskId, "completed", result);
|
|
96
|
+
return "No usable answer - using default interpretation";
|
|
99
97
|
}
|
|
100
98
|
/**
|
|
101
99
|
* Generates the final research report with educational content about tasks.
|
|
102
100
|
*/
|
|
103
|
-
function generateResearchReport(
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
: state.topic;
|
|
107
|
-
const report = `# Research Report: ${topic}
|
|
101
|
+
function generateResearchReport(topic, clarification) {
|
|
102
|
+
const subject = clarification ? `${topic} (${clarification})` : topic;
|
|
103
|
+
const report = `# Research Report: ${subject}
|
|
108
104
|
|
|
109
105
|
## Research Parameters
|
|
110
|
-
- **Topic**: ${
|
|
111
|
-
${
|
|
106
|
+
- **Topic**: ${topic}
|
|
107
|
+
${clarification ? `- **Clarification**: ${clarification}` : ""}
|
|
112
108
|
|
|
113
109
|
## Synthesis
|
|
114
110
|
This research query was processed through ${STAGES.length} stages:
|
|
@@ -116,136 +112,105 @@ ${STAGES.map((s, i) => `- Stage ${i + 1}: ${s} ✓`).join("\n")}
|
|
|
116
112
|
|
|
117
113
|
---
|
|
118
114
|
|
|
119
|
-
## About This Demo (SEP-
|
|
115
|
+
## About This Demo (SEP-2663: the Tasks extension)
|
|
120
116
|
|
|
121
117
|
This tool demonstrates MCP's task-based execution pattern for long-running operations:
|
|
122
118
|
|
|
123
119
|
**Task Lifecycle Demonstrated:**
|
|
124
|
-
1. \`tools/call\`
|
|
125
|
-
2. Client polls \`tasks/get\` →
|
|
126
|
-
3. Status progressed: \`working\` → ${
|
|
127
|
-
4.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
${
|
|
134
|
-
? `**Note:** Elicitation failed and a default interpretation was used.`
|
|
135
|
-
: `After receiving clarification ("${state.clarification}"), the task resumed processing and completed.`}
|
|
120
|
+
1. \`tools/call\` → the server returns a task handle (\`resultType: "task"\`), not the final result
|
|
121
|
+
2. Client polls \`tasks/get\` → the server returns the current status and \`statusMessage\`
|
|
122
|
+
3. Status progressed: \`working\` → ${clarification ? `\`input_required\` → \`working\` → ` : ""}\`completed\`
|
|
123
|
+
4. The \`completed\` status carries this final result
|
|
124
|
+
${clarification
|
|
125
|
+
? `
|
|
126
|
+
**Input Flow:**
|
|
127
|
+
The query was ambiguous, so the task paused with status \`input_required\`,
|
|
128
|
+
carrying an elicitation request. The client answered it with \`tasks/update\`
|
|
129
|
+
("${clarification}"), and the task resumed and completed.
|
|
136
130
|
`
|
|
137
131
|
: ""}
|
|
138
132
|
**Key Concepts:**
|
|
139
133
|
- Tasks enable "call now, fetch later" patterns
|
|
140
134
|
- \`statusMessage\` provides human-readable progress updates
|
|
141
|
-
- Tasks have TTL (
|
|
142
|
-
- \`
|
|
143
|
-
-
|
|
135
|
+
- Tasks have a TTL (\`ttlMs\`) for automatic cleanup
|
|
136
|
+
- \`pollIntervalMs\` suggests how often to check status
|
|
137
|
+
- A task asks for input in-band, through its \`input_required\` status
|
|
144
138
|
|
|
145
139
|
*This is a simulated research report from the Everything MCP Server.*
|
|
146
140
|
`;
|
|
147
|
-
return {
|
|
148
|
-
content: [
|
|
149
|
-
{
|
|
150
|
-
type: "text",
|
|
151
|
-
text: report,
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
};
|
|
141
|
+
return { content: [{ type: "text", text: report }] };
|
|
155
142
|
}
|
|
156
143
|
/**
|
|
157
|
-
* Registers the 'simulate-research-query' tool
|
|
144
|
+
* Registers the 'simulate-research-query' tool, for 2026-07-28 clients.
|
|
158
145
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
146
|
+
* A client that does not declare the tasks extension is refused with -32021
|
|
147
|
+
* before the tool runs (`guardTaskTools`), since it could not follow the task
|
|
148
|
+
* handle. `ambiguous` is ignored for a
|
|
149
|
+
* client that does not support elicitation.
|
|
162
150
|
*
|
|
163
151
|
* @param {McpServer} server - The McpServer instance where the tool will be registered.
|
|
164
152
|
*/
|
|
165
153
|
export const registerSimulateResearchQueryTool = (server) => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return result;
|
|
228
|
-
},
|
|
229
|
-
/* v8 ignore stop */
|
|
154
|
+
server.registerTool(name, config, async (args, ctx) => {
|
|
155
|
+
const { topic, ambiguous } = SimulateResearchQuerySchema.parse(args);
|
|
156
|
+
// The clarification is a form, so only a form-capable client is asked.
|
|
157
|
+
const canAsk = clientSupportsFormElicitation(ctx);
|
|
158
|
+
// The clock time the stages started counting from, and the stage they
|
|
159
|
+
// started at: an ambiguous query restarts the count once it is answered.
|
|
160
|
+
let startedAt = Date.now();
|
|
161
|
+
let startStage = 0;
|
|
162
|
+
let clarification;
|
|
163
|
+
const needsClarification = () => ambiguous && canAsk && clarification === undefined;
|
|
164
|
+
return createTask({
|
|
165
|
+
stateAt: (now) => {
|
|
166
|
+
const stage = startStage + Math.floor((now - startedAt) / STAGE_DURATION);
|
|
167
|
+
// When the clock reached `stage`, the moment the task entered it.
|
|
168
|
+
const reached = (at) => startedAt + (at - startStage) * STAGE_DURATION;
|
|
169
|
+
if (needsClarification() && stage >= CLARIFY_AT) {
|
|
170
|
+
return {
|
|
171
|
+
since: reached(CLARIFY_AT),
|
|
172
|
+
status: "input_required",
|
|
173
|
+
statusMessage: `Found multiple interpretations for "${topic}". Requesting clarification...`,
|
|
174
|
+
inputRequests: {
|
|
175
|
+
clarification: inputRequired.elicit({
|
|
176
|
+
message: `The research query "${topic}" could have multiple interpretations. Please clarify what you're looking for:`,
|
|
177
|
+
requestedSchema: {
|
|
178
|
+
type: "object",
|
|
179
|
+
properties: {
|
|
180
|
+
interpretation: {
|
|
181
|
+
type: "string",
|
|
182
|
+
title: "Clarification",
|
|
183
|
+
description: "Which interpretation of the topic do you mean?",
|
|
184
|
+
oneOf: getInterpretationsForTopic(topic),
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
required: ["interpretation"],
|
|
188
|
+
},
|
|
189
|
+
}),
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
if (stage >= STAGES.length) {
|
|
194
|
+
return {
|
|
195
|
+
since: reached(STAGES.length),
|
|
196
|
+
status: "completed",
|
|
197
|
+
statusMessage: "Research complete",
|
|
198
|
+
result: generateResearchReport(topic, clarification),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
since: reached(stage),
|
|
203
|
+
status: "working",
|
|
204
|
+
statusMessage: clarification !== undefined && stage === CLARIFY_AT
|
|
205
|
+
? `Continuing with interpretation: "${clarification}"...`
|
|
206
|
+
: `${STAGES[stage]}...`,
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
receive: (responses, now) => {
|
|
210
|
+
clarification = clarificationFrom(responses, topic);
|
|
211
|
+
startedAt = now;
|
|
212
|
+
startStage = CLARIFY_AT;
|
|
213
|
+
},
|
|
214
|
+
}, { ttlMs: 5 * 60_000, pollIntervalMs: STAGE_DURATION });
|
|
230
215
|
});
|
|
231
216
|
};
|
|
232
|
-
/**
|
|
233
|
-
* Returns contextual interpretation options based on the topic.
|
|
234
|
-
*/
|
|
235
|
-
function getInterpretationsForTopic(topic) {
|
|
236
|
-
const lowerTopic = topic.toLowerCase();
|
|
237
|
-
// Example: contextual interpretations for "python"
|
|
238
|
-
if (lowerTopic.includes("python")) {
|
|
239
|
-
return [
|
|
240
|
-
{ const: "programming", title: "Python programming language" },
|
|
241
|
-
{ const: "snake", title: "Python snake species" },
|
|
242
|
-
{ const: "comedy", title: "Monty Python comedy group" },
|
|
243
|
-
];
|
|
244
|
-
}
|
|
245
|
-
// Default generic interpretations
|
|
246
|
-
return [
|
|
247
|
-
{ const: "technical", title: "Technical/scientific perspective" },
|
|
248
|
-
{ const: "historical", title: "Historical perspective" },
|
|
249
|
-
{ const: "current", title: "Current events/news perspective" },
|
|
250
|
-
];
|
|
251
|
-
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
// The `toggle-simulated-logging` tool: starts or stops a timer that sends the
|
|
2
|
+
// client a random-leveled log message every five seconds, filtered by the
|
|
3
|
+
// level it set with `logging/setLevel`.
|
|
4
|
+
//
|
|
5
|
+
// 2025-era only, and deprecated: the 2026-07-28 revision removes
|
|
6
|
+
// `logging/setLevel` and unsolicited log messages (and deprecates logging),
|
|
7
|
+
// so the server factory registers this tool only for a 2025-era client.
|
|
8
|
+
// `trigger-log-messages` shows the 2026-07-28 replacement, a log level set
|
|
9
|
+
// per request. The timer belongs to the server instance serving this client,
|
|
10
|
+
// so no session map is needed (#4852).
|
|
11
|
+
import { beginSimulatedLogging } from "../server/logging.js";
|
|
2
12
|
// Tool configuration
|
|
3
13
|
const name = "toggle-simulated-logging";
|
|
4
14
|
const config = {
|
|
5
15
|
title: "Toggle Simulated Logging",
|
|
6
|
-
description: "Toggles simulated, random-leveled logging on or off."
|
|
16
|
+
description: "Toggles simulated, random-leveled logging on or off. Deprecated: 2025-era clients only, since " +
|
|
17
|
+
"protocol version 2026-07-28 removes logging/setLevel; use trigger-log-messages with a per-request " +
|
|
18
|
+
"log level instead.",
|
|
7
19
|
inputSchema: {},
|
|
8
20
|
annotations: {
|
|
9
21
|
readOnlyHint: false,
|
|
@@ -12,36 +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-simulated-logging` tool.
|
|
19
29
|
*
|
|
20
30
|
* The registered tool enables or disables the sending of periodic, random-leveled
|
|
21
|
-
* logging messages the connected client.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* current state. If logging for the specified session is active, it will be stopped;
|
|
25
|
-
* if it is inactive, logging will be started.
|
|
31
|
+
* logging messages to the connected client. Each call flips the state: it
|
|
32
|
+
* starts the messages when they are off and stops them when they are on. The
|
|
33
|
+
* messages also stop when the connection ends.
|
|
26
34
|
*
|
|
27
35
|
* @param {McpServer} server - The McpServer instance where the tool will be registered.
|
|
36
|
+
* @param {ServerContext} context - The instance's cleanup registry.
|
|
28
37
|
*/
|
|
29
|
-
export const registerToggleSimulatedLoggingTool = (server) => {
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
export const registerToggleSimulatedLoggingTool = (server, context) => {
|
|
39
|
+
let stop;
|
|
40
|
+
context.onCleanup(() => {
|
|
41
|
+
stop?.();
|
|
42
|
+
stop = undefined;
|
|
43
|
+
});
|
|
44
|
+
server.registerTool(name, config, async () => {
|
|
32
45
|
let response;
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
response =
|
|
46
|
+
if (stop) {
|
|
47
|
+
stop();
|
|
48
|
+
stop = undefined;
|
|
49
|
+
response = "Stopped simulated logging";
|
|
37
50
|
}
|
|
38
51
|
else {
|
|
39
|
-
beginSimulatedLogging(server
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
stop = beginSimulatedLogging(server);
|
|
53
|
+
response =
|
|
54
|
+
"Started simulated, random-leveled logging at a 5 second pace. Client's selected logging level will be respected. If an interval elapses and the message to be sent is below the selected level, it will not be sent. Thus at higher chosen logging levels, messages should arrive further apart.";
|
|
42
55
|
}
|
|
43
56
|
return {
|
|
44
|
-
content: [{ type: "text", text:
|
|
57
|
+
content: [{ type: "text", text: response }],
|
|
45
58
|
};
|
|
46
59
|
});
|
|
47
60
|
};
|