@cyanheads/mcp-ts-core 0.8.4 → 0.8.6
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/CLAUDE.md +22 -10
- package/README.md +2 -2
- package/changelog/0.8.x/0.8.5.md +42 -0
- package/changelog/0.8.x/0.8.6.md +22 -0
- package/dist/core/context.d.ts +79 -8
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +46 -9
- package/dist/core/context.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/logs/combined.log +4 -4
- package/dist/logs/error.log +4 -4
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +5 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +1 -3
- package/skills/add-app-tool/SKILL.md +2 -2
- package/skills/add-resource/SKILL.md +2 -2
- package/skills/add-service/SKILL.md +13 -2
- package/skills/add-tool/SKILL.md +43 -20
- package/skills/api-auth/SKILL.md +6 -5
- package/skills/api-context/SKILL.md +55 -6
- package/skills/api-errors/SKILL.md +62 -2
- package/skills/field-test/SKILL.md +2 -5
- package/skills/polish-docs-meta/references/readme.md +1 -8
- package/skills/report-issue-framework/SKILL.md +1 -1
- package/skills/report-issue-local/SKILL.md +1 -1
- package/templates/AGENTS.md +0 -2
- package/templates/CLAUDE.md +0 -2
- package/templates/package.json +0 -2
package/CLAUDE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Agent Protocol
|
|
2
2
|
|
|
3
|
-
**Package:** `@cyanheads/mcp-ts-core` · **Version:** 0.8.
|
|
3
|
+
**Package:** `@cyanheads/mcp-ts-core` · **Version:** 0.8.6
|
|
4
4
|
**npm:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) · **Docker:** [ghcr.io/cyanheads/mcp-ts-core](https://ghcr.io/cyanheads/mcp-ts-core)
|
|
5
5
|
|
|
6
6
|
> **Developer note:** Never assume. Read related files and docs before making changes. Read full file content for context. Never edit a file before reading it.
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
| Subpath | Key Exports | Purpose |
|
|
25
25
|
|:--------|:------------|:--------|
|
|
26
|
-
| `@cyanheads/mcp-ts-core` | `createApp`, `tool`, `resource`, `prompt`, `appTool`, `appResource`, `APP_RESOURCE_MIME_TYPE`, `Context`, `createFail`, `TypedFail`, `ReasonOf`, `HandlerContext`, `z` | Main entry point |
|
|
26
|
+
| `@cyanheads/mcp-ts-core` | `createApp`, `tool`, `resource`, `prompt`, `appTool`, `appResource`, `APP_RESOURCE_MIME_TYPE`, `Context`, `createFail`, `createRecoveryFor`, `TypedFail`, `TypedRecoveryFor`, `ReasonOf`, `HandlerContext`, `z` | Main entry point |
|
|
27
27
|
| `/worker` | `createWorkerHandler`, `CloudflareBindings` | Cloudflare Workers entry |
|
|
28
28
|
| `/tools` | `ToolDefinition`, `AnyToolDefinition`, `ToolAnnotations` | Tool definition types |
|
|
29
29
|
| `/resources` | `ResourceDefinition`, `AnyResourceDefinition` | Resource definition types |
|
|
@@ -193,7 +193,7 @@ export const myTool = tool('my_tool', {
|
|
|
193
193
|
});
|
|
194
194
|
```
|
|
195
195
|
|
|
196
|
-
**Steps:** Create `src/mcp-server/tools/definitions/[name].tool.ts` (kebab-case) → use `tool('snake_case', {...})` with Zod `.describe()` on all fields → implement `handler(input, ctx)` (pure, throws on failure) → add `auth`/`format` if needed → register in `definitions/index.ts` → `bun run devcheck` → smoke-test with `
|
|
196
|
+
**Steps:** Create `src/mcp-server/tools/definitions/[name].tool.ts` (kebab-case) → use `tool('snake_case', {...})` with Zod `.describe()` on all fields → implement `handler(input, ctx)` (pure, throws on failure) → add `auth`/`format` if needed → register in `definitions/index.ts` → `bun run devcheck` → smoke-test with `bun run rebuild && bun run start:stdio` (or `start:http`).
|
|
197
197
|
|
|
198
198
|
**Schema constraint:** Input/output schemas must use JSON-Schema-serializable Zod types only. The MCP SDK converts schemas to JSON Schema for `tools/list` — non-serializable types (`z.custom()`, `z.date()`, `z.transform()`, `z.bigint()`, `z.symbol()`, `z.void()`, `z.map()`, `z.set()`, `z.function()`, `z.nan()`) cause a hard runtime failure. Use structural equivalents instead (e.g., `z.string()` with `.describe('ISO 8601 date')` instead of `z.date()`). The linter validates this at startup.
|
|
199
199
|
|
|
@@ -299,6 +299,7 @@ interface Context {
|
|
|
299
299
|
readonly signal: AbortSignal; // cancellation
|
|
300
300
|
readonly progress?: ContextProgress; // present when task: true
|
|
301
301
|
readonly uri?: URL; // present for resource handlers
|
|
302
|
+
recoveryFor(reason: string): { recovery: { hint: string } } | {}; // opt-in contract resolver
|
|
302
303
|
}
|
|
303
304
|
```
|
|
304
305
|
|
|
@@ -320,7 +321,13 @@ const values = await ctx.state.getMany<Item>(['item:1', 'item:2']); // Map<strin
|
|
|
320
321
|
const page = await ctx.state.list('item:', { cursor, limit: 20 }); // { items, cursor? }
|
|
321
322
|
```
|
|
322
323
|
|
|
323
|
-
Throws `McpError(InvalidRequest)` if `tenantId` missing. Tenant ID
|
|
324
|
+
Throws `McpError(InvalidRequest)` if `tenantId` missing. Tenant ID resolution:
|
|
325
|
+
|
|
326
|
+
| Mode | `tenantId` source |
|
|
327
|
+
|:-----|:------------------|
|
|
328
|
+
| stdio (any auth) | `'default'` |
|
|
329
|
+
| HTTP + `MCP_AUTH_MODE=none` | `'default'` (single-tenant by design) |
|
|
330
|
+
| HTTP + `MCP_AUTH_MODE=jwt`/`oauth` | JWT `'tid'` claim — fail-closed if absent |
|
|
324
331
|
|
|
325
332
|
### `ctx.elicit` / `ctx.sample`
|
|
326
333
|
|
|
@@ -345,7 +352,7 @@ See `api-context` skill for full details.
|
|
|
345
352
|
|
|
346
353
|
## Error Handling
|
|
347
354
|
|
|
348
|
-
**Recommended path: declare a typed error contract.** Add `errors: [{ reason, code, when, recovery, retryable? }]` to `tool()` / `resource()`. The handler then receives `ctx.fail(reason, msg?, data?)` typed against the reason union — `ctx.fail('typo')` is a TypeScript error. The runtime auto-populates `data.reason` for observability and the linter enforces conformance against the handler body. The `recovery` field is required
|
|
355
|
+
**Recommended path: declare a typed error contract.** Add `errors: [{ reason, code, when, recovery, retryable? }]` to `tool()` / `resource()`. The handler then receives `ctx.fail(reason, msg?, data?)` typed against the reason union — `ctx.fail('typo')` is a TypeScript error. The runtime auto-populates `data.reason` for observability and the linter enforces conformance against the handler body. The `recovery` field is required (≥5 words, lint-validated) — it's the single source of truth for the recovery hint that flows to the wire. Spread `ctx.recoveryFor('reason')` into `data` to opt the contract recovery onto the wire (the framework mirrors `data.recovery.hint` into `content[]` text). Override with explicit `{ recovery: { hint: '...' } }` when runtime context matters.
|
|
349
356
|
|
|
350
357
|
```ts
|
|
351
358
|
errors: [
|
|
@@ -357,11 +364,18 @@ errors: [
|
|
|
357
364
|
recovery: 'Wait 30 seconds before retrying or reduce batch size.' },
|
|
358
365
|
],
|
|
359
366
|
async handler(input, ctx) {
|
|
360
|
-
|
|
361
|
-
|
|
367
|
+
// Static recovery — pulled from the contract via ctx.recoveryFor.
|
|
368
|
+
if (queue.full()) throw ctx.fail('queue_full', undefined, { ...ctx.recoveryFor('queue_full') });
|
|
369
|
+
// Dynamic recovery — interpolate runtime context, override the contract default.
|
|
370
|
+
if (!matched) throw ctx.fail('no_match', `No data for ${input.pmids.length} PMIDs`, {
|
|
371
|
+
pmids: input.pmids,
|
|
372
|
+
recovery: { hint: `Use pubmed_search_articles to discover valid PMIDs.` },
|
|
373
|
+
});
|
|
362
374
|
}
|
|
363
375
|
```
|
|
364
376
|
|
|
377
|
+
**`ctx.recoveryFor(reason)`** is the first member of a planned family of opt-in resolution helpers (future: `troubleshootingFor`, `userMessageFor`, …). Always present on `Context` (returns `{}` when no contract is attached or the reason is unknown — spread-safe), strictly typed on `HandlerContext<R>` against the declared reason union. The same resolver works in services that accept `ctx`: `throw validationError(msg, { reason: 'X', ...ctx.recoveryFor('X') })`. No auto-population — author opts in by typing the helper.
|
|
378
|
+
|
|
365
379
|
The contract describes the **public failure surface** — declare domain-specific failures only. **Baseline codes** (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`) bubble from anywhere and are auto-allowed by the conformance lint, so you don't need to enumerate them per-tool. The conformance lint scans handler source text only — failures thrown from called services aren't visible to it (still reach the client correctly via the auto-classifier, just without lint enforcement).
|
|
366
380
|
|
|
367
381
|
**Fallback for ad-hoc throws** (no contract entry fits, prototype tools, service-layer code): use error factories.
|
|
@@ -518,7 +532,7 @@ Detailed method signatures, options, and examples live in skill files. Read the
|
|
|
518
532
|
- **Registration:** definitions exported in `definitions/index.ts` barrel
|
|
519
533
|
- **Tests:** `createMockContext()`, `.handler()` tested directly
|
|
520
534
|
- **Gate:** `bun run devcheck` passes (includes MCP definition linting)
|
|
521
|
-
- **Smoke-test:**
|
|
535
|
+
- **Smoke-test:** `bun run rebuild && bun run start:stdio` (or `start:http`)
|
|
522
536
|
|
|
523
537
|
---
|
|
524
538
|
|
|
@@ -540,8 +554,6 @@ Detailed method signatures, options, and examples live in skill files. Read the
|
|
|
540
554
|
| `bun run lint:mcp` | Validate MCP definitions against spec |
|
|
541
555
|
| `bun run format` | Auto-fix Biome lint/format issues |
|
|
542
556
|
| `bun run test` | Unit/integration tests |
|
|
543
|
-
| `bun run dev:stdio` | Development mode (stdio) |
|
|
544
|
-
| `bun run dev:http` | Development mode (HTTP) |
|
|
545
557
|
| `bun run start:stdio` | Production mode (stdio, after build) |
|
|
546
558
|
| `bun run start:http` | Production mode (HTTP, after build) |
|
|
547
559
|
| `bun run changelog:build` | Regenerate `CHANGELOG.md` from `changelog/*.md` |
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
<div align="center">
|
|
7
7
|
|
|
8
|
-
[](./CHANGELOG.md) [](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/2025-11-25/changelog.mdx) [](https://modelcontextprotocol.io/) [](./LICENSE)
|
|
9
9
|
|
|
10
10
|
[](https://www.typescriptlang.org/) [](https://bun.sh/)
|
|
11
11
|
|
|
@@ -182,7 +182,7 @@ Handlers receive a unified `Context` object:
|
|
|
182
182
|
| `ctx.notifyResourceListChanged` | `Function?` | Notify clients the resource list changed |
|
|
183
183
|
| `ctx.progress` | `ContextProgress?` | Task progress reporting (when `task: true`) |
|
|
184
184
|
| `ctx.requestId` | `string` | Unique request ID |
|
|
185
|
-
| `ctx.tenantId` | `string?` | Tenant ID (
|
|
185
|
+
| `ctx.tenantId` | `string?` | Tenant ID (JWT `tid` claim, or `'default'` for stdio and HTTP+`MCP_AUTH_MODE=none`) |
|
|
186
186
|
|
|
187
187
|
### Subpath exports
|
|
188
188
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: "HTTP+MCP_AUTH_MODE=none defaults tenantId to 'default' so ctx.state works without minting JWTs. New ctx.recoveryFor opt-in contract resolver carries the contract recovery onto the wire — single source of truth for handler and service throws."
|
|
3
|
+
breaking: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 0.8.5 — 2026-04-29
|
|
7
|
+
|
|
8
|
+
Two changes shipped together. `MCP_AUTH_MODE=none` over HTTP now behaves as the documented "single-tenant, no auth" mode (closes [#87](https://github.com/cyanheads/mcp-ts-core/issues/87)). And the contract `recovery` field gets a typed runtime resolver — `ctx.recoveryFor(reason)` — that carries the lint-validated string onto the wire without authoring duplication, while preserving the "no auto-population, no hidden transformation" stance from [#85](https://github.com/cyanheads/mcp-ts-core/issues/85) (closes [#89](https://github.com/cyanheads/mcp-ts-core/issues/89), supersedes [#88](https://github.com/cyanheads/mcp-ts-core/issues/88)).
|
|
9
|
+
|
|
10
|
+
## Added
|
|
11
|
+
|
|
12
|
+
- **`ctx.recoveryFor(reason)`** (`src/core/context.ts`) — opt-in contract resolver. Returns the canonical wire shape `{ recovery: { hint } }` for declared reasons; returns `{}` when no contract is attached or the reason is unknown. Always present on `Context` (spread-safe with no optional chaining); strictly typed on `HandlerContext<R>` against the declared reason union. Same resolver works in services that accept `ctx`.
|
|
13
|
+
- **`createRecoveryFor(errors)`** (`src/core/context.ts`) — internal builder, mirrors `createFail`. Public re-export from `@cyanheads/mcp-ts-core` for advanced use.
|
|
14
|
+
- **`TypedRecoveryFor<R>`** type alias for the strict signature, exported alongside `TypedFail<R>`.
|
|
15
|
+
- **First member of a planned family of opt-in resolution helpers.** Future contract-bound fields (`troubleshootingFor`, `userMessageFor`, …) follow the same shape: single-purpose method, spreadable wire-shape return, `{}` fallback, strict variant on `HandlerContext<R>`.
|
|
16
|
+
|
|
17
|
+
## Fixed
|
|
18
|
+
|
|
19
|
+
- **`createContext`** (`src/core/context.ts`) — `tenantId` defaults to `'default'` when `MCP_AUTH_MODE=none`, regardless of transport. Stdio behavior unchanged. HTTP+`jwt`/`oauth` without `tid` still fails closed (security invariant: distinct authenticated callers must not silently share state).
|
|
20
|
+
- **`ctx.state` error message** — references `MCP_AUTH_MODE` semantics instead of stale "via createApp()" wording.
|
|
21
|
+
|
|
22
|
+
## Changed
|
|
23
|
+
|
|
24
|
+
- **`HandlerContext<R>`** — when `R` is a literal union, the type now uses `Omit<Context, 'recoveryFor'> & { fail: TypedFail<R>; recoveryFor: TypedRecoveryFor<R> }` (intersecting the loose `Context.recoveryFor` would widen `parameter(0)` back to `string` and lose typo-catching). Behavior unchanged for callers; type is strictly narrower for declared reasons.
|
|
25
|
+
- **`attachTypedFail`** (`src/core/context.ts`) — wires both `fail` and `recoveryFor` when the definition declares an `errors[]` contract. Bare `Context` carries a no-op `recoveryFor` so service-side spreads are always safe.
|
|
26
|
+
|
|
27
|
+
## Docs
|
|
28
|
+
|
|
29
|
+
- `AGENTS.md` / `CLAUDE.md` / `README.md` — `tenantId` resolution table covers all three modes; error handling section and Context interface documents `ctx.recoveryFor`; exports table includes `createRecoveryFor`, `TypedRecoveryFor`.
|
|
30
|
+
- `skills/api-context/SKILL.md` v1.1 → v1.2 — new `ctx.recoveryFor` section with signature, behavior table, and family-pattern note; identity field table and `ctx.state` notes carry the auth-none default.
|
|
31
|
+
- `skills/api-errors/SKILL.md` v1.3 → v1.4 — opt-in resolution subsection replaces the const-pattern guidance; gap callout removed; service-layer pattern updated.
|
|
32
|
+
- `skills/api-auth/SKILL.md` — `tenantId` sources table covers HTTP+`none`.
|
|
33
|
+
- `skills/add-tool/SKILL.md` v2.3 → v2.4 — template demonstrates static (`...ctx.recoveryFor('reason')`) and dynamic (inline `{ recovery: { hint } }`) recovery side by side; service-layer subsection now passes `ctx` and uses the resolver.
|
|
34
|
+
- `skills/add-service/SKILL.md` v1.4 → v1.5 — service-side spread pattern with `...ctx.recoveryFor('reason')`.
|
|
35
|
+
|
|
36
|
+
## Security note
|
|
37
|
+
|
|
38
|
+
HTTP+`MCP_AUTH_MODE=none` is **single-tenant by design** — all unauthenticated callers share the `'default'` tenant. Servers requiring per-caller isolation must use `MCP_AUTH_MODE=jwt` or `oauth` with tokens that carry a `tid` claim.
|
|
39
|
+
|
|
40
|
+
## Design principle (#85 / #88 / #89)
|
|
41
|
+
|
|
42
|
+
`ctx.recoveryFor` is **opt-in resolution**, not auto-population. The framework never attaches `data.recovery.hint` without an explicit signal at the throw site — authors opt in by typing the helper, the same way `ctx.fail('reason')` opts into resolving the contract `code`. The contract is the single source of truth for the recovery hint; the resolver is a typed lookup keyed by the same reason the author already typed. No magic, no hidden transformation. The `≥5 words` lint rule on contract `recovery` becomes load-bearing — every `ctx.recoveryFor` call site benefits from the thoughtfulness the contract enforced.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: "Remove `dev:stdio`/`dev:http` watch scripts from framework and template `package.json`; smoke-test path standardized to `bun run rebuild && bun run start:stdio` across docs and skills."
|
|
3
|
+
breaking: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 0.8.6 — 2026-04-29
|
|
7
|
+
|
|
8
|
+
Workflow cleanup. The `dev:stdio` / `dev:http` watch scripts overlapped with `dev` (already a `bun --watch` runner) and produced a dev-vs-prod split where smoke-tests ran against an unbuilt source tree. Standardizing on `bun run rebuild && bun run start:stdio` (or `start:http`) gives every smoke-test path the same execution surface as production.
|
|
9
|
+
|
|
10
|
+
## Removed
|
|
11
|
+
|
|
12
|
+
- **`package.json`** — `dev:stdio` and `dev:http` scripts. Use `bun run dev` for watch mode (transport via `MCP_TRANSPORT_TYPE`); use `bun run rebuild && bun run start:stdio` (or `start:http`) for production-shape smoke tests.
|
|
13
|
+
- **`templates/package.json`** — same removal in the scaffold so fresh projects don't carry the stale scripts.
|
|
14
|
+
|
|
15
|
+
## Changed
|
|
16
|
+
|
|
17
|
+
- **`AGENTS.md` / `CLAUDE.md`** — Adding a Tool steps and the Code Style & Checklist now reference `bun run rebuild && bun run start:stdio`. Commands table drops the two `dev:*` rows.
|
|
18
|
+
- **`templates/AGENTS.md` / `templates/CLAUDE.md`** — same Commands-table cleanup for scaffolded projects.
|
|
19
|
+
- **`skills/field-test/SKILL.md`** — Transport coverage section reframed: stdio is now a **boot check only** (`bun run rebuild && bun run start:stdio`, confirm clean banner + expected counts, kill it). HTTP remains the primary harness for handler behavior. Stdio inspector / mcp-cli fallbacks dropped — the boot check covers what stdio coverage was actually verifying.
|
|
20
|
+
- **`skills/add-tool/SKILL.md`** / **`skills/add-resource/SKILL.md`** / **`skills/add-app-tool/SKILL.md`** — smoke-test step and final checklist item updated to the rebuild + start path.
|
|
21
|
+
- **`skills/polish-docs-meta/references/readme.md`** — README scaffold drops the "Hot-reload dev mode" subsection; "Build and run" replaces "Build and run the production version".
|
|
22
|
+
- **`skills/report-issue-framework/SKILL.md`** / **`skills/report-issue-local/SKILL.md`** — log-attach example uses `bun run rebuild && bun run start:stdio 2>&1 | head -N` so captured logs come from the same path the bug report reproduces against.
|
package/dist/core/context.d.ts
CHANGED
|
@@ -96,6 +96,31 @@ export interface Context {
|
|
|
96
96
|
readonly notifyResourceUpdated?: ((uri: string) => void) | undefined;
|
|
97
97
|
/** Progress reporting for background tasks. Undefined for non-task tools. */
|
|
98
98
|
readonly progress?: ContextProgress | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Resolves a contract-bound recovery hint by reason and returns it in the
|
|
101
|
+
* canonical wire shape `{ recovery: { hint } }` — safe to spread directly into
|
|
102
|
+
* factory `data` or `ctx.fail`'s data argument:
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* throw ctx.fail('parse_failed', `Parse error: ${err.message}`, ctx.recoveryFor('parse_failed'));
|
|
106
|
+
* throw validationError('Parse failed', { reason: 'parse_failed', ...ctx.recoveryFor('parse_failed') });
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* Returns `{}` when the calling definition has no `errors[]` contract, or the
|
|
110
|
+
* reason isn't declared in it. Always safe to spread — no optional chaining
|
|
111
|
+
* needed at call sites. The strict, typed variant (which guarantees the
|
|
112
|
+
* non-empty return) lives on `HandlerContext<R>` when a contract is declared.
|
|
113
|
+
*
|
|
114
|
+
* Single source of truth pattern: write the recovery once in the contract entry
|
|
115
|
+
* (lint-validated for ≥5 words), reference it everywhere via this resolver.
|
|
116
|
+
* Authors who want runtime-context recovery (interpolating input values, IDs,
|
|
117
|
+
* queue state) override at the throw site as today.
|
|
118
|
+
*/
|
|
119
|
+
recoveryFor(reason: string): {
|
|
120
|
+
recovery: {
|
|
121
|
+
hint: string;
|
|
122
|
+
};
|
|
123
|
+
} | Record<string, never>;
|
|
99
124
|
/** Unique request ID for log correlation. */
|
|
100
125
|
readonly requestId: string;
|
|
101
126
|
/** Request LLM completion from the client. Present when client supports sampling. */
|
|
@@ -106,7 +131,13 @@ export interface Context {
|
|
|
106
131
|
readonly spanId?: string | undefined;
|
|
107
132
|
/** Key-value state scoped to the current tenant. Throws if tenantId is missing. */
|
|
108
133
|
readonly state: ContextState;
|
|
109
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Tenant ID. Sources, in order:
|
|
136
|
+
* - JWT `tid` claim — HTTP with `MCP_AUTH_MODE=jwt`/`oauth`
|
|
137
|
+
* - `'default'` — stdio (any auth mode) or HTTP with `MCP_AUTH_MODE=none`
|
|
138
|
+
* - `undefined` — HTTP with `jwt`/`oauth` when the token lacks `tid`
|
|
139
|
+
* (fail-closed: `ctx.state` will throw rather than silently share state)
|
|
140
|
+
*/
|
|
110
141
|
readonly tenantId?: string | undefined;
|
|
111
142
|
/** ISO 8601 creation time. */
|
|
112
143
|
readonly timestamp: string;
|
|
@@ -145,17 +176,39 @@ export type TypedFail<R extends string> = (reason: R, message?: string, data?: R
|
|
|
145
176
|
export type ReasonOf<E> = E extends readonly {
|
|
146
177
|
reason: infer R extends string;
|
|
147
178
|
}[] ? string extends R ? never : R : never;
|
|
179
|
+
/**
|
|
180
|
+
* Strict, typed contract-resolver signature attached to `HandlerContext<R>`
|
|
181
|
+
* when a definition declares `errors[]`. Tightens the loose `Context.recoveryFor`
|
|
182
|
+
* to:
|
|
183
|
+
* - `reason` is constrained to the declared union (TS catches typos)
|
|
184
|
+
* - return is the non-empty wire shape (no fallback `{}` branch)
|
|
185
|
+
*
|
|
186
|
+
* Family of opt-in resolution helpers — future contract-bound fields
|
|
187
|
+
* (`troubleshootingFor`, `userMessageFor`, …) follow the same shape.
|
|
188
|
+
*/
|
|
189
|
+
export type TypedRecoveryFor<R extends string> = (reason: R) => {
|
|
190
|
+
recovery: {
|
|
191
|
+
hint: string;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
148
194
|
/**
|
|
149
195
|
* Handler context. When a definition declares `errors[]`, the handler receives
|
|
150
|
-
* `Context & { fail: TypedFail<R> }` where
|
|
151
|
-
* When no contract is declared, the handler
|
|
152
|
-
*
|
|
196
|
+
* `Context & { fail: TypedFail<R>; recoveryFor: TypedRecoveryFor<R> }` where
|
|
197
|
+
* `R` is the declared reason union. When no contract is declared, the handler
|
|
198
|
+
* receives plain `Context` (its loose `recoveryFor` is still callable but
|
|
199
|
+
* always returns `{}`) and must throw `McpError` directly.
|
|
153
200
|
*
|
|
154
201
|
* The conditional `[R] extends [never]` distinguishes "no contract declared"
|
|
155
202
|
* (R = never) from "contract declared with reasons" (R = literal union).
|
|
203
|
+
*
|
|
204
|
+
* The contract branch uses `Omit<Context, 'recoveryFor'>` because intersecting
|
|
205
|
+
* the loose `Context.recoveryFor(string)` with the strict `TypedRecoveryFor<R>`
|
|
206
|
+
* would create an overload that widens `parameter(0)` back to `string` — losing
|
|
207
|
+
* the typo-catching benefit. Omit-and-replace narrows cleanly.
|
|
156
208
|
*/
|
|
157
|
-
export type HandlerContext<R extends string = never> = [R] extends [never] ? Context : Context & {
|
|
209
|
+
export type HandlerContext<R extends string = never> = [R] extends [never] ? Context : Omit<Context, 'recoveryFor'> & {
|
|
158
210
|
fail: TypedFail<R>;
|
|
211
|
+
recoveryFor: TypedRecoveryFor<R>;
|
|
159
212
|
};
|
|
160
213
|
/**
|
|
161
214
|
* @internal
|
|
@@ -174,9 +227,27 @@ export type HandlerContext<R extends string = never> = [R] extends [never] ? Con
|
|
|
174
227
|
*/
|
|
175
228
|
export declare function createFail(errors: readonly ErrorContract[]): TypedFail<string>;
|
|
176
229
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
230
|
+
* Builds a runtime `recoveryFor` resolver for a given contract. Looks up the
|
|
231
|
+
* entry by `reason` and returns the canonical wire shape `{ recovery: { hint } }`,
|
|
232
|
+
* safe to spread into factory `data` or `ctx.fail`'s data argument.
|
|
233
|
+
*
|
|
234
|
+
* Returns `{}` when the reason isn't declared — at runtime this protects JS
|
|
235
|
+
* callers and stale contracts; at compile time `TypedRecoveryFor<R>` constrains
|
|
236
|
+
* the reason to declared values. The `{}` fallback also keeps the bare-Context
|
|
237
|
+
* resolver (no contract attached) safe to spread without optional chaining.
|
|
238
|
+
*
|
|
239
|
+
* @internal
|
|
240
|
+
*/
|
|
241
|
+
export declare function createRecoveryFor(errors: readonly ErrorContract[]): (reason: string) => {
|
|
242
|
+
recovery: {
|
|
243
|
+
hint: string;
|
|
244
|
+
};
|
|
245
|
+
} | Record<string, never>;
|
|
246
|
+
/**
|
|
247
|
+
* Attaches a typed `fail` and `recoveryFor` helper to `ctx` when the definition
|
|
248
|
+
* declares an error contract. The bare `Context.recoveryFor` (always present
|
|
249
|
+
* via `createContext`) is overwritten with a contract-aware resolver. Used by
|
|
250
|
+
* the tool and resource handler factories so all call sites stay identical.
|
|
180
251
|
*
|
|
181
252
|
* @internal
|
|
182
253
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EACL,KAAK,aAAa,EAGlB,QAAQ,EACT,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAGtF,YAAY,EAAE,WAAW,EAAE,CAAC;AAM5B;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG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|
@@ -40,16 +40,43 @@ export function createFail(errors) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* Builds a runtime `recoveryFor` resolver for a given contract. Looks up the
|
|
44
|
+
* entry by `reason` and returns the canonical wire shape `{ recovery: { hint } }`,
|
|
45
|
+
* safe to spread into factory `data` or `ctx.fail`'s data argument.
|
|
46
|
+
*
|
|
47
|
+
* Returns `{}` when the reason isn't declared — at runtime this protects JS
|
|
48
|
+
* callers and stale contracts; at compile time `TypedRecoveryFor<R>` constrains
|
|
49
|
+
* the reason to declared values. The `{}` fallback also keeps the bare-Context
|
|
50
|
+
* resolver (no contract attached) safe to spread without optional chaining.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export function createRecoveryFor(errors) {
|
|
55
|
+
const byReason = new Map();
|
|
56
|
+
for (const entry of errors)
|
|
57
|
+
byReason.set(entry.reason, entry);
|
|
58
|
+
return (reason) => {
|
|
59
|
+
const entry = byReason.get(reason);
|
|
60
|
+
if (!entry)
|
|
61
|
+
return {};
|
|
62
|
+
return { recovery: { hint: entry.recovery } };
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Attaches a typed `fail` and `recoveryFor` helper to `ctx` when the definition
|
|
67
|
+
* declares an error contract. The bare `Context.recoveryFor` (always present
|
|
68
|
+
* via `createContext`) is overwritten with a contract-aware resolver. Used by
|
|
69
|
+
* the tool and resource handler factories so all call sites stay identical.
|
|
46
70
|
*
|
|
47
71
|
* @internal
|
|
48
72
|
*/
|
|
49
73
|
export function attachTypedFail(ctx, errors) {
|
|
50
74
|
if (!errors || errors.length === 0)
|
|
51
75
|
return ctx;
|
|
52
|
-
return Object.assign(ctx, {
|
|
76
|
+
return Object.assign(ctx, {
|
|
77
|
+
fail: createFail(errors),
|
|
78
|
+
recoveryFor: createRecoveryFor(errors),
|
|
79
|
+
});
|
|
53
80
|
}
|
|
54
81
|
/**
|
|
55
82
|
* Constructs a Context from internal dependencies.
|
|
@@ -58,13 +85,17 @@ export function attachTypedFail(ctx, errors) {
|
|
|
58
85
|
*/
|
|
59
86
|
export function createContext(deps) {
|
|
60
87
|
const { appContext, logger: pinoLogger, storage, signal } = deps;
|
|
61
|
-
// Default tenantId to 'default'
|
|
62
|
-
//
|
|
63
|
-
//
|
|
88
|
+
// Default tenantId to 'default' when no auth pipeline is expected to populate it:
|
|
89
|
+
// - stdio: single-client by nature, no auth middleware runs
|
|
90
|
+
// - HTTP + MCP_AUTH_MODE=none: single-tenant by design (auth=none means
|
|
91
|
+
// "no identity check, sharing is intentional")
|
|
92
|
+
// Preserves fail-closed for HTTP + jwt/oauth: a token missing the `tid` claim
|
|
93
|
+
// must NOT silently share state across distinct authenticated callers.
|
|
64
94
|
const isStdio = process.env.MCP_TRANSPORT_TYPE?.toLowerCase() !== 'http';
|
|
95
|
+
const isAuthDisabled = (process.env.MCP_AUTH_MODE ?? 'none').toLowerCase() === 'none';
|
|
65
96
|
const effectiveContext = appContext.tenantId
|
|
66
97
|
? appContext
|
|
67
|
-
: isStdio
|
|
98
|
+
: isStdio || isAuthDisabled
|
|
68
99
|
? { ...appContext, tenantId: 'default' }
|
|
69
100
|
: appContext;
|
|
70
101
|
const log = createContextLogger(pinoLogger, effectiveContext);
|
|
@@ -88,6 +119,12 @@ export function createContext(deps) {
|
|
|
88
119
|
notifyResourceUpdated: deps.notifyResourceUpdated,
|
|
89
120
|
progress,
|
|
90
121
|
uri: deps.uri,
|
|
122
|
+
// No-op resolver for definitions without a contract. `attachTypedFail`
|
|
123
|
+
// overwrites with a contract-aware resolver when `errors[]` is declared.
|
|
124
|
+
// Always-present so service code can spread `...ctx.recoveryFor('x')`
|
|
125
|
+
// without optional chaining, regardless of whether the calling tool
|
|
126
|
+
// declared a contract.
|
|
127
|
+
recoveryFor: () => ({}),
|
|
91
128
|
};
|
|
92
129
|
}
|
|
93
130
|
// ---------------------------------------------------------------------------
|
|
@@ -127,7 +164,7 @@ function createContextLogger(appLogger, appContext) {
|
|
|
127
164
|
function createContextState(storage, appContext, signal) {
|
|
128
165
|
const requireContext = () => {
|
|
129
166
|
if (!appContext.tenantId) {
|
|
130
|
-
throw invalidRequest('tenantId required for state operations.
|
|
167
|
+
throw invalidRequest('tenantId required for state operations. With MCP_AUTH_MODE=jwt|oauth, the token must include a "tid" claim. Stdio and HTTP+MCP_AUTH_MODE=none default tenantId to "default" automatically.');
|
|
131
168
|
}
|
|
132
169
|
return appContext;
|
|
133
170
|
};
|
package/dist/core/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,EAEL,cAAc,EACd,gBAAgB,EAChB,QAAQ,GACT,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,EAEL,cAAc,EACd,gBAAgB,EAChB,QAAQ,GACT,MAAM,0BAA0B,CAAC;AA8OlC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU,CAAC,MAAgC;IACzD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;IAClD,KAAK,MAAM,KAAK,IAAI,MAAM;QAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAE9D,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,oEAAoE;YACpE,wEAAwE;YACxE,+DAA+D;YAC/D,OAAO,IAAI,QAAQ,CACjB,gBAAg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G,CAAC,SAAS,GAAG,MAAM,EAAE,KAAK,IAAI,SAAS,GAAG,MAAM,CAAC,CAAC;YACtE,MAAM,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACjF,MAAM,KAAK,CAAC,gBAAgB,CAC1B,MAAM,EACN,SAAS,EACT,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,YAAY,CAAC,CAAC,CAAC,SAAS,CACjE,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,OAAO;YAClB,MAAM,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export type { CoreServices, CreateAppOptions, ServerHandle } from '../core/app.j
|
|
|
9
9
|
export { createApp } from '../core/app.js';
|
|
10
10
|
export type { LandingConfig, LandingLink } from '../core/serverManifest.js';
|
|
11
11
|
export { z } from 'zod';
|
|
12
|
-
export type { AuthContext, Context, ContextLogger, ContextProgress, ContextState, HandlerContext, ReasonOf, SamplingOpts, TypedFail, } from '../core/context.js';
|
|
13
|
-
export { createFail } from '../core/context.js';
|
|
12
|
+
export type { AuthContext, Context, ContextLogger, ContextProgress, ContextState, HandlerContext, ReasonOf, SamplingOpts, TypedFail, TypedRecoveryFor, } from '../core/context.js';
|
|
13
|
+
export { createFail, createRecoveryFor } from '../core/context.js';
|
|
14
14
|
export { APP_RESOURCE_MIME_TYPE, appResource, appTool } from '../mcp-server/apps/appBuilders.js';
|
|
15
15
|
export type { AnyPromptDefinition, PromptDefinition, } from '../mcp-server/prompts/utils/promptDefinition.js';
|
|
16
16
|
export { prompt } from '../mcp-server/prompts/utils/promptDefinition.js';
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAM1C,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAM3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,YAAY,EACV,WAAW,EACX,OAAO,EACP,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAM1C,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAM3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,YAAY,EACV,WAAW,EACX,OAAO,EACP,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAMlE,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAChG,YAAY,EACV,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,gDAAgD,CAAC;AACxE,YAAY,EACV,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,oDAAoD,CAAC;AAC9E,sEAAsE;AACtE,YAAY,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAC1E,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAMlE,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,UAAU,EACV,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAM3D,YAAY,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,eAAe,GAChB,MAAM,oCAAoC,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { createApp } from '../core/app.js';
|
|
|
10
10
|
// Zod re-export (consumers use the framework's copy, no separate zod dep)
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
export { z } from 'zod';
|
|
13
|
-
export { createFail } from '../core/context.js';
|
|
13
|
+
export { createFail, createRecoveryFor } from '../core/context.js';
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
// Definition builders & types
|
|
16
16
|
// ---------------------------------------------------------------------------
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAQ1C,8EAA8E;AAC9E,0EAA0E;AAC1E,8EAA8E;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAQ1C,8EAA8E;AAC9E,0EAA0E;AAC1E,8EAA8E;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkBxB,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAElE,8EAA8E;AAC9E,8BAA8B;AAC9B,8EAA8E;AAE9E,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAKhG,OAAO,EAAE,MAAM,EAAE,MAAM,gDAAgD,CAAC;AAKxE,OAAO,EAAE,QAAQ,EAAE,MAAM,oDAAoD,CAAC;AAQ9E,OAAO,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAalE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/logs/combined.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{"level":50,"time":
|
|
2
|
-
{"level":50,"time":
|
|
3
|
-
{"level":50,"time":
|
|
4
|
-
{"level":50,"time":
|
|
1
|
+
{"level":50,"time":1777501046747,"env":"testing","version":"0.0.0-test","pid":87645,"requestId":"0C362-5BC6L","timestamp":"2026-04-29T22:17:26.747Z","operation":"HandleToolRequest","critical":false,"errorCode":-32005,"originalErrorType":"McpError","finalErrorType":"McpError","sessionId":"06197534acbde11d6e26e711be49afbffc20b6a009f7ad4a0f88a0e85af5b057","toolName":"scoped_echo","tenantId":"authz-tenant","auth":{"sub":"authz-user","scopes":["tool:other:read"],"clientId":"authz-client","tenantId":"authz-tenant"},"errorData":{"sessionId":"06197534acbde11d6e26e711be49afbffc20b6a009f7ad4a0f88a0e85af5b057","toolName":"scoped_echo","requestId":"0C362-5BC6L","timestamp":"2026-04-29T22:17:26.747Z","tenantId":"authz-tenant","operation":"HandleToolRequest","auth":{"sub":"authz-user","scopes":["tool:other:read"],"clientId":"authz-client","tenantId":"authz-tenant"},"originalErrorName":"McpError","originalMessage":"Insufficient permissions.","originalStack":"McpError: Insufficient permissions.\n at forbidden (/Users/casey/Developer/github/mcp-ts-core/dist/types-global/errors.js:84:58)\n at withRequiredScopes (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/auth/lib/authUtils.js:61:15)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/tools/utils/toolHandlerFactory.js:133:17)\n at executeToolHandler (/Users/casey/Developer/github/mcp-ts-core/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js:231:34)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js:126:43)\n at processTicksAndRejections (native:7:39)"},"stack":"McpError: Insufficient permissions.\n at handleError (/Users/casey/Developer/github/mcp-ts-core/dist/utils/internal/error-handler/errorHandler.js:169:23)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/tools/utils/toolHandlerFactory.js:168:26)\n at executeToolHandler (/Users/casey/Developer/github/mcp-ts-core/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js:231:34)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js:126:43)\n at processTicksAndRejections (native:7:39)","msg":"Error in tool:scoped_echo: Insufficient permissions."}
|
|
2
|
+
{"level":50,"time":1777501047384,"env":"testing","version":"0.8.6","pid":87649,"requestId":"HGVJ8-F7EK7","timestamp":"2026-04-29T22:17:27.383Z","operation":"httpErrorHandler","critical":false,"errorCode":-32006,"originalErrorType":"McpError","finalErrorType":"McpError","path":"/mcp","method":"POST","errorData":{"path":"/mcp","method":"POST","requestId":"HGVJ8-F7EK7","timestamp":"2026-04-29T22:17:27.383Z","operation":"httpErrorHandler","originalErrorName":"McpError","originalMessage":"Missing or invalid Authorization header. Bearer scheme required.","originalStack":"McpError: Missing or invalid Authorization header. Bearer scheme required.\n at unauthorized (/Users/casey/Developer/github/mcp-ts-core/dist/types-global/errors.js:86:61)\n at authMiddleware (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/auth/authMiddleware.js:64:19)\n at dispatch (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/compose.js:22:23)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/http/httpTransport.js:232:22)\n at dispatch (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/compose.js:22:23)\n at cors2 (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/middleware/cors/index.js:82:11)\n at processTicksAndRejections (native:7:39)"},"stack":"McpError: Missing or invalid Authorization header. Bearer scheme required.\n at handleError (/Users/casey/Developer/github/mcp-ts-core/dist/utils/internal/error-handler/errorHandler.js:169:23)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/http/httpErrorHandler.js:59:39)\n at dispatch (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/compose.js:26:25)\n at processTicksAndRejections (native:7:39)","msg":"Error in httpTransport: Missing or invalid Authorization header. Bearer scheme required."}
|
|
3
|
+
{"level":50,"time":1777501047397,"env":"testing","version":"0.8.6","pid":87649,"requestId":"W6P3E-BGMMZ","timestamp":"2026-04-29T22:17:27.397Z","operation":"httpErrorHandler","critical":false,"errorCode":-32006,"originalErrorType":"McpError","finalErrorType":"McpError","path":"/mcp","method":"POST","errorData":{"path":"/mcp","method":"POST","requestId":"W6P3E-BGMMZ","timestamp":"2026-04-29T22:17:27.397Z","operation":"httpErrorHandler","originalErrorName":"McpError","originalMessage":"Token has expired.","originalStack":"McpError: Token has expired.\n at unauthorized (/Users/casey/Developer/github/mcp-ts-core/dist/types-global/errors.js:86:61)\n at handleJoseVerifyError (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/auth/lib/claimParser.js:56:11)\n at verify (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/auth/strategies/jwtStrategy.js:91:13)\n at processTicksAndRejections (native:7:39)"},"stack":"McpError: Token has expired.\n at handleError (/Users/casey/Developer/github/mcp-ts-core/dist/utils/internal/error-handler/errorHandler.js:169:23)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/http/httpErrorHandler.js:59:39)\n at dispatch (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/compose.js:26:25)\n at processTicksAndRejections (native:7:39)","msg":"Error in httpTransport: Token has expired."}
|
|
4
|
+
{"level":50,"time":1777501047400,"env":"testing","version":"0.8.6","pid":87649,"requestId":"AN6ZH-0RBVB","timestamp":"2026-04-29T22:17:27.400Z","operation":"httpErrorHandler","critical":false,"errorCode":-32006,"originalErrorType":"McpError","finalErrorType":"McpError","path":"/mcp","method":"GET","errorData":{"path":"/mcp","method":"GET","requestId":"AN6ZH-0RBVB","timestamp":"2026-04-29T22:17:27.400Z","operation":"httpErrorHandler","originalErrorName":"McpError","originalMessage":"Missing or invalid Authorization header. Bearer scheme required.","originalStack":"McpError: Missing or invalid Authorization header. Bearer scheme required.\n at unauthorized (/Users/casey/Developer/github/mcp-ts-core/dist/types-global/errors.js:86:61)\n at authMiddleware (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/auth/authMiddleware.js:64:19)\n at dispatch (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/compose.js:22:23)\n at dispatch (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/compose.js:22:23)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/http/httpTransport.js:232:22)\n at dispatch (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/compose.js:22:23)\n at cors2 (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/middleware/cors/index.js:82:11)\n at processTicksAndRejections (native:7:39)"},"stack":"McpError: Missing or invalid Authorization header. Bearer scheme required.\n at handleError (/Users/casey/Developer/github/mcp-ts-core/dist/utils/internal/error-handler/errorHandler.js:169:23)\n at <anonymous> (/Users/casey/Developer/github/mcp-ts-core/dist/mcp-server/transports/http/httpErrorHandler.js:59:39)\n at dispatch (/Users/casey/Developer/github/mcp-ts-core/node_modules/hono/dist/compose.js:26:25)\n at processTicksAndRejections (native:7:39)","msg":"Error in httpTransport: Missing or invalid Authorization header. Bearer scheme required."}
|