@procedures/mcp-server 0.24.1 → 0.26.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/CHANGELOG.md CHANGED
@@ -1,5 +1,81 @@
1
1
  # @procedures/mcp-server
2
2
 
3
+ ## 0.26.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a16af64]
8
+ - @procedures/client@0.26.0
9
+ - @procedures/mcp@0.26.0
10
+
11
+ ## 0.25.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 75bff3b: Breaking: an in-band end of a stream before its first item gets the default flag of its code (roadmap CLI-68, decision D25). The release before this one marked the old flag `false` as deprecated (D13).
16
+
17
+ The new behavior:
18
+
19
+ - A handler error without a `retryable` flag that ends a stream before its first item gets the flag of its code in `ERROR_CODES`. Thus `UNAVAILABLE`, `CONNECTION_CLOSED` and `RATE_LIMITED` are retryable there. The other codes stay `false`.
20
+ - This applies on each face: the `error` line of NDJSON, the `error` frame of WebSocket and the `_meta.retryable` of the MCP stream result. The HTTP status of an NDJSON stream stays 200.
21
+ - An error before the stream starts already got this default (CLI-48). Thus a streaming handler and a unary handler that throw the same error before their first item now give the same flag.
22
+ - After the first item, an error without a flag still gets `false` (CLI-58). An error with its own flag keeps it, before and after the first item.
23
+ - The retry middleware of the client retries while no item reached the reader. Thus it now retries a stream that fails with `UNAVAILABLE` before its first item. The caller gets the items of the retry, not the error.
24
+ - A keyed call to a procedure that is not idempotent: a retryable end of its stream lets the next try with the same idempotency key run again. Before, the next try got `DUPLICATE`.
25
+ - Without NDJSON (the last item as JSON), a stream error before the first item gets the flag and the HTTP status of its code, for example 503 for `UNAVAILABLE`. After an item, the flag is `false`, thus 500.
26
+
27
+ What a caller sees:
28
+
29
+ | Stream error without a `retryable` flag | Before | From this release |
30
+ |---|---|---|
31
+ | Before the first item, code `UNAVAILABLE` | `retryable: false`, no retry | `retryable: true`, the retry middleware sends the call again |
32
+ | Before the first item, a code that is not retryable | `retryable: false` | `retryable: false` |
33
+ | After the first item | `retryable: false` | `retryable: false` |
34
+ | A handler gives `retryable: true` or `false` | that flag | that flag |
35
+
36
+ The retry costs time and calls: each try waits for the backoff, and the server gets one more call for each try. A handler with an effect before its error does that effect again on each try.
37
+
38
+ New exports and options:
39
+
40
+ - `retryableOf(error, items)` of `@procedures/client` gives the flag of an error that ends a call, after `items` items. Each face uses it.
41
+ - The `errorOf` option of `writeNdjsonStream` also gets the count of the item lines before the error. A function with one parameter still works.
42
+ - `IdempotencyCache.forget(key, result)` removes the result of a key.
43
+
44
+ The opt-out:
45
+
46
+ - A handler that is not safe to run again gives `retryable: false` in its error. For example, `throw Object.assign(new Error("busy"), { code: "UNAVAILABLE", retryable: false })`.
47
+ - Or the caller does not use the retry middleware for that call. For example, give `shouldRetry` that gives `false` for that method, or set `retry: { maxAttempts: 1 }` in the context of the call.
48
+
49
+ Migration steps:
50
+
51
+ - A streaming handler that throws `UNAVAILABLE`, `CONNECTION_CLOSED` or `RATE_LIMITED` without a flag before its first item: is a second run safe? If not, give `retryable: false`.
52
+ - A test that expects `retryable: false` for such an end before the first item: expect the flag of the code.
53
+ - A custom `errorOf` of `writeNdjsonStream`: read its second parameter to give the same rule.
54
+ - The site: no change is necessary. The lab simulates its server with explicit flags. The streams of the journey do not fail.
55
+ - MiniMongo: no change is necessary. Its browser client has the retry middleware, but its procedures throw no `UNAVAILABLE`, `CONNECTION_CLOSED` or `RATE_LIMITED` without a flag.
56
+ - Graph: no change is necessary. Its handlers give `UNAVAILABLE` with an explicit flag, and it serves no stream procedure of its own.
57
+ - jarvis: no change is necessary. The cuts of its host have their own flag, and it uses no retry middleware.
58
+
59
+ ### Patch Changes
60
+
61
+ - 1d66fae: Deprecated (D13): the token options of the MCP face, and the token check of `guardMcpRequest`. The next MINOR of the client group changes them (roadmap CLI-2b). This release changes no behavior.
62
+
63
+ - After the change, the server of the face checks the credentials of each request one time. The face has no token check of its own.
64
+ - `HttpTransportOptions.token`: give the token to the server, for example `policy.token` of `createMcpHost()`. In `faces.http` of `createMcpHost()`, the token then becomes the token of the policy. A different token in the policy throws an error.
65
+ - `httpOptions.token` of `McpServerTransport`: give the token to the server, `new ProcedureServer({ token })`. After the change, `start()` throws an error for a token in `httpOptions`.
66
+ - `McpFaceOptions.token`: give the token only in `hostPolicy({ token })`. After the change, `mcpFace()` throws an error for a token that is not the token of the policy.
67
+ - `McpRequestGuardOptions.token`: give the token to the server. After the change, the option is removed, and a `token` option throws an error.
68
+ - The token check of `guardMcpRequest`: after the change, the function does only the browser checks. The owner of a listener then admits each request with `admission()` of the server.
69
+ - A token refusal of the server stays 401 with `UNAUTHORIZED` and the `WWW-Authenticate` header.
70
+
71
+ The doc comments of these options, of `guardMcpRequest` and of `McpHostFaces.http` have the deprecation notes. The README of the package has the section "Deprecated token options".
72
+
73
+ `mark mcp --http --token` and `@procedures/mcp-dev-tools`: no change for a client. The site, MiniMongo, Graph and jarvis: no change in this release.
74
+ - Updated dependencies [75bff3b]
75
+ - Updated dependencies [16562ee]
76
+ - @procedures/client@0.25.0
77
+ - @procedures/mcp@0.25.0
78
+
3
79
  ## 0.24.1
4
80
 
5
81
  ### Patch Changes
package/README.md CHANGED
@@ -104,7 +104,7 @@ Each face is one `McpServerTransport` on the server of the host. A host can have
104
104
  |---|---|
105
105
  | `stdio: true` | The standard input and output. Over stdio, `console.log` writes to stderr from `start()` on, because stdout carries the protocol. |
106
106
  | `stdio: { stdin, stdout, stopOnEnd, redirectConsole }` | Other streams, for a test or an embedding. With `stopOnEnd: true` (the default), the host stops when the input ends. |
107
- | `http: { path, token, allowedOrigins, allowedHosts, maxSessions, maxBodyBytes }` | Streamable HTTP on a listener of the app. Mount `host.handleHttp` on the listener. Without a token, the face takes the token of the policy. |
107
+ | `http: { path, token, allowedOrigins, allowedHosts, maxSessions, maxBodyBytes }` | Streamable HTTP on a listener of the app. Mount `host.handleHttp` on the listener. Without a token, the face takes the token of the policy. The `token` of the face is deprecated: give it in `policy.token`. |
108
108
  | `sdk` | One or more MCP SDK transports, for example the `InMemoryTransport` of a test. |
109
109
 
110
110
  When the client closes the input of stdio, the host stops, and `closed` resolves.
@@ -115,11 +115,23 @@ The Streamable HTTP face checks each request with `guardMcpRequest` before the r
115
115
 
116
116
  - A request on a loopback address must name a loopback host, or a host of `allowedHosts` (the default is `browser.allowedHosts` of the policy), in its `Host` header. Thus DNS rebinding cannot reach the tools. An `Origin` header must name the server or a permitted origin.
117
117
  - With a token, each request sends `Authorization: Bearer <token>`. The scheme has any case, for example `bearer` (RFC 7235). The check is `tokenMatches` of the core: its time does not tell the token. A request without the token gets 401 with a `WWW-Authenticate` header.
118
+ - Deprecated (CLI-2b): the token check of the face and of `guardMcpRequest`. Give the token to the server: `policy.token` of `createMcpHost()`, `hostPolicy({ token })` or `new ProcedureServer({ token })`. The server checks it for each request. Refer to [Deprecated token options](#deprecated-token-options).
118
119
  - Only an `initialize` request starts a session. Thus a stray POST makes no MCP server. The body of each request has a limit of 4 MiB (`maxBodyBytes`).
119
120
  - The face keeps at most 256 sessions by default (`maxSessions`, CLI-51). A new session above the limit closes the session that was idle longest: no task in progress and no open response (a call or a GET stream). When each session is busy, the new session gets 503 with a `Retry-After` header. A client that sends to a closed session gets 404, and a client of the MCP specification then sends a new `initialize`.
120
121
  - Each live client of the MCP SDK keeps its GET stream open. Thus the limit does not close the session of a live client, and 256 is much more than the clients of one host. To serve more clients, give a larger `maxSessions`. `maxSessions: Infinity` turns the limit off.
121
122
  - `assertLoopbackBind(host, allowRemote)` refuses a listener on an address that is not loopback, unless `allowRemote` is true.
122
123
 
124
+ ### Deprecated token options
125
+
126
+ The token options of the MCP face are deprecated (CLI-2b, decision D13). This release changes no behavior. From the next MINOR, the server of the face checks the credentials of each request one time. The face then has no token check of its own.
127
+
128
+ | Option | From the next MINOR | Replacement |
129
+ |---|---|---|
130
+ | `faces.http.token` of `createMcpHost()` | It becomes the token of the policy. A different token in the policy throws an error. | `policy.token` |
131
+ | `httpOptions.token` of `McpServerTransport` | `start()` throws an error. | `new ProcedureServer({ token })` |
132
+ | `token` of `mcpFace()` | A token that is not the token of the policy throws an error. | `hostPolicy({ token })` |
133
+ | `token` of `guardMcpRequest` | The option is removed, and a `token` option throws an error. The function does only the browser checks. | The token check of the server, and `admission()` of the server for each request |
134
+
123
135
  ## A host under the runner
124
136
 
125
137
  `host.declare(svc)` gives the host to a service of `@mark1russell7/service` (CLI-11). Then `run()` of the service starts the host, owns the signals, stops the host in stages and ends the process. The host does not start or stop by itself.
@@ -365,7 +377,7 @@ const faces = {
365
377
  | Option | Default | Function |
366
378
  |---|---|---|
367
379
  | `path` | `/mcp` | The path of the endpoint. |
368
- | `token` | the token of the policy | The token that each request sends as `Authorization: Bearer <token>`. |
380
+ | `token` | the token of the policy | The token that each request sends as `Authorization: Bearer <token>`. Deprecated: give the token only in `hostPolicy({ token })`. Refer to [Deprecated token options](#deprecated-token-options). |
369
381
  | `allowedOrigins` | the origins of the policy | The browser origins that can send requests to the endpoint. |
370
382
  | `narrowing` | none | A narrower capability for each call of the face, as a `CapabilityRequest` or a list of them. |
371
383