@cyanheads/mcp-ts-core 0.9.13 → 0.9.15
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 +559 -0
- package/CLAUDE.md +8 -4
- package/README.md +33 -44
- package/changelog/0.9.x/0.9.14.md +31 -0
- package/changelog/0.9.x/0.9.15.md +52 -0
- package/changelog/template.md +1 -1
- package/dist/core/context.d.ts +119 -14
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +70 -1
- 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/linter/rules/enrichment-rules.d.ts +41 -0
- package/dist/linter/rules/enrichment-rules.d.ts.map +1 -0
- package/dist/linter/rules/enrichment-rules.js +204 -0
- package/dist/linter/rules/enrichment-rules.js.map +1 -0
- package/dist/linter/rules/index.d.ts +1 -0
- package/dist/linter/rules/index.d.ts.map +1 -1
- package/dist/linter/rules/index.js +1 -0
- package/dist/linter/rules/index.js.map +1 -1
- package/dist/linter/rules/schema-rules.d.ts +4 -0
- package/dist/linter/rules/schema-rules.d.ts.map +1 -1
- package/dist/linter/rules/schema-rules.js +2 -2
- package/dist/linter/rules/schema-rules.js.map +1 -1
- package/dist/linter/rules/tool-rules.d.ts.map +1 -1
- package/dist/linter/rules/tool-rules.js +4 -0
- package/dist/linter/rules/tool-rules.js.map +1 -1
- package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -1
- package/dist/mcp-server/tools/tool-registration.js +7 -7
- package/dist/mcp-server/tools/tool-registration.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolDefinition.d.ts +81 -7
- package/dist/mcp-server/tools/utils/toolDefinition.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolDefinition.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +23 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js +118 -9
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +21 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/utils/internal/performance.d.ts +5 -1
- package/dist/utils/internal/performance.d.ts.map +1 -1
- package/dist/utils/internal/performance.js +10 -1
- package/dist/utils/internal/performance.js.map +1 -1
- package/dist/utils/telemetry/attributes.d.ts +2 -0
- package/dist/utils/telemetry/attributes.d.ts.map +1 -1
- package/dist/utils/telemetry/attributes.js +2 -0
- package/dist/utils/telemetry/attributes.js.map +1 -1
- package/package.json +5 -3
- package/scripts/build-changelog.ts +3 -1
- package/scripts/check-skills-sync.ts +42 -8
- package/skills/add-app-tool/SKILL.md +2 -2
- package/skills/add-export/SKILL.md +2 -2
- package/skills/add-service/SKILL.md +2 -2
- package/skills/add-tool/SKILL.md +85 -32
- package/skills/api-context/SKILL.md +68 -3
- package/skills/api-linter/SKILL.md +73 -2
- package/skills/design-mcp-server/SKILL.md +2 -1
- package/skills/git-wrapup/SKILL.md +22 -15
- package/skills/maintenance/SKILL.md +8 -7
- package/skills/orchestrations/SKILL.md +9 -5
- package/skills/orchestrations/workflows/maintenance-release.md +1 -1
- package/skills/polish-docs-meta/SKILL.md +1 -1
- package/skills/polish-docs-meta/references/agent-protocol.md +2 -2
- package/skills/polish-docs-meta/references/readme.md +3 -3
- package/skills/report-issue-framework/SKILL.md +8 -3
- package/skills/report-issue-local/SKILL.md +8 -3
- package/skills/setup/SKILL.md +5 -10
- package/templates/AGENTS.md +2 -1
- package/templates/CLAUDE.md +2 -1
- package/templates/_.mcpbignore +2 -0
- package/templates/changelog/template.md +1 -1
- package/templates/package.json +2 -1
- package/templates/src/mcp-server/tools/definitions/echo.tool.ts +10 -0
- package/dist/logs/combined.log +0 -4
- package/dist/logs/error.log +0 -2
- package/dist/logs/interactions.log +0 -0
|
@@ -47,6 +47,33 @@ export interface ToolAnnotations {
|
|
|
47
47
|
title?: string;
|
|
48
48
|
[key: string]: unknown;
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Per-field rendering config for the `enrichment` block's `content[]` trailer,
|
|
52
|
+
* keyed to the declared enrichment field names. The success-path analogue of how
|
|
53
|
+
* `format()` controls `output` rendering: `enrichment` is the data contract,
|
|
54
|
+
* `enrichmentTrailer` is its presentation.
|
|
55
|
+
*
|
|
56
|
+
* Scope: this shapes the `content[]` trailer text ONLY. It never affects
|
|
57
|
+
* `structuredContent`, which always carries the raw validated enrichment value
|
|
58
|
+
* (the object/array/scalar exactly as declared) — never the rendered markdown.
|
|
59
|
+
*
|
|
60
|
+
* Each entry is optional and may set:
|
|
61
|
+
* - `render` — maps the field's validated value to trailer markdown. Wins over
|
|
62
|
+
* the kind-tag and the generic `**key:** value` fallback. Use it to stop a
|
|
63
|
+
* structured (object/array) field from collapsing to a JSON blob in
|
|
64
|
+
* `content[]`; `structuredContent` always keeps the full structured value.
|
|
65
|
+
* - `label` — overrides the field-name shown in the generic / `delta` rendering
|
|
66
|
+
* (e.g. `Total Found` for a `totalFound` field, instead of the raw key).
|
|
67
|
+
*
|
|
68
|
+
* Resolves to `never` when no `enrichment` block is declared — `enrichmentTrailer`
|
|
69
|
+
* requires one.
|
|
70
|
+
*/
|
|
71
|
+
export type EnrichmentTrailerConfig<TEnrich extends ZodRawShape | undefined> = TEnrich extends ZodRawShape ? {
|
|
72
|
+
[K in keyof TEnrich]?: {
|
|
73
|
+
label?: string;
|
|
74
|
+
render?: (value: z.infer<TEnrich[K]>) => string;
|
|
75
|
+
};
|
|
76
|
+
} : never;
|
|
50
77
|
/**
|
|
51
78
|
* Represents the complete, self-contained definition of an MCP tool.
|
|
52
79
|
*
|
|
@@ -54,8 +81,12 @@ export interface ToolAnnotations {
|
|
|
54
81
|
* definition (or `undefined` when none are declared). The reason union extracted
|
|
55
82
|
* from `TErrors` flows into the handler's `ctx.fail` for compile-time-checked
|
|
56
83
|
* error throws.
|
|
84
|
+
*
|
|
85
|
+
* `TEnrich` is the `ZodRawShape` of the `enrichment` block (or `undefined` when
|
|
86
|
+
* none is declared). Its inferred fields type `ctx.enrich(...)` and are advertised
|
|
87
|
+
* to clients as part of `outputSchema`.
|
|
57
88
|
*/
|
|
58
|
-
export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TErrors extends readonly ErrorContract[] | undefined = undefined> {
|
|
89
|
+
export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TErrors extends readonly ErrorContract[] | undefined = undefined, TEnrich extends ZodRawShape | undefined = undefined> {
|
|
59
90
|
/** Protocol-level metadata (e.g., MCP Apps extension). */
|
|
60
91
|
_meta?: Record<string, unknown>;
|
|
61
92
|
/** UI/behavior hints for clients. */
|
|
@@ -64,6 +95,40 @@ export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObjec
|
|
|
64
95
|
auth?: string[];
|
|
65
96
|
/** LLM-facing description. */
|
|
66
97
|
description: string;
|
|
98
|
+
/**
|
|
99
|
+
* Declarative contract for agent-facing context on the success path — the
|
|
100
|
+
* counterpart to `errors[]`. A `ZodRawShape` (`{ <name>: <ZodType> }`) of
|
|
101
|
+
* fields the handler populates via `ctx.enrich(...)`: empty-result notices,
|
|
102
|
+
* the query/filter as the server parsed it, pagination totals.
|
|
103
|
+
*
|
|
104
|
+
* **Reaches both client surfaces.** Enrichment is merged into the validated
|
|
105
|
+
* output (→ `structuredContent`) and mirrored into `content[]` as a trailer —
|
|
106
|
+
* so `structuredContent`-only clients (e.g. Claude Code) and `content[]`-only
|
|
107
|
+
* clients (e.g. Claude Desktop) both see it, even when the tool defines no
|
|
108
|
+
* `format()`. The extended schema (`output.extend(enrichment)`) is advertised
|
|
109
|
+
* as the tool's `outputSchema` in `tools/list`.
|
|
110
|
+
*
|
|
111
|
+
* **Type-driven.** When declared, `ctx.enrich(...)` is typed to a `Partial` of
|
|
112
|
+
* these fields. Enrichment is not part of `output`, so `format-parity` never
|
|
113
|
+
* touches it. A *required* enrichment field that is never populated fails the
|
|
114
|
+
* effective-output parse — surfacing the bug rather than dropping it silently.
|
|
115
|
+
* Keys must be disjoint from `output` keys (lint-enforced; `.extend` would
|
|
116
|
+
* otherwise silently override).
|
|
117
|
+
*/
|
|
118
|
+
enrichment?: TEnrich;
|
|
119
|
+
/**
|
|
120
|
+
* Per-field `content[]` trailer rendering for the `enrichment` block — the
|
|
121
|
+
* presentation layer to `enrichment`'s data contract (mirrors `output` /
|
|
122
|
+
* `format`).
|
|
123
|
+
*
|
|
124
|
+
* Supply a `render` to stop a structured (object/array) enrichment field from
|
|
125
|
+
* collapsing to a JSON blob in `content[]` (it renders as bulleted markdown
|
|
126
|
+
* instead; `structuredContent` is unaffected), or a `label` to show a
|
|
127
|
+
* human-readable field name. Keyed to the declared `enrichment` fields and
|
|
128
|
+
* type-checked against them. The `enrichment-trailer-render` lint rule requires
|
|
129
|
+
* a `render` for any non-scalar enrichment field that isn't a `delta` shape.
|
|
130
|
+
*/
|
|
131
|
+
enrichmentTrailer?: EnrichmentTrailerConfig<TEnrich>;
|
|
67
132
|
/**
|
|
68
133
|
* Declarative contract describing the failure modes this tool can surface.
|
|
69
134
|
*
|
|
@@ -95,8 +160,13 @@ export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObjec
|
|
|
95
160
|
* clients can see. The `format-parity` lint rule enforces this at startup.
|
|
96
161
|
*
|
|
97
162
|
* If omitted, the handler factory JSON-stringifies the output as a fallback.
|
|
163
|
+
*
|
|
164
|
+
* Declared as a method (not an arrow property) for the same reason as `handler`:
|
|
165
|
+
* method parameters are checked bivariantly, so a concrete tool's narrow `format`
|
|
166
|
+
* stays assignable to the type-erased `AnyToolDefinition` (whose `format` param is
|
|
167
|
+
* the widened `Record<string, unknown>`).
|
|
98
168
|
*/
|
|
99
|
-
format
|
|
169
|
+
format?(result: z.infer<TOutput>): ContentBlock[];
|
|
100
170
|
/**
|
|
101
171
|
* The core handler function. Receives validated input and unified Context.
|
|
102
172
|
* Throw on failure — no try/catch needed.
|
|
@@ -105,11 +175,15 @@ export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObjec
|
|
|
105
175
|
* helper keyed by the declared reason union — `ctx.fail('typo')` is a TS error.
|
|
106
176
|
* Without `errors[]`, `ctx` is plain `Context` and you throw `McpError` directly.
|
|
107
177
|
*
|
|
178
|
+
* When `enrichment` is declared, `ctx.enrich(...)` is typed to a `Partial` of
|
|
179
|
+
* the declared fields; without it, the loose base `enrich` is available (a
|
|
180
|
+
* no-op merge, since nothing reads it).
|
|
181
|
+
*
|
|
108
182
|
* Declared as a method (not an arrow property) so TypeScript checks the
|
|
109
|
-
* signature bivariantly — concrete tools with narrow `ctx.fail`
|
|
110
|
-
* assignable to the type-erased `AnyToolDefinition` array.
|
|
183
|
+
* signature bivariantly — concrete tools with narrow `ctx.fail` / `ctx.enrich`
|
|
184
|
+
* types remain assignable to the type-erased `AnyToolDefinition` array.
|
|
111
185
|
*/
|
|
112
|
-
handler(input: z.infer<TInput>, ctx: HandlerContext<ReasonOf<TErrors
|
|
186
|
+
handler(input: z.infer<TInput>, ctx: HandlerContext<ReasonOf<TErrors>, TEnrich>): Promise<z.infer<TOutput>> | z.infer<TOutput>;
|
|
113
187
|
/** Zod schema for input validation. All fields need `.describe()`. */
|
|
114
188
|
input: TInput;
|
|
115
189
|
/** Programmatic unique name (snake_case). */
|
|
@@ -130,7 +204,7 @@ export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObjec
|
|
|
130
204
|
title?: string;
|
|
131
205
|
}
|
|
132
206
|
/** Type-erased union for mixed arrays passed to createApp(). */
|
|
133
|
-
export type AnyToolDefinition = ToolDefinition<ZodObject<ZodRawShape>, ZodObject<ZodRawShape>, readonly ErrorContract[] | undefined>;
|
|
207
|
+
export type AnyToolDefinition = ToolDefinition<ZodObject<ZodRawShape>, ZodObject<ZodRawShape>, readonly ErrorContract[] | undefined, ZodRawShape | undefined>;
|
|
134
208
|
/**
|
|
135
209
|
* Creates a tool definition with full type inference from Zod schemas.
|
|
136
210
|
*
|
|
@@ -178,5 +252,5 @@ export type AnyToolDefinition = ToolDefinition<ZodObject<ZodRawShape>, ZodObject
|
|
|
178
252
|
* });
|
|
179
253
|
* ```
|
|
180
254
|
*/
|
|
181
|
-
export declare function tool<TInput extends ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape>, const TErrors extends readonly ErrorContract[] | undefined = undefined>(name: string, options: Omit<ToolDefinition<TInput, TOutput, TErrors>, 'name'>): ToolDefinition<TInput, TOutput, TErrors>;
|
|
255
|
+
export declare function tool<TInput extends ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape>, const TErrors extends readonly ErrorContract[] | undefined = undefined, const TEnrich extends ZodRawShape | undefined = undefined>(name: string, options: Omit<ToolDefinition<TInput, TOutput, TErrors, TEnrich>, 'name'>): ToolDefinition<TInput, TOutput, TErrors, TEnrich>;
|
|
182
256
|
//# sourceMappingURL=toolDefinition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolDefinition.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,KAAK,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED
|
|
1
|
+
{"version":3,"file":"toolDefinition.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,KAAK,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,uBA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 @@
|
|
|
1
|
-
{"version":3,"file":"toolDefinition.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,EAAyB,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"toolDefinition.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,EAAyB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAuNzE,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,UAAU,IAAI,CAMlB,IAAY,EACZ,OAAwE;IAExE,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* @module src/mcp-server/tools/utils/toolHandlerFactory
|
|
5
5
|
*/
|
|
6
6
|
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
7
|
-
import type { CallToolResult, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import type { CallToolResult, ContentBlock, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
import { type ZodObject, type ZodRawShape } from 'zod';
|
|
9
|
+
import type { Context } from '../../../core/context.js';
|
|
8
10
|
import type { StorageService } from '../../../storage/core/StorageService.js';
|
|
9
11
|
import { type JsonRpcErrorCode } from '../../../types-global/errors.js';
|
|
10
12
|
import type { Logger } from '../../../utils/internal/logger.js';
|
|
@@ -62,6 +64,26 @@ export declare function buildToolErrorResult(code: JsonRpcErrorCode, message: st
|
|
|
62
64
|
* effects — this helper does not log.
|
|
63
65
|
*/
|
|
64
66
|
export declare function classifyAndBuildToolErrorResult(error: unknown): CallToolResult;
|
|
67
|
+
/**
|
|
68
|
+
* The output schema advertised to clients in `tools/list`. When a tool declares
|
|
69
|
+
* an `enrichment` block, that's `output.extend(enrichment)` so enrichment fields
|
|
70
|
+
* appear in the advertised `outputSchema`; otherwise the bare `output`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function effectiveOutputSchema(def: AnyToolDefinition): ZodObject<ZodRawShape>;
|
|
73
|
+
/**
|
|
74
|
+
* Shapes the success `CallToolResult` surfaces from the validated domain payload
|
|
75
|
+
* plus any accumulated enrichment:
|
|
76
|
+
* - `structuredContent` — domain output merged with enrichment (validated against
|
|
77
|
+
* `output.extend(enrichment)`); the bare domain output when no enrichment block.
|
|
78
|
+
* - `content[]` — the caller-rendered domain content (from `format()` or the
|
|
79
|
+
* JSON-stringify default, applied to the **domain payload only**) with the
|
|
80
|
+
* enrichment trailer always appended. Rendering the domain payload — never the
|
|
81
|
+
* merged object — keeps enrichment out of the JSON blob and avoids double-render.
|
|
82
|
+
*
|
|
83
|
+
* A required enrichment field the handler never populated fails the parse here,
|
|
84
|
+
* surfacing the authoring bug as a loud error rather than dropping it silently.
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildToolSuccessResult(def: AnyToolDefinition, ctx: Context, domainValidated: Record<string, unknown>, domainContent: ContentBlock[]): Pick<CallToolResult, 'content' | 'structuredContent'>;
|
|
65
87
|
/**
|
|
66
88
|
* Creates an MCP tool handler from a tool definition.
|
|
67
89
|
* The returned function is compatible with the MCP SDK's ToolCallback type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EACV,cAAc,
|
|
1
|
+
{"version":3,"file":"toolHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mc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,cAAc,CAchB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAO9E;AAMD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,CAAC,WAAW,CAAC,CAGpF;AAmED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,iBAAiB,EACtB,GAAG,EAAE,OAAO,EACZ,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,aAAa,EAAE,YAAY,EAAE,GAC5B,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,mBAAmB,CAAC,CAkBvD;AAwBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,iBAAiB,EACtB,QAAQ,EAAE,sBAAsB,EAChC,SAAS,EAAE,gBAAgB,GAC1B,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,cAAc,CAAC,CA6G9E"}
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ZodError } from 'zod';
|
|
7
7
|
import { config } from '../../../config/index.js';
|
|
8
|
-
import { attachTypedFail, createContext } from '../../../core/context.js';
|
|
8
|
+
import { attachTypedFail, createContext, readEnrichmentStore } from '../../../core/context.js';
|
|
9
9
|
import { withRequiredScopes } from '../../../mcp-server/transports/auth/lib/authUtils.js';
|
|
10
10
|
import { McpError } from '../../../types-global/errors.js';
|
|
11
11
|
import { ErrorHandler } from '../../../utils/internal/error-handler/errorHandler.js';
|
|
12
12
|
import { measureToolExecution } from '../../../utils/internal/performance.js';
|
|
13
13
|
import { requestContextService } from '../../../utils/internal/requestContext.js';
|
|
14
|
+
import { ATTR_MCP_TOOL_ENRICHED } from '../../../utils/telemetry/attributes.js';
|
|
14
15
|
// ---------------------------------------------------------------------------
|
|
15
16
|
// Default formatter
|
|
16
17
|
// ---------------------------------------------------------------------------
|
|
@@ -79,6 +80,110 @@ export function classifyAndBuildToolErrorResult(error) {
|
|
|
79
80
|
return buildToolErrorResult(code, message, data);
|
|
80
81
|
}
|
|
81
82
|
// ---------------------------------------------------------------------------
|
|
83
|
+
// Success response shaping — enrichment merge + trailer
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
/**
|
|
86
|
+
* The output schema advertised to clients in `tools/list`. When a tool declares
|
|
87
|
+
* an `enrichment` block, that's `output.extend(enrichment)` so enrichment fields
|
|
88
|
+
* appear in the advertised `outputSchema`; otherwise the bare `output`.
|
|
89
|
+
*/
|
|
90
|
+
export function effectiveOutputSchema(def) {
|
|
91
|
+
if (!def.enrichment)
|
|
92
|
+
return def.output;
|
|
93
|
+
return def.output.extend(def.enrichment);
|
|
94
|
+
}
|
|
95
|
+
/** Renders a non-kind-tagged enrichment value as compact trailer text. */
|
|
96
|
+
function formatEnrichmentScalar(value) {
|
|
97
|
+
if (value == null)
|
|
98
|
+
return String(value);
|
|
99
|
+
if (typeof value === 'object')
|
|
100
|
+
return JSON.stringify(value);
|
|
101
|
+
return String(value);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Renders accumulated enrichment as a single `content[]` trailer block, so
|
|
105
|
+
* `content[]`-only clients see the same context `structuredContent` clients get
|
|
106
|
+
* from the merged output. Per field, rendering resolves in order:
|
|
107
|
+
* 1. a per-field `enrichmentTrailer.render` (the author's full control; wins
|
|
108
|
+
* over everything — the escape hatch for structured fields that would
|
|
109
|
+
* otherwise JSON-blob),
|
|
110
|
+
* 2. the kind-tag set by a field-helper (notice → blockquote, total →
|
|
111
|
+
* "N total", echo → "Query: …", delta → "field: before → after"),
|
|
112
|
+
* 3. the generic `**key:** value` fallback (key overridable via `label`),
|
|
113
|
+
* `JSON.stringify`-ing non-scalars.
|
|
114
|
+
*
|
|
115
|
+
* `parsed` is the validated effective output, so renderers receive the typed,
|
|
116
|
+
* post-parse value rather than the raw accumulator entry. The rendered markdown
|
|
117
|
+
* is appended to `content[]` only — `structuredContent` is built separately from
|
|
118
|
+
* the raw merged values and never carries this trailer text. Returns `[]` when
|
|
119
|
+
* nothing was enriched.
|
|
120
|
+
*/
|
|
121
|
+
function renderEnrichmentTrailer(store, trailer, parsed) {
|
|
122
|
+
const lines = [];
|
|
123
|
+
for (const key of Object.keys(store.values)) {
|
|
124
|
+
// Skip keys the effective-output parse stripped (enriched but not declared in
|
|
125
|
+
// the block) — the trailer mirrors what reached structuredContent.
|
|
126
|
+
if (!(key in parsed))
|
|
127
|
+
continue;
|
|
128
|
+
const value = parsed[key];
|
|
129
|
+
const cfg = trailer?.[key];
|
|
130
|
+
if (cfg?.render) {
|
|
131
|
+
lines.push(cfg.render(value));
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
switch (store.kinds.get(key)) {
|
|
135
|
+
case 'notice':
|
|
136
|
+
lines.push(`> ${String(value)}`);
|
|
137
|
+
break;
|
|
138
|
+
case 'total':
|
|
139
|
+
lines.push(`**${String(value)} total**`);
|
|
140
|
+
break;
|
|
141
|
+
case 'echo':
|
|
142
|
+
lines.push(`Query: ${String(value)}`);
|
|
143
|
+
break;
|
|
144
|
+
case 'delta': {
|
|
145
|
+
const d = (value ?? {});
|
|
146
|
+
lines.push(`**${cfg?.label ?? key}:** ${formatEnrichmentScalar(d.before)} → ${formatEnrichmentScalar(d.after)}`);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
default:
|
|
150
|
+
lines.push(`**${cfg?.label ?? key}:** ${formatEnrichmentScalar(value)}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return lines.length > 0 ? [{ type: 'text', text: lines.join('\n') }] : [];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Shapes the success `CallToolResult` surfaces from the validated domain payload
|
|
157
|
+
* plus any accumulated enrichment:
|
|
158
|
+
* - `structuredContent` — domain output merged with enrichment (validated against
|
|
159
|
+
* `output.extend(enrichment)`); the bare domain output when no enrichment block.
|
|
160
|
+
* - `content[]` — the caller-rendered domain content (from `format()` or the
|
|
161
|
+
* JSON-stringify default, applied to the **domain payload only**) with the
|
|
162
|
+
* enrichment trailer always appended. Rendering the domain payload — never the
|
|
163
|
+
* merged object — keeps enrichment out of the JSON blob and avoids double-render.
|
|
164
|
+
*
|
|
165
|
+
* A required enrichment field the handler never populated fails the parse here,
|
|
166
|
+
* surfacing the authoring bug as a loud error rather than dropping it silently.
|
|
167
|
+
*/
|
|
168
|
+
export function buildToolSuccessResult(def, ctx, domainValidated, domainContent) {
|
|
169
|
+
if (!def.enrichment) {
|
|
170
|
+
return { structuredContent: domainValidated, content: domainContent };
|
|
171
|
+
}
|
|
172
|
+
const store = readEnrichmentStore(ctx);
|
|
173
|
+
const values = store?.values ?? {};
|
|
174
|
+
const structuredContent = effectiveOutputSchema(def).parse({
|
|
175
|
+
...domainValidated,
|
|
176
|
+
...values,
|
|
177
|
+
});
|
|
178
|
+
const trailer = store && Object.keys(values).length > 0
|
|
179
|
+
? renderEnrichmentTrailer(store, def.enrichmentTrailer, structuredContent)
|
|
180
|
+
: [];
|
|
181
|
+
return {
|
|
182
|
+
structuredContent,
|
|
183
|
+
content: trailer.length > 0 ? [...domainContent, ...trailer] : domainContent,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
82
187
|
// Capability detection helpers
|
|
83
188
|
// ---------------------------------------------------------------------------
|
|
84
189
|
function wrapElicit(sdkContext) {
|
|
@@ -165,20 +270,24 @@ export function createToolHandler(def, services, notifiers) {
|
|
|
165
270
|
}), def.errors);
|
|
166
271
|
// Execute handler with performance measurement.
|
|
167
272
|
// Wrap with Promise.resolve — handler may return sync or async.
|
|
168
|
-
const result = await measureToolExecution(() => Promise.resolve(def.handler(validatedInput, ctx)), { ...appContext, toolName: def.name }, validatedInput)
|
|
273
|
+
const result = await measureToolExecution(() => Promise.resolve(def.handler(validatedInput, ctx)), { ...appContext, toolName: def.name }, validatedInput, () => {
|
|
274
|
+
const store = readEnrichmentStore(ctx);
|
|
275
|
+
return store && Object.keys(store.values).length > 0
|
|
276
|
+
? { [ATTR_MCP_TOOL_ENRICHED]: true }
|
|
277
|
+
: {};
|
|
278
|
+
});
|
|
169
279
|
const validatedResult = def.output.parse(result);
|
|
170
|
-
//
|
|
171
|
-
|
|
280
|
+
// Render content[] from the domain payload only (Resolution B). Isolate
|
|
281
|
+
// formatter errors from handler errors so they get classified correctly.
|
|
282
|
+
let domainContent;
|
|
172
283
|
try {
|
|
173
|
-
|
|
284
|
+
domainContent = formatter(validatedResult);
|
|
174
285
|
}
|
|
175
286
|
catch (formatError) {
|
|
176
287
|
throw new Error(`Output formatting failed: ${formatError instanceof Error ? formatError.message : String(formatError)}`);
|
|
177
288
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
content,
|
|
181
|
-
};
|
|
289
|
+
// Merge enrichment into structuredContent and append the content[] trailer.
|
|
290
|
+
return buildToolSuccessResult(def, ctx, validatedResult, domainContent);
|
|
182
291
|
}
|
|
183
292
|
catch (error) {
|
|
184
293
|
ErrorHandler.handleError(error, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolHandlerFactory.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EAAE,QAAQ,EAAoC,MAAM,KAAK,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"toolHandlerFactory.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EAAE,QAAQ,EAAoC,MAAM,KAAK,C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CAAC;YAAC,OAAO,WAAW,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CACb,6BAA6B,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CACxG,CAAC;YACJ,CAAC;YAED,4EAA4E;YAC5E,OAAO,sBAAsB,CAC3B,GAAG,EACH,GAAG,EACH,eAA0C,EAC1C,aAAa,CACd,CAAC;QACJ,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,YAAY,CAAC,WAAW,CAAC,KAAK,EAAE;gBAC9B,SAAS,EAAE,QAAQ,GAAG,CAAC,IAAI,EAAE;gBAC7B,OAAO,EAAE,UAAU;aACpB,CAAC,CAAC;YACH,OAAO,+BAA+B,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -98,6 +98,19 @@ export declare function createMockLogger(): MockContextLogger;
|
|
|
98
98
|
* ```
|
|
99
99
|
*/
|
|
100
100
|
export declare function createMockContext(options?: MockContextOptions): Context;
|
|
101
|
+
/**
|
|
102
|
+
* Reads the enrichment a handler accumulated via `ctx.enrich(...)` on a mock
|
|
103
|
+
* context, for assertions. Returns the merged field values (empty object when
|
|
104
|
+
* nothing was enriched).
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const ctx = createMockContext();
|
|
109
|
+
* await search.handler(search.input.parse({ query: 'x' }), ctx);
|
|
110
|
+
* expect(getEnrichment(ctx)).toMatchObject({ effectiveQuery: 'x', totalCount: 0 });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function getEnrichment(ctx: Context): Record<string, unknown>;
|
|
101
114
|
/**
|
|
102
115
|
* Build a real `StorageService` backed by an in-memory provider, suitable for
|
|
103
116
|
* unit-testing services that accept a `StorageService` dependency.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAW,CAAC,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EACV,WAAW,EACX,OAAO,EACP,aAAa,EAGb,YAAY,EACb,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAW,CAAC,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EACV,WAAW,EACX,OAAO,EACP,aAAa,EAGb,YAAY,EACb,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAM9D,MAAM,WAAW,kBAAkB;IACjC,oBAAoB;IACpB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,gCAAgC;IAChC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACxF;;;;;OAKG;IACH,MAAM,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAClC,yCAAyC;IACzC,uBAAuB,CAAC,EAAE,MAAM,IAAI,CAAC;IACrC,2CAA2C;IAC3C,yBAAyB,CAAC,EAAE,MAAM,I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c,CAEvF"}
|
package/dist/testing/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `createInMemoryStorage()` for unit-testing services in isolation.
|
|
6
6
|
* @module src/testing/index
|
|
7
7
|
*/
|
|
8
|
-
import { attachTypedFail } from '../core/context.js';
|
|
8
|
+
import { attachTypedFail, createEnrich, createEnrichmentStore, readEnrichmentStore, stashEnrichmentStore, } from '../core/context.js';
|
|
9
9
|
import { StorageService } from '../storage/core/StorageService.js';
|
|
10
10
|
import { InMemoryProvider, } from '../storage/providers/inMemory/inMemoryProvider.js';
|
|
11
11
|
/**
|
|
@@ -157,6 +157,7 @@ export function createMockContext(options = {}) {
|
|
|
157
157
|
const log = createMockLogger();
|
|
158
158
|
const state = createMockState(options.tenantId);
|
|
159
159
|
const progress = options.progress ? createMockProgress() : undefined;
|
|
160
|
+
const enrichmentStore = createEnrichmentStore();
|
|
160
161
|
const ctx = {
|
|
161
162
|
requestId: options.requestId ?? 'test-request-id',
|
|
162
163
|
timestamp: new Date().toISOString(),
|
|
@@ -174,15 +175,34 @@ export function createMockContext(options = {}) {
|
|
|
174
175
|
notifyToolListChanged: options.notifyToolListChanged,
|
|
175
176
|
progress,
|
|
176
177
|
uri: options.uri,
|
|
178
|
+
enrich: createEnrich(enrichmentStore),
|
|
177
179
|
// No-op resolver for definitions without a contract. `attachTypedFail` below
|
|
178
180
|
// overwrites it with a contract-aware resolver when `options.errors` is set.
|
|
179
181
|
recoveryFor: () => ({}),
|
|
180
182
|
};
|
|
183
|
+
// Stash the enrichment store so `getEnrichment(ctx)` can read what a handler
|
|
184
|
+
// (or the service layer) accumulated via `ctx.enrich(...)` during the test.
|
|
185
|
+
stashEnrichmentStore(ctx, enrichmentStore);
|
|
181
186
|
// Mirror the production handler factory: when a contract is declared, attach
|
|
182
187
|
// a typed `fail` and `recoveryFor` keyed by the contract's reasons. Empty
|
|
183
188
|
// contracts leave the no-op resolver in place.
|
|
184
189
|
return attachTypedFail(ctx, options.errors);
|
|
185
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Reads the enrichment a handler accumulated via `ctx.enrich(...)` on a mock
|
|
193
|
+
* context, for assertions. Returns the merged field values (empty object when
|
|
194
|
+
* nothing was enriched).
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* const ctx = createMockContext();
|
|
199
|
+
* await search.handler(search.input.parse({ query: 'x' }), ctx);
|
|
200
|
+
* expect(getEnrichment(ctx)).toMatchObject({ effectiveQuery: 'x', totalCount: 0 });
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export function getEnrichment(ctx) {
|
|
204
|
+
return readEnrichmentStore(ctx)?.values ?? {};
|
|
205
|
+
}
|
|
186
206
|
// ---------------------------------------------------------------------------
|
|
187
207
|
// Storage helpers
|
|
188
208
|
// ---------------------------------------------------------------------------
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH,OAAO,EACL,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EACL,gBAAgB,GAEjB,MAAM,kDAAkD,CAAC;AAyD1D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,KAAK,GAA0D,EAAE,CAAC;IAExE,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE;QAC/E,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;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ED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,OAAO,mBAAmB,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC;AAChD,CAAC;AAED,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAiC;IACrE,OAAO,IAAI,cAAc,CAAC,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -63,11 +63,15 @@ export declare const nowMs: () => number;
|
|
|
63
63
|
* @param toolLogicFn - Zero-argument async function containing the tool's business logic.
|
|
64
64
|
* @param context - Request context extended with `toolName`; used for span/log correlation.
|
|
65
65
|
* @param inputPayload - The raw input object passed to the tool, serialized to compute byte size.
|
|
66
|
+
* @param successAttributes - Optional thunk evaluated after a successful run; its
|
|
67
|
+
* returned key/value map is set on the span as extra attributes. Lets callers
|
|
68
|
+
* attach post-hoc signals (e.g. `mcp.tool.enriched`) without coupling this
|
|
69
|
+
* function to their domain. Not called on the error path.
|
|
66
70
|
* @returns A promise that resolves with the tool's return value or rejects with the original error.
|
|
67
71
|
*/
|
|
68
72
|
export declare function measureToolExecution<T>(toolLogicFn: () => Promise<T>, context: RequestContext & {
|
|
69
73
|
toolName: string;
|
|
70
|
-
}, inputPayload: unknown): Promise<T>;
|
|
74
|
+
}, inputPayload: unknown, successAttributes?: () => Record<string, boolean | number | string>): Promise<T>;
|
|
71
75
|
/**
|
|
72
76
|
* Wraps a resource handler with observability: OTel span, metric counters/histogram,
|
|
73
77
|
* and a structured log. Mirrors {@link measureToolExecution} but tuned for resource reads.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performance.d.ts","sourceRoot":"","sources":["../../../src/utils/internal/performance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,IAAI,oBAAoB,EAAE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EAAE,OAAO,EACrB,iBAAiB,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,GAClE,OAAO,CAAC,CAAC,CAAC,CAwHZ;AAoCD;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAAC,CAAC,EAC9C,eAAe,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACjC,OAAO,EAAE,cAAc,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,EAClD,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACtC,OAAO,CAAC,CAAC,CAAC,CA8EZ;AAkDD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,uBAAuB,CAAC,CAAC,EAC7C,aAAa,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC/B,OAAO,EAAE,cAAc,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,EAChD,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC,CAAC,CAAC,CA8FZ"}
|
|
@@ -203,9 +203,13 @@ const toBytes = (payload) => {
|
|
|
203
203
|
* @param toolLogicFn - Zero-argument async function containing the tool's business logic.
|
|
204
204
|
* @param context - Request context extended with `toolName`; used for span/log correlation.
|
|
205
205
|
* @param inputPayload - The raw input object passed to the tool, serialized to compute byte size.
|
|
206
|
+
* @param successAttributes - Optional thunk evaluated after a successful run; its
|
|
207
|
+
* returned key/value map is set on the span as extra attributes. Lets callers
|
|
208
|
+
* attach post-hoc signals (e.g. `mcp.tool.enriched`) without coupling this
|
|
209
|
+
* function to their domain. Not called on the error path.
|
|
206
210
|
* @returns A promise that resolves with the tool's return value or rejects with the original error.
|
|
207
211
|
*/
|
|
208
|
-
export async function measureToolExecution(toolLogicFn, context, inputPayload) {
|
|
212
|
+
export async function measureToolExecution(toolLogicFn, context, inputPayload, successAttributes) {
|
|
209
213
|
const tracer = trace.getTracer(config.openTelemetry.serviceName, config.openTelemetry.serviceVersion);
|
|
210
214
|
const { toolName } = context;
|
|
211
215
|
return await tracer.startActiveSpan(`tool_execution:${toolName}`, async (span) => {
|
|
@@ -249,6 +253,11 @@ export async function measureToolExecution(toolLogicFn, context, inputPayload) {
|
|
|
249
253
|
if (batchSucceeded !== undefined)
|
|
250
254
|
span.setAttribute(ATTR_MCP_TOOL_BATCH_SUCCEEDED, batchSucceeded);
|
|
251
255
|
}
|
|
256
|
+
if (successAttributes) {
|
|
257
|
+
for (const [key, value] of Object.entries(successAttributes())) {
|
|
258
|
+
span.setAttribute(key, value);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
252
261
|
return result;
|
|
253
262
|
}
|
|
254
263
|
catch (err) {
|