@procedures/mcp-server 0.24.1 → 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,16 +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").
140
- *
141
- * @deprecated The flag false for an error without a flag before the first item of the stream is
142
- * deprecated (D13). From the next MINOR of the client group (CLI-68), that error gets the flag of
143
- * its code in `ERROR_CODES`. After the first item, the flag stays false.
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").
144
141
  */
145
- function streamErrorMeta(error: unknown): { code: string; retryable: boolean } {
146
- const { code, retryable } = (error ?? {}) as { code?: unknown; retryable?: unknown };
147
- 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) };
148
145
  }
149
146
 
150
147
  /** The text of a value: a string as it is, another value as JSON (pretty, or compact on one line). */
@@ -544,8 +541,9 @@ export class McpServerTransport implements ServerTransport {
544
541
  } catch (error) {
545
542
  blocks.push({ type: "text", text: error instanceof Error ? error.message : String(error) });
546
543
  // The code and the retryable flag of the end travel on each face: a stream that the
547
- // shutdown cuts ends with UNAVAILABLE (CLI-48)
548
- 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) };
549
547
  }
550
548
  if (count > MAX_STREAM_BLOCKS) {
551
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) */