@casys/mcp-server 0.22.0 → 0.23.0

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/src/types.ts CHANGED
@@ -152,12 +152,111 @@ export interface McpAppOptions {
152
152
  * - `"stateless"`: per-request transport, spec 2026-07-28. No handshake, no
153
153
  * `Mcp-Session-Id`. `protocolVersion` is read from
154
154
  * `params._meta["io.modelcontextprotocol/protocolVersion"]` on every
155
- * request. `GET /mcp` returns 405 (Track B will replace the SSE channel).
155
+ * request. `GET /mcp` returns 405 (Track G replaces the SSE channel with
156
+ * `subscriptions/listen`).
157
+ *
158
+ * The mode does **not** gate the spec-2026-07-28 result envelope — the
159
+ * negotiated version does. `"stateless"` also accepts `2025-06-18` and
160
+ * `2025-11-25`, and a peer on one of those gets the legacy shape over this same
161
+ * transport. `"stateful"` advertises `2025-06-18` and negotiates nothing
162
+ * per-request, so it never carries the envelope.
156
163
  *
157
164
  * Default: `"stateful"`.
158
165
  */
159
166
  // Track A — transport mode, défaut "stateful"
160
167
  transport?: "stateful" | "stateless";
168
+
169
+ /**
170
+ * Cache hints emitted on list and read results (spec 2026-07-28,
171
+ * `CacheableResult`, SEP-2549).
172
+ *
173
+ * `ttlMs` and `cacheScope` are **required** fields of those results, so the
174
+ * framework always emits them. The defaults are deliberately inert:
175
+ *
176
+ * - `ttlMs: 0` — "revalidate every time", the HTTP `max-age=0` equivalent.
177
+ * Caching is a per-deployment decision: a server whose tool list is built
178
+ * from a live database must not have a stale window chosen for it. Opt in
179
+ * with a real value.
180
+ * - `cacheScope: "private"` — shared intermediaries must not cache the
181
+ * response. Anything else would be unsafe by default here, since results can
182
+ * be scoped to the authenticated principal or tenant. Use `"public"` only for
183
+ * a server whose lists are genuinely identical for every caller.
184
+ */
185
+ cache?: {
186
+ /** Freshness window in milliseconds. Default `0`. */
187
+ ttlMs?: number;
188
+ /** Whether shared caches may store the response. Default `"private"`. */
189
+ scope?: "public" | "private";
190
+ };
191
+
192
+ /**
193
+ * Authorization key a task is bound to, derived from the request that created it.
194
+ *
195
+ * A task can only be read, answered or cancelled by a caller whose key matches.
196
+ * The default is the authenticated subject, which is right for a
197
+ * single-authority deployment and **not enough** for anything that authorizes on
198
+ * more than identity: a tenant-scoped server where the same subject may act for
199
+ * several tenants needs the tenant in the key, or a task created under one
200
+ * tenant stays reachable from another.
201
+ *
202
+ * The framework cannot derive that itself — tenancy lives in a consumer's own
203
+ * middleware — so it is a hook rather than a guess. Return a stable string; it is
204
+ * compared verbatim.
205
+ *
206
+ * **It must derive everything from its two arguments.** `tasks/*` requests do
207
+ * not run the middleware pipeline, so anything a middleware injects into the
208
+ * pipeline context — the built-in tenant middleware's `tenantId`, for instance —
209
+ * is NOT visible here. Read the header, or resolve it yourself; the hook may be
210
+ * async precisely so a lookup is possible. A hook that expects pipeline state
211
+ * silently sees `undefined` on every call, which collapses every caller onto one
212
+ * key.
213
+ *
214
+ * Returning an empty or non-string value is refused rather than accepted, since
215
+ * that is what the obvious implementation yields when the value it reads is
216
+ * absent, and accepting it would share tasks between callers.
217
+ *
218
+ * Called on task creation and on every `tasks/get` / `tasks/update` /
219
+ * `tasks/cancel`. It must return the same key for the same caller across those
220
+ * calls, or the creator stops being able to reach its own task (fail-closed).
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * taskOwnerKey: (authInfo, request) =>
225
+ * `${authInfo?.subject}@${request.headers.get("x-tenant-id")}`
226
+ * ```
227
+ */
228
+ taskOwnerKey?: (
229
+ authInfo: import("./auth/types.js").AuthInfo | undefined,
230
+ request: Request,
231
+ ) => string | Promise<string>;
232
+
233
+ /**
234
+ * Multi Round-Trip Requests (spec 2026-07-28, SEP-2322).
235
+ *
236
+ * Configures how `requestState` is protected when a tool handler asks the
237
+ * client for input mid-call. Only consulted on the stateless transport with a
238
+ * negotiated `2026-07-28`: MRTR replaces the server-initiated request pattern
239
+ * that earlier revisions still use, so it has no meaning on the legacy path.
240
+ *
241
+ * Without `signingKey`, `requestState` travels unprotected and the server logs
242
+ * a warning at startup. That is only acceptable when tampering with it can
243
+ * cause nothing worse than the request failing.
244
+ */
245
+ mrtr?: import("./mrtr/mod.js").MrtrOptions;
246
+
247
+ /**
248
+ * Protocol extensions this server declares (spec 2026-07-28).
249
+ *
250
+ * Keyed by reverse-DNS extension identifier — e.g.
251
+ * `{ "io.modelcontextprotocol/tasks": {} }`. Surfaced under
252
+ * `capabilities.extensions` on `server/discover` and `initialize`, and only
253
+ * when non-empty: an empty object would assert "no extensions supported",
254
+ * which is a claim the framework cannot make on a consumer's behalf.
255
+ *
256
+ * Declaring an extension here does not implement it — it advertises what the
257
+ * consumer has wired up.
258
+ */
259
+ extensions?: Readonly<Record<string, unknown>>;
161
260
  }
162
261
 
163
262
  // ============================================
@@ -473,6 +572,38 @@ export interface ToolHandlerContext {
473
572
  readonly authInfo?: import("./auth/types.js").AuthInfo;
474
573
  readonly clientInfo?: Implementation;
475
574
  readonly clientCapabilities?: ClientCapabilities;
575
+
576
+ /**
577
+ * Answers to a previous `InputRequiredResult`, keyed by the ids the server
578
+ * assigned (spec 2026-07-28 MRTR).
579
+ *
580
+ * Present only on a retry. Read from `params.inputResponses` — a sibling of
581
+ * `_meta`, not a member of it, unlike every other per-request field. Getting
582
+ * that wrong yields a silent `undefined` even when the client sent them.
583
+ */
584
+ readonly inputResponses?: Record<string, unknown>;
585
+
586
+ /**
587
+ * True when the client echoed a `requestState` that passed integrity
588
+ * verification, so the handler may trust this is a legitimate retry of its own
589
+ * earlier request.
590
+ *
591
+ * The token carries no application state — it binds the principal, method,
592
+ * argument digest and expiry. Since the digest guarantees the arguments are
593
+ * byte-identical to the original call, a handler reconstructs its context from
594
+ * those arguments rather than from the token.
595
+ */
596
+ readonly retryVerified?: boolean;
597
+
598
+ /**
599
+ * Log level requested for this call (spec 2026-07-28), read from
600
+ * `params._meta["io.modelcontextprotocol/logLevel"]`.
601
+ *
602
+ * `undefined` means the client requested no logging. A handler **MUST NOT**
603
+ * emit `notifications/message` in that case — the level is not a filter you
604
+ * may default, it is the client's opt-in.
605
+ */
606
+ readonly logLevel?: import("./middleware/types.js").McpLogLevel;
476
607
  }
477
608
 
478
609
  export type ToolHandler = (