cloakbrowser-mcp 1.2.7 → 1.4.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 +51 -17
- package/dist/bridge/config.d.ts +1 -1
- package/dist/bridge/config.d.ts.map +1 -1
- package/dist/bridge/config.js +4 -4
- package/dist/bridge/config.js.map +1 -1
- package/dist/bridge/env.d.ts +1 -0
- package/dist/bridge/env.d.ts.map +1 -1
- package/dist/bridge/env.js +3 -0
- package/dist/bridge/env.js.map +1 -1
- package/dist/bridge/tools.d.ts +3 -1
- package/dist/bridge/tools.d.ts.map +1 -1
- package/dist/bridge/tools.js +8 -6
- package/dist/bridge/tools.js.map +1 -1
- package/dist/cli/doctor.d.ts +31 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +157 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/options.d.ts +13 -2
- package/dist/cli/options.d.ts.map +1 -1
- package/dist/cli/options.js +103 -5
- package/dist/cli/options.js.map +1 -1
- package/dist/cli.js +26 -7
- package/dist/cli.js.map +1 -1
- package/dist/http/nodeServer.d.ts +9 -0
- package/dist/http/nodeServer.d.ts.map +1 -0
- package/dist/http/nodeServer.js +65 -0
- package/dist/http/nodeServer.js.map +1 -0
- package/dist/http/options.d.ts +20 -2
- package/dist/http/options.d.ts.map +1 -1
- package/dist/http/options.js +20 -4
- package/dist/http/options.js.map +1 -1
- package/dist/http/requests.d.ts +11 -0
- package/dist/http/requests.d.ts.map +1 -0
- package/dist/http/requests.js +54 -0
- package/dist/http/requests.js.map +1 -0
- package/dist/http/responses.d.ts +6 -0
- package/dist/http/responses.d.ts.map +1 -0
- package/dist/http/responses.js +24 -0
- package/dist/http/responses.js.map +1 -0
- package/dist/http/server.d.ts +5 -3
- package/dist/http/server.d.ts.map +1 -1
- package/dist/http/server.js +95 -102
- package/dist/http/server.js.map +1 -1
- package/dist/http/sessionStore.d.ts +3 -1
- package/dist/http/sessionStore.d.ts.map +1 -1
- package/dist/http/sessionStore.js +8 -5
- package/dist/http/sessionStore.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/logging/logger.d.ts +17 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +107 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/protocol/constants.d.ts +5 -0
- package/dist/protocol/constants.d.ts.map +1 -0
- package/dist/protocol/constants.js +5 -0
- package/dist/protocol/constants.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +4 -4
- package/package.json +36 -21
- package/server.json +5 -5
package/dist/cli/options.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, InvalidArgumentError, Option } from 'commander';
|
|
2
|
-
import { bridgeTransportModes, defaultStreamableHttpOptions, httpSessionBackends, } from '
|
|
2
|
+
import { BRIDGE_TRANSPORT_STDIO, HEALTHZ_PATH, HTTP_PROTOCOL_HTTP, READYZ_PATH, bridgeTransportModes, defaultStreamableHttpOptions, httpProtocols, httpSessionBackends, } from '#src/http/options';
|
|
3
3
|
export const cliDescription = 'Playwright MCP bridge backed by CloakBrowser.';
|
|
4
4
|
export const cliOptionDefinitions = [
|
|
5
5
|
{
|
|
@@ -8,9 +8,18 @@ export const cliOptionDefinitions = [
|
|
|
8
8
|
description: 'MCP transport exposed by the bridge.',
|
|
9
9
|
env: 'CLOAK_PLAYWRIGHT_MCP_TRANSPORT',
|
|
10
10
|
group: 'Transport',
|
|
11
|
-
defaultValue:
|
|
11
|
+
defaultValue: BRIDGE_TRANSPORT_STDIO,
|
|
12
12
|
choices: bridgeTransportModes,
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
name: 'httpProtocol',
|
|
16
|
+
flags: '--http-protocol <protocol>',
|
|
17
|
+
description: 'Streamable HTTP listener protocol.',
|
|
18
|
+
env: 'CLOAK_PLAYWRIGHT_MCP_HTTP_PROTOCOL',
|
|
19
|
+
group: 'Streamable HTTP',
|
|
20
|
+
defaultValue: defaultStreamableHttpOptions.protocol,
|
|
21
|
+
choices: httpProtocols,
|
|
22
|
+
},
|
|
14
23
|
{
|
|
15
24
|
name: 'httpHost',
|
|
16
25
|
flags: '--http-host <host>',
|
|
@@ -32,7 +41,7 @@ export const cliOptionDefinitions = [
|
|
|
32
41
|
{
|
|
33
42
|
name: 'httpEndpoint',
|
|
34
43
|
flags: '--http-endpoint <path>',
|
|
35
|
-
description: 'Streamable HTTP endpoint path.',
|
|
44
|
+
description: 'Streamable HTTP endpoint path. Reserved probe paths: /healthz, /readyz.',
|
|
36
45
|
env: 'CLOAK_PLAYWRIGHT_MCP_HTTP_ENDPOINT',
|
|
37
46
|
group: 'Streamable HTTP',
|
|
38
47
|
defaultValue: defaultStreamableHttpOptions.endpoint,
|
|
@@ -46,6 +55,38 @@ export const cliOptionDefinitions = [
|
|
|
46
55
|
group: 'Streamable HTTP',
|
|
47
56
|
parser: parseNonEmptyString('HTTP auth token must not be empty'),
|
|
48
57
|
},
|
|
58
|
+
{
|
|
59
|
+
name: 'httpsCert',
|
|
60
|
+
flags: '--https-cert <path>',
|
|
61
|
+
description: 'TLS certificate PEM file for HTTPS Streamable HTTP.',
|
|
62
|
+
env: 'CLOAK_PLAYWRIGHT_MCP_HTTPS_CERT',
|
|
63
|
+
group: 'Streamable HTTP',
|
|
64
|
+
parser: parseNonEmptyString('HTTPS certificate path must not be empty'),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'httpsKey',
|
|
68
|
+
flags: '--https-key <path>',
|
|
69
|
+
description: 'TLS private key PEM file for HTTPS Streamable HTTP.',
|
|
70
|
+
env: 'CLOAK_PLAYWRIGHT_MCP_HTTPS_KEY',
|
|
71
|
+
group: 'Streamable HTTP',
|
|
72
|
+
parser: parseNonEmptyString('HTTPS private key path must not be empty'),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'httpsPfx',
|
|
76
|
+
flags: '--https-pfx <path>',
|
|
77
|
+
description: 'TLS PFX/PKCS12 file for HTTPS Streamable HTTP.',
|
|
78
|
+
env: 'CLOAK_PLAYWRIGHT_MCP_HTTPS_PFX',
|
|
79
|
+
group: 'Streamable HTTP',
|
|
80
|
+
parser: parseNonEmptyString('HTTPS PFX path must not be empty'),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'httpsPassphrase',
|
|
84
|
+
flags: '--https-passphrase <value>',
|
|
85
|
+
description: 'Passphrase for an encrypted HTTPS key or PFX.',
|
|
86
|
+
env: 'CLOAK_PLAYWRIGHT_MCP_HTTPS_PASSPHRASE',
|
|
87
|
+
group: 'Streamable HTTP',
|
|
88
|
+
parser: parseNonEmptyString('HTTPS passphrase must not be empty'),
|
|
89
|
+
},
|
|
49
90
|
{
|
|
50
91
|
name: 'httpSessionBackend',
|
|
51
92
|
flags: '--http-session-backend <backend>',
|
|
@@ -74,17 +115,19 @@ export const cliOptionDefinitions = [
|
|
|
74
115
|
parser: parsePositiveInteger('HTTP session max'),
|
|
75
116
|
},
|
|
76
117
|
];
|
|
77
|
-
export function createCliCommand(version) {
|
|
118
|
+
export function createCliCommand(version, options = {}) {
|
|
78
119
|
const command = new Command()
|
|
79
120
|
.name('cloakbrowser-mcp')
|
|
80
121
|
.description(cliDescription)
|
|
81
122
|
.version(version)
|
|
82
123
|
.showHelpAfterError()
|
|
83
124
|
.showSuggestionAfterError()
|
|
84
|
-
.allowExcessArguments(false)
|
|
125
|
+
.allowExcessArguments(false)
|
|
126
|
+
.action(() => undefined);
|
|
85
127
|
for (const definition of cliOptionDefinitions) {
|
|
86
128
|
command.addOption(createCommanderOption(definition));
|
|
87
129
|
}
|
|
130
|
+
command.addCommand(createDoctorCommand(options.doctorAction));
|
|
88
131
|
return command;
|
|
89
132
|
}
|
|
90
133
|
export function parseCliOptions(args) {
|
|
@@ -112,11 +155,30 @@ This page is generated from the Commander.js CLI definition during MkDocs builds
|
|
|
112
155
|
${command.helpInformation().trimEnd()}
|
|
113
156
|
\`\`\`
|
|
114
157
|
|
|
158
|
+
## Commands
|
|
159
|
+
|
|
160
|
+
### \`doctor\`
|
|
161
|
+
|
|
162
|
+
\`\`\`text
|
|
163
|
+
${createDoctorCommand().helpInformation().trimEnd()}
|
|
164
|
+
\`\`\`
|
|
165
|
+
|
|
115
166
|
## Options
|
|
116
167
|
|
|
117
168
|
${renderOptionsTable()}
|
|
118
169
|
`;
|
|
119
170
|
}
|
|
171
|
+
function createDoctorCommand(action) {
|
|
172
|
+
const command = new Command('doctor')
|
|
173
|
+
.description('Run local diagnostics without starting the MCP bridge.')
|
|
174
|
+
.option('--json', 'Output diagnostics as JSON.');
|
|
175
|
+
if (action) {
|
|
176
|
+
command.action(async (options) => {
|
|
177
|
+
await action(options);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return command;
|
|
181
|
+
}
|
|
120
182
|
function createCommanderOption(definition) {
|
|
121
183
|
const option = new Option(definition.flags, definition.description)
|
|
122
184
|
.env(definition.env)
|
|
@@ -134,13 +196,17 @@ function createCommanderOption(definition) {
|
|
|
134
196
|
return option;
|
|
135
197
|
}
|
|
136
198
|
function toCliOptions(options) {
|
|
199
|
+
const tls = normalizeTlsOptions(options);
|
|
200
|
+
validateHttpProtocolOptions(options.httpProtocol, tls);
|
|
137
201
|
return {
|
|
138
202
|
transport: options.transport,
|
|
139
203
|
http: {
|
|
204
|
+
protocol: options.httpProtocol,
|
|
140
205
|
host: options.httpHost,
|
|
141
206
|
port: options.httpPort,
|
|
142
207
|
endpoint: options.httpEndpoint,
|
|
143
208
|
authToken: optionalString(options.httpAuthToken),
|
|
209
|
+
tls,
|
|
144
210
|
sessionBackend: options.httpSessionBackend,
|
|
145
211
|
sessionIdleTtlMs: options.httpSessionIdleTtlMs,
|
|
146
212
|
sessionMax: options.httpSessionMax,
|
|
@@ -148,6 +214,35 @@ function toCliOptions(options) {
|
|
|
148
214
|
},
|
|
149
215
|
};
|
|
150
216
|
}
|
|
217
|
+
function normalizeTlsOptions(options) {
|
|
218
|
+
return {
|
|
219
|
+
cert: optionalString(options.httpsCert),
|
|
220
|
+
key: optionalString(options.httpsKey),
|
|
221
|
+
pfx: optionalString(options.httpsPfx),
|
|
222
|
+
passphrase: optionalString(options.httpsPassphrase),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function validateHttpProtocolOptions(protocol, tls) {
|
|
226
|
+
const hasCert = tls.cert !== undefined;
|
|
227
|
+
const hasKey = tls.key !== undefined;
|
|
228
|
+
const hasPfx = tls.pfx !== undefined;
|
|
229
|
+
const hasPassphrase = tls.passphrase !== undefined;
|
|
230
|
+
const hasAnyTlsOption = hasCert || hasKey || hasPfx || hasPassphrase;
|
|
231
|
+
if (protocol === HTTP_PROTOCOL_HTTP) {
|
|
232
|
+
if (hasAnyTlsOption) {
|
|
233
|
+
throw new InvalidArgumentError('HTTPS certificate options require --http-protocol https');
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (hasPfx && (hasCert || hasKey)) {
|
|
238
|
+
throw new InvalidArgumentError('HTTPS must use either --https-pfx or --https-cert with --https-key');
|
|
239
|
+
}
|
|
240
|
+
if (hasPfx)
|
|
241
|
+
return;
|
|
242
|
+
if (hasCert && hasKey)
|
|
243
|
+
return;
|
|
244
|
+
throw new InvalidArgumentError('HTTPS requires either --https-cert and --https-key, or --https-pfx');
|
|
245
|
+
}
|
|
151
246
|
function renderCliReferenceFrontMatter() {
|
|
152
247
|
return `---
|
|
153
248
|
description: Generated CLI reference for cloakbrowser-mcp.
|
|
@@ -207,6 +302,9 @@ function parseHttpEndpoint(value) {
|
|
|
207
302
|
if (!value.startsWith('/') || value.includes('?') || value.includes('#')) {
|
|
208
303
|
throw new InvalidArgumentError('HTTP endpoint must be an absolute path such as "/mcp"');
|
|
209
304
|
}
|
|
305
|
+
if (value === HEALTHZ_PATH || value === READYZ_PATH) {
|
|
306
|
+
throw new InvalidArgumentError('HTTP endpoint must not use reserved probe paths "/healthz" or "/readyz"');
|
|
307
|
+
}
|
|
210
308
|
if (value.length > 1 && value.endsWith('/')) {
|
|
211
309
|
throw new InvalidArgumentError('HTTP endpoint must not end with "/"');
|
|
212
310
|
}
|
package/dist/cli/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/cli/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,mBAAmB,
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/cli/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACpB,4BAA4B,EAC5B,aAAa,EACb,mBAAmB,GAMpB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,cAAc,GAAG,+CAA+C,CAAC;AAuC9E,MAAM,CAAC,MAAM,oBAAoB,GAAmC;IAClE;QACE,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EAAE,sCAAsC;QACnD,GAAG,EAAE,gCAAgC;QACrC,KAAK,EAAE,WAAW;QAClB,YAAY,EAAE,sBAAsB;QACpC,OAAO,EAAE,oBAAoB;KAC9B;IACD;QACE,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,4BAA4B;QACnC,WAAW,EAAE,oCAAoC;QACjD,GAAG,EAAE,oCAAoC;QACzC,KAAK,EAAE,iBAAiB;QACxB,YAAY,EAAE,4BAA4B,CAAC,QAAQ;QACnD,OAAO,EAAE,aAAa;KACvB;IACD;QACE,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EA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AAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,oBAAoB,CAAC,uDAAuD,CAAC,CAAC;IAC1F,CAAC;IACD,IAAI,KAAK,KAAK,YAAY,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;QACpD,MAAM,IAAI,oBAAoB,CAAC,yEAAyE,CAAC,CAAC;IAC5G,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,oBAAoB,CAAC,qCAAqC,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAe;IAC1C,OAAO,CAAC,KAAa,EAAU,EAAE;QAC/B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC3D,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,KAAyB;IAC/C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AACjE,CAAC;AAED,SAAS,IAAI,CAAC,KAAa;IACzB,OAAO,KAAK,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC;AAC/C,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import process from 'node:process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { createDoctorReport, renderDoctorReport } from '#src/cli/doctor';
|
|
5
|
+
import { createCliCommand, readCliOptions } from '#src/cli/options';
|
|
6
|
+
import { BRIDGE_TRANSPORT_STREAMABLE_HTTP } from '#src/http/options';
|
|
7
|
+
import { startStreamableHttpBridge } from '#src/http/server';
|
|
8
|
+
import { createBridgeLogger } from '#src/logging/logger';
|
|
9
|
+
import { PROJECT_METADATA } from '#src/project/metadata';
|
|
10
|
+
import { startBridge } from '#src/server';
|
|
8
11
|
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
9
12
|
async function main() {
|
|
10
|
-
const command = createCliCommand(pkg.version
|
|
13
|
+
const command = createCliCommand(pkg.version, {
|
|
14
|
+
doctorAction: (options) => {
|
|
15
|
+
const report = createDoctorReport();
|
|
16
|
+
process.stdout.write(options.json ? `${JSON.stringify(report, null, 2)}\n` : renderDoctorReport(report));
|
|
17
|
+
if (report.status === 'error')
|
|
18
|
+
process.exitCode = 1;
|
|
19
|
+
},
|
|
20
|
+
});
|
|
11
21
|
command.action(async () => {
|
|
12
22
|
const options = readCliOptions(command);
|
|
13
23
|
const serverInfo = {
|
|
@@ -18,8 +28,8 @@ async function main() {
|
|
|
18
28
|
websiteUrl: PROJECT_METADATA.websiteUrl,
|
|
19
29
|
icons: PROJECT_METADATA.icons,
|
|
20
30
|
};
|
|
21
|
-
const running = options.transport ===
|
|
22
|
-
? await
|
|
31
|
+
const running = options.transport === BRIDGE_TRANSPORT_STREAMABLE_HTTP
|
|
32
|
+
? await startStreamableHttpCliBridge({ ...options.http, serverInfo })
|
|
23
33
|
: await startStdioBridge(serverInfo);
|
|
24
34
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
25
35
|
process.once(signal, () => {
|
|
@@ -35,6 +45,15 @@ async function startStdioBridge(serverInfo) {
|
|
|
35
45
|
close: () => bridge.dispose(),
|
|
36
46
|
};
|
|
37
47
|
}
|
|
48
|
+
async function startStreamableHttpCliBridge(options) {
|
|
49
|
+
const logger = createBridgeLogger();
|
|
50
|
+
const bridge = await startStreamableHttpBridge({
|
|
51
|
+
...options,
|
|
52
|
+
logger,
|
|
53
|
+
});
|
|
54
|
+
logger.info({ url: bridge.url }, 'streamable-http listening');
|
|
55
|
+
return bridge;
|
|
56
|
+
}
|
|
38
57
|
void main().catch((error) => {
|
|
39
58
|
process.stderr.write(`fatal: ${error.message}\n`);
|
|
40
59
|
process.exit(1);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAEvF,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAA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AC,OAAO,IAAI,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type IncomingMessage, type Server as HttpServer, type ServerResponse } from 'node:http';
|
|
2
|
+
import { type Server as HttpsServer } from 'node:https';
|
|
3
|
+
import { type StreamableHttpOptions } from '#src/http/options';
|
|
4
|
+
export type StreamableNodeServer = HttpServer | HttpsServer;
|
|
5
|
+
export declare function createStreamableNodeServer(options: StreamableHttpOptions, requestListener: (req: IncomingMessage, res: ServerResponse) => void): StreamableNodeServer;
|
|
6
|
+
export declare function formatHost(host: string): string;
|
|
7
|
+
export declare function closeHttpServer(server: StreamableNodeServer): Promise<void>;
|
|
8
|
+
export declare function listenHttpServer(server: StreamableNodeServer, port: number, host: string): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=nodeServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeServer.d.ts","sourceRoot":"","sources":["../../src/http/nodeServer.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,MAAM,IAAI,UAAU,EACzB,KAAK,cAAc,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAEL,KAAK,MAAM,IAAI,WAAW,EAE3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAuB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAEpF,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,WAAW,CAAC;AAE5D,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,GACnE,oBAAoB,CAMtB;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED,wBAAsB,eAAe,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQjF;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { createServer as createHttpServer, } from 'node:http';
|
|
3
|
+
import { createServer as createHttpsServer, } from 'node:https';
|
|
4
|
+
import { HTTP_PROTOCOL_HTTPS } from '#src/http/options';
|
|
5
|
+
export function createStreamableNodeServer(options, requestListener) {
|
|
6
|
+
if (options.protocol === HTTP_PROTOCOL_HTTPS) {
|
|
7
|
+
return createHttpsServer(readHttpsServerOptions(options), requestListener);
|
|
8
|
+
}
|
|
9
|
+
// HTTP is an explicit local/reverse-proxy mode; use `https` for direct TLS.
|
|
10
|
+
return createHttpServer(requestListener);
|
|
11
|
+
}
|
|
12
|
+
export function formatHost(host) {
|
|
13
|
+
if (host.startsWith('[') && host.endsWith(']'))
|
|
14
|
+
return host;
|
|
15
|
+
return host.includes(':') ? `[${host}]` : host;
|
|
16
|
+
}
|
|
17
|
+
export async function closeHttpServer(server) {
|
|
18
|
+
if (!server.listening)
|
|
19
|
+
return;
|
|
20
|
+
await new Promise((resolve, reject) => {
|
|
21
|
+
server.close((error) => {
|
|
22
|
+
if (error)
|
|
23
|
+
reject(error);
|
|
24
|
+
else
|
|
25
|
+
resolve();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export async function listenHttpServer(server, port, host) {
|
|
30
|
+
await new Promise((resolve, reject) => {
|
|
31
|
+
const cleanup = () => {
|
|
32
|
+
server.off('error', onError);
|
|
33
|
+
server.off('listening', onListening);
|
|
34
|
+
};
|
|
35
|
+
const onError = (error) => {
|
|
36
|
+
cleanup();
|
|
37
|
+
reject(error);
|
|
38
|
+
};
|
|
39
|
+
const onListening = () => {
|
|
40
|
+
cleanup();
|
|
41
|
+
resolve();
|
|
42
|
+
};
|
|
43
|
+
server.once('error', onError);
|
|
44
|
+
server.once('listening', onListening);
|
|
45
|
+
server.listen(port, host);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function readHttpsServerOptions(options) {
|
|
49
|
+
const { cert, key, pfx, passphrase } = options.tls;
|
|
50
|
+
if (pfx !== undefined) {
|
|
51
|
+
return {
|
|
52
|
+
pfx: readFileSync(pfx),
|
|
53
|
+
passphrase,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (cert !== undefined && key !== undefined) {
|
|
57
|
+
return {
|
|
58
|
+
cert: readFileSync(cert),
|
|
59
|
+
key: readFileSync(key),
|
|
60
|
+
passphrase,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
throw new Error('HTTPS requires either certificate/key files or a PFX file');
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=nodeServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeServer.js","sourceRoot":"","sources":["../../src/http/nodeServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EACL,YAAY,IAAI,gBAAgB,GAIjC,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,IAAI,iBAAiB,GAGlC,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAA8B,MAAM,mBAAmB,CAAC;AAIpF,MAAM,UAAU,0BAA0B,CACxC,OAA8B,EAC9B,eAAoE;IAEpE,IAAI,OAAO,CAAC,QAAQ,KAAK,mBAAmB,EAAE,CAAC;QAC7C,OAAO,iBAAiB,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC;IAC7E,CAAC;IACD,4EAA4E;IAC5E,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,UAAU,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,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,sBAAsB,CAAC,OAA8B;IAC5D,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IACnD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC;YACtB,UAAU;SACX,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QAC5C,OAAO;YACL,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC;YACxB,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC;YACtB,UAAU;SACX,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;AAC/E,CAAC"}
|
package/dist/http/options.d.ts
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export declare const BRIDGE_TRANSPORT_STDIO: "stdio";
|
|
2
|
+
export declare const BRIDGE_TRANSPORT_STREAMABLE_HTTP: "streamable-http";
|
|
3
|
+
export declare const HTTP_PROTOCOL_HTTP: "http";
|
|
4
|
+
export declare const HTTP_PROTOCOL_HTTPS: "https";
|
|
5
|
+
export declare const HTTP_SESSION_BACKEND_MEMORY: "memory";
|
|
6
|
+
export declare const HEALTHZ_PATH: "/healthz";
|
|
7
|
+
export declare const READYZ_PATH: "/readyz";
|
|
8
|
+
export type BridgeTransportMode = typeof BRIDGE_TRANSPORT_STDIO | typeof BRIDGE_TRANSPORT_STREAMABLE_HTTP;
|
|
9
|
+
export type HttpProtocol = typeof HTTP_PROTOCOL_HTTP | typeof HTTP_PROTOCOL_HTTPS;
|
|
10
|
+
export type HttpSessionBackend = typeof HTTP_SESSION_BACKEND_MEMORY;
|
|
3
11
|
export declare const bridgeTransportModes: readonly ["stdio", "streamable-http"];
|
|
12
|
+
export declare const httpProtocols: readonly ["http", "https"];
|
|
4
13
|
export declare const httpSessionBackends: readonly ["memory"];
|
|
14
|
+
export declare const streamableHttpProbePaths: readonly ["/healthz", "/readyz"];
|
|
15
|
+
export interface StreamableHttpTlsOptions {
|
|
16
|
+
cert?: string;
|
|
17
|
+
key?: string;
|
|
18
|
+
pfx?: string;
|
|
19
|
+
passphrase?: string;
|
|
20
|
+
}
|
|
5
21
|
export interface StreamableHttpOptions {
|
|
22
|
+
protocol: HttpProtocol;
|
|
6
23
|
host: string;
|
|
7
24
|
port: number;
|
|
8
25
|
endpoint: string;
|
|
9
26
|
authToken?: string;
|
|
27
|
+
tls: StreamableHttpTlsOptions;
|
|
10
28
|
sessionBackend: HttpSessionBackend;
|
|
11
29
|
sessionIdleTtlMs: number;
|
|
12
30
|
sessionMax: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/http/options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/http/options.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,EAAG,OAAgB,CAAC;AACvD,eAAO,MAAM,gCAAgC,EAAG,iBAA0B,CAAC;AAC3E,eAAO,MAAM,kBAAkB,EAAG,MAAe,CAAC;AAClD,eAAO,MAAM,mBAAmB,EAAG,OAAgB,CAAC;AACpD,eAAO,MAAM,2BAA2B,EAAG,QAAiB,CAAC;AAC7D,eAAO,MAAM,YAAY,EAAG,UAAmB,CAAC;AAChD,eAAO,MAAM,WAAW,EAAG,SAAkB,CAAC;AAE9C,MAAM,MAAM,mBAAmB,GAAG,OAAO,sBAAsB,GAAG,OAAO,gCAAgC,CAAC;AAC1G,MAAM,MAAM,YAAY,GAAG,OAAO,kBAAkB,GAAG,OAAO,mBAAmB,CAAC;AAClF,MAAM,MAAM,kBAAkB,GAAG,OAAO,2BAA2B,CAAC;AAEpE,eAAO,MAAM,oBAAoB,uCAGkB,CAAC;AACpD,eAAO,MAAM,aAAa,4BAGkB,CAAC;AAC7C,eAAO,MAAM,mBAAmB,qBAEkB,CAAC;AACnD,eAAO,MAAM,wBAAwB,kCAAuC,CAAC;AAE7E,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,wBAAwB,CAAC;IAC9B,cAAc,EAAE,kBAAkB,CAAC;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,mBAAmB,CAAC;IAC/B,IAAI,EAAE,qBAAqB,CAAC;CAC7B;AAED,eAAO,MAAM,4BAA4B,EAAE,qBAU1C,CAAC"}
|
package/dist/http/options.js
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
+
export const BRIDGE_TRANSPORT_STDIO = 'stdio';
|
|
2
|
+
export const BRIDGE_TRANSPORT_STREAMABLE_HTTP = 'streamable-http';
|
|
3
|
+
export const HTTP_PROTOCOL_HTTP = 'http';
|
|
4
|
+
export const HTTP_PROTOCOL_HTTPS = 'https';
|
|
5
|
+
export const HTTP_SESSION_BACKEND_MEMORY = 'memory';
|
|
6
|
+
export const HEALTHZ_PATH = '/healthz';
|
|
7
|
+
export const READYZ_PATH = '/readyz';
|
|
1
8
|
export const bridgeTransportModes = [
|
|
2
|
-
|
|
3
|
-
|
|
9
|
+
BRIDGE_TRANSPORT_STDIO,
|
|
10
|
+
BRIDGE_TRANSPORT_STREAMABLE_HTTP,
|
|
4
11
|
];
|
|
5
|
-
export const
|
|
12
|
+
export const httpProtocols = [
|
|
13
|
+
HTTP_PROTOCOL_HTTP,
|
|
14
|
+
HTTP_PROTOCOL_HTTPS,
|
|
15
|
+
];
|
|
16
|
+
export const httpSessionBackends = [
|
|
17
|
+
HTTP_SESSION_BACKEND_MEMORY,
|
|
18
|
+
];
|
|
19
|
+
export const streamableHttpProbePaths = [HEALTHZ_PATH, READYZ_PATH];
|
|
6
20
|
export const defaultStreamableHttpOptions = {
|
|
21
|
+
protocol: HTTP_PROTOCOL_HTTP,
|
|
7
22
|
host: '127.0.0.1',
|
|
8
23
|
port: 3000,
|
|
9
24
|
endpoint: '/mcp',
|
|
10
|
-
|
|
25
|
+
tls: {},
|
|
26
|
+
sessionBackend: HTTP_SESSION_BACKEND_MEMORY,
|
|
11
27
|
sessionIdleTtlMs: 3_600_000,
|
|
12
28
|
sessionMax: 32,
|
|
13
29
|
bodyLimitBytes: 1_048_576,
|
package/dist/http/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/http/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/http/options.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAgB,CAAC;AACvD,MAAM,CAAC,MAAM,gCAAgC,GAAG,iBAA0B,CAAC;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAe,CAAC;AAClD,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAgB,CAAC;AACpD,MAAM,CAAC,MAAM,2BAA2B,GAAG,QAAiB,CAAC;AAC7D,MAAM,CAAC,MAAM,YAAY,GAAG,UAAmB,CAAC;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG,SAAkB,CAAC;AAM9C,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,sBAAsB;IACtB,gCAAgC;CACiB,CAAC;AACpD,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,kBAAkB;IAClB,mBAAmB;CACuB,CAAC;AAC7C,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,2BAA2B;CACqB,CAAC;AACnD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,YAAY,EAAE,WAAW,CAAU,CAAC;AA2B7E,MAAM,CAAC,MAAM,4BAA4B,GAA0B;IACjE,QAAQ,EAAE,kBAAkB;IAC5B,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,MAAM;IAChB,GAAG,EAAE,EAAE;IACP,cAAc,EAAE,2BAA2B;IAC3C,gBAAgB,EAAE,SAAS;IAC3B,UAAU,EAAE,EAAE;IACd,cAAc,EAAE,SAAS;CAC1B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import { type StreamableHttpOptions } from '#src/http/options';
|
|
3
|
+
export declare function isEndpointRequest(req: IncomingMessage, endpoint: string, fallbackHost: string, protocol?: StreamableHttpOptions['protocol']): boolean;
|
|
4
|
+
export declare function requestPathName(req: IncomingMessage, fallbackHost: string, protocol: StreamableHttpOptions['protocol']): string;
|
|
5
|
+
export declare function hasJsonContentType(req: IncomingMessage): boolean;
|
|
6
|
+
export declare function readJsonBody(req: IncomingMessage, limitBytes: number): Promise<unknown>;
|
|
7
|
+
export declare function containsInitializeRequest(value: unknown): boolean;
|
|
8
|
+
export declare function getSingleHeader(req: IncomingMessage, name: string): string | undefined;
|
|
9
|
+
export declare class RequestBodyTooLargeError extends Error {
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=requests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../src/http/requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGjD,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG/D,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,QAAQ,GAAE,qBAAqB,CAAC,UAAU,CAAU,GACnD,OAAO,CAIT;AAED,wBAAgB,eAAe,CAC7B,GAAG,EAAE,eAAe,EACpB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC,GAC1C,MAAM,CAOR;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAGhE;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB7F;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGjE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAItF;AAED,qBAAa,wBAAyB,SAAQ,KAAK;CAAG"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { formatHost } from '#src/http/nodeServer';
|
|
3
|
+
import { JSON_CONTENT_TYPE } from '#src/protocol/constants';
|
|
4
|
+
export function isEndpointRequest(req, endpoint, fallbackHost, protocol = 'http') {
|
|
5
|
+
const host = getSingleHeader(req, 'host') ?? formatHost(fallbackHost);
|
|
6
|
+
const url = new URL(req.url ?? '/', `${protocol}://${host}`);
|
|
7
|
+
return url.pathname === endpoint;
|
|
8
|
+
}
|
|
9
|
+
export function requestPathName(req, fallbackHost, protocol) {
|
|
10
|
+
const host = getSingleHeader(req, 'host') ?? formatHost(fallbackHost);
|
|
11
|
+
try {
|
|
12
|
+
return new URL(req.url ?? '/', `${protocol}://${host}`).pathname;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return fallbackPathName(req.url);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function hasJsonContentType(req) {
|
|
19
|
+
const contentType = getSingleHeader(req, 'content-type');
|
|
20
|
+
return contentType?.toLowerCase().includes(JSON_CONTENT_TYPE) ?? false;
|
|
21
|
+
}
|
|
22
|
+
export async function readJsonBody(req, limitBytes) {
|
|
23
|
+
const contentLength = getSingleHeader(req, 'content-length');
|
|
24
|
+
if (contentLength !== undefined && Number.parseInt(contentLength, 10) > limitBytes) {
|
|
25
|
+
throw new RequestBodyTooLargeError();
|
|
26
|
+
}
|
|
27
|
+
const chunks = [];
|
|
28
|
+
let size = 0;
|
|
29
|
+
for await (const chunk of req) {
|
|
30
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
31
|
+
size += buffer.byteLength;
|
|
32
|
+
if (size > limitBytes)
|
|
33
|
+
throw new RequestBodyTooLargeError();
|
|
34
|
+
chunks.push(buffer);
|
|
35
|
+
}
|
|
36
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
37
|
+
}
|
|
38
|
+
export function containsInitializeRequest(value) {
|
|
39
|
+
const messages = Array.isArray(value) ? value : [value];
|
|
40
|
+
return messages.some((message) => isInitializeRequest(message));
|
|
41
|
+
}
|
|
42
|
+
export function getSingleHeader(req, name) {
|
|
43
|
+
const value = req.headers[name];
|
|
44
|
+
if (Array.isArray(value))
|
|
45
|
+
return value[0];
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
export class RequestBodyTooLargeError extends Error {
|
|
49
|
+
}
|
|
50
|
+
function fallbackPathName(url) {
|
|
51
|
+
const pathName = (url ?? '/').split(/[?#]/u, 1)[0];
|
|
52
|
+
return pathName.length > 0 ? pathName : '/';
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=requests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../src/http/requests.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,UAAU,iBAAiB,CAC/B,GAAoB,EACpB,QAAgB,EAChB,YAAoB,EACpB,WAA8C,MAAM;IAEpD,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;IACtE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,EAAE,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC,CAAC;IAC7D,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAoB,EACpB,YAAoB,EACpB,QAA2C;IAE3C,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;IACtE,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,EAAE,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,k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,CAAC;IACxD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAoB,EAAE,IAAY;IAChE,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAC1C,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;CAAG;AAEtD,SAAS,gBAAgB,CAAC,GAAuB;IAC/C,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ServerResponse } from 'node:http';
|
|
2
|
+
import { HttpStatus, JsonRpcErrorCode } from '#src/http/status';
|
|
3
|
+
export declare function writeJsonRpcError(res: ServerResponse, status: HttpStatus, code: JsonRpcErrorCode, message: string, headers?: Record<string, string>): void;
|
|
4
|
+
export declare function writeJsonResponse(res: ServerResponse, status: HttpStatus, body: Record<string, unknown>, headers?: Record<string, string>): void;
|
|
5
|
+
export declare function endResponse(res: ServerResponse, body?: string): void;
|
|
6
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/http/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGhE,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,IAAI,CAWN;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,IAAI,CAMN;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,SAAK,GAAG,IAAI,CAEhE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JSON_CONTENT_TYPE, JSON_RPC_VERSION } from '#src/protocol/constants';
|
|
2
|
+
export function writeJsonRpcError(res, status, code, message, headers = {}) {
|
|
3
|
+
const body = JSON.stringify({
|
|
4
|
+
jsonrpc: JSON_RPC_VERSION,
|
|
5
|
+
error: { code, message },
|
|
6
|
+
id: null,
|
|
7
|
+
});
|
|
8
|
+
res.writeHead(status, {
|
|
9
|
+
'Content-Type': JSON_CONTENT_TYPE,
|
|
10
|
+
...headers,
|
|
11
|
+
});
|
|
12
|
+
endResponse(res, body);
|
|
13
|
+
}
|
|
14
|
+
export function writeJsonResponse(res, status, body, headers = {}) {
|
|
15
|
+
res.writeHead(status, {
|
|
16
|
+
'Content-Type': JSON_CONTENT_TYPE,
|
|
17
|
+
...headers,
|
|
18
|
+
});
|
|
19
|
+
endResponse(res, JSON.stringify(body));
|
|
20
|
+
}
|
|
21
|
+
export function endResponse(res, body = '') {
|
|
22
|
+
res.end(body);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/http/responses.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE9E,MAAM,UAAU,iBAAiB,CAC/B,GAAmB,EACnB,MAAkB,EAClB,IAAsB,EACtB,OAAe,EACf,UAAkC,EAAE;IAEpC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1B,OAAO,EAAE,gBAAgB;QACzB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QACxB,EAAE,EAAE,IAAI;KACT,CAAC,CAAC;IACH,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE;QACpB,cAAc,EAAE,iBAAiB;QACjC,GAAG,OAAO;KACX,CAAC,CAAC;IACH,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,GAAmB,EACnB,MAAkB,EAClB,IAA6B,EAC7B,UAAkC,EAAE;IAEpC,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE;QACpB,cAAc,EAAE,iBAAiB;QACjC,GAAG,OAAO;KACX,CAAC,CAAC;IACH,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAmB,EAAE,IAAI,GAAG,EAAE;IACxD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
package/dist/http/server.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type IncomingMessage } from 'node:http';
|
|
2
2
|
import type { AddressInfo } from 'node:net';
|
|
3
3
|
import { type Implementation } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
-
import { type
|
|
5
|
-
import
|
|
4
|
+
import { type HttpSessionBackend, type StreamableHttpOptions } from '#src/http/options';
|
|
5
|
+
import { type SessionStore } from '#src/http/sessionStore';
|
|
6
|
+
import type { BridgeLogger } from '#src/logging/logger';
|
|
6
7
|
export interface StartStreamableHttpBridgeOptions extends StreamableHttpOptions {
|
|
7
8
|
serverInfo?: Partial<Implementation>;
|
|
8
9
|
sessionStore?: SessionStore;
|
|
10
|
+
logger?: BridgeLogger;
|
|
9
11
|
}
|
|
10
12
|
export interface StreamableHttpBridgeServer {
|
|
11
13
|
url: string;
|
|
@@ -14,6 +16,6 @@ export interface StreamableHttpBridgeServer {
|
|
|
14
16
|
}
|
|
15
17
|
export declare function startStreamableHttpBridge(options: StartStreamableHttpBridgeOptions): Promise<StreamableHttpBridgeServer>;
|
|
16
18
|
export declare function isAuthorizedRequest(req: IncomingMessage, authToken: string | undefined): boolean;
|
|
17
|
-
export
|
|
19
|
+
export { isEndpointRequest } from '#src/http/requests';
|
|
18
20
|
export type { HttpSessionBackend };
|
|
19
21
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/http/server.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/http/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAuB,MAAM,WAAW,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAuBxD,MAAM,WAAW,gCAAiC,SAAQ,qBAAqB;IAC7E,UAAU,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACrC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAQD,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,gCAAgC,GACxC,OAAO,CAAC,0BAA0B,CAAC,CAGrC;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAUhG;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AA6WvD,YAAY,EAAE,kBAAkB,EAAE,CAAC"}
|