cloakbrowser-mcp 1.3.0 → 1.5.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 +101 -19
- package/dist/bridge/config.d.ts +26 -3
- package/dist/bridge/config.d.ts.map +1 -1
- package/dist/bridge/config.js +187 -13
- 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 +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +3 -3
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/options.d.ts +11 -2
- package/dist/cli/options.d.ts.map +1 -1
- package/dist/cli/options.js +115 -3
- package/dist/cli/options.js.map +1 -1
- package/dist/cli/singleton-lock-cleanup.d.ts +34 -0
- package/dist/cli/singleton-lock-cleanup.d.ts.map +1 -0
- package/dist/cli/singleton-lock-cleanup.js +151 -0
- package/dist/cli/singleton-lock-cleanup.js.map +1 -0
- package/dist/cli.js +27 -10
- 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 +27 -2
- package/dist/http/options.d.ts.map +1 -1
- package/dist/http/options.js +25 -5
- package/dist/http/options.js.map +1 -1
- package/dist/http/requests.d.ts +16 -0
- package/dist/http/requests.d.ts.map +1 -0
- package/dist/http/requests.js +127 -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 +7 -3
- package/dist/http/server.d.ts.map +1 -1
- package/dist/http/server.js +61 -117
- 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 +6 -0
- package/dist/protocol/constants.d.ts.map +1 -0
- package/dist/protocol/constants.js +6 -0
- package/dist/protocol/constants.js.map +1 -0
- package/dist/runtime/humanize-init-page.cjs +19 -0
- package/dist/server.d.ts +3 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +5 -5
- package/dist/server.js.map +1 -1
- package/package.json +39 -18
- package/server.json +29 -5
|
@@ -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,Y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
|
-
|
|
2
|
-
export
|
|
1
|
+
import type { HumanPreset } from '#src/bridge/config';
|
|
2
|
+
export declare const BRIDGE_TRANSPORT_STDIO: "stdio";
|
|
3
|
+
export declare const BRIDGE_TRANSPORT_STREAMABLE_HTTP: "streamable-http";
|
|
4
|
+
export declare const HTTP_PROTOCOL_HTTP: "http";
|
|
5
|
+
export declare const HTTP_PROTOCOL_HTTPS: "https";
|
|
6
|
+
export declare const HTTP_SESSION_BACKEND_MEMORY: "memory";
|
|
7
|
+
export declare const HEALTHZ_PATH: "/healthz";
|
|
8
|
+
export declare const READYZ_PATH: "/readyz";
|
|
9
|
+
export type BridgeTransportMode = typeof BRIDGE_TRANSPORT_STDIO | typeof BRIDGE_TRANSPORT_STREAMABLE_HTTP;
|
|
10
|
+
export type HttpProtocol = typeof HTTP_PROTOCOL_HTTP | typeof HTTP_PROTOCOL_HTTPS;
|
|
11
|
+
export type HttpSessionBackend = typeof HTTP_SESSION_BACKEND_MEMORY;
|
|
3
12
|
export declare const bridgeTransportModes: readonly ["stdio", "streamable-http"];
|
|
13
|
+
export declare const httpProtocols: readonly ["http", "https"];
|
|
4
14
|
export declare const httpSessionBackends: readonly ["memory"];
|
|
5
15
|
export declare const streamableHttpProbePaths: readonly ["/healthz", "/readyz"];
|
|
16
|
+
export interface StreamableHttpTlsOptions {
|
|
17
|
+
cert?: string;
|
|
18
|
+
key?: string;
|
|
19
|
+
pfx?: string;
|
|
20
|
+
passphrase?: string;
|
|
21
|
+
}
|
|
6
22
|
export interface StreamableHttpOptions {
|
|
23
|
+
protocol: HttpProtocol;
|
|
7
24
|
host: string;
|
|
8
25
|
port: number;
|
|
9
26
|
endpoint: string;
|
|
10
27
|
authToken?: string;
|
|
28
|
+
tls: StreamableHttpTlsOptions;
|
|
11
29
|
sessionBackend: HttpSessionBackend;
|
|
12
30
|
sessionIdleTtlMs: number;
|
|
13
31
|
sessionMax: number;
|
|
14
32
|
bodyLimitBytes: number;
|
|
15
33
|
}
|
|
34
|
+
export interface BridgeOptions {
|
|
35
|
+
geoipProxyMatch: boolean;
|
|
36
|
+
humanize: boolean;
|
|
37
|
+
humanPreset: HumanPreset;
|
|
38
|
+
}
|
|
16
39
|
export interface CliOptions {
|
|
17
40
|
transport: BridgeTransportMode;
|
|
41
|
+
bridge: BridgeOptions;
|
|
18
42
|
http: StreamableHttpOptions;
|
|
19
43
|
}
|
|
44
|
+
export declare const defaultBridgeOptions: BridgeOptions;
|
|
20
45
|
export declare const defaultStreamableHttpOptions: StreamableHttpOptions;
|
|
21
46
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -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,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,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,aAAa;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,mBAAmB,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,qBAAqB,CAAC;CAC7B;AAED,eAAO,MAAM,oBAAoB,EAAE,aAIlC,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,qBAU1C,CAAC"}
|
package/dist/http/options.js
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
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
|
|
6
|
-
|
|
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];
|
|
20
|
+
export const defaultBridgeOptions = {
|
|
21
|
+
geoipProxyMatch: false,
|
|
22
|
+
humanize: false,
|
|
23
|
+
humanPreset: 'default',
|
|
24
|
+
};
|
|
7
25
|
export const defaultStreamableHttpOptions = {
|
|
26
|
+
protocol: HTTP_PROTOCOL_HTTP,
|
|
8
27
|
host: '127.0.0.1',
|
|
9
28
|
port: 3000,
|
|
10
29
|
endpoint: '/mcp',
|
|
11
|
-
|
|
30
|
+
tls: {},
|
|
31
|
+
sessionBackend: HTTP_SESSION_BACKEND_MEMORY,
|
|
12
32
|
sessionIdleTtlMs: 3_600_000,
|
|
13
33
|
sessionMax: 32,
|
|
14
34
|
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":"AAEA,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;AAkC7E,MAAM,CAAC,MAAM,oBAAoB,GAAkB;IACjD,eAAe,EAAE,KAAK;IACtB,QAAQ,EAAE,KAAK;IACf,WAAW,EAAE,SAAS;CACvB,CAAC;AAEF,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,16 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import { type PrepareBridgeRuntimeOptions } from '#src/bridge/config';
|
|
3
|
+
import { type StreamableHttpOptions } from '#src/http/options';
|
|
4
|
+
export declare function isEndpointRequest(req: IncomingMessage, endpoint: string, fallbackHost: string, protocol?: StreamableHttpOptions['protocol']): boolean;
|
|
5
|
+
export declare function requestPathName(req: IncomingMessage, fallbackHost: string, protocol: StreamableHttpOptions['protocol']): string;
|
|
6
|
+
export declare function hasJsonContentType(req: IncomingMessage): boolean;
|
|
7
|
+
export declare function readJsonBody(req: IncomingMessage, limitBytes: number): Promise<unknown>;
|
|
8
|
+
export declare function containsInitializeRequest(value: unknown): boolean;
|
|
9
|
+
export type BridgeInitializeRuntimeOptions = Pick<PrepareBridgeRuntimeOptions, 'geoipProxyMatch' | 'headless' | 'humanize' | 'humanPreset' | 'proxy'>;
|
|
10
|
+
export declare function readBridgeRuntimeOptionsFromInitialize(value: unknown): BridgeInitializeRuntimeOptions;
|
|
11
|
+
export declare function getSingleHeader(req: IncomingMessage, name: string): string | undefined;
|
|
12
|
+
export declare class RequestBodyTooLargeError extends Error {
|
|
13
|
+
}
|
|
14
|
+
export declare class InvalidBridgeInitializeMetaError extends Error {
|
|
15
|
+
}
|
|
16
|
+
//# 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;AAEjD,OAAO,EAIL,KAAK,2BAA2B,EACjC,MAAM,oBAAoB,CAAC;AAE5B,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,CAEjE;AAED,MAAM,MAAM,8BAA8B,GAAG,IAAI,CAC/C,2BAA2B,EAC3B,iBAAiB,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,GAAG,OAAO,CACtE,CAAC;AAEF,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,OAAO,GAAG,8BAA8B,CA+BrG;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAItF;AAED,qBAAa,wBAAyB,SAAQ,KAAK;CAAG;AAEtD,qBAAa,gCAAiC,SAAQ,KAAK;CAAG"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { parseHumanPreset, } from '#src/bridge/config';
|
|
3
|
+
import { formatHost } from '#src/http/nodeServer';
|
|
4
|
+
import { BRIDGE_INITIALIZE_META_KEY, JSON_CONTENT_TYPE } from '#src/protocol/constants';
|
|
5
|
+
export function isEndpointRequest(req, endpoint, fallbackHost, protocol = 'http') {
|
|
6
|
+
const host = getSingleHeader(req, 'host') ?? formatHost(fallbackHost);
|
|
7
|
+
const url = new URL(req.url ?? '/', `${protocol}://${host}`);
|
|
8
|
+
return url.pathname === endpoint;
|
|
9
|
+
}
|
|
10
|
+
export function requestPathName(req, fallbackHost, protocol) {
|
|
11
|
+
const host = getSingleHeader(req, 'host') ?? formatHost(fallbackHost);
|
|
12
|
+
try {
|
|
13
|
+
return new URL(req.url ?? '/', `${protocol}://${host}`).pathname;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return fallbackPathName(req.url);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function hasJsonContentType(req) {
|
|
20
|
+
const contentType = getSingleHeader(req, 'content-type');
|
|
21
|
+
return contentType?.toLowerCase().includes(JSON_CONTENT_TYPE) ?? false;
|
|
22
|
+
}
|
|
23
|
+
export async function readJsonBody(req, limitBytes) {
|
|
24
|
+
const contentLength = getSingleHeader(req, 'content-length');
|
|
25
|
+
if (contentLength !== undefined && Number.parseInt(contentLength, 10) > limitBytes) {
|
|
26
|
+
throw new RequestBodyTooLargeError();
|
|
27
|
+
}
|
|
28
|
+
const chunks = [];
|
|
29
|
+
let size = 0;
|
|
30
|
+
for await (const chunk of req) {
|
|
31
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
32
|
+
size += buffer.byteLength;
|
|
33
|
+
if (size > limitBytes)
|
|
34
|
+
throw new RequestBodyTooLargeError();
|
|
35
|
+
chunks.push(buffer);
|
|
36
|
+
}
|
|
37
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
38
|
+
}
|
|
39
|
+
export function containsInitializeRequest(value) {
|
|
40
|
+
return findInitializeRequest(value) !== undefined;
|
|
41
|
+
}
|
|
42
|
+
export function readBridgeRuntimeOptionsFromInitialize(value) {
|
|
43
|
+
const request = findInitializeRequest(value);
|
|
44
|
+
if (!request)
|
|
45
|
+
return {};
|
|
46
|
+
const meta = request.params._meta;
|
|
47
|
+
const bridgeMeta = meta?.[BRIDGE_INITIALIZE_META_KEY];
|
|
48
|
+
if (bridgeMeta === undefined)
|
|
49
|
+
return {};
|
|
50
|
+
if (!isRecord(bridgeMeta)) {
|
|
51
|
+
throw new InvalidBridgeInitializeMetaError(`${BRIDGE_INITIALIZE_META_KEY} initialize metadata must be an object`);
|
|
52
|
+
}
|
|
53
|
+
const proxyServer = readOptionalString(bridgeMeta, 'proxyServer');
|
|
54
|
+
const proxyBypass = readOptionalString(bridgeMeta, 'proxyBypass');
|
|
55
|
+
const geoipProxyMatch = readOptionalBoolean(bridgeMeta, 'geoipProxyMatch');
|
|
56
|
+
const headless = readOptionalBoolean(bridgeMeta, 'headless');
|
|
57
|
+
const humanize = readOptionalBoolean(bridgeMeta, 'humanize');
|
|
58
|
+
const humanPreset = readOptionalHumanPreset(bridgeMeta, 'humanPreset');
|
|
59
|
+
if (proxyBypass !== undefined && proxyServer === undefined) {
|
|
60
|
+
throw new InvalidBridgeInitializeMetaError('proxyBypass requires proxyServer');
|
|
61
|
+
}
|
|
62
|
+
const proxy = proxyServer === undefined ? undefined : createRuntimeProxy(proxyServer, proxyBypass);
|
|
63
|
+
return {
|
|
64
|
+
...(geoipProxyMatch === undefined ? {} : { geoipProxyMatch }),
|
|
65
|
+
...(headless === undefined ? {} : { headless }),
|
|
66
|
+
...(humanize === undefined ? {} : { humanize }),
|
|
67
|
+
...(humanPreset === undefined ? {} : { humanPreset }),
|
|
68
|
+
...(proxy === undefined ? {} : { proxy }),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function getSingleHeader(req, name) {
|
|
72
|
+
const value = req.headers[name];
|
|
73
|
+
if (Array.isArray(value))
|
|
74
|
+
return value[0];
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
export class RequestBodyTooLargeError extends Error {
|
|
78
|
+
}
|
|
79
|
+
export class InvalidBridgeInitializeMetaError extends Error {
|
|
80
|
+
}
|
|
81
|
+
function findInitializeRequest(value) {
|
|
82
|
+
const messages = Array.isArray(value) ? value : [value];
|
|
83
|
+
return messages.find((message) => isInitializeRequest(message));
|
|
84
|
+
}
|
|
85
|
+
function createRuntimeProxy(server, bypass) {
|
|
86
|
+
return bypass === undefined ? { server } : { server, bypass };
|
|
87
|
+
}
|
|
88
|
+
function readOptionalString(value, key) {
|
|
89
|
+
if (!(key in value))
|
|
90
|
+
return undefined;
|
|
91
|
+
const raw = value[key];
|
|
92
|
+
if (typeof raw !== 'string' || raw.trim().length === 0) {
|
|
93
|
+
throw new InvalidBridgeInitializeMetaError(`${key} must be a non-empty string`);
|
|
94
|
+
}
|
|
95
|
+
return raw.trim();
|
|
96
|
+
}
|
|
97
|
+
function readOptionalBoolean(value, key) {
|
|
98
|
+
if (!(key in value))
|
|
99
|
+
return undefined;
|
|
100
|
+
const raw = value[key];
|
|
101
|
+
if (typeof raw !== 'boolean') {
|
|
102
|
+
throw new InvalidBridgeInitializeMetaError(`${key} must be a boolean`);
|
|
103
|
+
}
|
|
104
|
+
return raw;
|
|
105
|
+
}
|
|
106
|
+
function readOptionalHumanPreset(value, key) {
|
|
107
|
+
if (!(key in value))
|
|
108
|
+
return undefined;
|
|
109
|
+
const raw = value[key];
|
|
110
|
+
if (typeof raw !== 'string') {
|
|
111
|
+
throw new InvalidBridgeInitializeMetaError(`${key} must be "default" or "careful"`);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return parseHumanPreset(raw.trim());
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
throw new InvalidBridgeInitializeMetaError(`${key} must be "default" or "careful"`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function isRecord(value) {
|
|
121
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
122
|
+
}
|
|
123
|
+
function fallbackPathName(url) {
|
|
124
|
+
const pathName = (url ?? '/').split(/[?#]/u, 1)[0];
|
|
125
|
+
return pathName.length > 0 ? pathName : '/';
|
|
126
|
+
}
|
|
127
|
+
//# 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,EAA0B,MAAM,oCAAoC,CAAC;AACjG,OAAO,EACL,gBAAgB,GAIjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAExF,MAAM,UAAU,iBAAiB,CAC/B,GAAoB,EACpB,Q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cErrorCode } 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,15 @@
|
|
|
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 { type
|
|
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';
|
|
7
|
+
import type { PrepareBridgeRuntimeOptions } from '#src/bridge/config';
|
|
6
8
|
export interface StartStreamableHttpBridgeOptions extends StreamableHttpOptions {
|
|
7
9
|
serverInfo?: Partial<Implementation>;
|
|
10
|
+
runtimeOptions?: Pick<PrepareBridgeRuntimeOptions, 'geoipProxyMatch' | 'headless' | 'humanize' | 'humanPreset' | 'proxy'>;
|
|
8
11
|
sessionStore?: SessionStore;
|
|
12
|
+
logger?: BridgeLogger;
|
|
9
13
|
}
|
|
10
14
|
export interface StreamableHttpBridgeServer {
|
|
11
15
|
url: string;
|
|
@@ -14,6 +18,6 @@ export interface StreamableHttpBridgeServer {
|
|
|
14
18
|
}
|
|
15
19
|
export declare function startStreamableHttpBridge(options: StartStreamableHttpBridgeOptions): Promise<StreamableHttpBridgeServer>;
|
|
16
20
|
export declare function isAuthorizedRequest(req: IncomingMessage, authToken: string | undefined): boolean;
|
|
17
|
-
export
|
|
21
|
+
export { isEndpointRequest } from '#src/http/requests';
|
|
18
22
|
export type { HttpSessionBackend };
|
|
19
23
|
//# 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;AAsBxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAItE,MAAM,WAAW,gCAAiC,SAAQ,qBAAqB;IAC7E,UAAU,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACrC,cAAc,CAAC,EAAE,IAAI,CACnB,2BAA2B,EAC3B,iBAAiB,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,GAAG,OAAO,CACtE,CAAC;IACF,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,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