@mcp-abap-adt/http 0.0.0-stage → 19.0.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/LICENSE +661 -0
- package/README.md +148 -2
- package/bin/mcp-abap-adt-http.js +23 -0
- package/dist/InstancePool.d.ts +127 -0
- package/dist/InstancePool.d.ts.map +1 -0
- package/dist/InstancePool.js +318 -0
- package/dist/InstancePool.js.map +1 -0
- package/dist/StreamableHttpServer.d.ts +160 -0
- package/dist/StreamableHttpServer.d.ts.map +1 -0
- package/dist/StreamableHttpServer.js +403 -0
- package/dist/StreamableHttpServer.js.map +1 -0
- package/dist/config/httpParameters.d.ts +45 -0
- package/dist/config/httpParameters.d.ts.map +1 -0
- package/dist/config/httpParameters.js +143 -0
- package/dist/config/httpParameters.js.map +1 -0
- package/dist/httpVersion.d.ts +11 -0
- package/dist/httpVersion.d.ts.map +1 -0
- package/dist/httpVersion.js +16 -0
- package/dist/httpVersion.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +42 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +132 -0
- package/dist/launcher.js.map +1 -0
- package/package.json +78 -4
package/README.md
CHANGED
|
@@ -1,3 +1,149 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mcp-abap-adt/http
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Streamable HTTP server of MCP ABAP ADT: the binary `mcp-abap-adt-http`, and
|
|
4
|
+
`StreamableHttpServer`, which serves the ADT tools of
|
|
5
|
+
[`@mcp-abap-adt/lib`](https://www.npmjs.com/package/@mcp-abap-adt/lib) over MCP Streamable HTTP on an
|
|
6
|
+
Express app, with DNS rebinding protection and optional TLS. Licensed AGPL-3.0-only.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install -g @mcp-abap-adt/http
|
|
10
|
+
mcp-abap-adt-http --port=3000 --system-type=onprem
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**The binary fixes the tool set (19.0.0).** `mcp-abap-adt-http` serves readonly (with system and search),
|
|
14
|
+
high, the debugger and background runs; the readonly
|
|
15
|
+
tools alone are [`@mcp-abap-adt/http-ro`](https://www.npmjs.com/package/@mcp-abap-adt/http-ro) (`mcp-abap-adt-http-ro`). There is no
|
|
16
|
+
`--exposition`: passing it, or a config file's `exposition`, stops the start with a sentence naming
|
|
17
|
+
the binary to install instead.
|
|
18
|
+
|
|
19
|
+
**No leftover-session tools, no session files (19.0.0).** One server holds the sessions of many
|
|
20
|
+
users, so it writes no runtime session file and serves no leftover-session tool; those are the
|
|
21
|
+
stdio binaries' (`mcp-abap-adt`, `mcp-abap-adt-ro`). Resuming a SAP session here is yours to do if you hold what it takes;
|
|
22
|
+
otherwise SAP ends it on its own timeout, which releases its locks: [MIGRATION-19.0](https://github.com/fr0ster/mcp-abap-adt/blob/main/docs/MIGRATION-19.0.md#stdio-leftover-sap-sessions-of-a-killed-process).
|
|
23
|
+
|
|
24
|
+
**No low set (19.0.0).** `--exposition=…,low` stops the start with this sentence: *"the low set is gone from mcp-abap-adt / -http / -sse; use mcp-abap-adt-compact (or -compact-http / -compact-sse)"*. Its single-step operations are compact's — see [MIGRATION-19.0](https://github.com/fr0ster/mcp-abap-adt/blob/main/docs/MIGRATION-19.0.md#the-low-set-leaves-the-full-binaries).
|
|
25
|
+
|
|
26
|
+
## Credentials: each request's headers, nothing else
|
|
27
|
+
|
|
28
|
+
Every request carries its own credentials, and the server takes them from nowhere else: no
|
|
29
|
+
destination, no service key, no session file, no login, no auth broker.
|
|
30
|
+
|
|
31
|
+
| Header | |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `x-sap-url` | the system's URL (required) |
|
|
34
|
+
| `x-sap-client` | the client (optional) |
|
|
35
|
+
| `x-sap-jwt-token` | a token you hold, presented as a Bearer token |
|
|
36
|
+
| `x-sap-login` + `x-sap-password` | a user and password (basic) |
|
|
37
|
+
|
|
38
|
+
- A request without `x-sap-url` and either a token or a user and password is answered `400`:
|
|
39
|
+
*this server takes credentials only from the request's headers: send x-sap-url with
|
|
40
|
+
x-sap-jwt-token, or with x-sap-login and x-sap-password*. `ping` answers without them.
|
|
41
|
+
- A request carrying `x-mcp-destination` is answered `400`: *destinations are served only by
|
|
42
|
+
mcp-abap-adt (stdio); send x-sap-* headers*. Destinations — service keys, sessions, the browser
|
|
43
|
+
login — are [`@mcp-abap-adt/core`](https://www.npmjs.com/package/@mcp-abap-adt/core)'s, over stdio.
|
|
44
|
+
- Each request builds its own credential and its own connection; nothing is stored, shared or
|
|
45
|
+
cached across requests. The one exception is held state (below): the connections it opened stay
|
|
46
|
+
with it until it ends.
|
|
47
|
+
- The system kind follows `--system-type` / `SAP_SYSTEM_TYPE` (`cloud`, `onprem`, `legacy`) and is
|
|
48
|
+
required — no request header states it: it decides the tools offered and how the system's
|
|
49
|
+
`systeminformation` is read. Without it the binary does not start: exit `1` before anything
|
|
50
|
+
listens, on stderr `[MCP] The SAP system type is required — set --system-type, SAP_SYSTEM_TYPE (the environment) or system-type
|
|
51
|
+
(YAML) to onprem, cloud or legacy; the server did not start`. (An embedder's own host of the
|
|
52
|
+
exported server class reads `SAP_SYSTEM_TYPE` at each call: a call without it is refused
|
|
53
|
+
`system_type_required`, nothing sent.)
|
|
54
|
+
|
|
55
|
+
Per request, beside the credential: `x-sap-responsible`, `x-sap-master-system`, `x-sap-language`,
|
|
56
|
+
and the debugger's `x-sap-debug-terminal-id` / `x-sap-debug-ide-id` (then `SAP_RESPONSIBLE`,
|
|
57
|
+
`SAP_MASTER_SYSTEM`, `SAP_DEBUG_TERMINAL_ID`, `SAP_DEBUG_IDE_ID` of the environment). With
|
|
58
|
+
`x-sap-login`, the login is the responsible when none is stated.
|
|
59
|
+
|
|
60
|
+
The system is asked first, when the instance's connection is created (`systeminformation`, by
|
|
61
|
+
`@mcp-abap-adt/responsible-rules`; each request's credential is its own destination): its user and system id win over
|
|
62
|
+
these headers. They count only where an on-premise system gives no information — the responsible
|
|
63
|
+
if stated, else the login, else the call is refused `system_user_unknown`; on ABAP Cloud no
|
|
64
|
+
information is an error (`cloud_without_systeminformation` for a `404`, else
|
|
65
|
+
`system_lookup_failed`). See [MIGRATION-19.0](https://github.com/fr0ster/mcp-abap-adt/blob/main/docs/MIGRATION-19.0.md#every-transport-only-lock-and-unlock-are-sent-stateful-and-an-instances-calls-run-one-at-a-time).
|
|
66
|
+
|
|
67
|
+
## Options
|
|
68
|
+
|
|
69
|
+
As before 19.0.0, under the same names: `--host` / `--http-host` / `MCP_HTTP_HOST`, `--port` /
|
|
70
|
+
`--http-port` / `MCP_HTTP_PORT` (default `3000`), `--path` / `--http-path` (default
|
|
71
|
+
`/mcp/stream/http`), `--http-json-response` / `MCP_HTTP_ENABLE_JSON_RESPONSE`,
|
|
72
|
+
`--http-allowed-hosts` / `MCP_HTTP_ALLOWED_HOSTS`, `--http-allowed-origins` /
|
|
73
|
+
`MCP_HTTP_ALLOWED_ORIGINS`, `--http-enable-dns-protection` / `MCP_HTTP_ENABLE_DNS_PROTECTION`,
|
|
74
|
+
`--tls-cert` / `--tls-key` / `--tls-ca` (`MCP_TLS_*`), `--system-type`, `--state-idle-minutes` / `MCP_STATE_IDLE_MINUTES`, `--conf`, `--help`, `--version`;
|
|
75
|
+
new in 19.0.0, `--shutdown-timeout` / `MCP_SHUTDOWN_TIMEOUT` (see [Shutdown](#shutdown)).
|
|
76
|
+
`mcp-abap-adt-http --help` lists them.
|
|
77
|
+
|
|
78
|
+
## Held state (the debugger)
|
|
79
|
+
|
|
80
|
+
Every request is an MCP session of its own. A tool that holds state (a debug session, a batch)
|
|
81
|
+
answers a `state_handle`; a request carrying it is routed to the instance that holds the state,
|
|
82
|
+
one request at a time, and its own headers give its credential. The handle travels in the
|
|
83
|
+
optional `x-mcp-state-handle` request header; without the header the pool reads a `tools/call`'s
|
|
84
|
+
`state_handle` argument, as the debugger tools send it. A tool call whose handle the pool does
|
|
85
|
+
not know — one that never existed, or whose state ended — is answered `state is not available`
|
|
86
|
+
by the pool itself, the same answer whatever the handle was, and no instance is made and nothing
|
|
87
|
+
logs on for it — a JSON-RPC array holding a tool call too, one such answer per request in it with
|
|
88
|
+
an `id` (an array whose tool call carries a `state_handle` argument is answered `400`); another request carrying such a handle (an `initialize`, a list) gets a new
|
|
89
|
+
instance, as a request without a handle does. The handle is a bearer secret: whoever holds it reaches the state. Held state ends
|
|
90
|
+
by its stop tool, the idle bound (`--state-idle-minutes`, 30–35 791, default 30), or the server's
|
|
91
|
+
stop. See
|
|
92
|
+
[the debugger guide](https://github.com/fr0ster/mcp-abap-adt/blob/main/docs/user-guide/DEBUGGER.md).
|
|
93
|
+
|
|
94
|
+
**Locks (compact).** compact `HandlerLock` holds the lock as the pooled instance's state and answers its `state_handle`;
|
|
95
|
+
`HandlerUpdate`, `HandlerDelete` of a class include and `HandlerUnlock` under that lock send it in the `x-mcp-state-handle` header
|
|
96
|
+
and reach the SAP session that holds the lock — without it they reach another instance and are
|
|
97
|
+
refused, sending nothing. A request with the same credential headers works on the held
|
|
98
|
+
connection; another credential retires it, and its logoff releases the lock. The hold ends at the
|
|
99
|
+
`UNLOCK`.
|
|
100
|
+
|
|
101
|
+
**Batch mode.** `BatchBegin` (compact: `HandlerBatch` with `action: 'begin'`) holds state and
|
|
102
|
+
answers the instance's `state_handle`: send it in `x-mcp-state-handle` on every call of the batch,
|
|
103
|
+
`BatchEnd` and `BatchAnswers` included. A call without it reaches an instance where no batch is
|
|
104
|
+
open. See
|
|
105
|
+
[Batch Mode](https://github.com/fr0ster/mcp-abap-adt/blob/main/docs/user-guide/BATCH_MODE.md#over-streamable-http).
|
|
106
|
+
|
|
107
|
+
## Every ADT session ends with a logoff
|
|
108
|
+
|
|
109
|
+
An instance logs off every ADT session it opened when it leaves the pool: a request's instance
|
|
110
|
+
after its request, when it holds nothing; a pooled instance when its state ends (its stop tool,
|
|
111
|
+
the idle bound). An instance whose state undo fails is kept for a retry — it has not left, and its
|
|
112
|
+
sessions stay open — until a later undo succeeds or the server shuts down, where its sessions are
|
|
113
|
+
logged off at once. (After the idle bound's stop a pooled instance's sessions are logged off even
|
|
114
|
+
when the undo failed.) The logoff is what releases a lock a tool left. A client that drops its
|
|
115
|
+
request closes nothing: the request's tool runs to its end, and its instance leaves the pool as
|
|
116
|
+
above — after its work when it holds nothing, at its state's end when it holds state.
|
|
117
|
+
|
|
118
|
+
## Shutdown
|
|
119
|
+
|
|
120
|
+
On `SIGTERM` / `SIGINT` / `SIGHUP` / `SIGQUIT` (`SIGBREAK` on Windows), or a crash outside a
|
|
121
|
+
tool (then exit `1`), the server stops taking requests (`503`, *the server is shutting down*;
|
|
122
|
+
a call already accepted whose body arrives later reaches no tool), stops listening, **logs off
|
|
123
|
+
every ADT session of every instance at once** — pooled instances and their held state's included;
|
|
124
|
+
no state undo is sent, the logoff ends the state — and interrupts the running tools: **nothing
|
|
125
|
+
waits for a running tool**, and a write whose `UNLOCK` was still to come never sends it (the
|
|
126
|
+
logoff releases its lock). Each logoff is let finish — until SAP answered it or its connection
|
|
127
|
+
failed. It exits `0`. There is no deadline. A killed process (`SIGKILL`, out of memory) sends no
|
|
128
|
+
logoff: SAP keeps its sessions until its own timeout. A second signal, or
|
|
129
|
+
`--shutdown-timeout=<seconds>` (no default), matters only while a logoff is still being written or
|
|
130
|
+
answered: exit `1` naming the requests still running. That forced close is the one end that does
|
|
131
|
+
not wait for SAP's answers, a deliberate exception: it exits once each logoff is written, so a
|
|
132
|
+
session whose logoff SAP had not received whole can stay until SAP's security-session timeout.
|
|
133
|
+
This server keeps no runtime session files, so nothing lists such a session
|
|
134
|
+
(`ListLeftoverSessions` is stdio's, where such a session keeps its file for the next process).
|
|
135
|
+
|
|
136
|
+
## Health
|
|
137
|
+
|
|
138
|
+
`GET /mcp/health` answers `{ status: 'ok', uptime, version, transport: 'http' }` without
|
|
139
|
+
credentials.
|
|
140
|
+
|
|
141
|
+
## Embedding
|
|
142
|
+
|
|
143
|
+
`new StreamableHttpServer(handlersRegistry, options)` — the same options, and `app` to register
|
|
144
|
+
the routes on your own Express (or CAP) application instead of listening itself. `main({ program,
|
|
145
|
+
version })` is the binary's launcher (`@mcp-abap-adt/http/launcher`). An embedder that stops the
|
|
146
|
+
server itself calls `stop()`: admission stops, the listener closes, the pool's instances are
|
|
147
|
+
disposed (their state undone) and logged off. The binary's own shutdown does not wait: it logs
|
|
148
|
+
every session off at once (lib's `installTransportShutdown`, with `releaseConnections()` after the
|
|
149
|
+
logoffs).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* mcp-abap-adt-http — the MCP ABAP ADT server over Streamable HTTP, with the full tool set.
|
|
5
|
+
*
|
|
6
|
+
* The launcher is required and started in this process; it starts nothing
|
|
7
|
+
* on import: `main` is called here with the tool set this command serves,
|
|
8
|
+
* and a sibling command (@mcp-abap-adt/compact-http) calls the same `main`
|
|
9
|
+
* with its own.
|
|
10
|
+
*/
|
|
11
|
+
const { main } = require('../dist/launcher.js');
|
|
12
|
+
const { HTTP_VERSION } = require('../dist/httpVersion.js');
|
|
13
|
+
const { fullToolSet } = require('@mcp-abap-adt/lib/tool-set');
|
|
14
|
+
|
|
15
|
+
void main({
|
|
16
|
+
toolSet: fullToolSet,
|
|
17
|
+
program: 'mcp-abap-adt-http',
|
|
18
|
+
version: HTTP_VERSION,
|
|
19
|
+
}).catch(() => {
|
|
20
|
+
// Fixed words: an error's message may quote a file or a header.
|
|
21
|
+
console.error('[MCP] launcher failed');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamable HTTP keeps the MCP instance that holds state between calls.
|
|
3
|
+
*
|
|
4
|
+
* The transport is stateless — every request is an MCP session of its own —
|
|
5
|
+
* and state lives in an instance (measured for the debugger: a continuous
|
|
6
|
+
* poll, an attach within seconds, the attaching ABAP session; over RFC nothing
|
|
7
|
+
* carries that session to another connection). So per request the host takes
|
|
8
|
+
* an instance once: the one the request's handle names (the
|
|
9
|
+
* `x-mcp-state-handle` header, else the `tools/call`'s `state_handle`), or a
|
|
10
|
+
* new one.
|
|
11
|
+
* The handle identifies an LLM session's state and is a bearer secret:
|
|
12
|
+
* whoever holds it reaches the instance, like a session cookie; keeping it
|
|
13
|
+
* safe is the deployer's. There is no owner and no limit of ours: two
|
|
14
|
+
* listeners of one SAP user meet as SAP answers them (see the debugger's
|
|
15
|
+
* `ids.ts`). One request at a time per instance (the SDK binds one
|
|
16
|
+
* transport).
|
|
17
|
+
* An instance that holds nothing is disposed once, after its work; a disposal
|
|
18
|
+
* that fails keeps the instance for a retry. The pool keeps no clock: the
|
|
19
|
+
* idle bound is the instance state's own (`InstanceState`), and an instance it
|
|
20
|
+
* empties leaves through `onEmpty` like any other.
|
|
21
|
+
*
|
|
22
|
+
* The pool knows `InstanceState` and nothing of what the state is.
|
|
23
|
+
*/
|
|
24
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
25
|
+
import { type InstanceState } from '@mcp-abap-adt/lib/state';
|
|
26
|
+
export interface Poolable {
|
|
27
|
+
readonly state: InstanceState;
|
|
28
|
+
readonly stateHandle: string;
|
|
29
|
+
holdsState(): boolean;
|
|
30
|
+
/** The state undo: callable again, each call retrying what is left. */
|
|
31
|
+
dispose(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* The terminal close: every connection the instance owns
|
|
34
|
+
* closed with a logoff. Run when the instance leaves the pool, after its
|
|
35
|
+
* undo, whatever the undo answered.
|
|
36
|
+
*/
|
|
37
|
+
terminalClose?(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/** The `400` words of a batch carrying `state_handle`. */
|
|
40
|
+
export declare const BATCH_WITH_HANDLE_WORDS = "a JSON-RPC batch cannot carry state_handle";
|
|
41
|
+
/** The `503` words of a request after the shutdown began. */
|
|
42
|
+
export declare const POOL_CLOSED_WORDS = "the server is shutting down";
|
|
43
|
+
export declare class BatchWithHandleError extends Error {
|
|
44
|
+
constructor();
|
|
45
|
+
}
|
|
46
|
+
export declare class PoolClosedError extends Error {
|
|
47
|
+
constructor();
|
|
48
|
+
}
|
|
49
|
+
/** The `state_handle` of a single `tools/call`; a batch carrying one is refused. */
|
|
50
|
+
export declare function handleOf(body: unknown): string | undefined;
|
|
51
|
+
/** The request header that carries the handle on Streamable HTTP. */
|
|
52
|
+
export declare const STATE_HANDLE_HEADER = "x-mcp-state-handle";
|
|
53
|
+
/**
|
|
54
|
+
* The handle a request routes by: the `x-mcp-state-handle` header first, else
|
|
55
|
+
* the `state_handle` of a single `tools/call` (`handleOf`; the debugger tools
|
|
56
|
+
* keep their argument). A JSON-RPC batch carrying `state_handle` is refused
|
|
57
|
+
* whether or not the header is there. A header that is not one non-empty
|
|
58
|
+
* value is absent.
|
|
59
|
+
*/
|
|
60
|
+
export declare function handleFrom(headers: IncomingHttpHeaders, body: unknown): string | undefined;
|
|
61
|
+
export declare class InstancePool<T extends Poolable> {
|
|
62
|
+
private readonly held;
|
|
63
|
+
/** handle → entry, kept in step with each instance's handle (`onChange`). */
|
|
64
|
+
private readonly index;
|
|
65
|
+
/** Requests working on an instance; no entry for an instance nobody works on. */
|
|
66
|
+
private readonly busy;
|
|
67
|
+
private readonly subscribed;
|
|
68
|
+
private readonly evicting;
|
|
69
|
+
/** Disposal failed: the message. */
|
|
70
|
+
private readonly failed;
|
|
71
|
+
/** Disposal failed or still finishing: owned for shutdown. */
|
|
72
|
+
private readonly retained;
|
|
73
|
+
private readonly active;
|
|
74
|
+
private admitting;
|
|
75
|
+
/** Instances whose terminal close ran: they left the pool for good. */
|
|
76
|
+
private readonly closed;
|
|
77
|
+
/**
|
|
78
|
+
* What a failure is named by: an ordinal per instance. Never the handle — it
|
|
79
|
+
* is a bearer secret, and these lines reach the log at shutdown.
|
|
80
|
+
*/
|
|
81
|
+
private readonly ordinals;
|
|
82
|
+
private nextOrdinal;
|
|
83
|
+
private nameOf;
|
|
84
|
+
size(): number;
|
|
85
|
+
private byHandle;
|
|
86
|
+
private keep;
|
|
87
|
+
/** The handle rotated (a complete stop): the old one stops routing at once. */
|
|
88
|
+
private rekey;
|
|
89
|
+
private drop;
|
|
90
|
+
/**
|
|
91
|
+
* `refuseUnknown` (a tool call): a handle that names no instance in the
|
|
92
|
+
* pool — never one, or one whose state ended — is refused here with
|
|
93
|
+
* `StateUnavailableError`, before any instance is made or anything logs
|
|
94
|
+
* on; the answer is the same whatever the handle was. Without a handle, a
|
|
95
|
+
* new instance as ever.
|
|
96
|
+
*/
|
|
97
|
+
serve(request: {
|
|
98
|
+
handle?: string;
|
|
99
|
+
refuseUnknown?: boolean;
|
|
100
|
+
}, create: () => T, work: (instance: T) => Promise<void>): Promise<void>;
|
|
101
|
+
private route;
|
|
102
|
+
private run;
|
|
103
|
+
/** After a request: what holds state is kept; the rest is disposed. */
|
|
104
|
+
private settle;
|
|
105
|
+
/**
|
|
106
|
+
* Once at a time per instance: dispose it. It leaves the pool only when it
|
|
107
|
+
* holds nothing afterwards — an asynchronous part may finish later, and
|
|
108
|
+
* `onEmpty` calls this again then. A disposal that fails keeps the instance,
|
|
109
|
+
* fresh or held, for a retry. The guard is set before disposing, so a part
|
|
110
|
+
* that empties synchronously inside dispose() re-enters harmlessly.
|
|
111
|
+
*/
|
|
112
|
+
private evict;
|
|
113
|
+
/** The terminal close of an instance leaving the pool, once. */
|
|
114
|
+
private terminalClose;
|
|
115
|
+
/** Stops admission (shutdown, in the latch's tick): every later request is `503`. */
|
|
116
|
+
stopAdmitting(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Stop admission; let running requests and disposals finish; dispose what is
|
|
119
|
+
* held or retained; wait until each has settled (an asynchronous part
|
|
120
|
+
* finishes when its last event arrives — no timer); retry once what still
|
|
121
|
+
* holds; report what is still left. Every instance it owned then leaves the
|
|
122
|
+
* pool through its terminal close — its connections closed with a logoff
|
|
123
|
+
* whatever its undo answered.
|
|
124
|
+
*/
|
|
125
|
+
shutdown(): Promise<string[]>;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=InstancePool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstancePool.d.ts","sourceRoot":"","sources":["../src/InstancePool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EACL,KAAK,aAAa,EAEnB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,UAAU,IAAI,OAAO,CAAC;IACtB,uEAAuE;IACvE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB;;;;OAIG;IACH,aAAa,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED,0DAA0D;AAC1D,eAAO,MAAM,uBAAuB,+CACU,CAAC;AAE/C,6DAA6D;AAC7D,eAAO,MAAM,iBAAiB,gCAAgC,CAAC;AAE/D,qBAAa,oBAAqB,SAAQ,KAAK;;CAK9C;AAED,qBAAa,eAAgB,SAAQ,KAAK;;CAKzC;AAOD,oFAAoF;AACpF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAc1D;AAED,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,uBAAuB,CAAC;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,OAAO,GACZ,MAAM,GAAG,SAAS,CAIpB;AAoCD,qBAAa,YAAY,CAAC,CAAC,SAAS,QAAQ;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyB;IAC9C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@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InstancePool = exports.STATE_HANDLE_HEADER = exports.PoolClosedError = exports.BatchWithHandleError = exports.POOL_CLOSED_WORDS = exports.BATCH_WITH_HANDLE_WORDS = void 0;
|
|
4
|
+
exports.handleOf = handleOf;
|
|
5
|
+
exports.handleFrom = handleFrom;
|
|
6
|
+
const auth_1 = require("@mcp-abap-adt/lib/auth");
|
|
7
|
+
const state_1 = require("@mcp-abap-adt/lib/state");
|
|
8
|
+
/** The `400` words of a batch carrying `state_handle`. */
|
|
9
|
+
exports.BATCH_WITH_HANDLE_WORDS = 'a JSON-RPC batch cannot carry state_handle';
|
|
10
|
+
/** The `503` words of a request after the shutdown began. */
|
|
11
|
+
exports.POOL_CLOSED_WORDS = 'the server is shutting down';
|
|
12
|
+
class BatchWithHandleError extends Error {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(exports.BATCH_WITH_HANDLE_WORDS);
|
|
15
|
+
this.name = 'BatchWithHandleError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.BatchWithHandleError = BatchWithHandleError;
|
|
19
|
+
class PoolClosedError extends Error {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(exports.POOL_CLOSED_WORDS);
|
|
22
|
+
this.name = 'PoolClosedError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.PoolClosedError = PoolClosedError;
|
|
26
|
+
/** The `state_handle` of a single `tools/call`; a batch carrying one is refused. */
|
|
27
|
+
function handleOf(body) {
|
|
28
|
+
const one = (m) => {
|
|
29
|
+
const call = m;
|
|
30
|
+
const handle = call?.params?.arguments?.state_handle;
|
|
31
|
+
return call?.method === 'tools/call' && typeof handle === 'string'
|
|
32
|
+
? handle
|
|
33
|
+
: undefined;
|
|
34
|
+
};
|
|
35
|
+
if (Array.isArray(body)) {
|
|
36
|
+
if (body.some((m) => one(m) !== undefined))
|
|
37
|
+
throw new BatchWithHandleError();
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return one(body);
|
|
41
|
+
}
|
|
42
|
+
/** The request header that carries the handle on Streamable HTTP. */
|
|
43
|
+
exports.STATE_HANDLE_HEADER = 'x-mcp-state-handle';
|
|
44
|
+
/**
|
|
45
|
+
* The handle a request routes by: the `x-mcp-state-handle` header first, else
|
|
46
|
+
* the `state_handle` of a single `tools/call` (`handleOf`; the debugger tools
|
|
47
|
+
* keep their argument). A JSON-RPC batch carrying `state_handle` is refused
|
|
48
|
+
* whether or not the header is there. A header that is not one non-empty
|
|
49
|
+
* value is absent.
|
|
50
|
+
*/
|
|
51
|
+
function handleFrom(headers, body) {
|
|
52
|
+
const argument = handleOf(body);
|
|
53
|
+
const header = headers[exports.STATE_HANDLE_HEADER];
|
|
54
|
+
return typeof header === 'string' && header !== '' ? header : argument;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* What a failed undo is reported as: the state's own words of what it could
|
|
58
|
+
* not undo (`StateCleanupError.failures`, the parts' fixed words), else what
|
|
59
|
+
* the failure reader makes of it, else its class — never a thrown message.
|
|
60
|
+
*/
|
|
61
|
+
const failureWordsOf = (e) => {
|
|
62
|
+
const failures = ownFailures(e);
|
|
63
|
+
if (failures !== undefined)
|
|
64
|
+
return failures.join('; ');
|
|
65
|
+
return (0, auth_1.failureOf)(e)?.message ?? (0, auth_1.errorClassOf)(e);
|
|
66
|
+
};
|
|
67
|
+
function ownFailures(e) {
|
|
68
|
+
if (e === null || typeof e !== 'object')
|
|
69
|
+
return undefined;
|
|
70
|
+
try {
|
|
71
|
+
const descriptor = Object.getOwnPropertyDescriptor(e, 'failures');
|
|
72
|
+
const value = descriptor && 'value' in descriptor ? descriptor.value : undefined;
|
|
73
|
+
return Array.isArray(value) && value.every((f) => typeof f === 'string')
|
|
74
|
+
? value
|
|
75
|
+
: undefined;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class InstancePool {
|
|
82
|
+
held = new Map();
|
|
83
|
+
/** handle → entry, kept in step with each instance's handle (`onChange`). */
|
|
84
|
+
index = new Map();
|
|
85
|
+
/** Requests working on an instance; no entry for an instance nobody works on. */
|
|
86
|
+
busy = new Map();
|
|
87
|
+
subscribed = new WeakSet();
|
|
88
|
+
evicting = new Map();
|
|
89
|
+
/** Disposal failed: the message. */
|
|
90
|
+
failed = new Map();
|
|
91
|
+
/** Disposal failed or still finishing: owned for shutdown. */
|
|
92
|
+
retained = new Set();
|
|
93
|
+
active = new Set();
|
|
94
|
+
admitting = true;
|
|
95
|
+
/** Instances whose terminal close ran: they left the pool for good. */
|
|
96
|
+
closed = new WeakSet();
|
|
97
|
+
/**
|
|
98
|
+
* What a failure is named by: an ordinal per instance. Never the handle — it
|
|
99
|
+
* is a bearer secret, and these lines reach the log at shutdown.
|
|
100
|
+
*/
|
|
101
|
+
ordinals = new WeakMap();
|
|
102
|
+
nextOrdinal = 1;
|
|
103
|
+
nameOf(instance) {
|
|
104
|
+
let n = this.ordinals.get(instance);
|
|
105
|
+
if (n === undefined) {
|
|
106
|
+
n = this.nextOrdinal++;
|
|
107
|
+
this.ordinals.set(instance, n);
|
|
108
|
+
}
|
|
109
|
+
return `instance ${n}`;
|
|
110
|
+
}
|
|
111
|
+
size() {
|
|
112
|
+
return this.held.size;
|
|
113
|
+
}
|
|
114
|
+
byHandle(handle) {
|
|
115
|
+
const entry = this.index.get(handle);
|
|
116
|
+
// The index follows rotation; the check keeps a stale key from ever routing.
|
|
117
|
+
return entry && entry.instance.stateHandle === handle ? entry : undefined;
|
|
118
|
+
}
|
|
119
|
+
keep(instance) {
|
|
120
|
+
if (this.held.has(instance))
|
|
121
|
+
return;
|
|
122
|
+
const entry = {
|
|
123
|
+
instance,
|
|
124
|
+
handle: instance.stateHandle,
|
|
125
|
+
tail: Promise.resolve(),
|
|
126
|
+
unsubscribe: () => { },
|
|
127
|
+
};
|
|
128
|
+
this.held.set(instance, entry);
|
|
129
|
+
this.index.set(entry.handle, entry);
|
|
130
|
+
entry.unsubscribe = instance.state.onChange(() => this.rekey(entry));
|
|
131
|
+
}
|
|
132
|
+
/** The handle rotated (a complete stop): the old one stops routing at once. */
|
|
133
|
+
rekey(entry) {
|
|
134
|
+
const now = entry.instance.stateHandle;
|
|
135
|
+
if (now === entry.handle)
|
|
136
|
+
return;
|
|
137
|
+
if (this.index.get(entry.handle) === entry)
|
|
138
|
+
this.index.delete(entry.handle);
|
|
139
|
+
entry.handle = now;
|
|
140
|
+
this.index.set(now, entry);
|
|
141
|
+
}
|
|
142
|
+
drop(instance) {
|
|
143
|
+
const entry = this.held.get(instance);
|
|
144
|
+
if (!entry)
|
|
145
|
+
return;
|
|
146
|
+
entry.unsubscribe();
|
|
147
|
+
this.held.delete(instance);
|
|
148
|
+
if (this.index.get(entry.handle) === entry)
|
|
149
|
+
this.index.delete(entry.handle);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* `refuseUnknown` (a tool call): a handle that names no instance in the
|
|
153
|
+
* pool — never one, or one whose state ended — is refused here with
|
|
154
|
+
* `StateUnavailableError`, before any instance is made or anything logs
|
|
155
|
+
* on; the answer is the same whatever the handle was. Without a handle, a
|
|
156
|
+
* new instance as ever.
|
|
157
|
+
*/
|
|
158
|
+
async serve(request, create, work) {
|
|
159
|
+
if (!this.admitting)
|
|
160
|
+
throw new PoolClosedError();
|
|
161
|
+
const run = this.route(request, create, work);
|
|
162
|
+
this.active.add(run);
|
|
163
|
+
try {
|
|
164
|
+
await run;
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
this.active.delete(run);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
route(request, create, work) {
|
|
171
|
+
const entry = request.handle ? this.byHandle(request.handle) : undefined;
|
|
172
|
+
// The handle is a bearer secret: it reaches its instance whoever sends it.
|
|
173
|
+
// An unknown handle on a tool call is not available, answered here; on any
|
|
174
|
+
// other request (initialize, a list) it gets a new instance, which logs on
|
|
175
|
+
// nowhere until a tool call.
|
|
176
|
+
if (!entry) {
|
|
177
|
+
if (request.handle && request.refuseUnknown)
|
|
178
|
+
return Promise.reject(new state_1.StateUnavailableError());
|
|
179
|
+
return this.run(create(), work);
|
|
180
|
+
}
|
|
181
|
+
const turn = entry.tail.then(() =>
|
|
182
|
+
// Revalidate: the instance may have left the pool, be leaving it, or
|
|
183
|
+
// have rotated its handle while this request waited.
|
|
184
|
+
this.held.get(entry.instance) === entry &&
|
|
185
|
+
!this.evicting.has(entry.instance) &&
|
|
186
|
+
entry.instance.stateHandle === request.handle
|
|
187
|
+
? this.run(entry.instance, work)
|
|
188
|
+
: request.refuseUnknown
|
|
189
|
+
? Promise.reject(new state_1.StateUnavailableError())
|
|
190
|
+
: this.run(create(), work));
|
|
191
|
+
entry.tail = turn.catch(() => undefined);
|
|
192
|
+
return turn;
|
|
193
|
+
}
|
|
194
|
+
async run(instance, work) {
|
|
195
|
+
if (!this.subscribed.has(instance)) {
|
|
196
|
+
this.subscribed.add(instance);
|
|
197
|
+
instance.state.onEmpty(() => {
|
|
198
|
+
if (!this.busy.get(instance))
|
|
199
|
+
void this.evict(instance);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
this.busy.set(instance, (this.busy.get(instance) ?? 0) + 1);
|
|
203
|
+
try {
|
|
204
|
+
await work(instance);
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
const left = (this.busy.get(instance) ?? 1) - 1;
|
|
208
|
+
if (left > 0)
|
|
209
|
+
this.busy.set(instance, left);
|
|
210
|
+
else
|
|
211
|
+
this.busy.delete(instance);
|
|
212
|
+
await this.settle(instance);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** After a request: what holds state is kept; the rest is disposed. */
|
|
216
|
+
async settle(instance) {
|
|
217
|
+
if (instance.holdsState()) {
|
|
218
|
+
this.keep(instance);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (!this.busy.get(instance))
|
|
222
|
+
await this.evict(instance);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Once at a time per instance: dispose it. It leaves the pool only when it
|
|
226
|
+
* holds nothing afterwards — an asynchronous part may finish later, and
|
|
227
|
+
* `onEmpty` calls this again then. A disposal that fails keeps the instance,
|
|
228
|
+
* fresh or held, for a retry. The guard is set before disposing, so a part
|
|
229
|
+
* that empties synchronously inside dispose() re-enters harmlessly.
|
|
230
|
+
*/
|
|
231
|
+
evict(instance) {
|
|
232
|
+
const running = this.evicting.get(instance);
|
|
233
|
+
if (running)
|
|
234
|
+
return running;
|
|
235
|
+
let done;
|
|
236
|
+
const eviction = new Promise((resolve) => {
|
|
237
|
+
done = resolve;
|
|
238
|
+
});
|
|
239
|
+
this.evicting.set(instance, eviction);
|
|
240
|
+
void (async () => {
|
|
241
|
+
try {
|
|
242
|
+
await instance.dispose();
|
|
243
|
+
this.failed.delete(instance);
|
|
244
|
+
if (!instance.holdsState()) {
|
|
245
|
+
this.drop(instance);
|
|
246
|
+
this.retained.delete(instance);
|
|
247
|
+
// It left the pool: its connections end with a logoff.
|
|
248
|
+
await this.terminalClose(instance);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
this.retained.add(instance); // still finishing: owned until it empties
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch (e) {
|
|
255
|
+
this.failed.set(instance, `${this.nameOf(instance)}: ${failureWordsOf(e)}`);
|
|
256
|
+
this.retained.add(instance); // fresh or held: kept for shutdown's retry
|
|
257
|
+
if (!instance.holdsState()) {
|
|
258
|
+
// Nothing left to route to: out of the index and the count; only
|
|
259
|
+
// `retained` keeps it, for the retry.
|
|
260
|
+
this.drop(instance);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
this.evicting.delete(instance);
|
|
265
|
+
done();
|
|
266
|
+
}
|
|
267
|
+
})();
|
|
268
|
+
return eviction;
|
|
269
|
+
}
|
|
270
|
+
/** The terminal close of an instance leaving the pool, once. */
|
|
271
|
+
async terminalClose(instance) {
|
|
272
|
+
if (this.closed.has(instance))
|
|
273
|
+
return;
|
|
274
|
+
this.closed.add(instance);
|
|
275
|
+
await instance.terminalClose?.();
|
|
276
|
+
}
|
|
277
|
+
/** Stops admission (shutdown, in the latch's tick): every later request is `503`. */
|
|
278
|
+
stopAdmitting() {
|
|
279
|
+
this.admitting = false;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Stop admission; let running requests and disposals finish; dispose what is
|
|
283
|
+
* held or retained; wait until each has settled (an asynchronous part
|
|
284
|
+
* finishes when its last event arrives — no timer); retry once what still
|
|
285
|
+
* holds; report what is still left. Every instance it owned then leaves the
|
|
286
|
+
* pool through its terminal close — its connections closed with a logoff
|
|
287
|
+
* whatever its undo answered.
|
|
288
|
+
*/
|
|
289
|
+
async shutdown() {
|
|
290
|
+
this.admitting = false;
|
|
291
|
+
await Promise.allSettled([...this.active]);
|
|
292
|
+
await Promise.allSettled([...this.evicting.values()]);
|
|
293
|
+
const owned = [...new Set([...this.held.keys(), ...this.retained])];
|
|
294
|
+
for (const instance of owned)
|
|
295
|
+
await this.evict(instance);
|
|
296
|
+
// Every instance settles first — a disposal that threw may still have
|
|
297
|
+
// cleanup finishing on its own.
|
|
298
|
+
await Promise.allSettled(owned.map((i) => i.state.settled()));
|
|
299
|
+
for (const instance of owned) {
|
|
300
|
+
// Clean: nothing held and no failure left (a later eviction cleared it).
|
|
301
|
+
if (!instance.holdsState() && !this.failed.has(instance))
|
|
302
|
+
continue;
|
|
303
|
+
this.failed.delete(instance);
|
|
304
|
+
// Still held, or a disposal that threw: once more, and what that leaves is reported.
|
|
305
|
+
await this.evict(instance);
|
|
306
|
+
await instance.state.settled();
|
|
307
|
+
if (instance.holdsState() && !this.failed.has(instance)) {
|
|
308
|
+
const left = instance.state.failures().join('; ');
|
|
309
|
+
this.failed.set(instance, `${this.nameOf(instance)}: ${left || 'state is still held'}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// Leaving for good: the logoffs are written whatever the undo answered.
|
|
313
|
+
await Promise.all(owned.map((instance) => this.terminalClose(instance)));
|
|
314
|
+
return [...this.failed.values()];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
exports.InstancePool = InstancePool;
|
|
318
|
+
//# sourceMappingURL=InstancePool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstancePool.js","sourceRoot":"","sources":["../src/InstancePool.ts"],"names":[],"mappings":";;;AAuEA,4BAcC;AAYD,gCAOC;AAhFD,iDAAiE;AACjE,mDAGiC;AAgBjC,0DAA0D;AAC7C,QAAA,uBAAuB,GAClC,4CAA4C,CAAC;AAE/C,6DAA6D;AAChD,QAAA,iBAAiB,GAAG,6BAA6B,CAAC;AAE/D,MAAa,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,+BAAuB,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC;AAED,MAAa,eAAgB,SAAQ,KAAK;IACxC;QACE,KAAK,CAAC,yBAAiB,CAAC,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAOD,oFAAoF;AACpF,SAAgB,QAAQ,CAAC,IAAa;IACpC,MAAM,GAAG,GAAG,CAAC,CAAU,EAAsB,EAAE;QAC7C,MAAM,IAAI,GAAG,CAAmC,CAAC;QACjD,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC;QACrD,OAAO,IAAI,EAAE,MAAM,KAAK,YAAY,IAAI,OAAO,MAAM,KAAK,QAAQ;YAChE,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC,CAAC;IACF,IAAI,KAAK,CAAC,OAAO,CAAC,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