@abgov/adsp-sdk-mcp-server 1.22.1 → 1.24.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 +83 -1
- package/assets/docs/services/agent-service.md +113 -27
- package/assets/docs/services/file-service.md +215 -116
- package/assets/docs/services/pdf-service.md +20 -0
- package/assets/docs/tutorials/file-service/file-types.md +2 -4
- package/assets/docs/tutorials/file-service/security.md +1 -1
- package/assets/docs/tutorials/file-service/working-with.md +5 -5
- package/package.json +6 -1
- package/src/config.d.ts +11 -0
- package/src/config.js +47 -0
- package/src/config.js.map +1 -0
- package/src/guards.d.ts +11 -0
- package/src/guards.js +94 -0
- package/src/guards.js.map +1 -0
- package/src/http.d.ts +17 -1
- package/src/http.js +39 -15
- package/src/http.js.map +1 -1
- package/src/main.js +13 -5
- package/src/main.js.map +1 -1
- package/src/metrics.d.ts +22 -0
- package/src/metrics.js +173 -0
- package/src/metrics.js.map +1 -0
- package/src/semaphore.d.ts +16 -0
- package/src/semaphore.js +71 -0
- package/src/semaphore.js.map +1 -0
- package/src/server.js +28 -3
- package/src/server.js.map +1 -1
- package/src/tools/liveToolLimit.d.ts +8 -0
- package/src/tools/liveToolLimit.js +45 -0
- package/src/tools/liveToolLimit.js.map +1 -0
- package/src/tools/registerConfigurationSchemaTool.js +7 -2
- package/src/tools/registerConfigurationSchemaTool.js.map +1 -1
- package/src/tools/registerServiceRolesTool.js +7 -2
- package/src/tools/registerServiceRolesTool.js.map +1 -1
- package/src/tools/types.d.ts +6 -2
- package/src/tools/upstreamErrors.d.ts +2 -0
- package/src/tools/upstreamErrors.js +18 -0
- package/src/tools/upstreamErrors.js.map +1 -0
package/src/guards.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendJsonRpcError = sendJsonRpcError;
|
|
4
|
+
exports.createCorsAndOriginGuard = createCorsAndOriginGuard;
|
|
5
|
+
exports.rateLimitKey = rateLimitKey;
|
|
6
|
+
exports.createRateLimit = createRateLimit;
|
|
7
|
+
exports.createInFlightGate = createInFlightGate;
|
|
8
|
+
const express_rate_limit_1 = require("express-rate-limit");
|
|
9
|
+
const metrics_1 = require("./metrics");
|
|
10
|
+
const RATE_LIMIT_WINDOW_MS = 60_000;
|
|
11
|
+
function sendJsonRpcError(res, status, message) {
|
|
12
|
+
res.status(status).json({ jsonrpc: '2.0', error: { code: -32000, message }, id: null });
|
|
13
|
+
}
|
|
14
|
+
function isAllowedOrigin(origin, corsOrigins) {
|
|
15
|
+
// Sandboxed frames and file: pages send "null", which can't be tied to any one site.
|
|
16
|
+
if (origin === 'null') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
// Exact match: browsers send Origin as scheme://host[:port], and trimming the client's value with a regex is
|
|
20
|
+
// quadratic on a header full of slashes. CORS_ORIGIN entries are normalised once in readConfig instead.
|
|
21
|
+
return corsOrigins === '*' || corsOrigins.includes(origin);
|
|
22
|
+
}
|
|
23
|
+
/** MCP requires servers to validate Origin (2025-11-25). Requests without one come from non-browser clients and pass. */
|
|
24
|
+
function createCorsAndOriginGuard(corsOrigins) {
|
|
25
|
+
return (req, res, next) => {
|
|
26
|
+
res.vary('Origin');
|
|
27
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
28
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, mcp-session-id, mcp-protocol-version');
|
|
29
|
+
res.setHeader('Access-Control-Expose-Headers', 'mcp-session-id');
|
|
30
|
+
const origin = req.headers.origin;
|
|
31
|
+
if (origin !== undefined) {
|
|
32
|
+
if (!isAllowedOrigin(origin, corsOrigins)) {
|
|
33
|
+
(0, metrics_1.getMetrics)().recordRejection('origin');
|
|
34
|
+
sendJsonRpcError(res, 403, 'Origin not allowed');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
res.setHeader('Access-Control-Allow-Origin', corsOrigins === '*' ? '*' : origin);
|
|
38
|
+
}
|
|
39
|
+
if (req.method === 'OPTIONS') {
|
|
40
|
+
res.sendStatus(204);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
next();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Keyed by client IP until authentication lands; then this should return the authenticated client. */
|
|
47
|
+
function rateLimitKey(req) {
|
|
48
|
+
return req.ip ?? 'unknown';
|
|
49
|
+
}
|
|
50
|
+
function createRateLimit(limitPerMinute) {
|
|
51
|
+
if (limitPerMinute === 0) {
|
|
52
|
+
return (_req, _res, next) => next();
|
|
53
|
+
}
|
|
54
|
+
return (0, express_rate_limit_1.rateLimit)({
|
|
55
|
+
windowMs: RATE_LIMIT_WINDOW_MS,
|
|
56
|
+
limit: limitPerMinute,
|
|
57
|
+
standardHeaders: 'draft-7',
|
|
58
|
+
legacyHeaders: false,
|
|
59
|
+
keyGenerator: rateLimitKey,
|
|
60
|
+
// With standardHeaders on, express-rate-limit sets Retry-After before calling the handler.
|
|
61
|
+
handler: (_req, res) => {
|
|
62
|
+
(0, metrics_1.getMetrics)().recordRejection('rate_limit');
|
|
63
|
+
sendJsonRpcError(res, 429, 'Rate limit exceeded');
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Holds each admitted request's slot until its response closes; `mcp.requests.in_flight` counts admitted requests. */
|
|
68
|
+
function createInFlightGate(semaphore, waitMs) {
|
|
69
|
+
return async (_req, res, next) => {
|
|
70
|
+
const closed = new AbortController();
|
|
71
|
+
res.on('close', () => closed.abort());
|
|
72
|
+
const release = await semaphore.acquire(waitMs, closed.signal);
|
|
73
|
+
if (!release) {
|
|
74
|
+
if (!closed.signal.aborted) {
|
|
75
|
+
(0, metrics_1.getMetrics)().recordRejection('in_flight_cap');
|
|
76
|
+
res.setHeader('Retry-After', '1');
|
|
77
|
+
sendJsonRpcError(res, 503, 'Server busy');
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (closed.signal.aborted) {
|
|
82
|
+
release();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const metrics = (0, metrics_1.getMetrics)();
|
|
86
|
+
metrics.addInFlight(1);
|
|
87
|
+
res.on('close', () => {
|
|
88
|
+
release();
|
|
89
|
+
metrics.addInFlight(-1);
|
|
90
|
+
});
|
|
91
|
+
next();
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../libs/adsp-sdk-mcp-server/src/guards.ts"],"names":[],"mappings":";;AAQA,4CAEC;AAaD,4DAuBC;AAGD,oCAEC;AAED,0CAgBC;AAGD,gDA2BC;AAlGD,2DAA+C;AAE/C,uCAAuC;AAGvC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC,SAAgB,gBAAgB,CAAC,GAAqB,EAAE,MAAc,EAAE,OAAe;IACrF,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,eAAe,CAAC,MAAc,EAAE,WAA2C;IAClF,qFAAqF;IACrF,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,6GAA6G;IAC7G,wGAAwG;IACxG,OAAO,WAAW,KAAK,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED,yHAAyH;AACzH,SAAgB,wBAAwB,CAAC,WAA2C;IAClF,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACxB,GAAG,CAA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E,GAAG,EAAE;YACnB,OAAO,EAAE,CAAC;YACV,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;QACH,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
package/src/http.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
|
+
import { Server as HttpServer } from 'http';
|
|
3
|
+
import { McpServerConfig } from './config';
|
|
2
4
|
import { CreateAdspMcpServerOptions } from './server';
|
|
3
|
-
export
|
|
5
|
+
export interface McpHttpAppOptions extends CreateAdspMcpServerOptions {
|
|
6
|
+
/** Defaults to `readConfig()` over `process.env`. */
|
|
7
|
+
config?: McpServerConfig;
|
|
8
|
+
}
|
|
9
|
+
export declare function createMcpHttpApp({ config, ...serverOptions }?: McpHttpAppOptions): express.Express;
|
|
10
|
+
export interface McpHttpServerOptions {
|
|
11
|
+
requestTimeoutMs?: number;
|
|
12
|
+
headersTimeoutMs?: number;
|
|
13
|
+
connectionsCheckingIntervalMs?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The in-flight gate admits a request before its body arrives, so a client that never finishes sending one would hold
|
|
17
|
+
* a slot until Node's 300 s default. These limits only cover receiving the request, not how long a tool call takes.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createMcpHttpServer(app: express.Express, options?: McpHttpServerOptions): HttpServer;
|
package/src/http.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMcpHttpApp = createMcpHttpApp;
|
|
4
|
+
exports.createMcpHttpServer = createMcpHttpServer;
|
|
4
5
|
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
5
6
|
const express = require("express");
|
|
7
|
+
const http_1 = require("http");
|
|
8
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
const guards_1 = require("./guards");
|
|
11
|
+
const metrics_1 = require("./metrics");
|
|
12
|
+
const semaphore_1 = require("./semaphore");
|
|
6
13
|
const server_1 = require("./server");
|
|
14
|
+
const liveToolLimit_1 = require("./tools/liveToolLimit");
|
|
7
15
|
const MAX_REQUEST_BODY_BYTES = 1024 * 1024;
|
|
8
|
-
function applyCorsHeaders(req, res, next) {
|
|
9
|
-
res.setHeader('Access-Control-Allow-Origin', process.env['CORS_ORIGIN'] ?? '*');
|
|
10
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
11
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, mcp-session-id, mcp-protocol-version');
|
|
12
|
-
res.setHeader('Access-Control-Expose-Headers', 'mcp-session-id');
|
|
13
|
-
if (req.method === 'OPTIONS') {
|
|
14
|
-
res.sendStatus(204);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
next();
|
|
18
|
-
}
|
|
19
16
|
function createStatelessPostHandler(options) {
|
|
20
17
|
return async (req, res) => {
|
|
18
|
+
const started = perf_hooks_1.performance.now();
|
|
19
|
+
const metrics = (0, metrics_1.getMetrics)();
|
|
20
|
+
let method = 'unparsed';
|
|
21
|
+
let messagesSeen = 0;
|
|
21
22
|
const server = (0, server_1.createAdspMcpServer)(options);
|
|
22
23
|
const transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
|
|
23
24
|
sessionIdGenerator: undefined,
|
|
@@ -28,9 +29,19 @@ function createStatelessPostHandler(options) {
|
|
|
28
29
|
res.on('close', () => {
|
|
29
30
|
transport.close();
|
|
30
31
|
server.close();
|
|
32
|
+
// Node leaves statusCode at 200 when the client goes away before a response is written.
|
|
33
|
+
const outcome = res.writableFinished ? res.statusCode : 'aborted';
|
|
34
|
+
metrics.recordRequest(method, outcome, (perf_hooks_1.performance.now() - started) / 1000);
|
|
31
35
|
});
|
|
32
36
|
try {
|
|
33
37
|
await server.connect(transport);
|
|
38
|
+
const deliver = transport.onmessage;
|
|
39
|
+
// The transport parses the body itself, so the JSON-RPC method is only visible as messages arrive.
|
|
40
|
+
transport.onmessage = (message, extra) => {
|
|
41
|
+
messagesSeen += 1;
|
|
42
|
+
method = messagesSeen > 1 ? 'batch' : (0, metrics_1.bucketMcpMethod)(message);
|
|
43
|
+
deliver?.(message, extra);
|
|
44
|
+
};
|
|
34
45
|
await transport.handleRequest(req, res);
|
|
35
46
|
}
|
|
36
47
|
catch (err) {
|
|
@@ -52,17 +63,30 @@ function methodNotAllowed(_req, res) {
|
|
|
52
63
|
.set('Allow', 'POST')
|
|
53
64
|
.json({ jsonrpc: '2.0', error: { code: -32000, message: 'Method not allowed.' }, id: null });
|
|
54
65
|
}
|
|
55
|
-
function createMcpHttpApp(
|
|
56
|
-
(0, server_1.loadAdspMcpTools)(
|
|
66
|
+
function createMcpHttpApp({ config = (0, config_1.readConfig)(), ...serverOptions } = {}) {
|
|
67
|
+
(0, server_1.loadAdspMcpTools)(serverOptions);
|
|
68
|
+
(0, liveToolLimit_1.configureLiveToolLimit)({ maxConcurrent: config.liveToolMaxConcurrent, waitMs: config.inFlightWaitMs });
|
|
57
69
|
// No express.json(): the transport reads the body so parse and size errors come back as JSON-RPC.
|
|
58
70
|
const app = express();
|
|
59
|
-
app.
|
|
71
|
+
app.set('trust proxy', config.trustedProxy);
|
|
60
72
|
app.get('/health', (_req, res) => {
|
|
61
73
|
res.json({ status: 'ok' });
|
|
62
74
|
});
|
|
63
|
-
app.
|
|
75
|
+
app.use('/mcp', (0, guards_1.createCorsAndOriginGuard)(config.corsOrigins));
|
|
76
|
+
app.post('/mcp', (0, guards_1.createRateLimit)(config.rateLimitPerMinute), (0, guards_1.createInFlightGate)(new semaphore_1.Semaphore(config.maxInFlight, { maxWaiters: config.maxInFlight }), config.inFlightWaitMs), createStatelessPostHandler(serverOptions));
|
|
64
77
|
app.get('/mcp', methodNotAllowed);
|
|
65
78
|
app.delete('/mcp', methodNotAllowed);
|
|
66
79
|
return app;
|
|
67
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* The in-flight gate admits a request before its body arrives, so a client that never finishes sending one would hold
|
|
83
|
+
* a slot until Node's 300 s default. These limits only cover receiving the request, not how long a tool call takes.
|
|
84
|
+
*/
|
|
85
|
+
function createMcpHttpServer(app, options = {}) {
|
|
86
|
+
return (0, http_1.createServer)({
|
|
87
|
+
requestTimeout: options.requestTimeoutMs ?? 30_000,
|
|
88
|
+
headersTimeout: options.headersTimeoutMs ?? 20_000,
|
|
89
|
+
connectionsCheckingInterval: options.connectionsCheckingIntervalMs ?? 5_000,
|
|
90
|
+
}, app);
|
|
91
|
+
}
|
|
68
92
|
//# sourceMappingURL=http.js.map
|
package/src/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../libs/adsp-sdk-mcp-server/src/http.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../libs/adsp-sdk-mcp-server/src/http.ts"],"names":[],"mappings":";;AAwEA,4CAuBC;AAYD,kDASC;AApHD,0FAAmG;AACnG,mCAAmC;AACnC,+BAA0D;AAC1D,2CAAyC;AACzC,qCAAuD;AACvD,qCAAyF;AACzF,uCAAwD;AACxD,2CAAwC;AACxC,qCAA6F;AAC7F,yDAA+D;AAE/D,MAAM,sBAAsB,GAAG,IAAI,GAAG,IAAI,CAAC;AAO3C,SAAS,0BAA0B,CAAC,OAAmC;IACrE,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QACxB,MAAM,OAAO,GAAG,wBAAW,CAAC,GAAG,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,IAAA,oBAAU,GAAE,CAAC;QAC7B,IAAI,MAAM,GAAG,UAAU,CAAC;QACxB,IAAI,YAAY,GAAG,CAAC,CAAC;QAErB,MAAM,MAAM,GAAG,IAAA,4BAAmB,EAAC,OAAO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AC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,IAAA,iCAAwB,EAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAC9D,GAAG,CAAC,IAAI,CACN,MAAM,EACN,IAAA,wBAAe,EAAC,MAAM,CAAC,kBAAkB,CAAC,EAC1C,IAAA,2BAAkB,EAAC,IAAI,qBAAS,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,EAChH,0BAA0B,CAAC,aAAa,CAAC,CAC1C,CAAC;IACF,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAClC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAErC,OAAO,GAAG,CAAC;AACb,CAAC;AAQD;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,GAAoB,EAAE,UAAgC,EAAE;IAC1F,OAAO,IAAA,mBAAY,EACjB;QACE,cAAc,EAAE,OAAO,CAAC,gBAAgB,IAAI,MAAM;QAClD,cAAc,EAAE,OAAO,CAAC,gBAAgB,IAAI,MAAM;QAClD,2BAA2B,EAAE,OAAO,CAAC,6BAA6B,IAAI,KAAK;KAC5E,EACD,GAAG,CACJ,CAAC;AACJ,CAAC"}
|
package/src/main.js
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
5
|
+
const config_1 = require("./config");
|
|
5
6
|
const http_1 = require("./http");
|
|
7
|
+
const metrics_1 = require("./metrics");
|
|
6
8
|
const server_1 = require("./server");
|
|
9
|
+
const liveToolLimit_1 = require("./tools/liveToolLimit");
|
|
7
10
|
function resolveTransport() {
|
|
8
11
|
const raw = process.env['MCP_TRANSPORT'] ?? 'stdio';
|
|
9
12
|
if (raw === 'stdio' || raw === 'http')
|
|
@@ -13,25 +16,30 @@ function resolveTransport() {
|
|
|
13
16
|
}
|
|
14
17
|
async function main() {
|
|
15
18
|
const transport = resolveTransport();
|
|
19
|
+
const config = (0, config_1.readConfig)();
|
|
16
20
|
console.error(`[adsp-sdk-mcp-server] transport=${transport}`);
|
|
17
21
|
if (transport === 'http') {
|
|
18
|
-
await startHttp();
|
|
22
|
+
await startHttp(config);
|
|
19
23
|
}
|
|
20
24
|
else {
|
|
25
|
+
(0, liveToolLimit_1.configureLiveToolLimit)({ maxConcurrent: config.liveToolMaxConcurrent, waitMs: config.inFlightWaitMs });
|
|
21
26
|
const server = (0, server_1.createAdspMcpServer)();
|
|
22
27
|
await server.connect(new stdio_js_1.StdioServerTransport());
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
|
-
async function startHttp() {
|
|
30
|
+
async function startHttp(config) {
|
|
26
31
|
const port = parseInt(process.env['PORT'] ?? '3000', 10);
|
|
27
|
-
|
|
32
|
+
// Started before the app so the docs index build, which the app triggers, is recorded.
|
|
33
|
+
const metrics = await (0, metrics_1.startMetricsFromEnv)();
|
|
34
|
+
const app = (0, http_1.createMcpHttpApp)({ config });
|
|
28
35
|
return new Promise((resolve) => {
|
|
29
|
-
const httpServer = app.listen(port, () => {
|
|
36
|
+
const httpServer = (0, http_1.createMcpHttpServer)(app).listen(port, () => {
|
|
30
37
|
console.error(`[adsp-sdk-mcp-server] HTTP server listening on :${port}`);
|
|
31
38
|
resolve();
|
|
32
39
|
});
|
|
33
40
|
function shutdown() {
|
|
34
|
-
|
|
41
|
+
const flushed = metrics?.shutdown().catch(() => undefined) ?? Promise.resolve();
|
|
42
|
+
httpServer.close(() => flushed.then(() => process.exit(0)));
|
|
35
43
|
setTimeout(() => process.exit(1), 5_000).unref();
|
|
36
44
|
}
|
|
37
45
|
process.on('SIGTERM', shutdown);
|
package/src/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../libs/adsp-sdk-mcp-server/src/main.ts"],"names":[],"mappings":";;;AACA,wEAAiF;AACjF,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../libs/adsp-sdk-mcp-server/src/main.ts"],"names":[],"mappings":";;;AACA,wEAAiF;AACjF,qCAAuD;AACvD,iCAA+D;AAC/D,uCAAgD;AAChD,qCAA+C;AAC/C,yDAA+D;AAI/D,SAAS,gBAAgB;IACvB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,OAAO,CAAC;IACpD,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,MAAM;QAAE,OAAO,GAAG,CAAC;IAClD,OAAO,CAAC,KAAK,CAAC,gDAAgD,GAAG,oDAAoD,CAAC,CAAC;IACvH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,gBAAgB,EAAE,CAAC;IACrC,MAAM,MAAM,GAAG,IAAA,mBAAU,GAAE,CAAC;IAC5B,OAAO,CAAC,KAAK,CAAC,mCAAmC,SAAS,EAAE,CAAC,CAAC;IAE9D,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;QACzB,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,IAAA,sCAAsB,EAAC,EAAE,aAAa,EAAE,MAAM,CAAC,qBAAqB,EAAE,MAAM,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;QACvG,MAAM,MAAM,GAAG,IAAA,4BAAmB,GAAE,CAAC;QACrC,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,+BAAoB,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,MAAuB;IAC9C,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,MA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d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MeterProvider } from '@opentelemetry/api';
|
|
2
|
+
export type RejectionReason = 'in_flight_cap' | 'rate_limit' | 'origin' | 'live_tool_cap';
|
|
3
|
+
export type ToolErrorType = 'tool_error' | 'exception' | 'unknown_tool' | 'busy';
|
|
4
|
+
export type UpstreamErrorType = 'http_4xx' | 'http_5xx' | 'network' | 'not_in_directory' | 'not_authenticated' | 'other';
|
|
5
|
+
export interface McpMetrics {
|
|
6
|
+
addInFlight(delta: 1 | -1): void;
|
|
7
|
+
recordRejection(reason: RejectionReason): void;
|
|
8
|
+
/** `method` must already be bucketed with `bucketMcpMethod`. */
|
|
9
|
+
recordRequest(method: string, outcome: number | 'aborted', durationSeconds: number): void;
|
|
10
|
+
recordToolCall(toolName: string, durationSeconds: number, errorType?: ToolErrorType): void;
|
|
11
|
+
recordUpstreamError(toolName: string, errorType: UpstreamErrorType): void;
|
|
12
|
+
recordDocsIndexBuild(durationSeconds: number): void;
|
|
13
|
+
}
|
|
14
|
+
export declare function getMetrics(): McpMetrics;
|
|
15
|
+
export declare function installMetrics(meterProvider: MeterProvider): {
|
|
16
|
+
uninstall(): void;
|
|
17
|
+
};
|
|
18
|
+
export interface StartedMetrics {
|
|
19
|
+
shutdown(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare function startMetricsFromEnv(env?: NodeJS.ProcessEnv): Promise<StartedMetrics | undefined>;
|
|
22
|
+
export declare function bucketMcpMethod(message: unknown): string;
|
package/src/metrics.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMetrics = getMetrics;
|
|
4
|
+
exports.installMetrics = installMetrics;
|
|
5
|
+
exports.startMetricsFromEnv = startMetricsFromEnv;
|
|
6
|
+
exports.bucketMcpMethod = bucketMcpMethod;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
10
|
+
const NOOP_METRICS = {
|
|
11
|
+
addInFlight: () => undefined,
|
|
12
|
+
recordRejection: () => undefined,
|
|
13
|
+
recordRequest: () => undefined,
|
|
14
|
+
recordToolCall: () => undefined,
|
|
15
|
+
recordUpstreamError: () => undefined,
|
|
16
|
+
recordDocsIndexBuild: () => undefined,
|
|
17
|
+
};
|
|
18
|
+
let current = NOOP_METRICS;
|
|
19
|
+
function getMetrics() {
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
const DURATION_BUCKETS_SECONDS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10];
|
|
23
|
+
const NANOSECONDS_PER_SECOND = 1e9;
|
|
24
|
+
const EVENT_LOOP_RESOLUTION_MS = 10;
|
|
25
|
+
function installMetrics(meterProvider) {
|
|
26
|
+
const meter = meterProvider.getMeter('adsp-sdk-mcp-server');
|
|
27
|
+
const durationAdvice = { advice: { explicitBucketBoundaries: DURATION_BUCKETS_SECONDS } };
|
|
28
|
+
const inFlight = meter.createUpDownCounter('mcp.requests.in_flight', {
|
|
29
|
+
description: 'MCP requests admitted and not yet answered.',
|
|
30
|
+
unit: '{request}',
|
|
31
|
+
});
|
|
32
|
+
const rejected = meter.createCounter('mcp.requests.rejected', {
|
|
33
|
+
description: 'MCP requests or tool calls refused by an overload guard, by reason.',
|
|
34
|
+
unit: '{request}',
|
|
35
|
+
});
|
|
36
|
+
const requestDuration = meter.createHistogram('mcp.request.duration', {
|
|
37
|
+
description: 'Time to answer a POST /mcp request, by JSON-RPC method.',
|
|
38
|
+
unit: 's',
|
|
39
|
+
...durationAdvice,
|
|
40
|
+
});
|
|
41
|
+
const toolDuration = meter.createHistogram('mcp.tool.duration', {
|
|
42
|
+
description: 'Time to run a tool call, by tool and error type.',
|
|
43
|
+
unit: 's',
|
|
44
|
+
...durationAdvice,
|
|
45
|
+
});
|
|
46
|
+
const upstreamErrors = meter.createCounter('mcp.live_tool.upstream.errors', {
|
|
47
|
+
description: 'Failed upstream calls made by the live tools.',
|
|
48
|
+
unit: '{error}',
|
|
49
|
+
});
|
|
50
|
+
const docsIndexBuild = meter.createHistogram('mcp.docs_index.build.duration', {
|
|
51
|
+
description: 'Time to build the docs index and tool definitions for a docs root.',
|
|
52
|
+
unit: 's',
|
|
53
|
+
...durationAdvice,
|
|
54
|
+
});
|
|
55
|
+
const eventLoopP50 = meter.createObservableGauge('nodejs.eventloop.delay.p50', { unit: 's' });
|
|
56
|
+
const eventLoopP99 = meter.createObservableGauge('nodejs.eventloop.delay.p99', { unit: 's' });
|
|
57
|
+
const eventLoopMax = meter.createObservableGauge('nodejs.eventloop.delay.max', { unit: 's' });
|
|
58
|
+
const heapUsed = meter.createObservableGauge('v8js.memory.heap.used', { unit: 'By' });
|
|
59
|
+
const rss = meter.createObservableGauge('process.memory.usage', { unit: 'By' });
|
|
60
|
+
const observables = [eventLoopP50, eventLoopP99, eventLoopMax, heapUsed, rss];
|
|
61
|
+
const eventLoopDelay = (0, perf_hooks_1.monitorEventLoopDelay)({ resolution: EVENT_LOOP_RESOLUTION_MS });
|
|
62
|
+
eventLoopDelay.enable();
|
|
63
|
+
const observe = (result) => {
|
|
64
|
+
if (eventLoopDelay.count > 0) {
|
|
65
|
+
result.observe(eventLoopP50, eventLoopDelay.percentile(50) / NANOSECONDS_PER_SECOND);
|
|
66
|
+
result.observe(eventLoopP99, eventLoopDelay.percentile(99) / NANOSECONDS_PER_SECOND);
|
|
67
|
+
result.observe(eventLoopMax, eventLoopDelay.max / NANOSECONDS_PER_SECOND);
|
|
68
|
+
}
|
|
69
|
+
// Reset so each export reports the delay since the previous one, not since startup.
|
|
70
|
+
eventLoopDelay.reset();
|
|
71
|
+
const memory = process.memoryUsage();
|
|
72
|
+
result.observe(heapUsed, memory.heapUsed);
|
|
73
|
+
result.observe(rss, memory.rss);
|
|
74
|
+
};
|
|
75
|
+
meter.addBatchObservableCallback(observe, observables);
|
|
76
|
+
current = {
|
|
77
|
+
addInFlight: (delta) => inFlight.add(delta),
|
|
78
|
+
recordRejection: (reason) => rejected.add(1, { reason }),
|
|
79
|
+
recordRequest: (method, outcome, durationSeconds) => requestDuration.record(durationSeconds, outcome === 'aborted'
|
|
80
|
+
? { 'mcp.method.name': method, 'error.type': 'aborted' }
|
|
81
|
+
: { 'mcp.method.name': method, 'http.response.status_code': outcome }),
|
|
82
|
+
recordToolCall: (toolName, durationSeconds, errorType) => toolDuration.record(durationSeconds, errorType ? { 'mcp.tool.name': toolName, 'error.type': errorType } : { 'mcp.tool.name': toolName }),
|
|
83
|
+
recordUpstreamError: (toolName, errorType) => upstreamErrors.add(1, { 'mcp.tool.name': toolName, 'error.type': errorType }),
|
|
84
|
+
recordDocsIndexBuild: (durationSeconds) => docsIndexBuild.record(durationSeconds),
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
uninstall() {
|
|
88
|
+
meter.removeBatchObservableCallback(observe, observables);
|
|
89
|
+
eventLoopDelay.disable();
|
|
90
|
+
current = NOOP_METRICS;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const DEFAULT_EXPORT_INTERVAL_MS = 60_000;
|
|
95
|
+
const EXPORT_TIMEOUT_MS = 30_000;
|
|
96
|
+
function readPackageVersion() {
|
|
97
|
+
try {
|
|
98
|
+
return JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json'), 'utf8')).version ?? 'unknown';
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return 'unknown';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function readExportIntervalMs(env) {
|
|
105
|
+
const interval = parseInt(env['OTEL_METRIC_EXPORT_INTERVAL'] ?? '', 10);
|
|
106
|
+
return interval > 0 ? interval : DEFAULT_EXPORT_INTERVAL_MS;
|
|
107
|
+
}
|
|
108
|
+
async function startMetricsFromEnv(env = process.env) {
|
|
109
|
+
const endpoint = env['OTEL_EXPORTER_OTLP_ENDPOINT']?.trim().replace(/\/+$/, '');
|
|
110
|
+
if (!endpoint) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
// Loaded only here so processes without an endpoint never load the OTel SDK.
|
|
115
|
+
const { MeterProvider, PeriodicExportingMetricReader } = await Promise.resolve().then(() => require('@opentelemetry/sdk-metrics'));
|
|
116
|
+
const { OTLPMetricExporter } = await Promise.resolve().then(() => require('@opentelemetry/exporter-metrics-otlp-http'));
|
|
117
|
+
const { defaultResource, resourceFromAttributes } = await Promise.resolve().then(() => require('@opentelemetry/resources'));
|
|
118
|
+
const exportIntervalMillis = readExportIntervalMs(env);
|
|
119
|
+
const provider = new MeterProvider({
|
|
120
|
+
resource: defaultResource().merge(resourceFromAttributes({ 'service.name': 'adsp-sdk-mcp-server', 'service.version': readPackageVersion() })),
|
|
121
|
+
readers: [
|
|
122
|
+
new PeriodicExportingMetricReader({
|
|
123
|
+
exporter: new OTLPMetricExporter({ url: `${endpoint}/v1/metrics` }),
|
|
124
|
+
exportIntervalMillis,
|
|
125
|
+
// The reader rejects a timeout longer than the interval.
|
|
126
|
+
exportTimeoutMillis: Math.min(EXPORT_TIMEOUT_MS, exportIntervalMillis),
|
|
127
|
+
}),
|
|
128
|
+
],
|
|
129
|
+
});
|
|
130
|
+
const { uninstall } = installMetrics(provider);
|
|
131
|
+
console.error(`[adsp-sdk-mcp-server] metrics -> ${endpoint}`);
|
|
132
|
+
return {
|
|
133
|
+
async shutdown() {
|
|
134
|
+
uninstall();
|
|
135
|
+
await provider.shutdown();
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
console.error(`[adsp-sdk-mcp-server] Metrics disabled: ${err instanceof Error ? err.message : String(err)}`);
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const KNOWN_MCP_METHODS = new Set([
|
|
145
|
+
'initialize',
|
|
146
|
+
'ping',
|
|
147
|
+
'tools/list',
|
|
148
|
+
'tools/call',
|
|
149
|
+
'resources/list',
|
|
150
|
+
'resources/read',
|
|
151
|
+
'resources/templates/list',
|
|
152
|
+
'resources/subscribe',
|
|
153
|
+
'resources/unsubscribe',
|
|
154
|
+
'prompts/list',
|
|
155
|
+
'prompts/get',
|
|
156
|
+
'logging/setLevel',
|
|
157
|
+
'completion/complete',
|
|
158
|
+
'notifications/initialized',
|
|
159
|
+
'notifications/cancelled',
|
|
160
|
+
'notifications/progress',
|
|
161
|
+
'notifications/roots/list_changed',
|
|
162
|
+
]);
|
|
163
|
+
function bucketMcpMethod(message) {
|
|
164
|
+
if (Array.isArray(message)) {
|
|
165
|
+
return 'batch';
|
|
166
|
+
}
|
|
167
|
+
const method = message?.method;
|
|
168
|
+
if (typeof message !== 'object' || typeof method !== 'string') {
|
|
169
|
+
return 'unparsed';
|
|
170
|
+
}
|
|
171
|
+
return KNOWN_MCP_METHODS.has(method) ? method : 'other';
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../../libs/adsp-sdk-mcp-server/src/metrics.ts"],"names":[],"mappings":";;AAoCA,gCAEC;AAMD,wCAoFC;AAsBD,kDAuCC;AAsBD,0CASC;AA3ND,2BAAkC;AAClC,+BAA4B;AAC5B,2CAAmD;AAsBnD,MAAM,YAAY,GAAe;IAC/B,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS;IAC5B,eAAe,EAAE,GAAG,EAAE,CAAC,SAAS;IAChC,aAAa,EAAE,GAAG,EAAE,CAAC,SAAS;IAC9B,cAAc,EAAE,GAAG,EAAE,CAAC,SAAS;IAC/B,mBAAmB,EAAE,GAAG,EAAE,CAAC,SAAS;IACpC,oBAAoB,EAAE,GAAG,EAAE,CAAC,SAAS;CACtC,CAAC;AAEF,IAAI,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AAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,YAAY;IACZ,MAAM;IACN,YAAY;IACZ,YAAY;IACZ,gBAAgB;IAChB,gBAAgB;IAChB,0BAA0B;IAC1B,qBAAqB;IACrB,uBAAuB;IACvB,cAAc;IACd,aAAa;IACb,kBAAkB;IAClB,qBAAqB;IACrB,2BAA2B;IAC3B,yBAAyB;IACzB,wBAAwB;IACxB,kCAAkC;CACnC,CAAC,CAAC;AAEH,SAAgB,eAAe,CAAC,OAAgB;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,MAAM,MAAM,GAAI,OAAmD,EAAE,MAAM,CAAC;IAC5E,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC9D,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,OAAO,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Frees the permit. Calling it more than once has no further effect. */
|
|
2
|
+
export type Release = () => void;
|
|
3
|
+
export declare class Semaphore {
|
|
4
|
+
private readonly max;
|
|
5
|
+
private active;
|
|
6
|
+
private readonly queue;
|
|
7
|
+
private readonly maxWaiters;
|
|
8
|
+
constructor(max: number, options?: {
|
|
9
|
+
maxWaiters?: number;
|
|
10
|
+
});
|
|
11
|
+
get inUse(): number;
|
|
12
|
+
get waiting(): number;
|
|
13
|
+
/** Resolves to a release function, or to undefined when the wait timed out, the queue was full or `signal` aborted. */
|
|
14
|
+
acquire(waitMs: number, signal?: AbortSignal): Promise<Release | undefined>;
|
|
15
|
+
private createRelease;
|
|
16
|
+
}
|
package/src/semaphore.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Semaphore = void 0;
|
|
4
|
+
class Semaphore {
|
|
5
|
+
max;
|
|
6
|
+
active = 0;
|
|
7
|
+
queue = [];
|
|
8
|
+
maxWaiters;
|
|
9
|
+
constructor(max, options = {}) {
|
|
10
|
+
this.max = max;
|
|
11
|
+
this.maxWaiters = options.maxWaiters ?? Infinity;
|
|
12
|
+
}
|
|
13
|
+
get inUse() {
|
|
14
|
+
return this.active;
|
|
15
|
+
}
|
|
16
|
+
get waiting() {
|
|
17
|
+
return this.queue.length;
|
|
18
|
+
}
|
|
19
|
+
/** Resolves to a release function, or to undefined when the wait timed out, the queue was full or `signal` aborted. */
|
|
20
|
+
acquire(waitMs, signal) {
|
|
21
|
+
if (signal?.aborted) {
|
|
22
|
+
return Promise.resolve(undefined);
|
|
23
|
+
}
|
|
24
|
+
if (this.active < this.max) {
|
|
25
|
+
this.active += 1;
|
|
26
|
+
return Promise.resolve(this.createRelease());
|
|
27
|
+
}
|
|
28
|
+
if (waitMs <= 0 || this.queue.length >= this.maxWaiters) {
|
|
29
|
+
return Promise.resolve(undefined);
|
|
30
|
+
}
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
const giveUp = () => {
|
|
33
|
+
this.queue.splice(this.queue.indexOf(waiter), 1);
|
|
34
|
+
stopWaiting();
|
|
35
|
+
resolve(undefined);
|
|
36
|
+
};
|
|
37
|
+
const timer = setTimeout(giveUp, waitMs);
|
|
38
|
+
const stopWaiting = () => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
signal?.removeEventListener('abort', giveUp);
|
|
41
|
+
};
|
|
42
|
+
const waiter = {
|
|
43
|
+
grant: (release) => {
|
|
44
|
+
stopWaiting();
|
|
45
|
+
resolve(release);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
signal?.addEventListener('abort', giveUp, { once: true });
|
|
49
|
+
this.queue.push(waiter);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
createRelease() {
|
|
53
|
+
let released = false;
|
|
54
|
+
return () => {
|
|
55
|
+
if (released) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
released = true;
|
|
59
|
+
// The permit passes straight to the next waiter, so `active` only drops when nobody is queued.
|
|
60
|
+
const next = this.queue.shift();
|
|
61
|
+
if (next) {
|
|
62
|
+
next.grant(this.createRelease());
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.active -= 1;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.Semaphore = Semaphore;
|
|
71
|
+
//# sourceMappingURL=semaphore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semaphore.js","sourceRoot":"","sources":["../../../../libs/adsp-sdk-mcp-server/src/semaphore.ts"],"names":[],"mappings":";;;AAOA,MAAa,SAAS;IAKS;IAJrB,MAAM,GAAG,CAAC,CAAC;IACF,KAAK,GAAa,EAAE,CAAC;IACrB,UAAU,CAAS;IAEpC,YAA6B,GAAW,EAAE,UAAmC,EAAE;QAAlD,QAAG,GAAH,GAAG,CAAQ;QACtC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAC;IACnD,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,uHAAuH;IACvH,OAAO,CAAC,MAAc,EAAE,MAAoB;QAC1C,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3B,IAAI,CAAC,MAA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