@procedures/mcp-server 0.26.2 → 0.27.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,70 @@
1
1
  # @procedures/mcp-server
2
2
 
3
+ ## 0.27.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7eac8b5: Each request of each face has one check of its Host header, one check of its origin and one check of its credentials (CLI-2b). Before, the MCP HTTP face compared the token itself, next to the token check of the server. The peer also kept its own token, host and origin functions.
8
+
9
+ MINOR: a breaking change before 1.0. Some refusals of the MCP HTTP face change, and some options of the MCP face stop with an error (decision D13).
10
+
11
+ Added:
12
+
13
+ - `ProcedureServer.admission(credentials)` admits a network request one time. It uses the request hook (`principalOf`), the token check and the authenticate function. It gives the admitted credentials and the principal, or `UNAUTHORIZED` with a message.
14
+ - A call with the admitted credentials gets the principal and the narrowing of the admission. The server does not do its checks again for it. A copy of the admitted credentials goes through the checks.
15
+ - The optional method `admission()` of `RequestHandler`, and the type `Admission`. The handler of a face of `createProcedureHost()` gives `admission()`.
16
+
17
+ Changed:
18
+
19
+ - The MCP HTTP face admits each HTTP request one time with `admission()` of its server. This applies to `initialize`, a tool call, the GET stream and the DELETE of a session.
20
+ - Each tool call of the request uses the admitted credentials.
21
+ - A request that the request hook refuses gets 401 with `WWW-Authenticate` at once. Before, such a client opened a session and listed the tools. Only each tool call got `UNAUTHORIZED`.
22
+ - The request hook operates for each HTTP request of the MCP face, also for a request without a tool call. A tool call adds no operation of the hook.
23
+ - On the MCP HTTP face, the request hook and the authenticate function operate one time for each HTTP request. Their request has an empty method, the id `admission`, no payload and no metadata. Thus a hook must not use the method, the payload or the transport of the request.
24
+ - `admits()` and `identify()` give the same shape of request, with the ids `connection` and `identify`. The doc comments of `PrincipalOf` and `authenticate` tell this.
25
+ - An error of the request hook gives 401 with `UNAUTHORIZED`, as before. The code of the error, for example `UNAVAILABLE`, and its retry flag are not in the answer.
26
+ - A refusal of the token stays 401 with `UNAUTHORIZED`, the same message and the same `WWW-Authenticate` header.
27
+ - The token of `faces.http` of `createMcpHost()` becomes the token of the policy. The server checks it. Two different tokens in the policy and in `faces.http` stop the host with an error.
28
+ - `McpServerTransport` refuses `httpOptions.token` with an error at `start()`. Give the token to the server.
29
+ - `mcpFace({ token })` with a token that is not the token of the policy stops the factory with an error.
30
+ - `mcpFace()` stops with an error for a handler without `admission()` when the policy has a token or a request hook. Thus no request gets to the tools without a check.
31
+ - `guardMcpRequest` does only the browser checks. The option `token` is removed from `McpRequestGuardOptions`.
32
+ - `guardMcpRequest` has no point of creation. Thus the first call with a `token` option throws a `TypeError` that names the migration. Each later call with it gives a refusal with the status 500 and the same message, without an error. Each request stays refused, and the log of the app gets one error.
33
+ - `McpGuardResult.status` can also be 500, with the code `INTERNAL_ERROR`. Before, it was only 401, 403, 405 or 415. A caller that switches on `status` must handle 500.
34
+ - The MCP face takes `browser.allowedOrigins` of the policy as it is: a list, `"*"` or a function. Before, the face took only a list, and it ignored `"*"` and a function.
35
+ - With `"*"`, the MCP face sends no CORS header, as the HTTP face. A request with a cookie still needs a named origin (CSRF).
36
+ - A server with a request hook trusts the cookies of each request by default (`ambientCredentials: "always"`). On such a server, `"*"` permits no other origin, also for a request without a cookie.
37
+ - The peer has no request checks of its own. Its origin rule (a loopback origin, or an origin of the list) is data for the browser checks of the core. The internal file `peer/security.ts` is removed. It was not an export.
38
+
39
+ Deprecated:
40
+
41
+ - `HttpTransportOptions.token` of `@procedures/mcp-server`. Give the token in the policy: `policy.token` of `createMcpHost()`, or `hostPolicy({ token })`.
42
+ - `McpFaceOptions.token`. Give the token only in the policy of the host.
43
+
44
+ Migration:
45
+
46
+ - A host with `faces: { http: { token } }`: no change. To prepare for the removal, move the token to `policy: { token }`.
47
+ - A caller of `new McpServerTransport(server, { httpOptions: { token } })`: give the token to the server, `new ProcedureServer({ token })`. Remove `token` from `httpOptions`.
48
+ - A caller of `guardMcpRequest(req, { token })` for a listener of its own: remove `token`. Then admit each request with `server.admission(credentials)`, and refuse it with 401 when `ok` is false. Until you do this, the first request throws a `TypeError`, and each later request gets 500.
49
+ - A caller of `mcpFace({ token })`: remove `token`, and give it in `hostPolicy({ token })`.
50
+ - A face of your own that gives `mcpFace()` a handler of its own: give the handler `admission: (credentials) => server.admission(credentials)`.
51
+ - An MCP client that a request hook refuses gets 401 at `initialize`. Give it valid credentials for each HTTP request.
52
+ - The site: no change. It has no MCP host, and it used no function of `peer/security.ts`.
53
+ - MiniMongo: no change. Its dev host has only the HTTP and WebSocket faces of `createProcedureHost()`. Each request of these faces had one check before.
54
+ - Graph: its `mcpFace()` on the procedures host uses `graphPrincipalOf` for each HTTP request. In the accounts mode, a request without a session gets `ANONYMOUS`. Thus an MCP client without a session gets no 401 at `initialize`.
55
+ - Graph: in the mode `on` (`AUTH_MODE=on`), a request without a tenant token gets 401 at `initialize`. Before, the client opened a session and listed the tools, and each tool call got `UNAUTHORIZED`.
56
+ - Graph: accounts that are not ready (the error `UNAVAILABLE` of the hook) give 401 at `initialize`, with `WWW-Authenticate: Bearer`. Before, `initialize` passed, and each tool call got `UNAUTHORIZED`. An MCP client can start its OAuth discovery on this 401.
57
+ - Graph: outside the accounts mode, the policy has `allowedOrigins: "*"`. The MCP face takes it, as the HTTP face does. A request with a cookie still needs a named origin. With the default `ambientCredentials: "always"` of its request hook, `"*"` permits no other origin.
58
+ - Graph: to keep only the own origin on the MCP face, give `mcpFace({ allowedOrigins: [] })`. Its MCP host over stdio has no change.
59
+ - jarvis: no change. Its procedures host has only the HTTP face, and its MCP host has only stdio and SDK faces.
60
+ - `mark mcp --http --token` and `@procedures/mcp-dev-tools`: no change for a client. The token is the token of the server, and the server checks each HTTP request one time.
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies [7eac8b5]
65
+ - @procedures/client@0.27.0
66
+ - @procedures/mcp@0.27.0
67
+
3
68
  ## 0.26.2
4
69
 
5
70
  ### Patch Changes
package/README.md CHANGED
@@ -104,18 +104,21 @@ 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. The `token` of the face is deprecated: give it in `policy.token`. |
107
+ | `http: { path, allowedOrigins, allowedHosts, maxSessions, maxBodyBytes }` | Streamable HTTP on a listener of the app. Mount `host.handleHttp` on the listener. The face takes the browser checks of the policy, and the server checks the token of the policy. A deprecated `token` of the face becomes the token of the policy. |
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.
111
111
 
112
- Each tool call over Streamable HTTP carries the credentials of its HTTP request: the bearer token, the cookies, the headers and the query. Thus the request hook of the policy (`principalOf`) and the token check of the server apply to each call. When the server reads cookies, the face trusts a request with a cookie only from a named origin (CSRF). A call over stdio or over a given SDK transport is local: it has the local marker `LOCAL_CREDENTIALS` (CLI-1). The peer of stdio is the parent process. Thus a host with a token serves the calls of its stdio face.
112
+ Each request over Streamable HTTP has one check of its credentials (CLI-2b). The server of the host admits the request one time (`admission()`), with the bearer token, the cookies, the headers and the query of the request. The admission uses the request hook of the policy (`principalOf`), the token check and the authenticate function of the server. Each request gets it: `initialize`, a tool call, the GET stream and the DELETE of a session. Each tool call of the request uses the admitted credentials, so the server does not do its checks again for it.
113
113
 
114
- The Streamable HTTP face checks each request with `guardMcpRequest` before the request reaches the MCP SDK. The owner of another listener calls the same function.
114
+ When the server reads cookies, the face trusts a request with a cookie only from a named origin (CSRF). A call over stdio or over a given SDK transport is local: it has the local marker `LOCAL_CREDENTIALS` (CLI-1). The peer of stdio is the parent process. Thus a host with a token serves the calls of its stdio face.
115
115
 
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
- - 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).
116
+ The Streamable HTTP face checks each request before the request reaches the MCP SDK. The face has no token check of its own.
117
+
118
+ - The browser checks come first, with `guardMcpRequest`. 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 (the default is `browser.allowedOrigins` of the policy).
119
+ - Then the admission of the server checks the credentials. 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 refused request gets 401 with a `WWW-Authenticate` header.
120
+ - The token of a host is the token of its policy. A `token` of the HTTP face of `createMcpHost` becomes the token of the policy, and two different tokens stop the host with an error. `McpServerTransport` refuses a token in its HTTP options: give the token to the server. Refer to [Deprecated token options](#deprecated-token-options).
121
+ - `guardMcpRequest` refuses a `token` option. The first call with it throws a `TypeError` that names the migration. Each later call with it gives a refusal with the status 500, without an error. Thus each request stays refused, and the log gets one error.
119
122
  - 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`).
120
123
  - 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`.
121
124
  - 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.
@@ -123,14 +126,14 @@ The Streamable HTTP face checks each request with `guardMcpRequest` before the r
123
126
 
124
127
  ### Deprecated token options
125
128
 
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.
129
+ The server of the face checks the credentials of each request one time (CLI-2b, decision D13). The face has no token check of its own. The token options of the face have these behaviors:
127
130
 
128
- | Option | From the next MINOR | Replacement |
131
+ | Option | Behavior | Replacement |
129
132
  |---|---|---|
130
133
  | `faces.http.token` of `createMcpHost()` | It becomes the token of the policy. A different token in the policy throws an error. | `policy.token` |
131
134
  | `httpOptions.token` of `McpServerTransport` | `start()` throws an error. | `new ProcedureServer({ token })` |
132
135
  | `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 |
136
+ | `token` of `guardMcpRequest` | The option is removed. The first call with it throws a `TypeError`, and each later call with it gets a refusal with the status 500. The function does only the browser checks. | The token check of the server, and `admission()` of the server for each request |
134
137
 
135
138
  ## A host under the runner
136
139
 
@@ -377,8 +380,8 @@ const faces = {
377
380
  | Option | Default | Function |
378
381
  |---|---|---|
379
382
  | `path` | `/mcp` | The path of the endpoint. |
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). |
381
- | `allowedOrigins` | the origins of the policy | The browser origins that can send requests to the endpoint. |
383
+ | `token` | the token of the policy | Deprecated. The server of the host checks the token of the policy. Another token stops the factory with an error (CLI-2b). Refer to [Deprecated token options](#deprecated-token-options). |
384
+ | `allowedOrigins` | the origins of the policy | The browser origins that can send requests to the endpoint: a list, `"*"` or a function. |
382
385
  | `narrowing` | none | A narrower capability for each call of the face, as a `CapabilityRequest` or a list of them. |
383
386
 
384
387
  The face adds `narrowing` to each call as one more source of the narrowing key (`procedure-narrowing`). Thus the server applies the meet of all the sources: the capability of the policy, the request hook and the key of the caller.