@cyanheads/mcp-ts-core 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CLAUDE.md +8 -2
  2. package/README.md +1 -1
  3. package/changelog/0.8.x/0.8.3.md +43 -0
  4. package/dist/logs/combined.log +12 -4
  5. package/dist/logs/error.log +12 -4
  6. package/dist/mcp-server/resources/resource-registration.d.ts.map +1 -1
  7. package/dist/mcp-server/resources/resource-registration.js +2 -3
  8. package/dist/mcp-server/resources/resource-registration.js.map +1 -1
  9. package/dist/mcp-server/resources/utils/resourceDefinition.d.ts +3 -3
  10. package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -1
  11. package/dist/mcp-server/tools/tool-registration.js +8 -12
  12. package/dist/mcp-server/tools/tool-registration.js.map +1 -1
  13. package/dist/mcp-server/tools/utils/toolDefinition.d.ts +2 -3
  14. package/dist/mcp-server/tools/utils/toolDefinition.d.ts.map +1 -1
  15. package/dist/mcp-server/tools/utils/toolDefinition.js.map +1 -1
  16. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +28 -0
  17. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
  18. package/dist/mcp-server/tools/utils/toolHandlerFactory.js +64 -23
  19. package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
  20. package/dist/types-global/errors.d.ts +3 -22
  21. package/dist/types-global/errors.d.ts.map +1 -1
  22. package/dist/types-global/errors.js +0 -19
  23. package/dist/types-global/errors.js.map +1 -1
  24. package/package.json +1 -1
  25. package/skills/add-resource/SKILL.md +1 -1
  26. package/skills/add-tool/SKILL.md +87 -20
  27. package/skills/api-errors/SKILL.md +21 -7
  28. package/skills/api-linter/SKILL.md +1 -1
  29. package/skills/design-mcp-server/SKILL.md +1 -1
  30. package/skills/field-test/SKILL.md +15 -6
  31. package/templates/AGENTS.md +3 -2
  32. package/templates/CLAUDE.md +3 -2
  33. package/templates/src/mcp-server/tools/definitions/echo.tool.ts +18 -1
@@ -6,6 +6,7 @@
6
6
  import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
7
7
  import type { CallToolResult, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
8
8
  import type { StorageService } from '../../../storage/core/StorageService.js';
9
+ import { type JsonRpcErrorCode } from '../../../types-global/errors.js';
9
10
  import type { Logger } from '../../../utils/internal/logger.js';
10
11
  import type { AnyToolDefinition } from './toolDefinition.js';
11
12
  type SdkExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;
@@ -25,6 +26,33 @@ export interface HandlerNotifiers {
25
26
  notifyResourceListChanged?: () => void;
26
27
  notifyResourceUpdated?: (uri: string) => void;
27
28
  }
29
+ /**
30
+ * Shapes a `CallToolResult` for a tool error response with parity across both
31
+ * surfaces clients forward to the agent:
32
+ * - `content[]` — read by clients like Claude Desktop (markdown)
33
+ * - `structuredContent.error` — read by clients like Claude Code (JSON)
34
+ *
35
+ * Both surfaces carry the same payload. When `data.recovery.hint` is present,
36
+ * it is also mirrored into the `content[]` text so format()-only clients see
37
+ * the recovery guidance.
38
+ *
39
+ * Note: `_meta.error` is intentionally NOT emitted — the error code, message,
40
+ * and data live on `structuredContent.error` instead, mirroring the success
41
+ * path's `structuredContent` surface.
42
+ */
43
+ export declare function buildToolErrorResult(code: JsonRpcErrorCode, message: string, data: Record<string, unknown> | undefined): CallToolResult;
44
+ /**
45
+ * Builds an error `CallToolResult` from a raw thrown value. Classifies via
46
+ * {@link ErrorHandler.classifyOnly} when the value isn't already an
47
+ * `McpError`. Only propagates data from `McpError` (its declared `data`) or
48
+ * `ZodError` (its `issues`) — other thrown values get a `structuredContent.error`
49
+ * with `code` and `message` only, so internal classification context never
50
+ * leaks to clients.
51
+ *
52
+ * Use after invoking {@link ErrorHandler.handleError} for OTel/logging side
53
+ * effects — this helper does not log.
54
+ */
55
+ export declare function classifyAndBuildToolErrorResult(error: unknown): CallToolResult;
28
56
  /**
29
57
  * Creates an MCP tool handler from a tool definition.
30
58
  * 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,EAEd,kBAAkB,EAClB,aAAa,EACd,MAAM,oCAAoC,CAAC;AAO5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAGvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAM7D,KAAK,QAAQ,GAAG,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAOvE,qEAAqE;AACrE,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,cAAc,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yBAAyB,CAAC,EAAE,MAAM,IAAI,CAAC;IACvC,qBAAqB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C;AAgCD;;;;;;;;;;;;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,CAwG9E"}
1
+ {"version":3,"file":"toolHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolHandlerFactory.ts"],"names":[],"mappings":"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CAAC,cAAc,CAAC,CAiF9E"}
@@ -6,7 +6,7 @@
6
6
  import { ZodError } from 'zod';
7
7
  import { attachTypedFail, createContext } from '../../../core/context.js';
8
8
  import { withRequiredScopes } from '../../../mcp-server/transports/auth/lib/authUtils.js';
9
- import { JsonRpcErrorCode, McpError } from '../../../types-global/errors.js';
9
+ import { McpError } from '../../../types-global/errors.js';
10
10
  import { ErrorHandler } from '../../../utils/internal/error-handler/errorHandler.js';
11
11
  import { measureToolExecution } from '../../../utils/internal/performance.js';
12
12
  import { requestContextService } from '../../../utils/internal/requestContext.js';
@@ -17,6 +17,67 @@ const defaultResponseFormatter = (result) => [
17
17
  { type: 'text', text: JSON.stringify(result, null, 2) },
18
18
  ];
19
19
  // ---------------------------------------------------------------------------
20
+ // Error response shaping
21
+ // ---------------------------------------------------------------------------
22
+ /**
23
+ * Pulls `data.recovery.hint` from an error data payload when present and
24
+ * non-empty. Returns `undefined` otherwise. Used to mirror the hint into
25
+ * `content[]` text so format()-only clients see the same recovery guidance
26
+ * structuredContent-only clients receive via `error.data.recovery.hint`.
27
+ */
28
+ function extractRecoveryHint(data) {
29
+ const hint = data?.recovery?.hint;
30
+ return typeof hint === 'string' && hint.length > 0 ? hint : undefined;
31
+ }
32
+ /**
33
+ * Shapes a `CallToolResult` for a tool error response with parity across both
34
+ * surfaces clients forward to the agent:
35
+ * - `content[]` — read by clients like Claude Desktop (markdown)
36
+ * - `structuredContent.error` — read by clients like Claude Code (JSON)
37
+ *
38
+ * Both surfaces carry the same payload. When `data.recovery.hint` is present,
39
+ * it is also mirrored into the `content[]` text so format()-only clients see
40
+ * the recovery guidance.
41
+ *
42
+ * Note: `_meta.error` is intentionally NOT emitted — the error code, message,
43
+ * and data live on `structuredContent.error` instead, mirroring the success
44
+ * path's `structuredContent` surface.
45
+ */
46
+ export function buildToolErrorResult(code, message, data) {
47
+ const hint = extractRecoveryHint(data);
48
+ const text = hint ? `Error: ${message}\n\nRecovery: ${hint}` : `Error: ${message}`;
49
+ return {
50
+ isError: true,
51
+ content: [{ type: 'text', text }],
52
+ structuredContent: {
53
+ error: {
54
+ code,
55
+ message,
56
+ ...(data !== undefined && { data }),
57
+ },
58
+ },
59
+ };
60
+ }
61
+ /**
62
+ * Builds an error `CallToolResult` from a raw thrown value. Classifies via
63
+ * {@link ErrorHandler.classifyOnly} when the value isn't already an
64
+ * `McpError`. Only propagates data from `McpError` (its declared `data`) or
65
+ * `ZodError` (its `issues`) — other thrown values get a `structuredContent.error`
66
+ * with `code` and `message` only, so internal classification context never
67
+ * leaks to clients.
68
+ *
69
+ * Use after invoking {@link ErrorHandler.handleError} for OTel/logging side
70
+ * effects — this helper does not log.
71
+ */
72
+ export function classifyAndBuildToolErrorResult(error) {
73
+ if (error instanceof McpError) {
74
+ return buildToolErrorResult(error.code, error.message, error.data);
75
+ }
76
+ const { code, message } = ErrorHandler.classifyOnly(error);
77
+ const data = error instanceof ZodError ? { issues: error.issues } : undefined;
78
+ return buildToolErrorResult(code, message, data);
79
+ }
80
+ // ---------------------------------------------------------------------------
20
81
  // Capability detection helpers
21
82
  // ---------------------------------------------------------------------------
22
83
  function wrapElicit(sdkContext) {
@@ -104,31 +165,11 @@ export function createToolHandler(def, services, notifiers) {
104
165
  };
105
166
  }
106
167
  catch (error) {
107
- const handled = ErrorHandler.handleError(error, {
168
+ ErrorHandler.handleError(error, {
108
169
  operation: `tool:${def.name}`,
109
170
  context: appContext,
110
171
  });
111
- const mcpError = handled instanceof McpError
112
- ? handled
113
- : new McpError(JsonRpcErrorCode.InternalError, handled.message, {
114
- originalError: handled.name,
115
- });
116
- // Surface error classification via _meta so programmatic clients can distinguish error types (auth, validation, not-found, etc.) without parsing the text message. Only propagate data from explicitly thrown McpError instances and ZodError (structured validation issues) — ErrorHandler enrichment contains internal context (stack traces, operation details) that shouldn't be client-visible.
117
- const originalData = error instanceof McpError
118
- ? error.data
119
- : error instanceof ZodError
120
- ? { issues: error.issues }
121
- : undefined;
122
- return {
123
- isError: true,
124
- content: [{ type: 'text', text: `Error: ${mcpError.message}` }],
125
- _meta: {
126
- error: {
127
- code: mcpError.code,
128
- ...(originalData !== undefined && { data: originalData }),
129
- },
130
- },
131
- };
172
+ return classifyAndBuildToolErrorResult(error);
132
173
  }
133
174
  };
134
175
  }
@@ -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;AAGjE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AAEnF,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAgC3E,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E,MAAM,wBAAwB,GAAG,CAAC,MAAe,EAAkB,EAAE,CAAC;IACpE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;CACxD,CAAC;AAEF,8EAA8E;AAC9E,+BAA+B;AAC/B,8EAA8E;AAE9E,SAAS,UAAU,CAAC,UAAkC;IACpD,IAAI,OAAO,UAAU,CAAC,WAAW,KAAK,UAAU;QAAE,OAAO;IACzD,MAAM,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC;IAClC,OAAO,CAAC,GAAW,EAAE,MAA8B,EAAE,EAAE,CACrD,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,CA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BACrB,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,OAAO;gBACL,iBAAiB,EAAE,eAAe;gBAClC,OAAO;aACR,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"}
@@ -116,13 +116,9 @@ export type ErrorResponse = z.infer<typeof ErrorSchema>;
116
116
  * Lets a definition advertise what it can fail with — the JSON-RPC code, a
117
117
  * stable machine-readable `reason`, and a human-readable `when` description.
118
118
  *
119
- * **Where it shows up:**
120
- * - Surfaced in `tools/list` / `resources/list` under
121
- * `_meta['mcp-ts-core/errors']`, so MCP clients and agents can preview failure
122
- * modes alongside the input/output schema.
123
- * - Validated by the startup linter — invalid codes, duplicate `reason` strings
124
- * within a single definition, and (with the conformance check enabled)
125
- * handler bodies that throw codes not in the contract are flagged.
119
+ * **Validation.** Checked by the startup linter — invalid codes, duplicate
120
+ * `reason` strings within a single definition, and (with the conformance check
121
+ * enabled) handler bodies that throw codes not in the contract are flagged.
126
122
  *
127
123
  * **Authoring guidance:**
128
124
  * - Keep `reason` short, snake_case, stable. Treat it like a CSS class name
@@ -171,19 +167,4 @@ export interface ErrorContract {
171
167
  */
172
168
  when: string;
173
169
  }
174
- /**
175
- * The MCP `_meta` namespace key under which `errors[]` is published in
176
- * `tools/list` and `resources/list`. Namespaced to avoid collisions with
177
- * other framework or vendor extensions.
178
- */
179
- export declare const ERROR_CONTRACT_META_KEY = "mcp-ts-core/errors";
180
- /**
181
- * Merges a tool/resource's `errors[]` contract into its `_meta` object under
182
- * {@link ERROR_CONTRACT_META_KEY}. Returns `undefined` when both sides are
183
- * absent so callers can spread conditionally without producing an empty
184
- * `_meta` field. Used by the tool and resource registries.
185
- *
186
- * @internal
187
- */
188
- export declare function buildMetaWithErrorContract(baseMeta: Record<string, unknown> | undefined, errors: readonly unknown[] | undefined): Record<string, unknown> | undefined;
189
170
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types-global/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,oBAAY,gBAAgB;IAE1B,UAAU,SAAS;IACnB,cAAc,SAAS;IACvB,cAAc,SAAS;IACvB,aAAa,SAAS;IACtB,aAAa,SAAS;IAGtB,kBAAkB,SAAS;IAC3B,QAAQ,SAAS;IACjB,QAAQ,SAAS;IACjB,WAAW,SAAS;IACpB,OAAO,SAAS;IAChB,SAAS,SAAS;IAClB,YAAY,SAAS;IACrB,eAAe,SAAS;IACxB,kBAAkB,SAAS;IAC3B,oBAAoB,SAAS;IAC7B,aAAa,SAAS;IACtB,kBAAkB,SAAS,CAAE,4CAA4C;IACzE,YAAY,SAAS;CACtB;AAED;;;;;;;GAOG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC;;OAEG;IACH,SAAgB,IAAI,EAAE,gBAAgB,CAAC;IAEvC;;;;OAIG;IACH,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE/C;;;;;;OAMG;gBAED,IAAI,EAAE,gBAAgB,EACtB,OAAO,CAAC,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE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rorSchema = z
138
138
  .describe('Optional structured data providing more context about the error'),
139
139
  })
140
140
  .describe('Schema for validating structured error objects, ensuring consistency in error reporting.');
141
- /**
142
- * The MCP `_meta` namespace key under which `errors[]` is published in
143
- * `tools/list` and `resources/list`. Namespaced to avoid collisions with
144
- * other framework or vendor extensions.
145
- */
146
- export const ERROR_CONTRACT_META_KEY = 'mcp-ts-core/errors';
147
- /**
148
- * Merges a tool/resource's `errors[]` contract into its `_meta` object under
149
- * {@link ERROR_CONTRACT_META_KEY}. Returns `undefined` when both sides are
150
- * absent so callers can spread conditionally without producing an empty
151
- * `_meta` field. Used by the tool and resource registries.
152
- *
153
- * @internal
154
- */
155
- export function buildMetaWithErrorContract(baseMeta, errors) {
156
- if (!errors || errors.length === 0)
157
- return baseMeta;
158
- return { ...(baseMeta ?? {}), [ERROR_CONTRACT_META_KEY]: errors };
159
- }
160
141
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types-global/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAN,IAAY,gBAsBX;AAtBD,WAAY,gBAAgB;IAC1B,+BAA+B;IAC/B,wEAAmB,CAAA;IACnB,gFAAuB,CAAA;IACvB,gFAAuB,CAAA;IACvB,8EAAsB,CAAA;IACtB,8EAAsB,CAAA;IAEtB,0DAA0D;IAC1D,wFAA2B,CAAA;IAC3B,oEAAiB,CAAA;IACjB,oEAAiB,CAAA;IACjB,0EAAoB,CAAA;IACpB,kEAAgB,CAAA;IAChB,sEAAkB,CAAA;IAClB,4EAAqB,CAAA;IACrB,kFAAwB,CAAA;IACxB,wFAA2B,CAAA;IAC3B,4FAA6B,CAAA;IAC7B,8EAAsB,CAAA;IACtB,wFAA2B,CAAA;IAC3B,4EAAqB,CAAA;AACvB,CAAC,EAtBW,gBAAgB,KAAhB,gBAA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oDAAoD,CAAC;IACjE;;;OAGG;IACH,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,gCAAgC,CAAC;SACxC,QAAQ,CAAC,uCAAuC,CAAC;IACpD;;;OAGG;IACH,IAAI,EAAE,CAAC;SACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SAC/B,QAAQ,EAAE;SACV,QAAQ,CAAC,iEAAiE,CAAC;CAC/E,CAAC;KACD,QAAQ,CACP,0FAA0F,CAC3F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyanheads/mcp-ts-core",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "mcpName": "io.github.cyanheads/mcp-ts-core",
5
5
  "description": "Agent-native TypeScript framework for building MCP servers. Declarative definitions with auth, multi-backend storage, OpenTelemetry, and first-class support for Bun/Node/Cloudflare Workers.",
6
6
  "main": "dist/core/index.js",
@@ -109,7 +109,7 @@ If the repo already uses `src/mcp-server/resources/definitions/index.ts`, update
109
109
 
110
110
  ### Optional: declarative `errors[]` contract
111
111
 
112
- Resources can opt into the same typed error contract as tools — surfaced in `resources/list` under `_meta['mcp-ts-core/errors']` and bound to a typed `ctx.fail(reason, …)` keyed by the declared reason union:
112
+ Resources can opt into the same typed error contract as tools — bound to a typed `ctx.fail(reason, …)` keyed by the declared reason union:
113
113
 
114
114
  ```typescript
115
115
  import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
@@ -4,7 +4,7 @@ description: >
4
4
  Scaffold a new MCP tool definition. Use when the user asks to add a tool, create a new tool, or implement a new capability for the server.
5
5
  metadata:
6
6
  author: cyanheads
7
- version: "1.9"
7
+ version: "2.0"
8
8
  audience: external
9
9
  type: reference
10
10
  ---
@@ -44,6 +44,7 @@ For shape selection (Workflow or Instruction variants — standard single-action
44
44
  */
45
45
 
46
46
  import { tool, z } from '@cyanheads/mcp-ts-core';
47
+ import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
47
48
 
48
49
  export const {{TOOL_EXPORT}} = tool('{{tool_name}}', {
49
50
  title: '{{TOOL_TITLE}}',
@@ -58,17 +59,25 @@ export const {{TOOL_EXPORT}} = tool('{{tool_name}}', {
58
59
  // All fields need .describe(). Only JSON-Schema-serializable Zod types allowed.
59
60
  }),
60
61
  // auth: ['tool:{{tool_name}}:read'],
61
- // errors: [
62
- // { reason: 'no_match', code: JsonRpcErrorCode.NotFound, when: 'No items matched the query.' },
63
- // { reason: 'queue_full', code: JsonRpcErrorCode.RateLimited, when: 'Local queue at capacity.', retryable: true },
64
- // ],
62
+
63
+ // Each entry declares a domain-specific failure mode and types
64
+ // `ctx.fail(reason, …)` against the declared union. Baseline codes
65
+ // (InternalError, ServiceUnavailable, Timeout, ValidationError,
66
+ // SerializationError) bubble freely — only declare domain-specific reasons.
67
+ // Delete this block if no domain failures apply.
68
+ errors: [
69
+ { reason: 'no_match', code: JsonRpcErrorCode.NotFound, when: 'No items matched the query.' },
70
+ { reason: 'queue_full', code: JsonRpcErrorCode.RateLimited, when: 'Local queue at capacity.', retryable: true },
71
+ ],
65
72
 
66
73
  async handler(input, ctx) {
67
74
  ctx.log.info('Processing', { /* relevant input fields */ });
68
75
  // Pure logic — throw on failure, no try/catch.
69
76
  // With an `errors[]` contract: `throw ctx.fail('reason_id', message?, data?)`.
70
77
  // Without: throw via factories (`notFound`, `validationError`, …) or plain `Error`.
71
- return { /* output */ };
78
+ const items = await search(input);
79
+ if (items.length === 0) throw ctx.fail('no_match', `No items matched "${input.query}"`);
80
+ return { items };
72
81
  },
73
82
 
74
83
  // format() populates MCP content[] — the markdown twin of structuredContent.
@@ -186,18 +195,38 @@ Single-item tools don't need this — they either succeed or throw. The partial
186
195
 
187
196
  ### Empty results need context
188
197
 
189
- An empty array with no explanation is a dead end. Echo back the criteria that produced zero results and, where possible, suggest how to broaden the search.
198
+ An empty array with no explanation is a dead end. Echo back the criteria that produced zero results and, where possible, suggest how to broaden the search. The recovery hint needs three pieces working together — schema entry, handler return, and `format()` rendering — or the `format-parity` lint will flag the missing field.
190
199
 
191
200
  ```typescript
192
- // In handlerafter getting zero results:
193
- if (results.length === 0) {
194
- return {
195
- items: [],
196
- totalCount: 0,
197
- message: `No items matched status="${input.status}" in project "${input.project}". `
198
- + `Try a broader status filter or verify the project name.`,
199
- };
200
- }
201
+ // 1. Output schema declare the recovery field so the linter sees it
202
+ output: z.object({
203
+ items: z.array(ItemSchema).describe('Matching items.'),
204
+ totalCount: z.number().describe('Total matches before pagination.'),
205
+ message: z.string().optional()
206
+ .describe('Recovery hint when results are empty — echoes filters and suggests how to broaden. Absent on successful result pages.'),
207
+ }),
208
+
209
+ // 2. Handler — populate `message` when the result is empty
210
+ async handler(input, ctx) {
211
+ const results = await search(input);
212
+ if (results.length === 0) {
213
+ return {
214
+ items: [],
215
+ totalCount: 0,
216
+ message: `No items matched status="${input.status}" in project "${input.project}". `
217
+ + `Try a broader status filter or verify the project name.`,
218
+ };
219
+ }
220
+ return { items: results, totalCount: results.length };
221
+ },
222
+
223
+ // 3. format() — render the recovery hint so content[]-only clients see it too
224
+ format: (result) => {
225
+ const lines = [`**Total:** ${result.totalCount}`];
226
+ if (result.message) lines.push(`\n> ${result.message}`);
227
+ for (const item of result.items) lines.push(`- ${item.name}`);
228
+ return [{ type: 'text', text: lines.join('\n') }];
229
+ },
201
230
  ```
202
231
 
203
232
  ### Sparse upstream data must stay honest
@@ -265,13 +294,51 @@ export const fetchArticles = tool('fetch_articles', {
265
294
  });
266
295
  ```
267
296
 
268
- **Baseline codes** (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`) bubble freely and don't need declaring. Omit the contract only for throwaway prototypes — declare it everywhere else. Wire-level behavior is identical when omitted, but you lose the type-checked `ctx.fail`, the `tools/list` advertisement, and conformance lint coverage.
297
+ **Baseline codes** (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`) bubble freely and don't need declaring. Wire-level behavior is identical when the contract is omitted, but you lose the type-checked `ctx.fail`, the `tools/list` advertisement, and conformance lint coverage — declare a contract whenever the tool has a domain-specific failure mode.
269
298
 
270
299
  `ctx.fail` accepts an optional 4th `options` argument for ES2022 cause chaining: `throw ctx.fail('upstream_error', 'Upstream returned 500', { url }, { cause: e })`.
271
300
 
272
- **Service-thrown contract reasons.** When the throw happens in a called service rather than the handler itself, `ctx.fail` isn't reachable — services don't have `ctx`. Pass `data: { reason: 'X' }` to the factory in the service; the framework's auto-classifier preserves `data` on the wire, so the contract reason rides through unchanged. The handler bubbles the error without catching. See `add-service` for the pattern.
301
+ #### Service-layer throws
302
+
303
+ API-wrapping tools usually delegate to a service: `const data = await ncbi.fetch(input)`. The throw lives in the service, not the handler — and services don't receive `ctx`, so `ctx.fail` is unreachable from there. The fix is to pass `data: { reason: 'X' }` to the factory in the service. The framework's auto-classifier preserves `data` on the wire, so clients see the same `error.data.reason` they would have seen from `ctx.fail`. The handler doesn't catch — it just bubbles.
304
+
305
+ The contract entry on the tool and the `data: { reason }` on the service throw need to use the **same reason string** so the two sides line up.
306
+
307
+ ```typescript
308
+ // service — passes data.reason to match the consuming tool's contract
309
+ import { serviceUnavailable } from '@cyanheads/mcp-ts-core/errors';
310
+
311
+ export class NcbiService {
312
+ async fetch(pmids: string[]) {
313
+ const response = await fetchWithRetry(...);
314
+ if (!response.ok) {
315
+ throw serviceUnavailable(
316
+ `NCBI returned HTTP ${response.status}`,
317
+ { reason: 'ncbi_unreachable', status: response.status }, // ← matches contract entry
318
+ { cause: undefined },
319
+ );
320
+ }
321
+ return response.json();
322
+ }
323
+ }
324
+
325
+ // tool — declares the matching contract entry, calls the service, doesn't catch
326
+ export const fetchArticles = tool('fetch_articles', {
327
+ errors: [
328
+ { reason: 'ncbi_unreachable', code: JsonRpcErrorCode.ServiceUnavailable,
329
+ when: 'NCBI E-utilities is unreachable.', retryable: true },
330
+ ],
331
+ async handler(input, ctx) {
332
+ return { articles: await ncbi.fetch(input.pmids) }; // throws bubble unchanged
333
+ },
334
+ });
335
+ ```
336
+
337
+ See `add-service` for the full pattern.
338
+
339
+ #### Ad-hoc factory throws (fallback)
273
340
 
274
- **Fallback: error factories.** Use when no contract entry fits — ad-hoc throws, prototype tools, or service-layer code. The framework also auto-classifies plain `throw new Error()` from message patterns as a last resort.
341
+ When no contract entry fits — prototype code, one-off throws, or service-layer fallbacks use error factories or plain `throw new Error()`. The framework auto-classifies plain `Error` from message patterns as a last resort.
275
342
 
276
343
  ```typescript
277
344
  // Client input error — agent can fix and retry
@@ -365,7 +432,7 @@ Large payloads burn the agent's context window. Default to curated summaries; of
365
432
  - [ ] `format()` renders every field in the output schema — enforced at lint time via sentinel injection, startup fails with `format-parity` errors otherwise. Different clients forward different surfaces (Claude Code → `structuredContent`, Claude Desktop → `content[]`); both must carry the same data. Primary fix: render the missing field in `format()` (use `z.discriminatedUnion` for list/detail variants). Escape hatch: if the output schema was over-typed for a genuinely dynamic upstream API, relax it (`z.object({}).passthrough()`) rather than maintaining aspirational typing
366
433
  - [ ] If wrapping external API: output schema and `format()` preserve uncertainty from sparse upstream payloads instead of inventing concrete values
367
434
  - [ ] `auth` scopes declared if the tool needs authorization
368
- - [ ] `errors: [...]` contract declared for known domain failure modes (recommended; omit only for throwaway prototypes)
435
+ - [ ] `errors: [...]` contract declared for the tool's domain-specific failure modes or block deleted if no domain failures apply (baseline codes bubble freely)
369
436
  - [ ] `task: true` added if the tool is long-running
370
437
  - [ ] Registered in the project's existing `createApp()` tool list (directly or via barrel)
371
438
  - [ ] `bun run devcheck` passes
@@ -61,11 +61,10 @@ export const fetchTool = tool('fetch_articles', {
61
61
  |:--------|:---------|
62
62
  | Compile time | `ctx.fail('typo')` is a TS error. Auto-completes declared reasons. |
63
63
  | Runtime | `ctx.fail(reason, msg?, data?, options?)` builds an `McpError(contract.code, msg, { ...data, reason }, options)` — `data.reason` is auto-populated from the contract and cannot be overridden by caller-supplied data (spread first, then `reason` written last), so observers see a stable identifier. `options` accepts `{ cause }` for ES2022 error chaining. |
64
- | `tools/list` | Contract surfaced under `_meta['mcp-ts-core/errors']` so clients/agents can preview failure modes. |
65
64
  | Lint (startup) | Each `code` validated against `JsonRpcErrorCode`. Reasons validated as snake_case + unique within contract. |
66
65
  | Lint (conformance) | If the handler `throw new McpError(JsonRpcErrorCode.X)` outside `ctx.fail`, conformance check warns when X isn't declared. |
67
66
 
68
- **Skip the contract** for one-off internal tools or quick prototypes — `ctx` is plain `Context` (no `fail`) and you throw via [factories](#error-factories-fallback) directly. Behavior is identical at the wire; the contract just adds compile-time safety + advertising.
67
+ **Skip the contract** for one-off internal tools or quick prototypes — `ctx` is plain `Context` (no `fail`) and you throw via [factories](#error-factories-fallback) directly. Behavior is identical at the wire; the contract just adds compile-time safety.
69
68
 
70
69
  > **Limits of the conformance lint.** The conformance and prefer-fail rules scan the handler's source text for `throw` statements. Errors thrown from called services (e.g. `await myService.fetch()` raising `RateLimited` internally) are invisible — the lint only sees what's lexically in the handler. Treat the contract as the *advertised* failure surface; bubbled-up codes still reach the client correctly via the auto-classifier, just without lint enforcement.
71
70
 
@@ -87,7 +86,7 @@ errors: [
87
86
  ]
88
87
  ```
89
88
 
90
- The handler doesn't catch and re-throw — letting service errors bubble unchanged keeps "logic throws, framework catches" intact. The contract still publishes in `tools/list`, the wire payload still carries `code` + `data.reason`, and clients can switch on reason without parsing message text. What's lost is lint-time enforcement that every reason is reachable; compensate with one wire-shape test per reason.
89
+ The handler doesn't catch and re-throw — letting service errors bubble unchanged keeps "logic throws, framework catches" intact. The wire payload still carries `code` + `data.reason`, and clients can switch on reason without parsing message text. What's lost is lint-time enforcement that every reason is reachable; compensate with one wire-shape test per reason.
91
90
 
92
91
  ---
93
92
 
@@ -266,9 +265,24 @@ Checked before common patterns. Cover: AWS exception names, HTTP status codes, D
266
265
  | Layer | Pattern |
267
266
  |:------|:--------|
268
267
  | Tool/resource handlers | Throw `McpError` — no try/catch |
269
- | Handler factory | Catches all errors, normalizes to `McpError`, sets `isError: true` |
268
+ | Handler factory (tools) | Catches all errors, normalizes to `McpError`, sets `isError: true`, mirrors error across both client surfaces (see [Error-path parity](#error-path-parity)) |
269
+ | Handler factory (resources) | Catches and re-throws to the SDK, which routes through the JSON-RPC error envelope |
270
270
  | Services/setup code | `ErrorHandler.tryCatch` for graceful recovery |
271
271
 
272
+ ### Error-path parity
273
+
274
+ MCP clients differ in which `CallToolResult` surface they forward to the agent. Tool errors mirror the success-path `format-parity` invariant — both surfaces carry the same payload:
275
+
276
+ | Surface | Content | Read by |
277
+ |:--------|:--------|:--------|
278
+ | `content[]` | Text rendering: `Error: <message>` (plus `Recovery: <hint>` when `data.recovery.hint` is present) | Claude Desktop and other format()-only clients |
279
+ | `structuredContent.error` | JSON `{ code, message, data? }` carrying the error code, message, and any structured data from the thrown `McpError` or `ZodError` | Claude Code and other structuredContent-only clients |
280
+
281
+ Important properties:
282
+ - **`_meta.error` is NOT emitted.** Error code/data live on `structuredContent.error` instead. Don't read `_meta.error` in clients or tests — it doesn't exist.
283
+ - **`data` propagation is restricted** to explicitly-thrown `McpError.data` and `ZodError.issues`. Auto-classified plain errors (`TypeError`, network errors, etc.) emit `code` + `message` only — no `data` — so internal classification context never leaks to clients.
284
+ - **Recovery hint mirroring is automatic.** When the thrown `McpError` carries `data.recovery.hint`, the handler factory appends it to the `content[]` text so the markdown surface matches the JSON surface. Authors don't need to format the hint manually.
285
+
272
286
  **Handler — throw freely, no try/catch:**
273
287
 
274
288
  ```ts
@@ -349,7 +363,7 @@ if (!response.ok) {
349
363
 
350
364
  Captures the response body (truncated, configurable limit) and `Retry-After` header (stored as `data.retryAfter`) into `error.data`. The codes it produces line up with `withRetry`'s transient-code set, so retryable responses are retried automatically.
351
365
 
352
- > **Body reaches the client.** `error.data` is forwarded to the MCP client as `_meta.error.data` (tool errors) or JSON-RPC `error.data` (resource errors). Upstream 401/403/422 responses sometimes echo token claims, internal user IDs, or schema validation hints — that text becomes client-visible. For sensitive endpoints, pass `captureBody: false` (or `bodyLimit: 0`) so the body stays out of `data`. Defaults remain `captureBody: true` because most upstreams return useful diagnostic text and silent dropping helps no one debug.
366
+ > **Body reaches the client.** `error.data` is forwarded to the MCP client as `structuredContent.error.data` (tool errors) or JSON-RPC `error.data` (resource errors). Upstream 401/403/422 responses sometimes echo token claims, internal user IDs, or schema validation hints — that text becomes client-visible. For sensitive endpoints, pass `captureBody: false` (or `bodyLimit: 0`) so the body stays out of `data`. Defaults remain `captureBody: true` because most upstreams return useful diagnostic text and silent dropping helps no one debug.
353
367
 
354
368
  Full status table:
355
369
 
@@ -408,7 +422,7 @@ The linter validates the structure of `errors[]` and (when present) cross-checks
408
422
 
409
423
  | Rule | Severity | Catches |
410
424
  |:-----|:---------|:--------|
411
- | `error-contract-conformance` | warning | Handler throws a non-baseline code that isn't in the contract. Suggests adding it to `errors[]` so `tools/list` advertises the failure mode. |
425
+ | `error-contract-conformance` | warning | Handler throws a non-baseline code that isn't in the contract. Suggests adding it to `errors[]` so the contract is the canonical source of truth for declared failure modes. |
412
426
  | `error-contract-prefer-fail` | warning | Handler throws a code that **is** in the contract directly (via factory or `new McpError`) instead of through `ctx.fail(reason, …)`. Encourages routing through the typed helper so observers see consistent `data.reason` values. |
413
427
 
414
428
  ### Baseline codes (auto-allowed)
@@ -421,7 +435,7 @@ These codes bubble up from anywhere — services, framework utilities, the auto-
421
435
  - `ValidationError` — schema violations, malformed input
422
436
  - `SerializationError` — JSON/XML parse failures
423
437
 
424
- If you *want* to advertise one of these as a domain-specific failure (e.g., a tool that intentionally times out under defined conditions), declare it in `errors[]` anyway — the contract still surfaces in `tools/list`. The lint just doesn't *require* you to.
438
+ If you *want* to declare one of these as a domain-specific failure (e.g., a tool that intentionally times out under defined conditions), put it in `errors[]` anyway — the contract still binds `ctx.fail(reason)` and the conformance lint will catch undeclared throws. The lint just doesn't *require* you to enumerate baselines.
425
439
 
426
440
  ### When to declare vs. let it bubble
427
441
 
@@ -502,7 +502,7 @@ throw serviceUnavailable('Upstream failed', { upstreamError: e }, { cause: e });
502
502
 
503
503
  Validate the optional `errors[]` declarative contract on tool/resource definitions. Structural rules check the shape of contract entries; conformance rules cross-check the handler body against the declared codes.
504
504
 
505
- When a contract is declared, surfaced under `_meta['mcp-ts-core/errors']` in `tools/list` / `resources/list`, and the handler receives a typed `ctx.fail(reason, …)` keyed by the declared reason union. See `skills/api-errors/SKILL.md` for runtime semantics.
505
+ When a contract is declared, the handler receives a typed `ctx.fail(reason, …)` keyed by the declared reason union. See `skills/api-errors/SKILL.md` for runtime semantics.
506
506
 
507
507
  ### error-contract-type
508
508
 
@@ -323,7 +323,7 @@ The pattern: name the shortcut for what it does (`text_search`, `name_search`),
323
323
 
324
324
  Errors are part of the tool's interface — design them during the design phase, not as an afterthought. Three aspects: **the contract** (which failures are public), **classification** (what error code), and **messaging** (what the LLM reads).
325
325
 
326
- **Declare a typed contract for domain failures.** When a tool has known failure modes the agent should plan around (`no_match`, `queue_full`, `vendor_down`), enumerate them as `errors: [{ reason, code, when, retryable? }]` on the definition. The framework publishes the contract under `tools/list` `_meta['mcp-ts-core/errors']` so capable clients can preview failure modes, types `ctx.fail(reason, …)` against the declared reason union (typos become TS errors), and auto-populates `_meta.error.data.reason` on responses for stable observability. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`) bubble from anywhere and don't need to be enumerated. See `api-errors` skill for the full pattern.
326
+ **Declare a typed contract for domain failures.** When a tool has known failure modes the agent should plan around (`no_match`, `queue_full`, `vendor_down`), enumerate them as `errors: [{ reason, code, when, retryable? }]` on the definition. The framework types `ctx.fail(reason, …)` against the declared reason union (typos become TS errors) and auto-populates `data.reason` on the thrown error for stable observability. The error reaches clients with parity across both surfaces — `structuredContent.error` (Claude Code) and `content[]` text (Claude Desktop). Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`) bubble from anywhere and don't need to be enumerated. See `api-errors` skill for the full pattern.
327
327
 
328
328
  **Classify errors by origin.** Different error sources need different codes and different recovery guidance. Map the failure modes for each tool during design:
329
329