@abgov/adsp-sdk-mcp-server 1.21.0 → 1.22.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 +18 -0
- package/package.json +1 -1
- package/src/http.d.ts +1 -8
- package/src/http.js +36 -73
- package/src/http.js.map +1 -1
- package/src/main.js +3 -5
- package/src/main.js.map +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,24 @@ Add it to your MCP client's server config, run via `npx`:
|
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
### HTTP transport
|
|
46
|
+
|
|
47
|
+
To host the server instead of running it per user, start it with `MCP_TRANSPORT=http`. It serves Streamable HTTP
|
|
48
|
+
at `POST /mcp`, with a liveness check at `GET /health`.
|
|
49
|
+
|
|
50
|
+
| Variable | Default | Purpose |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `MCP_TRANSPORT` | `stdio` | `http` to serve HTTP |
|
|
53
|
+
| `PORT` | `3000` | Port to listen on |
|
|
54
|
+
| `CORS_ORIGIN` | `*` | Value of `Access-Control-Allow-Origin` |
|
|
55
|
+
|
|
56
|
+
HTTP mode is stateless: each `POST /mcp` gets its own MCP server, the response is JSON (the server never streams),
|
|
57
|
+
and nothing is kept between requests. The response carries no `Mcp-Session-Id`, so any replica can serve any request
|
|
58
|
+
and an idle client never loses its session. `GET /mcp` and `DELETE /mcp` return `405` with `Allow: POST`, because
|
|
59
|
+
there is no stream to open and no session to delete.
|
|
60
|
+
|
|
61
|
+
`SESSION_TTL_MINUTES` has been removed and is ignored: there are no sessions to expire.
|
|
62
|
+
|
|
45
63
|
### Using `list_service_roles`
|
|
46
64
|
|
|
47
65
|
That one tool needs a real ADSP environment and a logged-in session (via `@abgov/adsp-cli`, a separate package this
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/adsp-sdk-mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Government of Alberta - MCP server for ADSP documentation and Node SDK reference lookup.",
|
|
6
6
|
"repository": "https://github.com/GovAlta/adsp-monorepo",
|
package/src/http.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import { CreateAdspMcpServerOptions } from './server';
|
|
3
|
-
export
|
|
4
|
-
sessionTtlMs: number;
|
|
5
|
-
}
|
|
6
|
-
export interface McpHttpApp {
|
|
7
|
-
app: express.Express;
|
|
8
|
-
close(): void;
|
|
9
|
-
}
|
|
10
|
-
export declare function createMcpHttpApp(options: McpHttpAppOptions): McpHttpApp;
|
|
3
|
+
export declare function createMcpHttpApp(options?: CreateAdspMcpServerOptions): express.Express;
|
package/src/http.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMcpHttpApp = createMcpHttpApp;
|
|
4
4
|
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
5
|
-
const crypto_1 = require("crypto");
|
|
6
5
|
const express = require("express");
|
|
7
6
|
const server_1 = require("./server");
|
|
7
|
+
const MAX_REQUEST_BODY_BYTES = 1024 * 1024;
|
|
8
8
|
function applyCorsHeaders(req, res, next) {
|
|
9
9
|
res.setHeader('Access-Control-Allow-Origin', process.env['CORS_ORIGIN'] ?? '*');
|
|
10
10
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
11
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, mcp-session-id');
|
|
11
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, mcp-session-id, mcp-protocol-version');
|
|
12
12
|
res.setHeader('Access-Control-Expose-Headers', 'mcp-session-id');
|
|
13
13
|
if (req.method === 'OPTIONS') {
|
|
14
14
|
res.sendStatus(204);
|
|
@@ -16,90 +16,53 @@ function applyCorsHeaders(req, res, next) {
|
|
|
16
16
|
}
|
|
17
17
|
next();
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const timer = setInterval(() => {
|
|
21
|
-
const now = Date.now();
|
|
22
|
-
for (const [id, entry] of sessions) {
|
|
23
|
-
if (now - entry.lastActivity > sessionTtlMs) {
|
|
24
|
-
sessions.delete(id);
|
|
25
|
-
entry.server.close();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}, 60_000);
|
|
29
|
-
timer.unref();
|
|
30
|
-
return timer;
|
|
31
|
-
}
|
|
32
|
-
function createPostHandler(sessions, options) {
|
|
19
|
+
function createStatelessPostHandler(options) {
|
|
33
20
|
return async (req, res) => {
|
|
34
|
-
const
|
|
35
|
-
if (sessionId && sessions.has(sessionId)) {
|
|
36
|
-
const entry = sessions.get(sessionId);
|
|
37
|
-
entry.lastActivity = Date.now();
|
|
38
|
-
await entry.transport.handleRequest(req, res, req.body);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const newId = (0, crypto_1.randomUUID)();
|
|
42
|
-
const sessionServer = (0, server_1.createAdspMcpServer)(options);
|
|
21
|
+
const server = (0, server_1.createAdspMcpServer)(options);
|
|
43
22
|
const transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
|
|
44
|
-
sessionIdGenerator:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
23
|
+
sessionIdGenerator: undefined,
|
|
24
|
+
enableJsonResponse: true,
|
|
25
|
+
maxRequestBodySize: MAX_REQUEST_BODY_BYTES,
|
|
48
26
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
27
|
+
// Registered before handling starts so a client that disconnects mid-request still releases both.
|
|
28
|
+
res.on('close', () => {
|
|
29
|
+
transport.close();
|
|
30
|
+
server.close();
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
await server.connect(transport);
|
|
34
|
+
await transport.handleRequest(req, res);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
console.error('[adsp-sdk-mcp-server] Failed to handle MCP request:', err);
|
|
38
|
+
sendInternalError(res);
|
|
39
|
+
}
|
|
58
40
|
};
|
|
59
41
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return undefined;
|
|
42
|
+
function sendInternalError(res) {
|
|
43
|
+
if (res.headersSent) {
|
|
44
|
+
res.end();
|
|
45
|
+
return;
|
|
65
46
|
}
|
|
66
|
-
|
|
47
|
+
res.status(500).json({ jsonrpc: '2.0', error: { code: -32603, message: 'Internal server error' }, id: null });
|
|
67
48
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const found = findSession(sessions, req, res);
|
|
74
|
-
if (!found)
|
|
75
|
-
return;
|
|
76
|
-
found[1].lastActivity = Date.now();
|
|
77
|
-
await found[1].transport.handleRequest(req, res);
|
|
78
|
-
});
|
|
79
|
-
app.delete('/mcp', async (req, res) => {
|
|
80
|
-
const found = findSession(sessions, req, res);
|
|
81
|
-
if (!found)
|
|
82
|
-
return;
|
|
83
|
-
sessions.delete(found[0]);
|
|
84
|
-
await found[1].transport.handleRequest(req, res);
|
|
85
|
-
});
|
|
86
|
-
return () => {
|
|
87
|
-
clearInterval(cleanupTimer);
|
|
88
|
-
for (const [id, entry] of sessions) {
|
|
89
|
-
sessions.delete(id);
|
|
90
|
-
entry.server.close();
|
|
91
|
-
}
|
|
92
|
-
};
|
|
49
|
+
function methodNotAllowed(_req, res) {
|
|
50
|
+
res
|
|
51
|
+
.status(405)
|
|
52
|
+
.set('Allow', 'POST')
|
|
53
|
+
.json({ jsonrpc: '2.0', error: { code: -32000, message: 'Method not allowed.' }, id: null });
|
|
93
54
|
}
|
|
94
|
-
function createMcpHttpApp(options) {
|
|
55
|
+
function createMcpHttpApp(options = {}) {
|
|
95
56
|
(0, server_1.loadAdspMcpTools)(options);
|
|
57
|
+
// No express.json(): the transport reads the body so parse and size errors come back as JSON-RPC.
|
|
96
58
|
const app = express();
|
|
97
|
-
app.use(express.json({ limit: '1mb' }));
|
|
98
59
|
app.use(applyCorsHeaders);
|
|
99
60
|
app.get('/health', (_req, res) => {
|
|
100
61
|
res.json({ status: 'ok' });
|
|
101
62
|
});
|
|
102
|
-
|
|
103
|
-
|
|
63
|
+
app.post('/mcp', createStatelessPostHandler(options));
|
|
64
|
+
app.get('/mcp', methodNotAllowed);
|
|
65
|
+
app.delete('/mcp', methodNotAllowed);
|
|
66
|
+
return app;
|
|
104
67
|
}
|
|
105
68
|
//# 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":";;AAyDA,4CAgBC;AAzED,0FAAmG;AACnG,mCAAmC;AACnC,qCAA6F;AAE7F,MAAM,sBAAsB,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C,SAAS,gBAAgB,CAAC,GAAoB,EAAE,GAAqB,EAAE,IAA0B;IAC/F,GAAG,CAAC,SAAS,CAAC,6BAA6B,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,CAAC;IAChF,GAAG,CAAC,SAAS,CAAC,8BAA8B,EAAE,4BAA4B,CAAC,CAAC;IAC5E,GAAG,CAAC,SAAS,CAAC,8BAA8B,EAAE,oDAAoD,CAAC,CAAC;IACpG,GAAG,CAAC,SAAS,CAAC,+BAA+B,EAAE,gBAAgB,CAAC,CAAC;IACjE,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CA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AAChH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAqB,EAAE,GAAqB;IACpE,GAAG;SACA,MAAM,CAAC,GAAG,CAAC;SACX,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC;SACpB,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,qBAAqB,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACjG,CAAC;AAED,SAAgB,gBAAgB,CAAC,UAAsC,EAAE;IACvE,IAAA,yBAAgB,EAAC,OAAO,CAAC,CAAC;IAE1B,kGAAkG;IAClG,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAE1B,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAC/B,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,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"}
|
package/src/main.js
CHANGED
|
@@ -13,7 +13,7 @@ function resolveTransport() {
|
|
|
13
13
|
}
|
|
14
14
|
async function main() {
|
|
15
15
|
const transport = resolveTransport();
|
|
16
|
-
console.error(`[adsp-sdk-mcp-server] transport=${transport}
|
|
16
|
+
console.error(`[adsp-sdk-mcp-server] transport=${transport}`);
|
|
17
17
|
if (transport === 'http') {
|
|
18
18
|
await startHttp();
|
|
19
19
|
}
|
|
@@ -22,17 +22,15 @@ async function main() {
|
|
|
22
22
|
await server.connect(new stdio_js_1.StdioServerTransport());
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
const SESSION_TTL_MS = parseInt(process.env['SESSION_TTL_MINUTES'] ?? '30', 10) * 60 * 1000;
|
|
26
25
|
async function startHttp() {
|
|
27
26
|
const port = parseInt(process.env['PORT'] ?? '3000', 10);
|
|
28
|
-
const
|
|
27
|
+
const app = (0, http_1.createMcpHttpApp)();
|
|
29
28
|
return new Promise((resolve) => {
|
|
30
|
-
const httpServer =
|
|
29
|
+
const httpServer = app.listen(port, () => {
|
|
31
30
|
console.error(`[adsp-sdk-mcp-server] HTTP server listening on :${port}`);
|
|
32
31
|
resolve();
|
|
33
32
|
});
|
|
34
33
|
function shutdown() {
|
|
35
|
-
mcpApp.close();
|
|
36
34
|
httpServer.close(() => process.exit(0));
|
|
37
35
|
setTimeout(() => process.exit(1), 5_000).unref();
|
|
38
36
|
}
|
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,iCAA0C;AAC1C,qCAA+C;AAI/C,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,OAAO,CAAC,KAAK,CAAC,mCAAmC,SAAS,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../libs/adsp-sdk-mcp-server/src/main.ts"],"names":[],"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