@mcp-abap-adt/core 18.1.0 → 19.1.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/README.md +26 -5
- package/bin/mcp-abap-adt.js +15 -15
- package/dist/StdioServer.d.ts +68 -14
- package/dist/StdioServer.d.ts.map +1 -1
- package/dist/StdioServer.js +101 -31
- package/dist/StdioServer.js.map +1 -1
- package/dist/auth/IAuthBrokerFactory.d.ts +62 -0
- package/dist/auth/IAuthBrokerFactory.d.ts.map +1 -0
- package/dist/auth/IAuthBrokerFactory.js +8 -0
- package/dist/auth/IAuthBrokerFactory.js.map +1 -0
- package/dist/auth/IAuthBrokerFactoryConfig.d.ts +90 -0
- package/dist/auth/IAuthBrokerFactoryConfig.d.ts.map +1 -0
- package/dist/auth/IAuthBrokerFactoryConfig.js +8 -0
- package/dist/auth/IAuthBrokerFactoryConfig.js.map +1 -0
- package/dist/auth/brokerFactory.d.ts +93 -0
- package/dist/auth/brokerFactory.d.ts.map +1 -0
- package/dist/auth/brokerFactory.js +341 -0
- package/dist/auth/brokerFactory.js.map +1 -0
- package/dist/auth/browser.d.ts +60 -0
- package/dist/auth/browser.d.ts.map +1 -0
- package/dist/auth/browser.js +116 -0
- package/dist/auth/browser.js.map +1 -0
- package/dist/auth/countedProvider.d.ts +43 -0
- package/dist/auth/countedProvider.d.ts.map +1 -0
- package/dist/auth/countedProvider.js +105 -0
- package/dist/auth/countedProvider.js.map +1 -0
- package/dist/auth/destinationFailure.d.ts +69 -0
- package/dist/auth/destinationFailure.d.ts.map +1 -0
- package/dist/auth/destinationFailure.js +183 -0
- package/dist/auth/destinationFailure.js.map +1 -0
- package/dist/auth/destinationStores.d.ts +55 -0
- package/dist/auth/destinationStores.d.ts.map +1 -0
- package/dist/auth/destinationStores.js +158 -0
- package/dist/auth/destinationStores.js.map +1 -0
- package/dist/auth/handlers/basic.d.ts +3 -0
- package/dist/auth/handlers/basic.d.ts.map +1 -0
- package/dist/auth/handlers/basic.js +8 -0
- package/dist/auth/handlers/basic.js.map +1 -0
- package/dist/auth/handlers/index.d.ts +15 -0
- package/dist/auth/handlers/index.d.ts.map +1 -0
- package/dist/auth/handlers/index.js +32 -0
- package/dist/auth/handlers/index.js.map +1 -0
- package/dist/auth/handlers/jwtAuthorizationCode.d.ts +8 -0
- package/dist/auth/handlers/jwtAuthorizationCode.d.ts.map +1 -0
- package/dist/auth/handlers/jwtAuthorizationCode.js +32 -0
- package/dist/auth/handlers/jwtAuthorizationCode.js.map +1 -0
- package/dist/auth/handlers/snc.d.ts +3 -0
- package/dist/auth/handlers/snc.d.ts.map +1 -0
- package/dist/auth/handlers/snc.js +14 -0
- package/dist/auth/handlers/snc.js.map +1 -0
- package/dist/auth/handlers/types.d.ts +30 -0
- package/dist/auth/handlers/types.d.ts.map +1 -0
- package/dist/auth/handlers/types.js +3 -0
- package/dist/auth/handlers/types.js.map +1 -0
- package/dist/auth/index.d.ts +15 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +38 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/serverLogin.d.ts +75 -0
- package/dist/auth/serverLogin.d.ts.map +1 -0
- package/dist/auth/serverLogin.js +138 -0
- package/dist/auth/serverLogin.js.map +1 -0
- package/dist/auth/serverSentences.d.ts +39 -0
- package/dist/auth/serverSentences.d.ts.map +1 -0
- package/dist/auth/serverSentences.js +49 -0
- package/dist/auth/serverSentences.js.map +1 -0
- package/dist/auth/vocabulary.d.ts +28 -0
- package/dist/auth/vocabulary.d.ts.map +1 -0
- package/dist/auth/vocabulary.js +67 -0
- package/dist/auth/vocabulary.js.map +1 -0
- package/dist/config/coreParameters.d.ts +125 -0
- package/dist/config/coreParameters.d.ts.map +1 -0
- package/dist/config/coreParameters.js +331 -0
- package/dist/config/coreParameters.js.map +1 -0
- package/dist/config/envFileContext.d.ts +26 -0
- package/dist/config/envFileContext.d.ts.map +1 -0
- package/dist/config/envFileContext.js +90 -0
- package/dist/config/envFileContext.js.map +1 -0
- package/dist/config/envResolver.d.ts +6 -0
- package/dist/config/envResolver.d.ts.map +1 -0
- package/dist/config/envResolver.js +81 -0
- package/dist/config/envResolver.js.map +1 -0
- package/dist/config/platformPaths.d.ts +28 -0
- package/dist/config/platformPaths.d.ts.map +1 -0
- package/dist/config/platformPaths.js +152 -0
- package/dist/config/platformPaths.js.map +1 -0
- package/dist/destinationSource.d.ts +26 -0
- package/dist/destinationSource.d.ts.map +1 -0
- package/dist/destinationSource.js +43 -0
- package/dist/destinationSource.js.map +1 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -11
- package/dist/index.js.map +1 -1
- package/dist/launcher.d.ts +102 -59
- package/dist/launcher.d.ts.map +1 -1
- package/dist/launcher.js +419 -286
- package/dist/launcher.js.map +1 -1
- package/dist/shutdown.d.ts +76 -24
- package/dist/shutdown.d.ts.map +1 -1
- package/dist/shutdown.js +114 -57
- package/dist/shutdown.js.map +1 -1
- package/package.json +22 -39
- package/dist/InstancePool.d.ts +0 -87
- package/dist/InstancePool.d.ts.map +0 -1
- package/dist/InstancePool.js +0 -240
- package/dist/InstancePool.js.map +0 -1
- package/dist/SseServer.d.ts +0 -144
- package/dist/SseServer.d.ts.map +0 -1
- package/dist/SseServer.js +0 -359
- package/dist/SseServer.js.map +0 -1
- package/dist/StreamableHttpServer.d.ts +0 -143
- package/dist/StreamableHttpServer.d.ts.map +0 -1
- package/dist/StreamableHttpServer.js +0 -349
- package/dist/StreamableHttpServer.js.map +0 -1
- package/dist/destinationRequest.d.ts +0 -38
- package/dist/destinationRequest.d.ts.map +0 -1
- package/dist/destinationRequest.js +0 -85
- package/dist/destinationRequest.js.map +0 -1
- package/dist/dnsRebindingProtection.d.ts +0 -21
- package/dist/dnsRebindingProtection.d.ts.map +0 -1
- package/dist/dnsRebindingProtection.js +0 -45
- package/dist/dnsRebindingProtection.js.map +0 -1
- package/dist/stateClose.d.ts +0 -8
- package/dist/stateClose.d.ts.map +0 -1
- package/dist/stateClose.js +0 -14
- package/dist/stateClose.js.map +0 -1
- package/dist/tlsUtils.d.ts +0 -19
- package/dist/tlsUtils.d.ts.map +0 -1
- package/dist/tlsUtils.js +0 -77
- package/dist/tlsUtils.js.map +0 -1
package/dist/SseServer.js
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SseServer = void 0;
|
|
7
|
-
const auth_1 = require("@mcp-abap-adt/lib/auth");
|
|
8
|
-
const embeddable_1 = require("@mcp-abap-adt/lib/embeddable");
|
|
9
|
-
const logger_1 = require("@mcp-abap-adt/lib/logger");
|
|
10
|
-
const request_context_1 = require("@mcp-abap-adt/lib/request-context");
|
|
11
|
-
const state_1 = require("@mcp-abap-adt/lib/state");
|
|
12
|
-
const sse_js_1 = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
13
|
-
const express_1 = __importDefault(require("express"));
|
|
14
|
-
const coreVersion_js_1 = require("./coreVersion.js");
|
|
15
|
-
const destinationRequest_js_1 = require("./destinationRequest.js");
|
|
16
|
-
const dnsRebindingProtection_js_1 = require("./dnsRebindingProtection.js");
|
|
17
|
-
const tlsUtils_js_1 = require("./tlsUtils.js");
|
|
18
|
-
/**
|
|
19
|
-
* Minimal SSE server: creates a new BaseMcpServer per GET connection, routes POST by sessionId.
|
|
20
|
-
*
|
|
21
|
-
* Supports two modes:
|
|
22
|
-
* 1. Standalone mode: Creates its own Express server (when no app option provided)
|
|
23
|
-
* 2. Embedded mode: Registers routes on external app (when app option provided)
|
|
24
|
-
*/
|
|
25
|
-
class SseServer {
|
|
26
|
-
handlersRegistry;
|
|
27
|
-
destinations;
|
|
28
|
-
host;
|
|
29
|
-
port;
|
|
30
|
-
ssePath;
|
|
31
|
-
postPath;
|
|
32
|
-
defaultDestination;
|
|
33
|
-
sessions = new Map();
|
|
34
|
-
/** Disposals of closed sessions still running; stop() waits for them. */
|
|
35
|
-
closingSessions = new Set();
|
|
36
|
-
/** Per-destination lock around the first connect: it serialises the first login. */
|
|
37
|
-
firstConnect = new destinationRequest_js_1.FirstConnectLock();
|
|
38
|
-
logger;
|
|
39
|
-
version;
|
|
40
|
-
externalApp;
|
|
41
|
-
standaloneServer;
|
|
42
|
-
tls;
|
|
43
|
-
allowDestinationHeader;
|
|
44
|
-
allowedHosts;
|
|
45
|
-
allowedOrigins;
|
|
46
|
-
enableDnsRebindingProtection;
|
|
47
|
-
stateIdleMinutes;
|
|
48
|
-
stateLogger;
|
|
49
|
-
constructor(handlersRegistry,
|
|
50
|
-
/** The destinations: settings and the counted provider, nothing else. */
|
|
51
|
-
destinations, opts) {
|
|
52
|
-
this.handlersRegistry = handlersRegistry;
|
|
53
|
-
this.destinations = destinations;
|
|
54
|
-
this.host = opts?.host ?? '127.0.0.1';
|
|
55
|
-
this.port = opts?.port ?? 3001;
|
|
56
|
-
this.ssePath = opts?.ssePath ?? '/sse';
|
|
57
|
-
this.postPath = opts?.postPath ?? '/messages';
|
|
58
|
-
this.defaultDestination = opts?.defaultDestination;
|
|
59
|
-
this.logger = opts?.logger ?? logger_1.noopLogger;
|
|
60
|
-
this.version = opts?.version ?? coreVersion_js_1.CORE_VERSION;
|
|
61
|
-
this.externalApp = opts?.app;
|
|
62
|
-
this.tls = opts?.tls;
|
|
63
|
-
this.allowDestinationHeader = opts?.allowDestinationHeader ?? false;
|
|
64
|
-
this.allowedHosts = opts?.allowedHosts;
|
|
65
|
-
this.allowedOrigins = opts?.allowedOrigins;
|
|
66
|
-
this.enableDnsRebindingProtection = opts?.enableDnsRebindingProtection;
|
|
67
|
-
// Refused here, at startup, rather than at a session's first request.
|
|
68
|
-
this.stateIdleMinutes =
|
|
69
|
-
opts?.stateIdleMinutes === undefined
|
|
70
|
-
? undefined
|
|
71
|
-
: (0, state_1.parseStateIdleMinutes)(opts.stateIdleMinutes, 'stateIdleMinutes');
|
|
72
|
-
// From the options as given: the silent default of `this.logger` is never the state's.
|
|
73
|
-
this.stateLogger = (0, state_1.stateLoggerOf)(opts ?? {});
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Register routes on an external HTTP application
|
|
77
|
-
* Use this when integrating with existing Express/CDS/CAP server
|
|
78
|
-
*
|
|
79
|
-
* @param app - External HTTP application (Express, CDS, etc.)
|
|
80
|
-
* @param options - Route registration options
|
|
81
|
-
*/
|
|
82
|
-
registerRoutes(app, _options) {
|
|
83
|
-
// Health check endpoint — lightweight, no MCP protocol logic
|
|
84
|
-
app.get('/mcp/health', ((_req, res) => {
|
|
85
|
-
res.json({
|
|
86
|
-
status: 'ok',
|
|
87
|
-
uptime: Math.floor(process.uptime()),
|
|
88
|
-
version: this.version,
|
|
89
|
-
transport: 'sse',
|
|
90
|
-
activeSessions: this.sessions.size,
|
|
91
|
-
});
|
|
92
|
-
}));
|
|
93
|
-
const dnsOpts = {
|
|
94
|
-
enable: this.enableDnsRebindingProtection,
|
|
95
|
-
allowedHosts: this.allowedHosts,
|
|
96
|
-
allowedOrigins: this.allowedOrigins,
|
|
97
|
-
};
|
|
98
|
-
app.get(this.ssePath, (0, dnsRebindingProtection_js_1.withDnsRebindingProtection)((async (req, res) => {
|
|
99
|
-
await this.handleGet(req, res);
|
|
100
|
-
}), dnsOpts));
|
|
101
|
-
app.post(this.postPath, (0, dnsRebindingProtection_js_1.withDnsRebindingProtection)((async (req, res) => {
|
|
102
|
-
const url = new URL(req.originalUrl, `http://${req.headers.host}`);
|
|
103
|
-
await this.handlePost(req, res, url);
|
|
104
|
-
}), dnsOpts));
|
|
105
|
-
console.error(`[SseServer] Routes registered on external app`);
|
|
106
|
-
console.error(`[SseServer] SSE endpoint: ${this.ssePath}`);
|
|
107
|
-
console.error(`[SseServer] POST endpoint: ${this.postPath}`);
|
|
108
|
-
if (this.defaultDestination) {
|
|
109
|
-
console.error(`[SseServer] Default destination: ${this.defaultDestination}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get the configured SSE endpoint path
|
|
114
|
-
*/
|
|
115
|
-
getSsePath() {
|
|
116
|
-
return this.ssePath;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Get the configured POST endpoint path
|
|
120
|
-
*/
|
|
121
|
-
getPostPath() {
|
|
122
|
-
return this.postPath;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Start the server
|
|
126
|
-
*
|
|
127
|
-
* In standalone mode (no external app): Creates Express server and starts listening
|
|
128
|
-
* In embedded mode (external app provided): Only registers routes on external app
|
|
129
|
-
*/
|
|
130
|
-
async start() {
|
|
131
|
-
// If external app was provided in constructor, register routes on it
|
|
132
|
-
if (this.externalApp) {
|
|
133
|
-
this.registerRoutes(this.externalApp);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
// Standalone mode: create own Express server
|
|
137
|
-
const app = (0, express_1.default)();
|
|
138
|
-
app.use(express_1.default.json());
|
|
139
|
-
this.registerRoutes(app);
|
|
140
|
-
await new Promise((resolve, reject) => {
|
|
141
|
-
const protocol = (0, tlsUtils_js_1.getProtocol)(this.tls);
|
|
142
|
-
const server = (0, tlsUtils_js_1.createServerListener)(app, this.tls);
|
|
143
|
-
this.standaloneServer = server;
|
|
144
|
-
server.listen(this.port, this.host);
|
|
145
|
-
server.once('listening', () => {
|
|
146
|
-
console.error(`[SseServer] Server started on ${this.host}:${this.port}`);
|
|
147
|
-
console.error(`[SseServer] SSE endpoint: ${protocol}://${this.host}:${this.port}${this.ssePath}`);
|
|
148
|
-
console.error(`[SseServer] POST endpoint: ${protocol}://${this.host}:${this.port}${this.postPath}`);
|
|
149
|
-
resolve();
|
|
150
|
-
});
|
|
151
|
-
server.once('error', reject);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Stops taking connections (shutdown, step 1). Requests already running are
|
|
156
|
-
* not waited for, nor is an open stream: the factory's gate holds them.
|
|
157
|
-
* Embedded on an external app, there is no listener of its own to stop.
|
|
158
|
-
* It then waits for the state of every session to be gone, and rejects with
|
|
159
|
-
* what could not be undone.
|
|
160
|
-
*/
|
|
161
|
-
async stop() {
|
|
162
|
-
const server = this.standaloneServer;
|
|
163
|
-
if (server) {
|
|
164
|
-
this.standaloneServer = undefined;
|
|
165
|
-
server.close();
|
|
166
|
-
server.closeIdleConnections();
|
|
167
|
-
}
|
|
168
|
-
// Every open session's instance is disposed, and the sessions that closed
|
|
169
|
-
// earlier are waited for (no timer): on an external app there is no
|
|
170
|
-
// listener here, but the sessions are still ours to drain.
|
|
171
|
-
const pending = [...this.closingSessions];
|
|
172
|
-
for (const [id, entry] of this.sessions) {
|
|
173
|
-
pending.push(entry.server
|
|
174
|
-
.shutdownState()
|
|
175
|
-
.then((left) => left.map((l) => `${id}: ${l}`)));
|
|
176
|
-
}
|
|
177
|
-
this.sessions.clear();
|
|
178
|
-
const failures = (await Promise.all(pending)).flat();
|
|
179
|
-
if (failures.length) {
|
|
180
|
-
throw new Error(`state cleanup failed: ${failures.join('; ')}`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
async handleGet(req, res) {
|
|
184
|
-
let destination;
|
|
185
|
-
let fromHeaders = false;
|
|
186
|
-
try {
|
|
187
|
-
// Priority 1: x-mcp-destination (only with --allow-destination-header),
|
|
188
|
-
// refused when it is not a destination name
|
|
189
|
-
const destinationHeader = (0, destinationRequest_js_1.destinationFromHeader)(req.headers, this.allowDestinationHeader);
|
|
190
|
-
if (destinationHeader !== undefined) {
|
|
191
|
-
destination = destinationHeader;
|
|
192
|
-
}
|
|
193
|
-
// Priority 2: Check SAP connection headers (x-sap-url + auth params)
|
|
194
|
-
// The settings and the credential come from the headers, no destination
|
|
195
|
-
else if (this.hasSapConnectionHeaders(req.headers)) {
|
|
196
|
-
destination = undefined;
|
|
197
|
-
fromHeaders = true;
|
|
198
|
-
}
|
|
199
|
-
// Priority 3: Use default destination
|
|
200
|
-
else if (this.defaultDestination) {
|
|
201
|
-
destination = this.defaultDestination;
|
|
202
|
-
}
|
|
203
|
-
// Priority 4: No auth params at all -> reject request
|
|
204
|
-
else {
|
|
205
|
-
res
|
|
206
|
-
.status(400)
|
|
207
|
-
.send('Missing SAP connection context. Provide x-mcp-destination header, configure default destination (--mcp/--env-path), or pass x-sap-* headers.');
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
this.answerFailure(res, error);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
this.logger.debug(`SSE GET: destination=${destination ?? 'none'}`);
|
|
216
|
-
class SessionServer extends embeddable_1.BaseMcpServer {
|
|
217
|
-
registry;
|
|
218
|
-
loggerImpl;
|
|
219
|
-
ver;
|
|
220
|
-
constructor(registry, loggerImpl, ver, state) {
|
|
221
|
-
super({
|
|
222
|
-
name: 'mcp-abap-adt-sse',
|
|
223
|
-
version: ver,
|
|
224
|
-
logger: loggerImpl,
|
|
225
|
-
...state,
|
|
226
|
-
});
|
|
227
|
-
this.registry = registry;
|
|
228
|
-
this.loggerImpl = loggerImpl;
|
|
229
|
-
this.ver = ver;
|
|
230
|
-
}
|
|
231
|
-
async init(dest, destinations, firstConnect, hdrs) {
|
|
232
|
-
if (dest) {
|
|
233
|
-
await firstConnect.run(dest, () => this.setConnectionContext(dest, destinations), () => this.getConnection());
|
|
234
|
-
}
|
|
235
|
-
else if (hdrs) {
|
|
236
|
-
this.setConnectionContextFromHeaders(hdrs);
|
|
237
|
-
}
|
|
238
|
-
this.registerHandlers(this.registry);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const server = new SessionServer(this.handlersRegistry, this.logger, this.version, {
|
|
242
|
-
stateIdleMinutes: this.stateIdleMinutes,
|
|
243
|
-
stateLogger: this.stateLogger,
|
|
244
|
-
});
|
|
245
|
-
try {
|
|
246
|
-
await server.init(destination, this.destinations, this.firstConnect, fromHeaders ? req.headers : undefined);
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
this.answerFailure(res, error);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const transport = new sse_js_1.SSEServerTransport(this.postPath, res);
|
|
253
|
-
const sessionId = transport.sessionId;
|
|
254
|
-
console.error(`[SSE GET] Created session ${sessionId} for destination ${destination}`);
|
|
255
|
-
// Capture what the session states (x-sap-language, x-sap-responsible,
|
|
256
|
-
// x-sap-master-system) once at connection time; it is scoped around each
|
|
257
|
-
// POST dispatch below so it never leaks into other sessions via a
|
|
258
|
-
// process-global cache (#110).
|
|
259
|
-
const requestContext = (0, request_context_1.requestContextFromHeaders)(req.headers);
|
|
260
|
-
this.sessions.set(sessionId, { server, transport, requestContext });
|
|
261
|
-
console.error(`[SSE GET] Session stored, total sessions: ${this.sessions.size}`);
|
|
262
|
-
// Connect transport to server BEFORE registering close handler
|
|
263
|
-
// This ensures connection is established before any cleanup can happen
|
|
264
|
-
try {
|
|
265
|
-
await server.connect(transport);
|
|
266
|
-
this.logger.debug(`SSE GET: server connected for session ${sessionId}`);
|
|
267
|
-
}
|
|
268
|
-
catch (error) {
|
|
269
|
-
this.logger.error(`SSE GET: failed to connect for session ${sessionId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
270
|
-
this.sessions.delete(sessionId);
|
|
271
|
-
if (!res.headersSent) {
|
|
272
|
-
res.writeHead(500).end('Internal Server Error');
|
|
273
|
-
}
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
// Register cleanup handler AFTER successful connection
|
|
277
|
-
res.on('close', () => {
|
|
278
|
-
console.error(`[SSE CLOSE] Connection closed for session ${sessionId}`);
|
|
279
|
-
const owned = this.sessions.delete(sessionId);
|
|
280
|
-
void transport.close();
|
|
281
|
-
void server.close();
|
|
282
|
-
// stop() took the session already and disposes it itself: its drain
|
|
283
|
-
// reports the outcome, so a late close adds nothing untracked.
|
|
284
|
-
if (!owned)
|
|
285
|
-
return;
|
|
286
|
-
// The session's instance is owned until its state is gone: it settles on its own (an AMDP
|
|
287
|
-
// session when its last event batch arrives); stop() waits for it.
|
|
288
|
-
const closing = server.shutdownState().then((left) => {
|
|
289
|
-
if (left.length) {
|
|
290
|
-
// The state's line: always written (stderr unless an embedder chose a logger).
|
|
291
|
-
this.stateLogger.error(`[SSE CLOSE] state cleanup for session ${sessionId} left: ${left.join('; ')}`);
|
|
292
|
-
}
|
|
293
|
-
return left.map((l) => `${sessionId}: ${l}`);
|
|
294
|
-
});
|
|
295
|
-
this.closingSessions.add(closing);
|
|
296
|
-
void closing.finally(() => this.closingSessions.delete(closing));
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
async handlePost(req, res, url) {
|
|
300
|
-
const sessionId = (url?.searchParams.get('sessionId') ||
|
|
301
|
-
req.headers['x-session-id'] ||
|
|
302
|
-
'');
|
|
303
|
-
const mcpMethod = req.body?.method;
|
|
304
|
-
const isPing = mcpMethod === 'ping';
|
|
305
|
-
if (!isPing) {
|
|
306
|
-
console.error(`[SSE POST] sessionId=${sessionId}, activeSessions=${this.sessions.size}, keys=[${Array.from(this.sessions.keys()).join(', ')}]`);
|
|
307
|
-
}
|
|
308
|
-
const entry = this.sessions.get(sessionId);
|
|
309
|
-
if (!entry) {
|
|
310
|
-
console.error(`[SSE POST] Invalid session ${sessionId} - session not found!`);
|
|
311
|
-
res.writeHead(400).end('Invalid session');
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
// Pass pre-parsed body from express.json() middleware (like reference implementation)
|
|
315
|
-
// express.json() already read and parsed the body into req.body
|
|
316
|
-
if (!isPing) {
|
|
317
|
-
console.error(`[SSE POST] Calling handlePostMessage with req.body for session ${sessionId}`);
|
|
318
|
-
}
|
|
319
|
-
try {
|
|
320
|
-
await (0, request_context_1.runWithRequestContext)({ ...entry.requestContext }, () => entry.transport.handlePostMessage(req, res, req.body));
|
|
321
|
-
if (!isPing) {
|
|
322
|
-
console.error(`[SSE POST] Successfully processed for session ${sessionId}`);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
catch (error) {
|
|
326
|
-
console.error(`[SSE POST] FAILED for session ${sessionId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
327
|
-
console.error(`[SSE POST] Error stack:`, error);
|
|
328
|
-
if (!res.headersSent) {
|
|
329
|
-
res.writeHead(500).end('Internal Server Error');
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
/** A session whose destination failed: the error's words, or as before. */
|
|
334
|
-
answerFailure(res, error) {
|
|
335
|
-
const answer = (0, destinationRequest_js_1.destinationFailureAnswer)(error);
|
|
336
|
-
if (answer.known) {
|
|
337
|
-
console.error(`[SSE GET] FAILED: ${answer.text}`);
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
// No words for it: its class only — a message may quote a file (H4).
|
|
341
|
-
console.error(`[SSE GET] FAILED: ${(0, auth_1.errorClassOf)(error)}`);
|
|
342
|
-
}
|
|
343
|
-
if (!res.headersSent) {
|
|
344
|
-
res.status(answer.status).send(answer.text);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Check if request has SAP connection headers
|
|
349
|
-
*/
|
|
350
|
-
hasSapConnectionHeaders(headers) {
|
|
351
|
-
const hasUrl = headers['x-sap-url'] || headers['X-SAP-URL'];
|
|
352
|
-
const hasJwtAuth = headers['x-sap-jwt-token'] || headers['X-SAP-JWT-Token'];
|
|
353
|
-
const hasBasicAuth = (headers['x-sap-login'] || headers['X-SAP-Login']) &&
|
|
354
|
-
(headers['x-sap-password'] || headers['X-SAP-Password']);
|
|
355
|
-
return !!(hasUrl && (hasJwtAuth || hasBasicAuth));
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
exports.SseServer = SseServer;
|
|
359
|
-
//# sourceMappingURL=SseServer.js.map
|
package/dist/SseServer.js.map
D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AC5C,MAAM,MAAM,GAAG,IAAA,gDAAwB,EAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CAAC,qBAAqB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,qEAAqE;YACrE,OAAO,CAAC,KAAK,CAAC,qBAAqB,IAAA,mBAAY,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YACrB,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;OAEG;IACK,uBAAuB,CAAC,OAAY;QAC1C,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;QAC5D,MAAM,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC5E,MAAM,YAAY,GAChB,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;YAClD,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAE3D,OAAO,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,IAAI,YAAY,CAAC,CAAC,CAAC;IACpD,CAAC;CACF;AA3aD,8BA2aC"}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { type IDestinations } from '@mcp-abap-adt/lib/auth';
|
|
2
|
-
import type { TlsConfig } from '@mcp-abap-adt/lib/config';
|
|
3
|
-
import type { IHttpApplication, RouteRegistrationOptions } from '@mcp-abap-adt/lib/embeddable';
|
|
4
|
-
import { BaseMcpServer } from '@mcp-abap-adt/lib/embeddable';
|
|
5
|
-
import type { IHandlersRegistry } from '@mcp-abap-adt/lib/handlers';
|
|
6
|
-
import { type StateLogger } from '@mcp-abap-adt/lib/state';
|
|
7
|
-
import type { Logger } from '@mcp-abap-adt/logger';
|
|
8
|
-
export interface StreamableHttpServerOptions {
|
|
9
|
-
/**
|
|
10
|
-
* The idle bound on held state, in minutes: each instance's state ends
|
|
11
|
-
* after this long without a tool call. At least 30; default 30.
|
|
12
|
-
*/
|
|
13
|
-
stateIdleMinutes?: number;
|
|
14
|
-
/** Where the state's lifecycle lines go; default stderr, always on. */
|
|
15
|
-
stateLogger?: StateLogger;
|
|
16
|
-
/**
|
|
17
|
-
* Host to bind to (only used when no external app is provided)
|
|
18
|
-
* @default "127.0.0.1"
|
|
19
|
-
*/
|
|
20
|
-
host?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Port to listen on (only used when no external app is provided)
|
|
23
|
-
* @default 3000
|
|
24
|
-
*/
|
|
25
|
-
port?: number;
|
|
26
|
-
/**
|
|
27
|
-
* Whether to return JSON responses (vs SSE streams)
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
enableJsonResponse?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Default SAP destination to use if not specified in headers
|
|
33
|
-
*/
|
|
34
|
-
defaultDestination?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Path for the MCP endpoint
|
|
37
|
-
* @default "/mcp/stream/http"
|
|
38
|
-
*/
|
|
39
|
-
path?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Logger instance
|
|
42
|
-
*/
|
|
43
|
-
logger?: Logger;
|
|
44
|
-
/**
|
|
45
|
-
* Server version
|
|
46
|
-
*/
|
|
47
|
-
version?: string;
|
|
48
|
-
/**
|
|
49
|
-
* External HTTP application to register routes on
|
|
50
|
-
* When provided, start() will only register routes without creating a server
|
|
51
|
-
* This enables integration with existing Express/CDS/CAP servers
|
|
52
|
-
*/
|
|
53
|
-
app?: IHttpApplication;
|
|
54
|
-
/**
|
|
55
|
-
* TLS configuration for HTTPS support
|
|
56
|
-
*/
|
|
57
|
-
tls?: TlsConfig;
|
|
58
|
-
/**
|
|
59
|
-
* Allow x-mcp-destination header to override default destination
|
|
60
|
-
* @default false
|
|
61
|
-
*/
|
|
62
|
-
allowDestinationHeader?: boolean;
|
|
63
|
-
/** Allowed Host header values (DNS-rebinding protection; exact, incl. port) */
|
|
64
|
-
allowedHosts?: string[];
|
|
65
|
-
/** Allowed Origin header values (DNS-rebinding protection; exact, incl. scheme) */
|
|
66
|
-
allowedOrigins?: string[];
|
|
67
|
-
/** Enable DNS-rebinding protection (requires allowedHosts and/or allowedOrigins) */
|
|
68
|
-
enableDnsRebindingProtection?: boolean;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Minimal Streamable HTTP server implementation.
|
|
72
|
-
* Creates new transport for each HTTP POST and forwards request to the MCP server.
|
|
73
|
-
* Destination is taken from x-mcp-destination header or defaultDestination.
|
|
74
|
-
*
|
|
75
|
-
* Supports two modes:
|
|
76
|
-
* 1. Standalone mode: Creates its own Express server (when no app option provided)
|
|
77
|
-
* 2. Embedded mode: Registers routes on external app (when app option provided)
|
|
78
|
-
*/
|
|
79
|
-
export declare class StreamableHttpServer extends BaseMcpServer {
|
|
80
|
-
private readonly handlersRegistry;
|
|
81
|
-
/** The destinations: settings and the counted provider, nothing else. */
|
|
82
|
-
private readonly destinations;
|
|
83
|
-
private readonly host;
|
|
84
|
-
private readonly port;
|
|
85
|
-
private readonly enableJsonResponse;
|
|
86
|
-
private readonly defaultDestination?;
|
|
87
|
-
private readonly path;
|
|
88
|
-
private readonly externalApp?;
|
|
89
|
-
private readonly version;
|
|
90
|
-
private standaloneServer?;
|
|
91
|
-
private readonly tls?;
|
|
92
|
-
private readonly allowDestinationHeader;
|
|
93
|
-
private readonly allowedHosts?;
|
|
94
|
-
private readonly allowedOrigins?;
|
|
95
|
-
private readonly enableDnsRebindingProtection?;
|
|
96
|
-
/** Per-destination lock around the first connect: it serialises the first login. */
|
|
97
|
-
private readonly firstConnect;
|
|
98
|
-
/** The instances that hold state between requests (spec D9). */
|
|
99
|
-
private readonly pool;
|
|
100
|
-
private readonly stateIdleMinutes?;
|
|
101
|
-
private readonly stateLogger;
|
|
102
|
-
constructor(handlersRegistry: IHandlersRegistry,
|
|
103
|
-
/** The destinations: settings and the counted provider, nothing else. */
|
|
104
|
-
destinations: IDestinations, opts?: StreamableHttpServerOptions);
|
|
105
|
-
/**
|
|
106
|
-
* Creates the request handler function
|
|
107
|
-
* Can be used to register on external app or internal Express
|
|
108
|
-
*/
|
|
109
|
-
private createRequestHandler;
|
|
110
|
-
/**
|
|
111
|
-
* Register routes on an external HTTP application
|
|
112
|
-
* Use this when integrating with existing Express/CDS/CAP server
|
|
113
|
-
*
|
|
114
|
-
* @param app - External HTTP application (Express, CDS, etc.)
|
|
115
|
-
* @param options - Route registration options
|
|
116
|
-
*/
|
|
117
|
-
registerRoutes(app: IHttpApplication, _options?: RouteRegistrationOptions): void;
|
|
118
|
-
/**
|
|
119
|
-
* Get the configured endpoint path
|
|
120
|
-
*/
|
|
121
|
-
getPath(): string;
|
|
122
|
-
/**
|
|
123
|
-
* Start the server
|
|
124
|
-
*
|
|
125
|
-
* In standalone mode (no external app): Creates Express server and starts listening
|
|
126
|
-
* In embedded mode (external app provided): Only registers routes on external app
|
|
127
|
-
*/
|
|
128
|
-
start(): Promise<void>;
|
|
129
|
-
/**
|
|
130
|
-
* Stops taking connections (shutdown, step 1), then the pool: no request is
|
|
131
|
-
* admitted any more, the running ones finish, every instance that holds
|
|
132
|
-
* state is disposed and waited for (no timer). Rejects with what could not
|
|
133
|
-
* be undone. Embedded on an external app, there is no listener of its own
|
|
134
|
-
* to stop, but the pool is still ours to drain.
|
|
135
|
-
*/
|
|
136
|
-
stop(): Promise<void>;
|
|
137
|
-
/**
|
|
138
|
-
* Check if request has SAP connection headers
|
|
139
|
-
*/
|
|
140
|
-
private hasSapConnectionHeaders;
|
|
141
|
-
private createPerRequestServer;
|
|
142
|
-
}
|
|
143
|
-
//# sourceMappingURL=StreamableHttpServer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StreamableHttpServer.d.ts","sourceRoot":"","sources":["../src/StreamableHttpServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAMpE,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,yBAAyB,CAAC;AAC1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAmBnD,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uEAAuE;IACvE,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,GAAG,CAAC,EAAE,gBAAgB,CAAC;IACvB;;OAEG;IACH,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,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