@procedures/mcp-server 0.24.0 → 0.25.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.
@@ -32,7 +32,7 @@ import type {
32
32
  Principal,
33
33
  ReportProgress,
34
34
  } from "@procedures/client";
35
- import { LOCAL_CREDENTIALS, NARROWING_METADATA_KEY, PROCEDURE_REGISTRY, addNarrowing, pathToMethod, createElicit, elicitWithPolicy, requestCredentials, untrustedTextsOf } from "@procedures/client";
35
+ import { LOCAL_CREDENTIALS, NARROWING_METADATA_KEY, PROCEDURE_REGISTRY, addNarrowing, pathToMethod, createElicit, elicitWithPolicy, requestCredentials, retryableOf, untrustedTextsOf } from "@procedures/client";
36
36
  import {
37
37
  proceduresToMcpTools,
38
38
  toToolDefinition,
@@ -135,12 +135,13 @@ const MAX_STREAM_BLOCKS = 100;
135
135
  /**
136
136
  * The `_meta` of the error of a stream: its code and its retryable flag, as the error line of
137
137
  * NDJSON and the error frame of WebSocket give them (CLI-48). A code that is not a string gives `HANDLER_ERROR`.
138
- * An error without a flag gets false, not the flag of its code: the end is in-band, and a retry can
139
- * send the items again (CLI-58, `WIRE-PROTOCOL.md`, section "Error codes").
138
+ * `items` is the count of the items before the error. An error without a flag gets the flag of its
139
+ * code before the first item (CLI-68). After the first item, it gets false: a retry can send the
140
+ * items again (CLI-58, `retryableOf`, `WIRE-PROTOCOL.md`, section "Error codes").
140
141
  */
141
- function streamErrorMeta(error: unknown): { code: string; retryable: boolean } {
142
- const { code, retryable } = (error ?? {}) as { code?: unknown; retryable?: unknown };
143
- return { code: typeof code === "string" ? code : "HANDLER_ERROR", retryable: typeof retryable === "boolean" ? retryable : false };
142
+ function streamErrorMeta(error: unknown, items: number): { code: string; retryable: boolean } {
143
+ const code = (error as { code?: unknown } | null | undefined)?.code;
144
+ return { code: typeof code === "string" ? code : "HANDLER_ERROR", retryable: retryableOf(error, items) };
144
145
  }
145
146
 
146
147
  /** The text of a value: a string as it is, another value as JSON (pretty, or compact on one line). */
@@ -540,8 +541,9 @@ export class McpServerTransport implements ServerTransport {
540
541
  } catch (error) {
541
542
  blocks.push({ type: "text", text: error instanceof Error ? error.message : String(error) });
542
543
  // The code and the retryable flag of the end travel on each face: a stream that the
543
- // shutdown cuts ends with UNAVAILABLE (CLI-48)
544
- return { content: blocks, isError: true, _meta: streamErrorMeta(error) };
544
+ // shutdown cuts ends with UNAVAILABLE (CLI-48). Before the first item, an error without a
545
+ // flag gets the flag of its code (CLI-68).
546
+ return { content: blocks, isError: true, _meta: streamErrorMeta(error, count) };
545
547
  }
546
548
  if (count > MAX_STREAM_BLOCKS) {
547
549
  blocks.unshift({ type: "text", text: `(${count} items: the first ${count - MAX_STREAM_BLOCKS} are not shown)` });
package/src/types.ts CHANGED
@@ -60,7 +60,16 @@ export type McpToolContentHook = (result: McpToolContentInput) => McpToolContent
60
60
  export interface HttpTransportOptions {
61
61
  /** The path of the MCP endpoint (default: "/mcp") */
62
62
  path?: string | undefined;
63
- /** A secret that each request must send as `Authorization: Bearer <token>` */
63
+ /**
64
+ * A secret that each request must send as `Authorization: Bearer <token>`. The endpoint
65
+ * compares it itself, next to the token check of the server.
66
+ * @deprecated Give the token to the server: `policy.token` of `createMcpHost()`,
67
+ * `hostPolicy({ token })`, or `new ProcedureServer({ token })`. The server checks it for each
68
+ * request (CLI-2b). From the next MINOR, the endpoint has no token check of its own:
69
+ * `McpServerTransport` throws an error at `start()` for `httpOptions.token`. In `faces.http` of
70
+ * `createMcpHost()`, the token becomes the token of the policy, and a different token of the
71
+ * policy throws an error.
72
+ */
64
73
  token?: string | undefined;
65
74
  /** Browser origins that can call the server, besides loopback origins */
66
75
  allowedOrigins?: string[] | undefined;
@@ -115,7 +124,13 @@ export interface McpServerTransportOptions {
115
124
  */
116
125
  transport?: "stdio" | "sse" | "http";
117
126
 
118
- /** The options of the Streamable HTTP transport. */
127
+ /**
128
+ * The options of the Streamable HTTP transport.
129
+ *
130
+ * Deprecated (CLI-2b): `httpOptions.token`. Give the token to the server of the transport,
131
+ * `new ProcedureServer({ token })`: the server checks it for each request. From the next MINOR,
132
+ * `start()` throws an error for a token in `httpOptions`.
133
+ */
119
134
  httpOptions?: HttpTransportOptions | undefined;
120
135
 
121
136
  /** Procedure registry to use (defaults to PROCEDURE_REGISTRY) */