@procedures/mcp-server 0.22.1 → 0.23.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 +38 -0
- package/README.md +19 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +2 -0
- package/dist/face.js.map +1 -1
- package/dist/host.d.ts +3 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tasks.d.ts +84 -8
- package/dist/tasks.d.ts.map +1 -1
- package/dist/tasks.js +136 -27
- package/dist/tasks.js.map +1 -1
- package/dist/transport/mcp-transport.d.ts +8 -1
- package/dist/transport/mcp-transport.d.ts.map +1 -1
- package/dist/transport/mcp-transport.js +23 -4
- package/dist/transport/mcp-transport.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/face.ts +2 -0
- package/src/host.ts +3 -2
- package/src/index.ts +2 -2
- package/src/tasks.ts +170 -30
- package/src/transport/mcp-transport.ts +33 -4
- package/src/types.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @procedures/mcp-server
|
|
2
2
|
|
|
3
|
+
## 0.23.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f20beb1: The task store of an MCP host gives each client a fair share of its tasks (CLI-69). Before, the sessions of one client could fill the store (CLI-51). Then each other client got `TASKS_FULL` until those tasks ended their time.
|
|
8
|
+
|
|
9
|
+
MINOR: a breaking change before 1.0. Near the limit, the store refuses a client with its share or more, also when the store has free slots. Before, the store refused a task only when it was full (decision D13).
|
|
10
|
+
|
|
11
|
+
Changed:
|
|
12
|
+
|
|
13
|
+
- The key of a task (`shareKey`) tells its client. The default `mcpTaskShareKey` gives the principal of the request, else the session. The principal of the host token is the same for each caller, so a request with only the token gets the key of its session.
|
|
14
|
+
- The share of a client is `maxStored / (k + 1)`. `k` is the number of clients with tasks in the store, the new client included.
|
|
15
|
+
- When `reserve` slots or fewer are free, a client with its share or more gets no more tasks. Its new task replaces the oldest task of its session that ended. Without such a task, the request gets the error `-32600` with the code `TASKS_FULL`, as for a full store.
|
|
16
|
+
- A client below its share gets a task while the store has a free slot. Thus one client keeps at most `maxStored - reserve` tasks, also with many sessions.
|
|
17
|
+
- The total limit (`maxStored`, 1000 by default) and the limit of 100 tasks of a session stay as they are.
|
|
18
|
+
|
|
19
|
+
Added:
|
|
20
|
+
|
|
21
|
+
- The options `reserve`, `shareKey` and `clock` of `McpTaskStore`, and of `tasks` of `createMcpHost()` and `mcpFace()`. The default `reserve` is a tenth of `maxStored`, rounded down: 100 of 1000. `reserve: 0` turns the fair share off.
|
|
22
|
+
- `mcpTaskShareKey`, and the types `McpTaskShareContext` and `McpTaskCaller`. `createTask` of the store takes the caller as its fifth argument.
|
|
23
|
+
- `MCP_TASK_LIMITS.reserveDivisor`: 10.
|
|
24
|
+
- `identify(credentials)` of `ProcedureServer`, and the optional `identify` of `RequestHandler`. It gives the principal of a request before a call, from the checks of each call. The face handler of the procedures host and the narrowed handler of `mcpFace()` give it too. The MCP face uses it for the key of a task. Thus the request hook and the authenticate function run one more time for each new task.
|
|
25
|
+
|
|
26
|
+
Migration:
|
|
27
|
+
|
|
28
|
+
- The site and MiniMongo: no change. They have no MCP host.
|
|
29
|
+
- Graph: no change. Its MCP hosts have no task store.
|
|
30
|
+
- jarvis: no change. Its MCP host has no tasks.
|
|
31
|
+
- polite-crawler-mcp: no change. Each request has the host token, so each session is one client. A session with 100 tasks gets fewer tasks only when ten or more sessions are near the limit. To keep the rule of CLI-51, give `new McpTaskStore({ reserve: 0 })`.
|
|
32
|
+
- A host whose clients each have many sessions under one principal: each client keeps at most `maxStored - reserve` tasks. To keep the rule of CLI-51, give `reserve: 0` in `tasks` of the host or in `new McpTaskStore()`.
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [f20beb1]
|
|
37
|
+
- Updated dependencies [71091a5]
|
|
38
|
+
- @procedures/client@0.23.0
|
|
39
|
+
- @procedures/mcp@0.23.0
|
|
40
|
+
|
|
3
41
|
## 0.22.1
|
|
4
42
|
|
|
5
43
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -250,10 +250,29 @@ host.tasks?.running(); // the tasks that did not end, for a status page
|
|
|
250
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. Thus the client gets a task, and the result of the task gives the reason. A full store is different: refer to `maxStored` below.
|
|
251
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
252
|
- The store keeps at most 100 tasks for one session, and at most 1000 tasks for all the sessions together (`maxStored`, CLI-51). A new task removes the oldest task of its own session that ended. The store can be full, and the session can have no task that ended. Then the request of the new task gets the error `-32600`, and the store keeps nothing of it. Thus a client cannot remove the results of another session. `maxStored: Infinity` turns the total limit off.
|
|
253
|
+
- The fair share (CLI-69) keeps one client from the whole store. The store keeps the last `reserve` slots (100 of 1000 by default) for the clients below their share. The rules follow this list.
|
|
254
|
+
- The function `shareKey` gives the client of a task. The default `mcpTaskShareKey` gives the principal of the request, else the session. The token of the host is the same for each caller, so it does not identify a client.
|
|
255
|
+
- The timers of the store use its `clock`. A test gives a fake clock.
|
|
253
256
|
- The call of a task cannot ask the person: the procedure gets no `ctx.elicit`.
|
|
254
257
|
- 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`.
|
|
255
258
|
- To share one store with other parts, give `tasks: { store: new McpTaskStore({ maxRunning: 4 }) }`. The host closes only a store that it made.
|
|
256
259
|
|
|
260
|
+
The fair share applies these rules to a new task of a client:
|
|
261
|
+
|
|
262
|
+
1. The share of the client is `maxStored / (k + 1)`. `k` is the number of clients with tasks in the store, the new client included. The `+ 1` keeps a share for the client that comes next.
|
|
263
|
+
2. When `reserve` slots or fewer are free, a client with its share or more gets no more tasks. Its new task replaces the oldest task of its session that ended. Without such a task, the request gets the error `TASKS_FULL`.
|
|
264
|
+
3. A client below its share gets a task while the store has a free slot.
|
|
265
|
+
|
|
266
|
+
Thus one client keeps at most `maxStored - reserve` tasks, also with many sessions under one principal. A session of another client still gets a task. `reserve: 0` turns the fair share off. The principal comes from `identify` of the handler of the face: the request hook, the token check and the authenticate function of the server.
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
// One key for each tenant: the tasks of all the users of a tenant count as one client
|
|
270
|
+
const host = createMcpHost({
|
|
271
|
+
modules: [crawlModule],
|
|
272
|
+
tasks: { shareKey: ({ principal, sessionId }) => String(principal?.claims?.["tenant"] ?? sessionId ?? "local") },
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
257
276
|
## Text from outside the host
|
|
258
277
|
|
|
259
278
|
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.
|