@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
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* Constructs Context (with `uri`), checks inline auth, validates params, formats response.
|
|
4
4
|
* @module src/mcp-server/resources/utils/resourceHandlerFactory
|
|
5
5
|
*/
|
|
6
|
+
import { resolveDeclaredFailure } from '../../../core/context.js';
|
|
6
7
|
import { buildHandlerContext, handlerParentContext, resolveHandlerRequest, } from '../../handlerContext.js';
|
|
7
|
-
import { isInputRequiredSignal } from '../../inputRequired.js';
|
|
8
|
+
import { isInputRequiredSignal, sealThrown, } from '../../inputRequired.js';
|
|
8
9
|
import { parseOutputContract } from '../../outputContract.js';
|
|
9
10
|
import { withRequiredScopes } from '../../transports/auth/lib/authUtils.js';
|
|
10
|
-
import { McpError } from '../../../types-global/errors.js';
|
|
11
|
+
import { JsonRpcErrorCode, McpError } from '../../../types-global/errors.js';
|
|
11
12
|
import { asRequestCancelled, ErrorHandler } from '../../../utils/internal/error-handler/errorHandler.js';
|
|
12
13
|
import { measureResourceExecution } from '../../../utils/internal/performance.js';
|
|
13
14
|
import { requestContextService } from '../../../utils/internal/requestContext.js';
|
|
@@ -62,9 +63,10 @@ function observableResourceUri(uri) {
|
|
|
62
63
|
* - Checks inline `auth` scopes if defined
|
|
63
64
|
* - Validates params via Zod schema
|
|
64
65
|
* - Formats response via `format` or JSON default
|
|
65
|
-
* - Catches errors and re-throws for the SDK
|
|
66
|
+
* - Catches errors and re-throws for the SDK, with the declared recovery filled
|
|
67
|
+
* (#579) and the read's request id added (#576)
|
|
66
68
|
*/
|
|
67
|
-
export function createResourceHandler(def, services, notifiers,
|
|
69
|
+
export function createResourceHandler(def, services, notifiers, capabilities) {
|
|
68
70
|
const mimeType = def.mimeType ?? 'application/json';
|
|
69
71
|
const formatter = def.format ?? defaultResponseFormatter;
|
|
70
72
|
const resourceName = def.name ?? def.uriTemplate;
|
|
@@ -74,7 +76,7 @@ export function createResourceHandler(def, services, notifiers, inputGate) {
|
|
|
74
76
|
// The URI template already captures the named segments; anything else is
|
|
75
77
|
// query-string / caller-supplied and belongs in metrics, not logs.
|
|
76
78
|
const appContext = requestContextService.createRequestContext({
|
|
77
|
-
parentContext: handlerParentContext(
|
|
79
|
+
parentContext: handlerParentContext(serverContext),
|
|
78
80
|
operation: 'HandleResourceRead',
|
|
79
81
|
additionalContext: {
|
|
80
82
|
resourceName,
|
|
@@ -94,7 +96,7 @@ export function createResourceHandler(def, services, notifiers, inputGate) {
|
|
|
94
96
|
// outcome, so a failure in either is a failed read. Closing the span when
|
|
95
97
|
// the handler returned recorded those as successes (#346).
|
|
96
98
|
return await measureResourceExecution(async (spanContext, recordOutput) => {
|
|
97
|
-
const ctx = buildHandlerContext(request, services, spanContext, def.errors,
|
|
99
|
+
const ctx = buildHandlerContext(request, services, spanContext, def.errors, capabilities, uri);
|
|
98
100
|
try {
|
|
99
101
|
// Handler may return sync or async.
|
|
100
102
|
const handlerResult = await def.handler(validatedParams, ctx);
|
|
@@ -115,8 +117,10 @@ export function createResourceHandler(def, services, notifiers, inputGate) {
|
|
|
115
117
|
catch (error) {
|
|
116
118
|
// Inside the measurement on purpose: the completion log's
|
|
117
119
|
// `metrics.errorCode` and the span's error-code attribute are
|
|
118
|
-
// derived from what leaves this callback (#421).
|
|
119
|
-
|
|
120
|
+
// derived from what leaves this callback (#421). An input-required
|
|
121
|
+
// signal leaves with its `requestState` sealed when a key is
|
|
122
|
+
// configured, so a sealing failure is a failed read like any other.
|
|
123
|
+
throw asRequestCancelled(await sealThrown(error, services.requestState, serverContext), request.signal);
|
|
120
124
|
}
|
|
121
125
|
}, { ...appContext, resourceName }, { uri: resourceUri, mimeType });
|
|
122
126
|
}
|
|
@@ -128,13 +132,37 @@ export function createResourceHandler(def, services, notifiers, inputGate) {
|
|
|
128
132
|
// an `McpError` carrying the reason and hint (#379).
|
|
129
133
|
if (isInputRequiredSignal(error))
|
|
130
134
|
return error.result;
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
const { code, message, data } = ErrorHandler.classifyOnly(error);
|
|
136
|
-
throw new McpError(code, message, data, { cause: error });
|
|
135
|
+
// Classified without logging: the completion record carries the code.
|
|
136
|
+
const { failure } = resolveDeclaredFailure(def.errors, asMcpError(error));
|
|
137
|
+
throw withRequestId(failure, appContext.requestId);
|
|
137
138
|
}
|
|
138
139
|
};
|
|
139
140
|
}
|
|
141
|
+
/** The thrown value as an `McpError`, classified by {@link ErrorHandler.classifyOnly} when it is not one. */
|
|
142
|
+
function asMcpError(error) {
|
|
143
|
+
if (error instanceof McpError)
|
|
144
|
+
return error;
|
|
145
|
+
const { code, message, data } = ErrorHandler.classifyOnly(error);
|
|
146
|
+
return new McpError(code, message, data, { cause: error });
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The error the SDK serializes into the read's JSON-RPC `error`, carrying the
|
|
150
|
+
* read's `requestId` as `data.requestId` (#576) — the id its completion record
|
|
151
|
+
* logs — so a failure reported from the client can be matched to that record.
|
|
152
|
+
* Set after the thrown data, so the framework's value replaces a thrown one.
|
|
153
|
+
*
|
|
154
|
+
* A `-32602` whose `data` is exactly `{ uri }` passes through untouched: it is
|
|
155
|
+
* the spec's resource-not-found shape, which clients recognize by that exact
|
|
156
|
+
* `data`.
|
|
157
|
+
*/
|
|
158
|
+
function withRequestId(error, requestId) {
|
|
159
|
+
const { data } = error;
|
|
160
|
+
const isResourceNotFound = error.code === JsonRpcErrorCode.InvalidParams &&
|
|
161
|
+
data !== undefined &&
|
|
162
|
+
typeof data.uri === 'string' &&
|
|
163
|
+
Object.keys(data).length === 1;
|
|
164
|
+
if (isResourceNotFound)
|
|
165
|
+
return error;
|
|
166
|
+
return new McpError(error.code, error.message, { ...data, requestId }, { cause: error });
|
|
167
|
+
}
|
|
140
168
|
//# sourceMappingURL=resourceHandlerFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceHandlerFactory.js","sourceRoot":"","sources":["../../../../src/mcp-server/resources/utils/resourceHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EACL,mBAAmB,EAEnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,gCAAgC,C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IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,aAAa,CAAC,KAAe,EAAE,SAAiB;IACvD,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACvB,MAAM,kBAAkB,GACtB,KAAK,CAAC,IAAI,KAAK,gBAAgB,CAAC,aAAa;QAC7C,IAAI,KAAK,SAAS;QAClB,OAAO,IAAI,CAAC,GAAG,KAAK,QAAQ;QAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACjC,IAAI,kBAAkB;QAAE,OAAO,KAAK,CAAC;IACrC,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAC3F,CAAC"}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { type Implementation, McpServer, type ServerNotifier } from '@modelcontextprotocol/server';
|
|
13
13
|
import type { AppConfig } from '../config/index.js';
|
|
14
14
|
import type { CacheHints } from './cacheHints.js';
|
|
15
|
+
import { type RequestStateSealer } from './inputRequired.js';
|
|
15
16
|
import type { PromptRegistry } from './prompts/prompt-registration.js';
|
|
16
17
|
import type { ResourceRegistry } from './resources/resource-registration.js';
|
|
17
18
|
import type { ToolRegistry } from './tools/tool-registration.js';
|
|
@@ -57,6 +58,14 @@ export interface McpServerDeps {
|
|
|
57
58
|
*/
|
|
58
59
|
notifier?: ServerNotifier;
|
|
59
60
|
promptRegistry: PromptRegistry;
|
|
61
|
+
/**
|
|
62
|
+
* The process's `requestState` sealer, built once from
|
|
63
|
+
* `MCP_REQUEST_STATE_KEY`. Its `verify` becomes the instance's
|
|
64
|
+
* `requestState.verify`, so every echoed state is checked before a handler
|
|
65
|
+
* runs, on the 2025-era shim's rounds as on 2026-07-28 retries. Absent when
|
|
66
|
+
* no key is configured, and the SDK then receives no `requestState` option.
|
|
67
|
+
*/
|
|
68
|
+
requestState?: RequestStateSealer;
|
|
60
69
|
resourceRegistry: ResourceRegistry;
|
|
61
70
|
/**
|
|
62
71
|
* Human-readable display name forwarded to `new McpServer({ serverInfo })`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp-server/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,KAAK,cAAc,EACnB,SAAS,EAET,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp-server/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,KAAK,cAAc,EACnB,SAAS,EAET,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAwB,KAAK,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAC9F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iDAAiD,CAAC;AAExF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAI5E,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,MAAM,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,mEAAmE;IACnE,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IAChC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,cAAc,EAAE,cAAc,CAAC;IAC/B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAuFrF"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @module src/mcp-server/server
|
|
11
11
|
*/
|
|
12
12
|
import { McpServer, } from '@modelcontextprotocol/server';
|
|
13
|
-
import {
|
|
13
|
+
import { clientCapabilityView } from './inputRequired.js';
|
|
14
14
|
import { installResourceSubscriptions } from './resources/resourceSubscriptions.js';
|
|
15
15
|
import { logger } from '../utils/internal/logger.js';
|
|
16
16
|
import { requestContextService } from '../utils/internal/requestContext.js';
|
|
@@ -58,31 +58,32 @@ export async function createMcpServerInstance(deps) {
|
|
|
58
58
|
// `elicitation/create` round trips over the live session) on 2025-era
|
|
59
59
|
// ones, so handlers are written once.
|
|
60
60
|
inputRequired: { legacyShim: true },
|
|
61
|
+
...(deps.requestState && { requestState: { verify: deps.requestState.verify } }),
|
|
61
62
|
});
|
|
63
|
+
const era = deps.era ?? 'legacy';
|
|
62
64
|
// The `resources/subscribe` registry is a 2025-era mechanism: the method
|
|
63
65
|
// does not exist on 2026-07-28, where the client opts in through
|
|
64
66
|
// `subscriptions/listen` and the SDK filters delivery. Installing it on a
|
|
65
67
|
// modern instance would leave the registry permanently empty and silently
|
|
66
68
|
// drop every `ctx.notifyResourceUpdated(uri)` — the notifiers read `undefined`
|
|
67
69
|
// as "no subscription tracking on this connection" and emit unconditionally.
|
|
68
|
-
const subscriptions =
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
: undefined;
|
|
70
|
+
const subscriptions = era === 'legacy' ? installResourceSubscriptions(server) : undefined;
|
|
71
|
+
// What the client declared, resolved per request from the source this era
|
|
72
|
+
// has (#580): the `initialize` value on a 2025-era instance, the request's
|
|
73
|
+
// envelope on a modern one. One view per instance feeds
|
|
74
|
+
// `ctx.clientCapabilities`, the filter over `ctx.inputs` (#496), and — on
|
|
75
|
+
// the 2025-era arm only, where the SDK's shim refusal cannot be shaped into
|
|
76
|
+
// an error envelope (#379) — the gate `ctx.requestInput` runs.
|
|
77
|
+
const capabilities = clientCapabilityView(era, server);
|
|
77
78
|
try {
|
|
78
79
|
logger.debug('Registering all MCP capabilities via registries...', context);
|
|
79
80
|
// The bus reaches a modern instance only. Passing it to a legacy one would
|
|
80
81
|
// route `ctx.notify*` away from the live session that can actually deliver
|
|
81
82
|
// it — the 2025 era has no `subscriptions/listen` stream to publish to.
|
|
82
|
-
const bus =
|
|
83
|
+
const bus = era === 'modern' ? deps.notifier : undefined;
|
|
83
84
|
await Promise.all([
|
|
84
|
-
deps.toolRegistry.registerAll(server, subscriptions, bus,
|
|
85
|
-
deps.resourceRegistry.registerAll(server, subscriptions, bus,
|
|
85
|
+
deps.toolRegistry.registerAll(server, subscriptions, bus, capabilities),
|
|
86
|
+
deps.resourceRegistry.registerAll(server, subscriptions, bus, capabilities),
|
|
86
87
|
deps.promptRegistry.registerAll(server),
|
|
87
88
|
]);
|
|
88
89
|
logger.debug('All MCP capabilities registered successfully', context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp-server/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAEL,SAAS,GAGV,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp-server/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAEL,SAAS,GAGV,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAE,oBAAoB,EAA2B,MAAM,+BAA+B,CAAC;AAG9F,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAmE3E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAAmB;IAC/D,MAAM,OAAO,GAAG,qBAAqB,CAAC,oBAAoB,CAAC;QACzD,SAAS,EAAE,yBAAyB;KACrC,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,OAAO,CAAC,CAAC;IAE1D,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B;QACE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa;QAC/B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB;QACrC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QACxC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,C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McpServer, 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 { AnyToolDefinition } from './utils/toolDefinition.js';
|
|
9
9
|
import { type HandlerServices } from './utils/toolHandlerFactory.js';
|
|
@@ -20,8 +20,12 @@ export declare class ToolRegistry {
|
|
|
20
20
|
/** Tracks registered tool names to detect duplicates at startup. */
|
|
21
21
|
private readonly registeredNames;
|
|
22
22
|
constructor(toolDefs: AnyToolDef[], services: HandlerServices);
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Registers all tool 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.
|
|
27
|
+
*/
|
|
28
|
+
registerAll(server: McpServer, subscriptions?: ResourceSubscriptions, bus?: ServerNotifier, capabilities?: ClientCapabilityView): Promise<void>;
|
|
25
29
|
/** Throws at startup if a tool with the same name was already registered. */
|
|
26
30
|
private assertUniqueName;
|
|
27
31
|
/** Registers a standard tool definition. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registration.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/tools/tool-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAgB,MAAM,8BAA8B,CAAC;AAE5F,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"tool-registration.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/tools/tool-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAgB,MAAM,8BAA8B,CAAC;AAE5F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAG3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,gDAAgD,CAAC;AAMxD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAU3C,qBAAa,YAAY;IAKrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAL3B,oEAAoE;IACpE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IAErD,YACmB,QAAQ,EAAE,UAAU,EAAE,EACtB,QAAQ,EAAE,eAAe,EACxC;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,CA8Cf;IAED,6EAA6E;IAC7E,OAAO,CAAC,gBAAgB;IAUxB,4CAA4C;YAC9B,YAAY;CAkD3B"}
|
|
@@ -21,8 +21,12 @@ export class ToolRegistry {
|
|
|
21
21
|
this.toolDefs = toolDefs;
|
|
22
22
|
this.services = services;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Registers all tool definitions with the provided McpServer instance.
|
|
26
|
+
* `capabilities` is the instance's view of what its client declared (#580),
|
|
27
|
+
* which every handler context resolves per request.
|
|
28
|
+
*/
|
|
29
|
+
async registerAll(server, subscriptions, bus, capabilities) {
|
|
26
30
|
// Reset per-server uniqueness tracking — registries are shared across
|
|
27
31
|
// per-request McpServer instances under HTTP serving.
|
|
28
32
|
this.registeredNames.clear();
|
|
@@ -57,7 +61,7 @@ export class ToolRegistry {
|
|
|
57
61
|
// `tools` capability, so a server with every tool disabled still answers
|
|
58
62
|
// `tools/list` with an empty array rather than `-32601`.
|
|
59
63
|
for (const toolDef of tools) {
|
|
60
|
-
await this.registerTool(server, toolDef, notifiers,
|
|
64
|
+
await this.registerTool(server, toolDef, notifiers, capabilities);
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
/** Throws at startup if a tool with the same name was already registered. */
|
|
@@ -69,7 +73,7 @@ export class ToolRegistry {
|
|
|
69
73
|
this.registeredNames.add(name);
|
|
70
74
|
}
|
|
71
75
|
/** Registers a standard tool definition. */
|
|
72
|
-
async registerTool(server, tool, notifiers,
|
|
76
|
+
async registerTool(server, tool, notifiers, capabilities) {
|
|
73
77
|
const registrationContext = requestContextService.createRequestContext({
|
|
74
78
|
operation: 'ToolRegistry.registerTool',
|
|
75
79
|
additionalContext: { toolName: tool.name },
|
|
@@ -77,7 +81,7 @@ export class ToolRegistry {
|
|
|
77
81
|
logger.debug(`Registering tool: '${tool.name}'`, registrationContext);
|
|
78
82
|
this.assertUniqueName(tool.name);
|
|
79
83
|
await ErrorHandler.tryCatch(() => {
|
|
80
|
-
const handler = createToolHandler(tool, this.services, notifiers,
|
|
84
|
+
const handler = createToolHandler(tool, this.services, notifiers, capabilities);
|
|
81
85
|
const title = tool.title ?? tool.annotations?.title ?? deriveTitleFromName(tool.name);
|
|
82
86
|
// Advertised verbatim; the same schema rejects the same arguments one
|
|
83
87
|
// layer down, where a rejection can carry the framework's structured
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registration.js","sourceRoot":"","sources":["../../../src/mcp-server/tools/tool-registration.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAEhF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAGlB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC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AG,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;YAChF,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEtF,sEAAsE;YACtE,qEAAqE;YACrE,uEAAuE;YACvE,yDAAyD;YACzD,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAiC,CAAC;YAErF,sFAAsF;YACtF,MAAM,CAAC,YAAY,CACjB,IAAI,CAAC,IAAI,EACT;gBACE,KAAK;gBACL,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,WAAW;gBACX,YAAY,EAAE,sBAAsB,CAAC,IAAI,CAAC;gBAC1C,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC1D,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;aACzC,EACD,OAA0C,CAC3C,CAAC;YAEF,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,4BAA4B,EAAE,mBAAmB,CAAC,CAAC;QACpF,CAAC,EACD;YACE,SAAS,EAAE,mBAAmB,IAAI,CAAC,IAAI,EAAE;YACzC,OAAO,EAAE,mBAAmB;YAC5B,SAAS,EAAE,gBAAgB,CAAC,oBAAoB;YAChD,QAAQ,EAAE,IAAI;SACf,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -14,28 +14,47 @@
|
|
|
14
14
|
* in another case style (`max_results` for `maxResults`). Rewritten to the
|
|
15
15
|
* canonical key before parsing. A one-to-one mapping fixed ahead of time, not
|
|
16
16
|
* the nearest-key guess #232 rejected.
|
|
17
|
-
* 3. **Representation repair (#234)** — a JSON-stringified array
|
|
18
|
-
* was declared
|
|
19
|
-
* only
|
|
20
|
-
*
|
|
21
|
-
* valid.
|
|
17
|
+
* 3. **Representation repair (#234, #479, #487)** — a JSON-stringified array or
|
|
18
|
+
* object where one was declared, or an integer where a string was. Applied
|
|
19
|
+
* only *after* the parse has already failed, and kept only when it flips the
|
|
20
|
+
* arguments from invalid to valid: the author's schema is the sole arbiter,
|
|
21
|
+
* so a repair can never touch input that was already valid.
|
|
22
|
+
*
|
|
23
|
+
* The drop runs first, so it also discards a key the alias stage would have
|
|
24
|
+
* resolved: an underscore spelling of a declared key (`_query`), a declared
|
|
25
|
+
* `_q` alias, an ignore-listed key a declared alias names. When the arguments
|
|
26
|
+
* then fail, repair included, the two stages run once more with the alias
|
|
27
|
+
* stage first, and that retry — with its own repair — is kept only if it
|
|
28
|
+
* validates (#563). A call the first order validates never reaches the retry,
|
|
29
|
+
* so the retry never changes which calls validate. A call neither order
|
|
30
|
+
* validates carries the retry's rejection, where the discarded keys reached
|
|
31
|
+
* their targets: a declared `_q` alias with a bad value is reported as
|
|
32
|
+
* validated under `query`, with the value's own failure, not as a dropped key
|
|
33
|
+
* beside a missing field.
|
|
22
34
|
*
|
|
23
35
|
* All three are on by default and each has a server-level switch on
|
|
24
36
|
* `createApp({ input })` / `createWorkerHandler({ input })`. None of them
|
|
25
|
-
* changes what `tools/list` advertises
|
|
26
|
-
* a rewrite, and a repair each emit one
|
|
27
|
-
* instead
|
|
37
|
+
* changes what `tools/list` advertises. A call they rescue carries nothing
|
|
38
|
+
* about them in its response: a drop, a rewrite, and a repair each emit one
|
|
39
|
+
* debug log and one counter increment instead — for the attempt whose
|
|
40
|
+
* arguments the handler receives, never one the parse discarded. A call they
|
|
41
|
+
* cannot rescue is rejected with the rewrites and underscore-rule drops of the
|
|
42
|
+
* attempt whose rejection it carries reported (#468), since without them the caller cannot
|
|
43
|
+
* tell a bad value from a key that was moved or discarded; a repair the
|
|
44
|
+
* re-parse discarded leaves no trace there.
|
|
28
45
|
*
|
|
29
|
-
* The split between
|
|
30
|
-
* author- or framework-defined — the ignore-list entry that
|
|
31
|
-
* declared key a rewrite resolved to — because a metric label
|
|
32
|
-
* caller's own key text mints a permanent time series per spelling
|
|
33
|
-
* invents (#114). The raw key and alias go to the debug log, which is
|
|
34
|
-
* operator looks when a counter shows a new client artifact and where
|
|
35
|
-
* cardinality costs nothing
|
|
46
|
+
* The split between log and counter is deliberate. Counter attributes are
|
|
47
|
+
* bounded and author- or framework-defined — the ignore-list entry that
|
|
48
|
+
* matched, the declared key a rewrite resolved to — because a metric label
|
|
49
|
+
* carrying the caller's own key text mints a permanent time series per spelling
|
|
50
|
+
* a client invents (#114). The raw key and alias go to the debug log, which is
|
|
51
|
+
* where an operator looks when a counter shows a new client artifact and where
|
|
52
|
+
* cardinality costs nothing — and, on a rejection, back to the caller who sent
|
|
53
|
+
* them, since an error payload is per call rather than a permanent series.
|
|
36
54
|
*
|
|
37
55
|
* @module src/mcp-server/tools/utils/inputPrevalidation
|
|
38
56
|
*/
|
|
57
|
+
import type { ZodError } from 'zod';
|
|
39
58
|
import { type RequestContext } from '../../../utils/internal/requestContext.js';
|
|
40
59
|
import type { AnyToolDefinition } from './toolDefinition.js';
|
|
41
60
|
/**
|
|
@@ -54,8 +73,10 @@ export interface InputHandlingOptions {
|
|
|
54
73
|
caseStyleAliases?: boolean;
|
|
55
74
|
/**
|
|
56
75
|
* Retry a failed parse once against repaired argument *values* — a
|
|
57
|
-
* JSON-stringified array parsed back into
|
|
58
|
-
*
|
|
76
|
+
* JSON-stringified array or object parsed back into what it encodes, or a
|
|
77
|
+
* safe integer sent where a string was expected turned into its decimal
|
|
78
|
+
* string. `false` turns the repair off, so each order of the key stages is
|
|
79
|
+
* parsed once, with the values as sent. Default `true`.
|
|
59
80
|
*/
|
|
60
81
|
coerce?: boolean;
|
|
61
82
|
/**
|
|
@@ -66,8 +87,89 @@ export interface InputHandlingOptions {
|
|
|
66
87
|
*/
|
|
67
88
|
ignoreKeys?: readonly string[] | false;
|
|
68
89
|
}
|
|
69
|
-
/**
|
|
70
|
-
|
|
90
|
+
/**
|
|
91
|
+
* The repairs {@link repairRepresentations} performs, as `mcp.input.coercion`
|
|
92
|
+
* labels them, in the order a call's debug log names them — paired with how
|
|
93
|
+
* that log reads each one.
|
|
94
|
+
*/
|
|
95
|
+
declare const COERCION_KINDS: {
|
|
96
|
+
readonly stringified_array: 'a stringified array';
|
|
97
|
+
readonly stringified_object: 'a stringified object';
|
|
98
|
+
readonly integer_as_string: 'an integer sent for a string';
|
|
99
|
+
};
|
|
100
|
+
/** One repair {@link repairRepresentations} can perform. */
|
|
101
|
+
export type CoercionKind = keyof typeof COERCION_KINDS;
|
|
102
|
+
/** Which half of the alias stage rewrote a key. */
|
|
103
|
+
type AliasKind = 'case_style' | 'declared';
|
|
104
|
+
/** One Zod issue from a failed parse of the arguments. */
|
|
105
|
+
type ArgumentIssue = ZodError['issues'][number];
|
|
106
|
+
/**
|
|
107
|
+
* What the pre-parse stages changed that the caller wrote, reported on an
|
|
108
|
+
* argument rejection (#468) so a caller can tell a bad value from a key that
|
|
109
|
+
* was moved or discarded. Keys only, never values.
|
|
110
|
+
*/
|
|
111
|
+
export interface PrevalidationReport {
|
|
112
|
+
/** Root keys rewritten to their canonical spelling, in argument order. */
|
|
113
|
+
readonly aliased: ReadonlyArray<{
|
|
114
|
+
readonly alias: string;
|
|
115
|
+
readonly target: string;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* Undeclared underscore-prefixed root keys the drop stage discarded, in
|
|
119
|
+
* argument order. An ignore-list drop is never listed: it is a client
|
|
120
|
+
* artifact the model did not write and cannot remove.
|
|
121
|
+
*/
|
|
122
|
+
readonly ignored: readonly string[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* One key a pre-parse stage rewrote or dropped, as {@link recordPrevalidation}
|
|
126
|
+
* counts and logs it. `rule` is the ignore-list entry that matched, or
|
|
127
|
+
* {@link UNDERSCORE_RULE}.
|
|
128
|
+
*/
|
|
129
|
+
export type PrevalidationChange = {
|
|
130
|
+
readonly alias: string;
|
|
131
|
+
readonly aliasKind: AliasKind;
|
|
132
|
+
readonly kind: 'aliased';
|
|
133
|
+
readonly target: string;
|
|
134
|
+
} | {
|
|
135
|
+
readonly key: string;
|
|
136
|
+
readonly kind: 'dropped';
|
|
137
|
+
readonly rule: string;
|
|
138
|
+
};
|
|
139
|
+
/** One ordering of the pre-parse stages — what {@link prevalidateToolArguments} hands the parse. */
|
|
140
|
+
export interface PrevalidatedArguments {
|
|
141
|
+
/** The arguments to parse — the caller's own object when nothing applied. */
|
|
142
|
+
readonly args: unknown;
|
|
143
|
+
/**
|
|
144
|
+
* Every rewrite and drop, in the order the stages made them. Nothing is
|
|
145
|
+
* emitted while the stages run: the parse decides which attempt the handler
|
|
146
|
+
* receives, and {@link recordPrevalidation} emits that one.
|
|
147
|
+
*/
|
|
148
|
+
readonly changes: readonly PrevalidationChange[];
|
|
149
|
+
/** Present only when a rewrite or an underscore-rule drop happened. */
|
|
150
|
+
readonly report?: PrevalidationReport;
|
|
151
|
+
}
|
|
152
|
+
/** What {@link repairRepresentations} produced. */
|
|
153
|
+
export interface RepairedArguments {
|
|
154
|
+
/** The repaired arguments — the input itself when nothing was repairable. */
|
|
155
|
+
readonly args: unknown;
|
|
156
|
+
/** Each kind that fired at least once, in {@link COERCION_KINDS} order. */
|
|
157
|
+
readonly kinds: readonly CoercionKind[];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Emits one counter increment and one debug log per change an attempt made, in
|
|
161
|
+
* the order its stages made them. {@link parseToolArguments} calls it once per
|
|
162
|
+
* call, for the attempt whose arguments the handler receives — or, on a
|
|
163
|
+
* rejection, the first attempt, the one the rejection reports — so a key the
|
|
164
|
+
* alias-first retry rewrote never also counts as dropped (#563).
|
|
165
|
+
*/
|
|
166
|
+
export declare function recordPrevalidation(def: AnyToolDefinition, attempt: PrevalidatedArguments, context: RequestContext | undefined): void;
|
|
167
|
+
/**
|
|
168
|
+
* One increment per repaired call and kind — a call repairing an array and an
|
|
169
|
+
* object adds one to each series, and one repairing three arrays adds one — and
|
|
170
|
+
* one debug log per call naming every kind that fired.
|
|
171
|
+
*/
|
|
172
|
+
export declare function countCoerced(toolName: string, kinds: readonly CoercionKind[], context: RequestContext | undefined): void;
|
|
71
173
|
/**
|
|
72
174
|
* `Max-Results`, `max_results`, and `maxResults` all fold to `maxresults`.
|
|
73
175
|
*
|
|
@@ -77,18 +179,33 @@ export declare function countCoerced(toolName: string, context: RequestContext |
|
|
|
77
179
|
*/
|
|
78
180
|
export declare function foldArgumentKey(key: string): string;
|
|
79
181
|
/**
|
|
80
|
-
* Runs the pre-parse half of the step — drop client-added
|
|
81
|
-
* key aliases — and returns the arguments to parse
|
|
182
|
+
* Runs the pre-parse half of the step in its first order — drop client-added
|
|
183
|
+
* keys, then rewrite key aliases — and returns the arguments to parse, with
|
|
184
|
+
* what the two stages changed that the caller wrote.
|
|
82
185
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
186
|
+
* `args` is the caller's own object when nothing applied. Non-object arguments
|
|
187
|
+
* are handed straight back: the schema's own rejection already says what
|
|
188
|
+
* arrived.
|
|
86
189
|
*/
|
|
87
|
-
export declare function prevalidateToolArguments(def: AnyToolDefinition, args: unknown, options: InputHandlingOptions | undefined
|
|
190
|
+
export declare function prevalidateToolArguments(def: AnyToolDefinition, args: unknown, options: InputHandlingOptions | undefined): PrevalidatedArguments;
|
|
88
191
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* a
|
|
192
|
+
* The retry for a call whose first attempt failed (#563): the same stages with
|
|
193
|
+
* the alias stage first, so a key the drop discarded — an underscore spelling
|
|
194
|
+
* of a declared key, a declared `_q` alias, an ignore-listed key a declared
|
|
195
|
+
* alias names — reaches the rewrite. An underscore-prefixed key the alias stage
|
|
196
|
+
* cannot resolve is still dropped after it.
|
|
197
|
+
*
|
|
198
|
+
* `undefined` when there is nothing to retry: the first attempt dropped no key,
|
|
199
|
+
* or this order hands the parse the same arguments, which would only repeat
|
|
200
|
+
* the first attempt's failure.
|
|
201
|
+
*/
|
|
202
|
+
export declare function prevalidateAliasFirst(def: AnyToolDefinition, args: unknown, first: PrevalidatedArguments, options: InputHandlingOptions | undefined): PrevalidatedArguments | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Undoes a representation slip at each path the failed parse's issues named:
|
|
205
|
+
* a string whose trimmed form is a JSON array or object is parsed back into
|
|
206
|
+
* what it encodes (#234, #479), and a safe integer where a string was expected
|
|
207
|
+
* becomes its decimal string (#487). Keys are never added, dropped, or renamed,
|
|
208
|
+
* and a value no issue points at is returned untouched.
|
|
92
209
|
*
|
|
93
210
|
* **Targeted, not a full walk.** A rejection names exactly the values the schema
|
|
94
211
|
* could not accept, and repairing anything else loses repairs that should have
|
|
@@ -96,19 +213,25 @@ export declare function prevalidateToolArguments(def: AnyToolDefinition, args: u
|
|
|
96
213
|
* free-text field legitimately holding `"[1,2]"` would have both rewritten, the
|
|
97
214
|
* re-parse would fail on the free-text field, and the whole call would be
|
|
98
215
|
* rejected over a value that was valid all along. An `invalid_union` issue's
|
|
99
|
-
* outer path counts like any other — that is the value the union rejected
|
|
216
|
+
* outer path counts like any other — that is the value the union rejected, and
|
|
217
|
+
* the only one read: a number inside one branch of a union field stays as sent.
|
|
218
|
+
*
|
|
219
|
+
* **One pass, no stacking.** Only a value the first parse rejected is repaired,
|
|
220
|
+
* and at most once, so a value one repair produced is never repaired again — an
|
|
221
|
+
* integer inside a stringified array, a stringified field inside a stringified
|
|
222
|
+
* object. The caller re-parses once.
|
|
100
223
|
*
|
|
101
|
-
* `JSON.parse` is the exact inverse of the `JSON.stringify` that produced
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* when it then
|
|
224
|
+
* `JSON.parse` is the exact inverse of the `JSON.stringify` that produced a
|
|
225
|
+
* string, and `String(n)` of a safe integer is the digits the caller sent, so
|
|
226
|
+
* each repair undoes a known encoding rather than matching a nearest candidate —
|
|
227
|
+
* the distinction that makes it safe where nearest-key matching is not (#232).
|
|
228
|
+
* Safety does not rest on that alone: {@link parseToolArguments} runs this only
|
|
229
|
+
* after validation has already failed and keeps the result only when it then
|
|
230
|
+
* passes.
|
|
107
231
|
*
|
|
108
|
-
*
|
|
109
|
-
* the caller uses to skip the second parse.
|
|
232
|
+
* `args` is the argument itself when nothing was repairable, which is the
|
|
233
|
+
* signal the caller uses to skip the second parse.
|
|
110
234
|
*/
|
|
111
|
-
export declare function repairRepresentations(args: unknown, issues:
|
|
112
|
-
|
|
113
|
-
}>): unknown;
|
|
235
|
+
export declare function repairRepresentations(args: unknown, issues: readonly ArgumentIssue[]): RepairedArguments;
|
|
236
|
+
export {};
|
|
114
237
|
//# sourceMappingURL=inputPrevalidation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputPrevalidation.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/inputPrevalidation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"inputPrevalidation.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/inputPrevalidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAmC,MAAM,KAAK,CAAC;AAGrE,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,oCAAoC,CAAC;AAW5C,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAM9E;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,SAAS,MAAM,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