@procedures/mcp-server 0.13.2 → 0.14.1
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 +78 -0
- package/README.md +100 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/face.d.ts +20 -1
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +49 -3
- package/dist/face.js.map +1 -1
- package/dist/host.d.ts +64 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +73 -11
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/tasks.d.ts +131 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +276 -0
- package/dist/tasks.js.map +1 -0
- package/dist/transport/guard.d.ts +61 -0
- package/dist/transport/guard.d.ts.map +1 -0
- package/dist/transport/guard.js +58 -0
- package/dist/transport/guard.js.map +1 -0
- package/dist/transport/http.d.ts +17 -2
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +157 -37
- package/dist/transport/http.js.map +1 -1
- package/dist/transport/mcp-transport.d.ts +19 -0
- package/dist/transport/mcp-transport.d.ts.map +1 -1
- package/dist/transport/mcp-transport.js +194 -76
- package/dist/transport/mcp-transport.js.map +1 -1
- package/dist/types.d.ts +43 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/face.ts +82 -4
- package/src/host.ts +133 -21
- package/src/index.ts +23 -1
- package/src/tasks.ts +318 -0
- package/src/transport/guard.ts +90 -0
- package/src/transport/http.ts +164 -36
- package/src/transport/mcp-transport.ts +213 -82
- package/src/types.ts +44 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,83 @@
|
|
|
1
1
|
# @procedures/mcp-server
|
|
2
2
|
|
|
3
|
+
## 0.14.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 85999c1: MCP tasks and the guards of the HTTP face (CLI-35).
|
|
8
|
+
|
|
9
|
+
- A procedure with `metadata.taskSupport` (`"optional"` or `"required"`) can run as an MCP task. `@procedures/mcp` gives it in the tool definition as `execution.taskSupport`, and exports `taskSupportOf`.
|
|
10
|
+
- `createMcpHost` and `McpServerTransport` take the option `tasks`: a store (`McpTaskStore`), or the options of a new store (`maxRunning`, `ttl`). The host shares one store with each face, and `host.tasks` gives it. A task holds its place in the limit until its procedure returns, also after a cancel. A task above the limit starts and then fails at once with the reason, and the store keeps it for 1 minute. The time to keep a task starts when the task ends, and each session keeps at most 100 tasks. A cancel aborts `ctx.signal` of the procedure. The close of a session and the stop of the host cancel their tasks. Without the option `tasks`, the tools do not change.
|
|
11
|
+
- The checks of a request to the Streamable HTTP face are in one function, `guardMcpRequest`, with the browser checks and `tokenMatches` of the core. A 401 now has a `WWW-Authenticate` header. The package also exports `assertLoopbackBind`, for the owner of a listener.
|
|
12
|
+
- The HTTP face takes `allowedHosts`, `maxSessions` and `maxBodyBytes`. `createMcpHost` and `mcpFace` give the face `browser.allowedHosts` of the policy, so a host of that list can reach the endpoint. Before, the face refused it. Thus a policy with `allowedHosts: "*"` now also turns off the DNS-rebinding check of the face, as it does for the other faces.
|
|
13
|
+
- `maxSessions` has no default: the sessions have no limit, as before. With it, a new session above the limit closes the session that was idle longest (no task in progress and no open response), and when each session is busy, the new session gets 503 with `Retry-After`.
|
|
14
|
+
- `maxBodyBytes` (4 MiB by default, the limit of the SDK) applies to each request of the face.
|
|
15
|
+
- The state of an HTTP face (`getState()`, and `host.state().faces`) gives `sessions`, the count of its open sessions.
|
|
16
|
+
- `@procedures/client/node` exports `readJsonBody` and `BodyError`: the procedure handler and the MCP face read a JSON body with this one function.
|
|
17
|
+
|
|
18
|
+
One default of the Streamable HTTP face changes: only an `initialize` request starts a session. Before, a POST without a session id made a new MCP server, and then the SDK refused the request with 400 ("Server not initialized"). Now the face refuses it with 400 before it makes a server, so a stray request uses no memory. This agrees with the MCP specification, and a caller sees the same status. When the SDK refuses an `initialize` (for example 406), the face now closes the server of that request.
|
|
19
|
+
- 5efe2d2: New: the option `narrowing` of `mcpFace()` (CLI-43). The option gives each call of the face a narrower capability, as a `CapabilityRequest` or a list of them. The face adds it as one more source of the narrowing key (`procedure-narrowing`, CLI-30), so the server applies the meet of all the sources. A narrowing can only narrow: a part that asks for more than the policy of the host gives has no effect. The face lists only the tools that the narrowed capability permits. Thus `mcpFace({ narrowing: { effects: { writes: [] } } })` is a read-only MCP face on the port of the host, as `mark mcp --read-only` is over stdio. A narrowing that is not valid stops the factory with an error. Without the option, the face does not change.
|
|
20
|
+
- a96c870: The MCP hosts run under `run()` of `@mark1russell7/service` (CLI-11, step 1).
|
|
21
|
+
|
|
22
|
+
- `McpHost.declare(svc)` gives an MCP host to a service. The server of the host is a transport part, and each storage is a dependency. A host with a stdio face declares the trigger `stdin-close`. Then the runner starts the host and stops it in stages.
|
|
23
|
+
- `McpHost.handleHttp(req, res)` answers for the Streamable HTTP face with `mount: true`. Mount it on a listener, for example an `httpTransport` of `@mark1russell7/service/http`.
|
|
24
|
+
- `runDevToolsServer()` of `@procedures/mcp-dev-tools` runs the dev-tools server under `run()`. Over stdio, the profile is `ephemeral`, and the end of the input stops the server. With HTTP, the profile is `localDev`, and a listener of the service answers at `/mcp`. `dist/server.js` and `mark mcp` use it.
|
|
25
|
+
|
|
26
|
+
PATCH: each change adds a function or an option, and the old ones still operate.
|
|
27
|
+
|
|
28
|
+
Deprecated, and the next MINOR removes them (decision D13):
|
|
29
|
+
|
|
30
|
+
- The listener of the Streamable HTTP face: the options `port`, `host` and `server` of `HttpTransportOptions`, and `McpHttpTransport.listen()`. Give `mount: true`, and mount `McpHost.handleHttp` on a listener of the service.
|
|
31
|
+
- `startDevToolsServer()` of `@procedures/mcp-dev-tools`. Use `runDevToolsServer()`.
|
|
32
|
+
|
|
33
|
+
Migration for the next MINOR: the site uses none of them. MiniMongo uses none of them. Graph mounts `mcpFace()` on its host, and its stdio host keeps `createMcpHost()` with `stdio`: no change. jarvis uses `createMcpHost()` with stdio and SDK faces: no change. A host with `faces.http: { port }` moves to `faces.http: { mount: true }` and a listener of the service.
|
|
34
|
+
- Updated dependencies [85999c1]
|
|
35
|
+
- Updated dependencies [fc968f6]
|
|
36
|
+
- Updated dependencies [dc7a462]
|
|
37
|
+
- Updated dependencies [e091108]
|
|
38
|
+
- Updated dependencies [073e4c3]
|
|
39
|
+
- Updated dependencies [6969637]
|
|
40
|
+
- @procedures/mcp@0.14.1
|
|
41
|
+
- @procedures/client@0.14.1
|
|
42
|
+
|
|
43
|
+
## 0.14.0
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 217a90f: From 0.14.0, a call that the shutdown cuts ends with `UNAVAILABLE` and `retryable: false` when the call can have had its effect. Before, it ended with `INTERNAL_ERROR` (server stack CLI-48). This is true before and after the first item. This change is a break of the server stack, thus it is its own MINOR (decision D13). No 0.13 release marks the old code as deprecated, because no host relies on it.
|
|
48
|
+
|
|
49
|
+
The error registry gives `INTERNAL_ERROR` to a bug of the server, with the severity `CRITICAL`. A cut is not a bug: the server stopped. Thus an alert on `INTERNAL_ERROR` does not fire at each deploy that cuts a write. The code tells why the call ended, and the flag `retryable` tells if a retry is safe.
|
|
50
|
+
|
|
51
|
+
The behavior that changes:
|
|
52
|
+
|
|
53
|
+
- `createProcedureHost()` of `@procedures/peer`: each cut has the code `UNAVAILABLE`. This is the same on HTTP, WebSocket and MCP.
|
|
54
|
+
- A cut after the first item ends the stream in-band. A cut before the first item is the answer of the call. Before, a cut of a call that can have had its effect had the code `INTERNAL_ERROR` in the two cases.
|
|
55
|
+
- The flag `retryable` of a cut comes from the operation of the call. It is false for a call that can have had its effect (the operation `once`), and true for a repeatable call.
|
|
56
|
+
- `procedureHandler()` of `@procedures/client`: a handler error with `retryable: false` gets the HTTP status 500, not 503. A 503 invites a retry at the HTTP level (decision D3). Thus a cut before the first item of a call that can have had its effect is 500 with `UNAVAILABLE`, with no `Retry-After`. A retryable cut stays 503.
|
|
57
|
+
- `ProcedureServer` of `@procedures/client`: a handler error without a retryable flag gets the flag of its code in `ERROR_CODES`. Before, it got false. Thus `UNAVAILABLE` without a flag is retryable, and it keeps the HTTP status 503.
|
|
58
|
+
- The close of each face and of each listener of the host first waits until each answer that a face ended has gone out. It waits for the event `finish` of each ended response, and for the write callback of each upgraded socket. Thus the close of the transports does not lose the answer of a call that the deadline of the drain cuts. An open stream that is not ended does not hold the close.
|
|
59
|
+
- The WebSocket face keeps its connections open after the cooperative abort of the drain, until each cut call ends in-band. Before, the connections closed at the abort, and a cut call lost its end.
|
|
60
|
+
- `@procedures/mcp-server`: the error result of a failed stream has `_meta` with `code` and `retryable`. The error result of a failed call also has `retryable` in `_meta`. These fields are new.
|
|
61
|
+
|
|
62
|
+
The behavior that does not change:
|
|
63
|
+
|
|
64
|
+
- A real failure of a handler keeps its own code, for example `INTERNAL_ERROR` or `HANDLER_ERROR`.
|
|
65
|
+
- A refusal at the stop of the intake stays `UNAVAILABLE`, 503 and retryable.
|
|
66
|
+
- The retry middleware reads the flag `retryable`, not the code. Thus it does not retry a cut of a call that can have had its effect.
|
|
67
|
+
|
|
68
|
+
Migration steps:
|
|
69
|
+
|
|
70
|
+
- A caller that finds a cut by the code `INTERNAL_ERROR`: look for `UNAVAILABLE` in its place. Do not retry the call when `retryable` is false.
|
|
71
|
+
- A handler that throws `UNAVAILABLE` with `retryable: false`: its HTTP status is 500 in place of 503. Without the flag, the error is retryable and gets 503. A retry middleware then sends the call again, so give `retryable: false` when the call can have had its effect.
|
|
72
|
+
- The site: no change is necessary. Its code does not read the code of a cut, or the HTTP status 503.
|
|
73
|
+
- MiniMongo: no change is necessary. Its code does not read `INTERNAL_ERROR`, `UNAVAILABLE` or the severity of an error.
|
|
74
|
+
- The procedures host of Graph (GRAPH-11): no change is necessary. Its code does not read `INTERNAL_ERROR`. Its error "the server has no AGENT_TOKEN" is `UNAVAILABLE` with `retryable: false`, so its HTTP status is 500 in place of 503. No code of Graph reads that status.
|
|
75
|
+
- jarvis: no change is necessary. Its drain test already expects `UNAVAILABLE` with `retryable: false` for a cut procedure call (S6 A12). Its code reads only `NOT_FOUND` and `FORBIDDEN`.
|
|
76
|
+
- The `mark` CLI and `procedure-server`: no change is necessary. The lifecycle test of CI-2 expects `UNAVAILABLE` for the cut of `lifecycle.ticksOnce`.
|
|
77
|
+
- Updated dependencies [217a90f]
|
|
78
|
+
- @procedures/client@0.14.0
|
|
79
|
+
- @procedures/mcp@0.14.0
|
|
80
|
+
|
|
3
81
|
## 0.13.2
|
|
4
82
|
|
|
5
83
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -15,11 +15,14 @@
|
|
|
15
15
|
- [Install](#install)
|
|
16
16
|
- [Start a host](#start-a-host)
|
|
17
17
|
- [The faces](#the-faces)
|
|
18
|
+
- [A host under the runner](#a-host-under-the-runner)
|
|
18
19
|
- [Questions to the person](#questions-to-the-person)
|
|
19
20
|
- [Progress and cancel](#progress-and-cancel)
|
|
21
|
+
- [Tasks](#tasks)
|
|
20
22
|
- [Text from outside the host](#text-from-outside-the-host)
|
|
21
23
|
- [The result of a tool](#the-result-of-a-tool)
|
|
22
24
|
- [The transport](#the-transport)
|
|
25
|
+
- [The face of a procedures host](#the-face-of-a-procedures-host)
|
|
23
26
|
- [The procedures of this package](#the-procedures-of-this-package)
|
|
24
27
|
- [Set up Claude](#set-up-claude)
|
|
25
28
|
|
|
@@ -101,13 +104,50 @@ Each face is one `McpServerTransport` on the server of the host. A host can have
|
|
|
101
104
|
|---|---|
|
|
102
105
|
| `stdio: true` | The standard input and output. Over stdio, `console.log` writes to stderr from `start()` on, because stdout carries the protocol. |
|
|
103
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. |
|
|
104
|
-
| `http: {
|
|
107
|
+
| `http: { mount: true, 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. |
|
|
108
|
+
| `http: { port, host, path, token, allowedOrigins }` | Deprecated. The face has a listener of its own, on `127.0.0.1` by default. The next MINOR removes it (CLI-11). |
|
|
105
109
|
| `sdk` | One or more MCP SDK transports, for example the `InMemoryTransport` of a test. |
|
|
106
110
|
|
|
107
|
-
When the client closes the input of stdio, the host stops, and `closed` resolves.
|
|
111
|
+
When the client closes the input of stdio, the host stops, and `closed` resolves.
|
|
108
112
|
|
|
109
113
|
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 comes from this process and has no credentials.
|
|
110
114
|
|
|
115
|
+
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.
|
|
116
|
+
|
|
117
|
+
- 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.
|
|
118
|
+
- With a token, each request sends `Authorization: Bearer <token>`. 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.
|
|
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`).
|
|
120
|
+
- The sessions have no limit by default. With `maxSessions`, 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
|
+
- `assertLoopbackBind(host, allowRemote)` refuses a listener on an address that is not loopback, unless `allowRemote` is true.
|
|
122
|
+
|
|
123
|
+
## A host under the runner
|
|
124
|
+
|
|
125
|
+
`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.
|
|
126
|
+
|
|
127
|
+
- The server of the host is the transport part `mcp`. Each storage of the server is a dependency.
|
|
128
|
+
- A host with a stdio face declares the trigger `stdin-close`. The end of the input starts the stop in stages, and the face does not stop the host by itself.
|
|
129
|
+
- The HTTP face (`mount: true`) has no listener. Mount `host.handleHttp` on an `httpTransport` of `@mark1russell7/service/http`, and declare that transport on the service.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { createServer } from "node:http";
|
|
133
|
+
import { ephemeral, localDev, service } from "@mark1russell7/service";
|
|
134
|
+
import { httpTransport } from "@mark1russell7/service/http";
|
|
135
|
+
|
|
136
|
+
// Over stdio: the profile ephemeral and the trigger stdin-close
|
|
137
|
+
const stdioHost = createMcpHost({ registry, faces: { stdio: true } });
|
|
138
|
+
await stdioHost.declare(service("my-mcp").profile(ephemeral)).run();
|
|
139
|
+
|
|
140
|
+
// Over Streamable HTTP: a listener of the service, and the face at /mcp on it
|
|
141
|
+
const httpHost = createMcpHost({ registry, policy: { token }, faces: { http: { mount: true } } });
|
|
142
|
+
const listener = httpTransport(createServer(), knobs, { listen: { port: 3003, host: "127.0.0.1" } });
|
|
143
|
+
listener.mount((req, res) => httpHost.handleHttp(req, res));
|
|
144
|
+
const svc = httpHost.declare(service("my-mcp").profile(localDev));
|
|
145
|
+
svc.server("my-mcp.listen", listener.knobs, listener);
|
|
146
|
+
await svc.run();
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The `localDev` profile has no policies of readiness, liveness and startup. Declare them on the service before `run()`. The dev-tools server of `@procedures/mcp-dev-tools` (`runDevToolsServer()`) is an example of each mode.
|
|
150
|
+
|
|
111
151
|
## Questions to the person
|
|
112
152
|
|
|
113
153
|
A procedure can ask the person at the caller for input or a confirmation during a call. MCP elicitation is one face that answers. The shape is not specific to MCP: another face (a terminal) can answer the same questions.
|
|
@@ -185,6 +225,34 @@ handler: async (input, ctx) => {
|
|
|
185
225
|
- A stream does not need it: the face gives each item of a stream as progress. When the procedure of a stream uses `ctx.progress`, the face gives only those updates.
|
|
186
226
|
- When the client cancels a call (`notifications/cancelled`), `ctx.signal` of the procedure aborts.
|
|
187
227
|
|
|
228
|
+
## Tasks
|
|
229
|
+
|
|
230
|
+
A long call can run as an MCP task (MCP 2025-11-25). The client gets a task at once, polls its status, gets the result later, and can cancel the task. Two parts turn it on:
|
|
231
|
+
|
|
232
|
+
- The procedure declares it in its metadata: `taskSupport: "optional"` (a task or a normal call) or `taskSupport: "required"` (only a task).
|
|
233
|
+
- The host has a task store: the option `tasks`.
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
const crawlSite = createProcedure()
|
|
237
|
+
.path(["crawl", "site"])
|
|
238
|
+
.meta({ description: "Crawl a site", effects: { reads: ["net"], writes: ["store"] }, taskSupport: "optional" })
|
|
239
|
+
// input, output and handler as for each procedure
|
|
240
|
+
.build();
|
|
241
|
+
|
|
242
|
+
const host = createMcpHost({ modules: [crawlModule], tasks: { maxRunning: 4 } });
|
|
243
|
+
await host.start();
|
|
244
|
+
host.tasks?.running(); // the tasks that did not end, for a status page
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
- The tool list gives `execution.taskSupport` of each such tool. Without the option `tasks`, the list does not give it, and each call is a normal request.
|
|
248
|
+
- A progress of the procedure becomes the status message of its task, for example `2 of 5 done`. The message holds only the counts, so no text of the work leaves its envelopes. A client that sent a progress token also gets the progress notifications.
|
|
249
|
+
- A cancel of the task (`tasks/cancel`) aborts `ctx.signal` of the procedure. The close of a session cancels its tasks, and the stop of the host cancels each task.
|
|
250
|
+
- The store runs at most `maxRunning` tasks at one time (8 by default). A task holds its place until its procedure returns, also after a cancel. A task above the limit starts, and then fails at once. The result of the task gives the reason. (The SDK 1.32.1 cannot give an error for a task request.)
|
|
251
|
+
- The time to keep a task (`ttl`) starts when the task ends. The store does not remove a task whose procedure still runs.
|
|
252
|
+
- The call of a task cannot ask the person: the procedure gets no `ctx.elicit`.
|
|
253
|
+
- A normal call of an optional tool runs in the request, with the progress and the cancel of the request. A normal call of a tool with `taskSupport: "required"`, or a task for a tool without task support, gets the error `-32601`.
|
|
254
|
+
- To share one store with other parts, give `tasks: { store: new McpTaskStore({ maxRunning: 4 }) }`. The host closes only a store that it made.
|
|
255
|
+
|
|
188
256
|
## Text from outside the host
|
|
189
257
|
|
|
190
258
|
A procedure that gives text from outside the host (a web page, a mail) declares the fields of its output that hold it. Then a model gets that text apart from the data, as data and not as instructions.
|
|
@@ -215,7 +283,7 @@ createProcedure()
|
|
|
215
283
|
- The hints of a tool (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) come from the declared `effects` of its procedure.
|
|
216
284
|
- `metadata.toolHints` of a procedure can make its tool look more dangerous than its effects. Refer to [Hint overrides](#hint-overrides).
|
|
217
285
|
- `metadata.title` of a procedure gives the `title` of its tool.
|
|
218
|
-
- A failed call gives `isError` with the code and the reason in `_meta`.
|
|
286
|
+
- A failed call gives `isError` with the code, the flag `retryable` and the reason in `_meta`. A failed stream gives its code and its flag too (CLI-48).
|
|
219
287
|
- The host option `content` can give other text blocks for a result that is a value. It gets the tool, the value and the default content, and it gives undefined for the default.
|
|
220
288
|
- The host option `json: "compact"` gives the JSON of the default blocks on one line. Use it in place of a content hook for that change only.
|
|
221
289
|
|
|
@@ -258,6 +326,35 @@ await server.start();
|
|
|
258
326
|
- `transport: "http"` with `httpOptions` gives Streamable HTTP. `sdkTransport` connects an MCP SDK transport.
|
|
259
327
|
- `transport: "sse"` is not implemented.
|
|
260
328
|
|
|
329
|
+
## The face of a procedures host
|
|
330
|
+
|
|
331
|
+
`mcpFace()` gives the MCP face of a procedures host (`createProcedureHost()` of `@procedures/peer`). The face serves Streamable HTTP at a path of a listener of the host, next to the other faces.
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
import { mcpFace } from "@procedures/mcp-server";
|
|
335
|
+
|
|
336
|
+
const faces = {
|
|
337
|
+
http: true,
|
|
338
|
+
mcp: mcpFace({ serverInfo: { name: "graph", version: "0.1.0" } }),
|
|
339
|
+
// A read-only MCP face of the same server
|
|
340
|
+
mcpRead: mcpFace({ path: "/mcp-read", serverInfo: { name: "graph", version: "0.1.0" }, narrowing: { effects: { writes: [] } } }),
|
|
341
|
+
};
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
| Option | Default | Function |
|
|
345
|
+
|---|---|---|
|
|
346
|
+
| `path` | `/mcp` | The path of the endpoint. |
|
|
347
|
+
| `token` | the token of the policy | The token that each request sends as `Authorization: Bearer <token>`. |
|
|
348
|
+
| `allowedOrigins` | the origins of the policy | The browser origins that can send requests to the endpoint. |
|
|
349
|
+
| `narrowing` | none | A narrower capability for each call of the face, as a `CapabilityRequest` or a list of them. |
|
|
350
|
+
|
|
351
|
+
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.
|
|
352
|
+
|
|
353
|
+
- The read-only mode is `{ effects: { writes: [] } }`. The face then lists and starts only the tools that change nothing, as `mark mcp --read-only` does.
|
|
354
|
+
- A narrowing can only narrow. A part that asks for more than the policy gives has no effect.
|
|
355
|
+
- The face lists only the tools that the narrowed capability permits. The time of a narrowing limits each call, not the tools.
|
|
356
|
+
- A narrowing that is not valid stops the factory with an error. Examples are an unknown field and a clearance outside the order of the policy.
|
|
357
|
+
|
|
261
358
|
## The procedures of this package
|
|
262
359
|
|
|
263
360
|
| Procedure | Function |
|