@cyanheads/mcp-ts-core 0.13.8 → 0.13.10
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/AGENTS.md +51 -24
- package/CLAUDE.md +51 -24
- package/README.md +10 -10
- package/changelog/0.13.x/0.13.10.md +118 -0
- package/changelog/0.13.x/0.13.9.md +113 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +31 -9
- package/dist/config/index.js.map +1 -1
- package/dist/core/app.d.ts +6 -3
- package/dist/core/app.d.ts.map +1 -1
- package/dist/core/app.js +21 -5
- package/dist/core/app.js.map +1 -1
- package/dist/core/context.d.ts +114 -21
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +40 -0
- package/dist/core/context.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/serverManifest.d.ts +6 -0
- package/dist/core/serverManifest.d.ts.map +1 -1
- package/dist/core/serverManifest.js +6 -0
- package/dist/core/serverManifest.js.map +1 -1
- package/dist/core/worker.d.ts +6 -0
- package/dist/core/worker.d.ts.map +1 -1
- package/dist/core/worker.js +1 -0
- package/dist/core/worker.js.map +1 -1
- package/dist/linter/rules/error-contract-rules.d.ts +3 -44
- package/dist/linter/rules/error-contract-rules.d.ts.map +1 -1
- package/dist/linter/rules/error-contract-rules.js +8 -144
- package/dist/linter/rules/error-contract-rules.js.map +1 -1
- package/dist/linter/rules/index.d.ts +1 -1
- package/dist/linter/rules/index.d.ts.map +1 -1
- package/dist/linter/rules/index.js +1 -1
- package/dist/linter/rules/index.js.map +1 -1
- package/dist/linter/rules/resource-rules.d.ts.map +1 -1
- package/dist/linter/rules/resource-rules.js +1 -2
- package/dist/linter/rules/resource-rules.js.map +1 -1
- package/dist/linter/rules/tool-rules.d.ts +2 -1
- package/dist/linter/rules/tool-rules.d.ts.map +1 -1
- package/dist/linter/rules/tool-rules.js +37 -3
- package/dist/linter/rules/tool-rules.js.map +1 -1
- package/dist/mcp-server/handlerContext.d.ts +26 -13
- package/dist/mcp-server/handlerContext.d.ts.map +1 -1
- package/dist/mcp-server/handlerContext.js +32 -17
- package/dist/mcp-server/handlerContext.js.map +1 -1
- package/dist/mcp-server/inputRequired.d.ts +133 -12
- package/dist/mcp-server/inputRequired.d.ts.map +1 -1
- package/dist/mcp-server/inputRequired.js +192 -20
- package/dist/mcp-server/inputRequired.js.map +1 -1
- package/dist/mcp-server/prompts/prompt-registration.d.ts +10 -2
- package/dist/mcp-server/prompts/prompt-registration.d.ts.map +1 -1
- package/dist/mcp-server/prompts/prompt-registration.js +49 -11
- package/dist/mcp-server/prompts/prompt-registration.js.map +1 -1
- package/dist/mcp-server/resources/resource-registration.d.ts +4 -2
- package/dist/mcp-server/resources/resource-registration.d.ts.map +1 -1
- package/dist/mcp-server/resources/resource-registration.js +6 -4
- package/dist/mcp-server/resources/resource-registration.js.map +1 -1
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts +4 -3
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +42 -14
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -1
- package/dist/mcp-server/server.d.ts +9 -0
- package/dist/mcp-server/server.d.ts.map +1 -1
- package/dist/mcp-server/server.js +14 -13
- package/dist/mcp-server/server.js.map +1 -1
- package/dist/mcp-server/tools/tool-registration.d.ts +7 -3
- package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -1
- package/dist/mcp-server/tools/tool-registration.js +9 -5
- package/dist/mcp-server/tools/tool-registration.js.map +1 -1
- package/dist/mcp-server/tools/utils/inputPrevalidation.d.ts +163 -40
- package/dist/mcp-server/tools/utils/inputPrevalidation.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/inputPrevalidation.js +330 -114
- package/dist/mcp-server/tools/utils/inputPrevalidation.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +40 -19
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js +387 -130
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
- package/dist/mcp-server/transports/http/httpErrorHandler.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/httpErrorHandler.js +7 -1
- package/dist/mcp-server/transports/http/httpErrorHandler.js.map +1 -1
- package/dist/mcp-server/transports/http/httpTransport.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/httpTransport.js +65 -9
- package/dist/mcp-server/transports/http/httpTransport.js.map +1 -1
- package/dist/mcp-server/transports/stdio/stdioTransport.d.ts +9 -5
- package/dist/mcp-server/transports/stdio/stdioTransport.d.ts.map +1 -1
- package/dist/mcp-server/transports/stdio/stdioTransport.js +9 -5
- package/dist/mcp-server/transports/stdio/stdioTransport.js.map +1 -1
- package/dist/services/canvas/core/CanvasRegistry.d.ts +6 -2
- package/dist/services/canvas/core/CanvasRegistry.d.ts.map +1 -1
- package/dist/services/canvas/core/CanvasRegistry.js +7 -3
- package/dist/services/canvas/core/CanvasRegistry.js.map +1 -1
- package/dist/services/canvas/providers/duckdb/DuckdbProvider.d.ts +82 -18
- package/dist/services/canvas/providers/duckdb/DuckdbProvider.d.ts.map +1 -1
- package/dist/services/canvas/providers/duckdb/DuckdbProvider.js +620 -328
- package/dist/services/canvas/providers/duckdb/DuckdbProvider.js.map +1 -1
- package/dist/services/canvas/providers/duckdb/exportWriter.d.ts +11 -7
- package/dist/services/canvas/providers/duckdb/exportWriter.d.ts.map +1 -1
- package/dist/services/canvas/providers/duckdb/exportWriter.js +19 -16
- package/dist/services/canvas/providers/duckdb/exportWriter.js.map +1 -1
- package/dist/services/mirror/core/defineMirror.d.ts +1 -0
- package/dist/services/mirror/core/defineMirror.d.ts.map +1 -1
- package/dist/services/mirror/core/defineMirror.js +1 -0
- package/dist/services/mirror/core/defineMirror.js.map +1 -1
- package/dist/testing/index.d.ts +17 -2
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +21 -7
- package/dist/testing/index.js.map +1 -1
- package/dist/types-global/errors.d.ts +18 -15
- package/dist/types-global/errors.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/internal/error-handler/errorHandler.d.ts +5 -4
- package/dist/utils/internal/error-handler/errorHandler.d.ts.map +1 -1
- package/dist/utils/internal/error-handler/errorHandler.js +9 -7
- package/dist/utils/internal/error-handler/errorHandler.js.map +1 -1
- package/dist/utils/internal/error-handler/types.d.ts +3 -1
- package/dist/utils/internal/error-handler/types.d.ts.map +1 -1
- package/dist/utils/internal/performance.d.ts +4 -2
- package/dist/utils/internal/performance.d.ts.map +1 -1
- package/dist/utils/internal/performance.js +8 -6
- package/dist/utils/internal/performance.js.map +1 -1
- package/dist/utils/internal/telemetryMessages.d.ts +0 -1
- package/dist/utils/internal/telemetryMessages.d.ts.map +1 -1
- package/dist/utils/internal/telemetryMessages.js +0 -1
- package/dist/utils/internal/telemetryMessages.js.map +1 -1
- package/dist/utils/network/pacer.d.ts +38 -5
- package/dist/utils/network/pacer.d.ts.map +1 -1
- package/dist/utils/network/pacer.js +87 -25
- package/dist/utils/network/pacer.js.map +1 -1
- package/dist/utils/telemetry/attributes.d.ts +10 -5
- package/dist/utils/telemetry/attributes.d.ts.map +1 -1
- package/dist/utils/telemetry/attributes.js +10 -5
- package/dist/utils/telemetry/attributes.js.map +1 -1
- package/framework-skills/add-app-tool/SKILL.md +3 -3
- package/framework-skills/add-export/SKILL.md +5 -16
- package/framework-skills/add-prompt/SKILL.md +7 -3
- package/framework-skills/add-resource/SKILL.md +7 -5
- package/framework-skills/add-service/SKILL.md +3 -12
- package/framework-skills/add-test/SKILL.md +6 -3
- package/framework-skills/add-tool/SKILL.md +40 -42
- package/framework-skills/api-auth/SKILL.md +2 -2
- package/framework-skills/api-canvas/SKILL.md +17 -8
- package/framework-skills/api-config/SKILL.md +5 -4
- package/framework-skills/api-context/SKILL.md +168 -42
- package/framework-skills/api-errors/SKILL.md +48 -51
- package/framework-skills/api-linter/SKILL.md +30 -35
- package/framework-skills/api-mirror/SKILL.md +2 -1
- package/framework-skills/api-telemetry/SKILL.md +14 -10
- package/framework-skills/api-testing/SKILL.md +43 -11
- package/framework-skills/api-utils/SKILL.md +2 -2
- package/framework-skills/api-workers/SKILL.md +3 -1
- package/framework-skills/design-mcp-server/SKILL.md +6 -6
- package/framework-skills/field-test/SKILL.md +5 -5
- package/framework-skills/git-wrapup/SKILL.md +8 -6
- package/framework-skills/orchestrations/SKILL.md +7 -6
- package/framework-skills/orchestrations/workflows/field-test-fix.md +9 -19
- package/framework-skills/orchestrations/workflows/fix-wrapup-release.md +7 -7
- package/framework-skills/orchestrations/workflows/greenfield-build.md +8 -5
- package/framework-skills/orchestrations/workflows/maintenance-release.md +8 -8
- package/framework-skills/polish-docs-meta/SKILL.md +4 -4
- package/framework-skills/release-and-publish/SKILL.md +8 -6
- package/framework-skills/release-pr-review/SKILL.md +38 -24
- package/framework-skills/report-issue-framework/SKILL.md +7 -5
- package/framework-skills/report-issue-local/SKILL.md +8 -6
- package/framework-skills/security-pass/SKILL.md +14 -13
- package/package.json +6 -5
- package/scripts/devcheck.ts +7 -6
- package/scripts/install-otel.ts +84 -0
- package/scripts/lint-mcp.ts +87 -27
- package/scripts/lint-packaging.ts +226 -4
- package/scripts/release-github.ts +117 -5
- package/templates/.env.example +2 -0
- package/templates/AGENTS.md +5 -4
- package/templates/CLAUDE.md +5 -4
- package/templates/Dockerfile +67 -50
- package/templates/_.mcpbignore +2 -0
- package/templates/src/mcp-server/tools/definitions/echo.tool.ts +3 -8
|
@@ -15,11 +15,16 @@
|
|
|
15
15
|
* returns against 2025-era clients by issuing real `elicitation/create` /
|
|
16
16
|
* `sampling/createMessage` / `roots/list` requests and re-entering the handler.
|
|
17
17
|
*
|
|
18
|
+
* What a handler reads back is bounded by what its client declared: the
|
|
19
|
+
* per-request capability view (#580) decides which responses reach
|
|
20
|
+
* `ctx.inputs` (#496), and an opt-in key seals the `requestState` a handler
|
|
21
|
+
* returns so a retry can only echo what this server minted.
|
|
22
|
+
*
|
|
18
23
|
* @see {@link https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr | MCP Multi-Round-Trip Requests}
|
|
19
24
|
* @module src/mcp-server/inputRequired
|
|
20
25
|
*/
|
|
21
|
-
import { acceptedContent, inputRequired, inputResponse, } from '@modelcontextprotocol/server';
|
|
22
|
-
import { JsonRpcErrorCode, McpError } from '../types-global/errors.js';
|
|
26
|
+
import { acceptedContent, CLIENT_CAPABILITIES_META_KEY, createRequestStateCodec, inputRequired, inputResponse, } from '@modelcontextprotocol/server';
|
|
27
|
+
import { configurationError, internalError, JsonRpcErrorCode, McpError, } from '../types-global/errors.js';
|
|
23
28
|
/**
|
|
24
29
|
* Thrown by `ctx.requestInput(...)` and caught by the handler factories, which
|
|
25
30
|
* return the carried `input_required` result to the SDK instead of a normal
|
|
@@ -45,6 +50,23 @@ export function isInputRequiredSignal(error) {
|
|
|
45
50
|
error !== null &&
|
|
46
51
|
error.isInputRequiredSignal === true));
|
|
47
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* The view for one instance: on a 2025-era instance the `initialize`-declared
|
|
55
|
+
* value, read through the instance on every call so an `initialize` that lands
|
|
56
|
+
* after registration is seen; on a 2026-07-28 instance the request's own
|
|
57
|
+
* `io.modelcontextprotocol/clientCapabilities` envelope key, which the SDK has
|
|
58
|
+
* validated before dispatch. `getClientCapabilities()` is not used there — a
|
|
59
|
+
* 2026-07-28 stdio instance never has it backfilled.
|
|
60
|
+
*/
|
|
61
|
+
export function clientCapabilityView(era, server) {
|
|
62
|
+
if (era === 'modern') {
|
|
63
|
+
return {
|
|
64
|
+
era,
|
|
65
|
+
capabilities: (mcpReq) => mcpReq?.envelope?.[CLIENT_CAPABILITIES_META_KEY],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { era, capabilities: () => server.server.getClientCapabilities() };
|
|
69
|
+
}
|
|
48
70
|
// ---------------------------------------------------------------------------
|
|
49
71
|
// Client-capability gate (#379)
|
|
50
72
|
// ---------------------------------------------------------------------------
|
|
@@ -54,7 +76,7 @@ export function isInputRequiredSignal(error) {
|
|
|
54
76
|
* declare it in `errors[]`, because it names a property of the connection
|
|
55
77
|
* rather than a domain outcome.
|
|
56
78
|
*/
|
|
57
|
-
const CLIENT_CAPABILITY_MISSING_REASON = 'client_capability_missing';
|
|
79
|
+
export const CLIENT_CAPABILITY_MISSING_REASON = 'client_capability_missing';
|
|
58
80
|
/**
|
|
59
81
|
* What an embedded request kind requires, mode-aware where the capability is:
|
|
60
82
|
* URL-mode elicitation needs `elicitation.url`, form-mode (or mode-omitted)
|
|
@@ -103,7 +125,9 @@ function capabilityPath({ capability, member }) {
|
|
|
103
125
|
return member === undefined ? capability : `${capability}.${member}`;
|
|
104
126
|
}
|
|
105
127
|
/**
|
|
106
|
-
* Builds the gate for one
|
|
128
|
+
* Builds the gate for one request from the capabilities its client declared —
|
|
129
|
+
* the value the instance's {@link ClientCapabilityView} resolved, which
|
|
130
|
+
* `ctx.clientCapabilities` carries too.
|
|
107
131
|
*
|
|
108
132
|
* Only the 2025-era arm needs it. There the refusal is produced by the SDK's
|
|
109
133
|
* legacy shim, which runs *above* the handler callback on the result that
|
|
@@ -115,16 +139,20 @@ function capabilityPath({ capability, member }) {
|
|
|
115
139
|
* the SDK itself, which raises `MissingRequiredClientCapabilityError`
|
|
116
140
|
* (`-32021`) — that arm takes no gate.
|
|
117
141
|
*
|
|
118
|
-
* `
|
|
119
|
-
*
|
|
120
|
-
*
|
|
142
|
+
* `declared` being `undefined` is the per-request legacy case: an instance that
|
|
143
|
+
* never saw an `initialize` holds no capability view, so every embedded
|
|
144
|
+
* request is refused, and the message and hint say so.
|
|
145
|
+
*
|
|
146
|
+
* The hint ends at reconnecting (#495). Whether the caller could instead
|
|
147
|
+
* supply the answer as an argument is the handler's knowledge, not the gate's:
|
|
148
|
+
* a consent gate deliberately has no such field, so the gate appends a
|
|
149
|
+
* fallback only when the handler passed one.
|
|
121
150
|
*/
|
|
122
|
-
export function createInputRequiredGate(
|
|
123
|
-
return (result) => {
|
|
151
|
+
export function createInputRequiredGate(declared) {
|
|
152
|
+
return (result, fallbackHint) => {
|
|
124
153
|
const requests = result.inputRequests;
|
|
125
154
|
if (requests === undefined)
|
|
126
155
|
return;
|
|
127
|
-
const declared = clientCapabilities();
|
|
128
156
|
for (const [key, entry] of Object.entries(requests)) {
|
|
129
157
|
const requirement = capabilityRequirement(entry);
|
|
130
158
|
if (requirement === undefined || isDeclared(requirement, declared))
|
|
@@ -132,15 +160,14 @@ export function createInputRequiredGate(clientCapabilities) {
|
|
|
132
160
|
const path = capabilityPath(requirement);
|
|
133
161
|
const method = entry.method;
|
|
134
162
|
const blind = declared === undefined;
|
|
163
|
+
const reconnect = blind
|
|
164
|
+
? `No client capabilities are visible on a per-request connection, so \`${path}\` cannot be requested here. Reconnect over a stateful session whose client declares it.`
|
|
165
|
+
: `Reconnect with a client that declares the \`${path}\` capability.`;
|
|
135
166
|
return new McpError(JsonRpcErrorCode.InvalidRequest, `Cannot request input '${key}' (${method}): the client on this 2025-era connection did not declare the \`${path}\` capability${blind
|
|
136
167
|
? ' (this request is served per-request, so no client capabilities are available and no server-to-client round trip can be made)'
|
|
137
168
|
: ''}`, {
|
|
138
169
|
reason: CLIENT_CAPABILITY_MISSING_REASON,
|
|
139
|
-
recovery: {
|
|
140
|
-
hint: blind
|
|
141
|
-
? `No client capabilities are visible on a per-request connection, so \`${path}\` cannot be requested here. Reconnect over a stateful session whose client declares it, or call again supplying the value this request would have asked for.`
|
|
142
|
-
: `Reconnect with a client that declares the \`${path}\` capability, or call again supplying the value this request would have asked for.`,
|
|
143
|
-
},
|
|
170
|
+
recovery: { hint: fallbackHint ? `${reconnect} ${fallbackHint}` : reconnect },
|
|
144
171
|
});
|
|
145
172
|
}
|
|
146
173
|
return;
|
|
@@ -158,24 +185,94 @@ export function createInputRequiredGate(clientCapabilities) {
|
|
|
158
185
|
* error path shapes it. Resolving it any later — in a factory's catch, after
|
|
159
186
|
* the measured region has closed — would record a refused call as a successful
|
|
160
187
|
* input-required round while the client is told the call failed.
|
|
188
|
+
*
|
|
189
|
+
* `options.fallbackHint` goes to the gate alone; it never enters the
|
|
190
|
+
* `input_required` result.
|
|
161
191
|
*/
|
|
162
192
|
export function createRequestInput(gate) {
|
|
163
|
-
return (spec) => {
|
|
193
|
+
return (spec, options) => {
|
|
164
194
|
const result = inputRequired(spec);
|
|
165
|
-
const refusal = gate?.(result);
|
|
195
|
+
const refusal = gate?.(result, options?.fallbackHint);
|
|
166
196
|
if (refusal !== undefined)
|
|
167
197
|
throw refusal;
|
|
168
198
|
throw new InputRequiredSignal(result);
|
|
169
199
|
};
|
|
170
200
|
}
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
// ctx.inputs — responses filtered by declared capability (#496)
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
/** Content block types only a tool-enabled sampling result carries. */
|
|
205
|
+
const TOOL_BLOCK_TYPES = new Set(['tool_use', 'tool_result']);
|
|
206
|
+
/** Whether sampling content — one block or an array — holds a tool block. */
|
|
207
|
+
function carriesToolBlock(content) {
|
|
208
|
+
return (Array.isArray(content) ? content : [content]).some((block) => typeof block === 'object' &&
|
|
209
|
+
block !== null &&
|
|
210
|
+
TOOL_BLOCK_TYPES.has(block.type));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* What one response requires — the response-side twin of
|
|
214
|
+
* {@link capabilityRequirement}, so an answer needs whatever the request it
|
|
215
|
+
* answers would have needed. An elicit result carrying `content` is a
|
|
216
|
+
* form-mode answer and needs `elicitation.form`; one without (a URL-mode
|
|
217
|
+
* accept, a decline, a cancel) needs `elicitation` in any mode. A sampling
|
|
218
|
+
* result holding a `tool_use` or `tool_result` block answers a tool-enabled
|
|
219
|
+
* request and needs `sampling.tools`; any other needs `sampling`. A roots
|
|
220
|
+
* result needs `roots`. `undefined` for an entry the SDK's classifier reads as
|
|
221
|
+
* no kind.
|
|
222
|
+
*
|
|
223
|
+
* `content` is read off the raw `entry`, not the view: the view keeps it only
|
|
224
|
+
* when it is an object, while `ctx.inputs.responses` exposes the entry as sent.
|
|
225
|
+
*/
|
|
226
|
+
function responseRequirement(view, entry) {
|
|
227
|
+
switch (view.kind) {
|
|
228
|
+
case 'elicit':
|
|
229
|
+
return entry.content === undefined
|
|
230
|
+
? { capability: 'elicitation' }
|
|
231
|
+
: { capability: 'elicitation', member: 'form' };
|
|
232
|
+
case 'sampling':
|
|
233
|
+
return carriesToolBlock(view.result.content)
|
|
234
|
+
? { capability: 'sampling', member: 'tools' }
|
|
235
|
+
: { capability: 'sampling' };
|
|
236
|
+
case 'roots':
|
|
237
|
+
return { capability: 'roots' };
|
|
238
|
+
default:
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
171
242
|
/**
|
|
172
|
-
*
|
|
243
|
+
* The entries of `responses` the client's declared capabilities cover, at the
|
|
244
|
+
* same mode level the gate applies to requests ({@link responseRequirement},
|
|
245
|
+
* {@link isDeclared}), or `undefined` when none survives.
|
|
246
|
+
*
|
|
247
|
+
* The SDK lifts `inputResponses` off every client request, a first call and a
|
|
248
|
+
* 2025-era request included, so a client can arrive pre-answered with no
|
|
249
|
+
* `input_required` result ever sent. An answer the client's modes do not cover
|
|
250
|
+
* cannot have come from a round this server asked for: on the 2025 arm the
|
|
251
|
+
* legacy shim only issues requests the connection declared, and on 2026-07-28
|
|
252
|
+
* the SDK refuses an embedded request the envelope does not cover. Dropping
|
|
253
|
+
* those closes the pre-answered consent-gate bypass — a URL-only client's form
|
|
254
|
+
* answer included — without touching a legitimate round. With no view
|
|
255
|
+
* (`declared` undefined) nothing survives, and an entry the SDK's classifier
|
|
256
|
+
* cannot read as any kind has no capability to justify it either.
|
|
257
|
+
*/
|
|
258
|
+
export function declaredResponses(responses, declared) {
|
|
259
|
+
if (responses === undefined || declared === undefined)
|
|
260
|
+
return;
|
|
261
|
+
const kept = Object.entries(responses).filter(([key, entry]) => {
|
|
262
|
+
const requirement = responseRequirement(inputResponse(responses, key), entry);
|
|
263
|
+
return requirement !== undefined && isDeclared(requirement, declared);
|
|
264
|
+
});
|
|
265
|
+
return kept.length > 0 ? Object.fromEntries(kept) : undefined;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Builds the `ctx.inputs` reader over a retried request's `inputResponses`,
|
|
269
|
+
* keeping only the answers `declared` covers ({@link declaredResponses}).
|
|
173
270
|
*
|
|
174
271
|
* Values arrive from the client and are never re-validated by the SDK — pass a
|
|
175
272
|
* schema to `accepted()` wherever the content matters.
|
|
176
273
|
*/
|
|
177
|
-
export function createContextInputs(mcpReq) {
|
|
178
|
-
return contextInputsFrom(mcpReq?.inputResponses, mcpReq?.droppedInputResponseKeys ?? [], () => mcpReq?.requestState());
|
|
274
|
+
export function createContextInputs(mcpReq, declared) {
|
|
275
|
+
return contextInputsFrom(declaredResponses(mcpReq?.inputResponses, declared), mcpReq?.droppedInputResponseKeys ?? [], () => mcpReq?.requestState());
|
|
179
276
|
}
|
|
180
277
|
/**
|
|
181
278
|
* The `ctx.inputs` reader over an explicit set of responses — what
|
|
@@ -194,4 +291,79 @@ export function contextInputsFrom(responses, dropped, state) {
|
|
|
194
291
|
view: (key) => inputResponse(responses, key),
|
|
195
292
|
};
|
|
196
293
|
}
|
|
294
|
+
// ---------------------------------------------------------------------------
|
|
295
|
+
// requestState sealing (MCP_REQUEST_STATE_KEY)
|
|
296
|
+
// ---------------------------------------------------------------------------
|
|
297
|
+
/**
|
|
298
|
+
* How long a sealed `requestState` verifies, in seconds. Longer than the SDK
|
|
299
|
+
* legacy shim's 600 s per-round timeout, so a 2025-era round the shim holds
|
|
300
|
+
* open never outlives its own state; the codec's 600 s default leaves no
|
|
301
|
+
* margin.
|
|
302
|
+
*/
|
|
303
|
+
const REQUEST_STATE_TTL_SECONDS = 900;
|
|
304
|
+
/** The shortest key the SDK codec accepts, in UTF-8 bytes. */
|
|
305
|
+
const REQUEST_STATE_KEY_MIN_BYTES = 32;
|
|
306
|
+
/**
|
|
307
|
+
* The principal a sealed state is bound to: the request's authenticated
|
|
308
|
+
* `clientId`, `subject`, and `tenantId`, each empty when absent — as they all
|
|
309
|
+
* are on stdio and under `MCP_AUTH_MODE=none`. The codec stores an HMAC tag of
|
|
310
|
+
* it, never the value.
|
|
311
|
+
*/
|
|
312
|
+
function principalOf(ctx) {
|
|
313
|
+
const auth = ctx.http?.authInfo;
|
|
314
|
+
return JSON.stringify([auth?.clientId ?? '', auth?.subject ?? '', auth?.tenantId ?? '']);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The process's sealer, or `undefined` when no key is configured — in which
|
|
318
|
+
* case nothing reaches the SDK and handlers read the raw wire string, exactly
|
|
319
|
+
* as before the option existed. There is deliberately no per-process random
|
|
320
|
+
* key: a 2026-07-28 retry can land on another instance or outlive a restart,
|
|
321
|
+
* and every instance that may receive an echoed state needs the same key.
|
|
322
|
+
*
|
|
323
|
+
* @throws {McpError} `ConfigurationError` naming `MCP_REQUEST_STATE_KEY` when
|
|
324
|
+
* the key is shorter than 32 UTF-8 bytes. The key itself is never included.
|
|
325
|
+
*/
|
|
326
|
+
export function createRequestStateSealer(key) {
|
|
327
|
+
if (key === undefined)
|
|
328
|
+
return;
|
|
329
|
+
if (new TextEncoder().encode(key).byteLength < REQUEST_STATE_KEY_MIN_BYTES) {
|
|
330
|
+
throw configurationError(`MCP_REQUEST_STATE_KEY must be at least ${REQUEST_STATE_KEY_MIN_BYTES} bytes. Set a longer random secret, shared by every instance that serves this server, or unset it.`, { variable: 'MCP_REQUEST_STATE_KEY', minimumBytes: REQUEST_STATE_KEY_MIN_BYTES });
|
|
331
|
+
}
|
|
332
|
+
const codec = createRequestStateCodec({
|
|
333
|
+
key,
|
|
334
|
+
ttlSeconds: REQUEST_STATE_TTL_SECONDS,
|
|
335
|
+
bind: principalOf,
|
|
336
|
+
});
|
|
337
|
+
return {
|
|
338
|
+
async seal(result, ctx) {
|
|
339
|
+
if (typeof result.requestState !== 'string')
|
|
340
|
+
return result;
|
|
341
|
+
return { ...result, requestState: await codec.mint(result.requestState, ctx) };
|
|
342
|
+
},
|
|
343
|
+
verify: (state, ctx) => codec.verify(state, ctx),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* What a handler factory rethrows for a value its handler threw: an
|
|
348
|
+
* input-required signal carrying its `requestState` sealed when `sealer` is
|
|
349
|
+
* configured, anything else unchanged.
|
|
350
|
+
*
|
|
351
|
+
* The factories call it inside the measured region, where the signal is
|
|
352
|
+
* rethrown. Minting can reject — WebCrypto failing, or no request context for
|
|
353
|
+
* the principal binding — and a rejection there would escape the factory with
|
|
354
|
+
* no error envelope, no failure record, and no request id. It resolves to an
|
|
355
|
+
* `InternalError` instead, so the call fails through the family's ordinary
|
|
356
|
+
* error path; the codec's error rides as `cause` into the server log only, and
|
|
357
|
+
* no part of the key reaches it.
|
|
358
|
+
*/
|
|
359
|
+
export async function sealThrown(thrown, sealer, ctx) {
|
|
360
|
+
if (sealer === undefined || !isInputRequiredSignal(thrown))
|
|
361
|
+
return thrown;
|
|
362
|
+
try {
|
|
363
|
+
return new InputRequiredSignal(await sealer.seal(thrown.result, ctx));
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
return internalError('Could not seal the requestState of an input_required result.', undefined, { cause: error });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
197
369
|
//# sourceMappingURL=inputRequired.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputRequired.js","sourceRoot":"","sources":["../../src/mcp-server/inputRequired.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"inputRequ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,YAAY,EAAE,2BAA2B,EAAE,CACjF,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,uBAAuB,CAAS;QAC5C,GAAG;QACH,UAAU,EAAE,yBAAyB;QACrC,IAAI,EAAE,WAAW;KAClB,CAAC,CAAC;IACH,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG;YACpB,IAAI,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ;gBAAE,OAAO,MAAM,CAAC;YAC3D,OAAO,EAAE,GAAG,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC;QACjF,CAAC;QACD,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC;KACjD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAe,EACf,MAAsC,EACtC,GAAkB;IAElB,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC1E,IAAI,CAAC;QACH,OAAO,IAAI,mBAAmB,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACxE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,aAAa,CAClB,8DAA8D,EAC9D,SAAS,EACT,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -6,16 +6,24 @@
|
|
|
6
6
|
* @module src/mcp-server/prompts/prompt-registration
|
|
7
7
|
*/
|
|
8
8
|
import type { McpServer } from '@modelcontextprotocol/server';
|
|
9
|
+
import { type RequestStateSealer } from '../inputRequired.js';
|
|
9
10
|
import type { AnyPromptDefinition } from './utils/promptDefinition.js';
|
|
10
11
|
import type { logger as defaultLogger } from '../../utils/internal/logger.js';
|
|
11
12
|
export declare class PromptRegistry {
|
|
12
13
|
private promptDefs;
|
|
13
14
|
private logger;
|
|
15
|
+
private requestState?;
|
|
14
16
|
/** Tracks registered prompt names to detect duplicates at startup. */
|
|
15
17
|
private readonly registeredNames;
|
|
16
|
-
constructor(promptDefs: AnyPromptDefinition[], logger: typeof defaultLogger);
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* @param requestState - The process's `requestState` sealer, present when
|
|
20
|
+
* `MCP_REQUEST_STATE_KEY` is set; an `input_required` result leaves with
|
|
21
|
+
* its state sealed, as a tool's and a resource's do.
|
|
22
|
+
*/
|
|
23
|
+
constructor(promptDefs: AnyPromptDefinition[], logger: typeof defaultLogger, requestState?: RequestStateSealer | undefined);
|
|
24
|
+
/**
|
|
25
|
+
* Registers all prompts on the given MCP server. Registration logs under one
|
|
26
|
+
* context; each `prompts/get` call logs under its own.
|
|
19
27
|
*/
|
|
20
28
|
registerAll(server: McpServer): Promise<void>;
|
|
21
29
|
/** Throws at startup if a prompt with the same name was already registered. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-registration.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/prompts/prompt-registration.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"prompt-registration.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/prompts/prompt-registration.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAGV,SAAS,EAEV,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAG1F,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI1E,qBAAa,cAAc;IAUvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY,CAAC;IAXvB,sEAAsE;IACtE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IAErD;;;;OAIG;IACH,YACU,UAAU,EAAE,mBAAmB,EAAE,EACjC,MAAM,EAAE,OAAO,aAAa,EAC5B,YAAY,CAAC,EAAE,kBAAkB,YAAA,EACvC;IAEJ;;;OAGG;IACG,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBlD;IAED,+EAA+E;IAC/E,OAAO,CAAC,gBAAgB;YAUV,cAAc;CAsG7B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handlerParentContext } from '../handlerContext.js';
|
|
2
|
+
import { isInputRequiredSignal, sealThrown, } from '../inputRequired.js';
|
|
2
3
|
import { JsonRpcErrorCode, McpError } from '../../types-global/errors.js';
|
|
3
4
|
import { ErrorHandler } from '../../utils/internal/error-handler/errorHandler.js';
|
|
4
5
|
import { measurePromptGeneration } from '../../utils/internal/performance.js';
|
|
@@ -6,14 +7,22 @@ import { requestContextService } from '../../utils/internal/requestContext.js';
|
|
|
6
7
|
export class PromptRegistry {
|
|
7
8
|
promptDefs;
|
|
8
9
|
logger;
|
|
10
|
+
requestState;
|
|
9
11
|
/** Tracks registered prompt names to detect duplicates at startup. */
|
|
10
12
|
registeredNames = new Set();
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @param requestState - The process's `requestState` sealer, present when
|
|
15
|
+
* `MCP_REQUEST_STATE_KEY` is set; an `input_required` result leaves with
|
|
16
|
+
* its state sealed, as a tool's and a resource's do.
|
|
17
|
+
*/
|
|
18
|
+
constructor(promptDefs, logger, requestState) {
|
|
12
19
|
this.promptDefs = promptDefs;
|
|
13
20
|
this.logger = logger;
|
|
21
|
+
this.requestState = requestState;
|
|
14
22
|
}
|
|
15
23
|
/**
|
|
16
|
-
* Registers all prompts on the given MCP server.
|
|
24
|
+
* Registers all prompts on the given MCP server. Registration logs under one
|
|
25
|
+
* context; each `prompts/get` call logs under its own.
|
|
17
26
|
*/
|
|
18
27
|
async registerAll(server) {
|
|
19
28
|
this.registeredNames.clear();
|
|
@@ -52,10 +61,34 @@ export class PromptRegistry {
|
|
|
52
61
|
...(promptDef.args && {
|
|
53
62
|
argsSchema: promptDef.args,
|
|
54
63
|
}),
|
|
55
|
-
}, async (
|
|
64
|
+
}, async (...params) => {
|
|
65
|
+
// The SDK calls a prompt registered with `argsSchema` as
|
|
66
|
+
// `(args, ctx)` and one without as `(ctx)` alone (#581).
|
|
67
|
+
const [args, serverContext] = (promptDef.args ? params : [undefined, params[0]]);
|
|
68
|
+
// Per call, as for tools and resources, not the registration `context`:
|
|
69
|
+
// its `requestId` is the one the call's records carry and its error
|
|
70
|
+
// `data` returns (#576).
|
|
71
|
+
const requestContext = requestContextService.createRequestContext({
|
|
72
|
+
parentContext: handlerParentContext(serverContext),
|
|
73
|
+
operation: 'HandlePromptGet',
|
|
74
|
+
additionalContext: { promptName: promptDef.name },
|
|
75
|
+
});
|
|
56
76
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
// An argless prompt's `generate` is typed to receive `{}`; its
|
|
78
|
+
// input measures as nothing.
|
|
79
|
+
const validatedArgs = promptDef.args ? promptDef.args.parse(args) : {};
|
|
80
|
+
const messages = await measurePromptGeneration(async () => {
|
|
81
|
+
try {
|
|
82
|
+
return await promptDef.generate(validatedArgs);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// Inside the measurement, as for tools and resources: an
|
|
86
|
+
// input-required signal leaves with its `requestState`
|
|
87
|
+
// sealed when a key is configured, so a sealing failure
|
|
88
|
+
// is a failed call like any other.
|
|
89
|
+
throw await sealThrown(error, this.requestState, serverContext);
|
|
90
|
+
}
|
|
91
|
+
}, { ...requestContext, promptName: promptDef.name }, promptDef.args ? validatedArgs : undefined);
|
|
59
92
|
return { messages };
|
|
60
93
|
}
|
|
61
94
|
catch (error) {
|
|
@@ -65,15 +98,20 @@ export class PromptRegistry {
|
|
|
65
98
|
if (isInputRequiredSignal(error))
|
|
66
99
|
return error.result;
|
|
67
100
|
/**
|
|
68
|
-
* `handleError`
|
|
69
|
-
*
|
|
70
|
-
*
|
|
101
|
+
* `handleError` writes the call's one `error` record, with the
|
|
102
|
+
* stack and cause chain; the completion record stays at `info`
|
|
103
|
+
* (#582). The client gets the classified code and message, plus
|
|
104
|
+
* only the `data` a thrown `McpError` declared and the call's
|
|
105
|
+
* `requestId` (#576) — the same wire shape as tools and resources.
|
|
71
106
|
*/
|
|
72
107
|
const handled = ErrorHandler.handleError(error, {
|
|
73
108
|
operation: `prompt:${promptDef.name}`,
|
|
74
|
-
context,
|
|
109
|
+
context: requestContext,
|
|
75
110
|
});
|
|
76
|
-
throw new McpError(handled instanceof McpError ? handled.code : JsonRpcErrorCode.InternalError, handled.message,
|
|
111
|
+
throw new McpError(handled instanceof McpError ? handled.code : JsonRpcErrorCode.InternalError, handled.message, {
|
|
112
|
+
...(error instanceof McpError ? error.data : undefined),
|
|
113
|
+
requestId: requestContext.requestId,
|
|
114
|
+
}, { cause: error });
|
|
77
115
|
}
|
|
78
116
|
});
|
|
79
117
|
this.logger.debug(`Registered prompt: ${promptDef.name}`, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-registration.js","sourceRoot":"","sources":["../../../src/mcp-server/prompts/prompt-registration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt-registration.js","sourceRoot":"","sources":["../../../src/mcp-server/prompts/prompt-registration.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EACL,qBAAqB,EAErB,UAAU,GACX,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MA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f;wBACE,GAAG,CAAC,KAAK,YAAY,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;wBACvD,SAAS,EAAE,cAAc,CAAC,SAAS;qBACpC,EACD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;gBACJ,CAAC;YACH,CAAC,CACF,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QACrE,CAAC,EACD;YACE,SAAS,EAAE,qBAAqB,SAAS,CAAC,IAAI,EAAE;YAChD,OAAO;YACP,SAAS,EAAE,gBAAgB,CAAC,oBAAoB;YAChD,QAAQ,EAAE,IAAI;SACf,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module src/mcp-server/resources/resource-registration
|
|
4
4
|
*/
|
|
5
5
|
import { type McpServer, type ServerNotifier } from '@modelcontextprotocol/server';
|
|
6
|
-
import type {
|
|
6
|
+
import type { ClientCapabilityView } from '../inputRequired.js';
|
|
7
7
|
import type { ResourceSubscriptions } from '../notifications.js';
|
|
8
8
|
import type { AnyResourceDefinition } from './utils/resourceDefinition.js';
|
|
9
9
|
import { type HandlerServices } from './utils/resourceHandlerFactory.js';
|
|
@@ -15,8 +15,10 @@ export declare class ResourceRegistry {
|
|
|
15
15
|
constructor(resourceDefs: AnyResourceDefinition[], services: HandlerServices);
|
|
16
16
|
/**
|
|
17
17
|
* Registers all resolved resource definitions with the provided McpServer instance.
|
|
18
|
+
* `capabilities` is the instance's view of what its client declared (#580),
|
|
19
|
+
* which every handler context resolves per request.
|
|
18
20
|
*/
|
|
19
|
-
registerAll(server: McpServer, subscriptions?: ResourceSubscriptions, bus?: ServerNotifier,
|
|
21
|
+
registerAll(server: McpServer, subscriptions?: ResourceSubscriptions, bus?: ServerNotifier, capabilities?: ClientCapabilityView): Promise<void>;
|
|
20
22
|
/** Throws at startup if a resource with the same name was already registered. */
|
|
21
23
|
private assertUniqueName;
|
|
22
24
|
private registerResource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-registration.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/resources/resource-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"resource-registration.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/resources/resource-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAC;AAChG,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,wDAAwD,CAAC;AAUhE,qBAAa,gBAAgB;IAKzB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,QAAQ;IALlB,wEAAwE;IACxE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IAErD,YACU,YAAY,EAAE,qBAAqB,EAAE,EACrC,QAAQ,EAAE,eAAe,EAC/B;IAEJ;;;;OAIG;IACU,WAAW,CACtB,MAAM,EAAE,SAAS,EACjB,aAAa,CAAC,EAAE,qBAAqB,EACrC,GAAG,CAAC,EAAE,cAAc,EACpB,YAAY,CAAC,EAAE,oBAAoB,GAClC,OAAO,CAAC,IAAI,CAAC,CA4Bf;IAED,iFAAiF;IACjF,OAAO,CAAC,gBAAgB;YAUV,gBAAgB;CAyD/B"}
|
|
@@ -22,8 +22,10 @@ export class ResourceRegistry {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Registers all resolved resource definitions with the provided McpServer instance.
|
|
25
|
+
* `capabilities` is the instance's view of what its client declared (#580),
|
|
26
|
+
* which every handler context resolves per request.
|
|
25
27
|
*/
|
|
26
|
-
async registerAll(server, subscriptions, bus,
|
|
28
|
+
async registerAll(server, subscriptions, bus, capabilities) {
|
|
27
29
|
this.registeredNames.clear();
|
|
28
30
|
// Per-server notifier closures targeting `server.send*ListChanged()`. Bound
|
|
29
31
|
// once per registerAll() call — never mutated on a shared services object
|
|
@@ -45,7 +47,7 @@ export class ResourceRegistry {
|
|
|
45
47
|
// declared `resources` capability, so a server with no resources still
|
|
46
48
|
// answers `resources/list` with an empty array rather than `-32601`.
|
|
47
49
|
for (const resourceDef of this.resourceDefs) {
|
|
48
|
-
await this.registerResource(server, resourceDef, notifiers,
|
|
50
|
+
await this.registerResource(server, resourceDef, notifiers, capabilities);
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
/** Throws at startup if a resource with the same name was already registered. */
|
|
@@ -56,7 +58,7 @@ export class ResourceRegistry {
|
|
|
56
58
|
}
|
|
57
59
|
this.registeredNames.add(name);
|
|
58
60
|
}
|
|
59
|
-
async registerResource(server, def, notifiers,
|
|
61
|
+
async registerResource(server, def, notifiers, capabilities) {
|
|
60
62
|
const resourceName = def.name ?? def.uriTemplate;
|
|
61
63
|
const registrationContext = requestContextService.createRequestContext({
|
|
62
64
|
operation: 'ResourceRegistry.registerResource',
|
|
@@ -65,7 +67,7 @@ export class ResourceRegistry {
|
|
|
65
67
|
logger.debug(`Registering resource: '${resourceName}'`, registrationContext);
|
|
66
68
|
this.assertUniqueName(resourceName);
|
|
67
69
|
await ErrorHandler.tryCatch(() => {
|
|
68
|
-
const handler = createResourceHandler(def, this.services, notifiers,
|
|
70
|
+
const handler = createResourceHandler(def, this.services, notifiers, capabilities);
|
|
69
71
|
const title = def.title ?? resourceName;
|
|
70
72
|
const mimeType = def.mimeType ?? 'application/json';
|
|
71
73
|
const metadata = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-registration.js","sourceRoot":"","sources":["../../../src/mcp-server/resources/resource-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEL,gBAAgB,GAEjB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EACL,qBAAqB,GAGtB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E,SAAS,uBAAuB,CAAC,WAAmB;IAClD,OAAO,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,OAAO,gBAAgB;IAKjB,YAAY;IACZ,QAAQ;IALlB,wEAAwE;IACvD,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAErD,YACU,YAAqC,EACrC,QAAyB;4BADzB,YAAY;wBACZ,QAAQ;IACf,CAAC;IAEJ
|
|
1
|
+
{"version":3,"file":"resource-registration.js","sourceRoot":"","sources":["../../../src/mcp-server/resources/resource-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEL,gBAAgB,GAEjB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EACL,qBAAqB,GAGtB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E,SAAS,uBAAuB,CAAC,WAAmB;IAClD,OAAO,WAAW,CAAC,IAAI,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
import type { InputRequiredResult, ReadResourceResult, ServerContext, Variables } from '@modelcontextprotocol/server';
|
|
7
7
|
import { type HandlerServices } from '../../handlerContext.js';
|
|
8
|
-
import { type
|
|
8
|
+
import { type ClientCapabilityView } from '../../inputRequired.js';
|
|
9
9
|
import type { NotifierSources } from '../../notifications.js';
|
|
10
10
|
import type { AnyResourceDefinition } from './resourceDefinition.js';
|
|
11
11
|
/** The factory's own contract, shared with the tool factory. */
|
|
@@ -30,7 +30,8 @@ export declare function defaultResponseFormatter(result: unknown, meta: {
|
|
|
30
30
|
* - Checks inline `auth` scopes if defined
|
|
31
31
|
* - Validates params via Zod schema
|
|
32
32
|
* - Formats response via `format` or JSON default
|
|
33
|
-
* - Catches errors and re-throws for the SDK
|
|
33
|
+
* - Catches errors and re-throws for the SDK, with the declared recovery filled
|
|
34
|
+
* (#579) and the read's request id added (#576)
|
|
34
35
|
*/
|
|
35
|
-
export declare function createResourceHandler(def: AnyResourceDefinition, services: HandlerServices, notifiers: NotifierSources,
|
|
36
|
+
export declare function createResourceHandler(def: AnyResourceDefinition, services: HandlerServices, notifiers: NotifierSources, capabilities?: ClientCapabilityView): (uri: URL, variables: Variables, ctx: ServerContext) => Promise<ReadResourceResult | InputRequiredResult>;
|
|
36
37
|
//# sourceMappingURL=resourceHandlerFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/resources/utils/resourceHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,SAAS,EACV,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"resourceHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/resources/utils/resourceHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,SAAS,EACV,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAEL,KAAK,eAAe,EAGrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAC;AAWhG,gEAAgE;AAChE,YAAY,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,YAAY,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAiBrE;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,OAAO,EACf,IAAI,EAAE;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACnC,kBAAkB,CAAC,UAAU,CAAC,CAShC;AAkBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,qBAAqB,EAC1B,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,eAAe,EAC1B,YAAY,CAAC,EAAE,oBAAoB,GAClC,CACD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,aAAa,KACf,OAAO,CAAC,kBAAkB,GAAG,mBAAmB,CAAC,CAgGrD"}
|