@lushly-dev/afd-server 0.6.0 → 2.0.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 +320 -14
- package/dist/bootstrap/afd-context.d.ts +11 -2
- package/dist/bootstrap/afd-context.d.ts.map +1 -1
- package/dist/bootstrap/afd-context.js +56 -11
- package/dist/bootstrap/afd-context.js.map +1 -1
- package/dist/bootstrap/afd-docs.d.ts +6 -3
- package/dist/bootstrap/afd-docs.d.ts.map +1 -1
- package/dist/bootstrap/afd-docs.js +14 -9
- package/dist/bootstrap/afd-docs.js.map +1 -1
- package/dist/bootstrap/afd-help.d.ts +6 -3
- package/dist/bootstrap/afd-help.d.ts.map +1 -1
- package/dist/bootstrap/afd-help.js +10 -8
- package/dist/bootstrap/afd-help.js.map +1 -1
- package/dist/bootstrap/afd-schema.d.ts +8 -4
- package/dist/bootstrap/afd-schema.d.ts.map +1 -1
- package/dist/bootstrap/afd-schema.js +55 -42
- package/dist/bootstrap/afd-schema.js.map +1 -1
- package/dist/bootstrap/described-command.d.ts +32 -0
- package/dist/bootstrap/described-command.d.ts.map +1 -0
- package/dist/bootstrap/described-command.js +12 -0
- package/dist/bootstrap/described-command.js.map +1 -0
- package/dist/bootstrap/index.d.ts +1 -0
- package/dist/bootstrap/index.d.ts.map +1 -1
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/bootstrap/json-schema-to-ts.d.ts +27 -0
- package/dist/bootstrap/json-schema-to-ts.d.ts.map +1 -0
- package/dist/bootstrap/json-schema-to-ts.js +154 -0
- package/dist/bootstrap/json-schema-to-ts.js.map +1 -0
- package/dist/bootstrap/registry.d.ts +17 -6
- package/dist/bootstrap/registry.d.ts.map +1 -1
- package/dist/bootstrap/registry.js +32 -5
- package/dist/bootstrap/registry.js.map +1 -1
- package/dist/command-names.d.ts +19 -0
- package/dist/command-names.d.ts.map +1 -0
- package/dist/command-names.js +33 -0
- package/dist/command-names.js.map +1 -0
- package/dist/command-routing.d.ts +47 -0
- package/dist/command-routing.d.ts.map +1 -0
- package/dist/command-routing.js +75 -0
- package/dist/command-routing.js.map +1 -0
- package/dist/context-scope.d.ts +26 -0
- package/dist/context-scope.d.ts.map +1 -0
- package/dist/context-scope.js +31 -0
- package/dist/context-scope.js.map +1 -0
- package/dist/define.d.ts +42 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +41 -0
- package/dist/define.js.map +1 -0
- package/dist/direct-registry.d.ts +103 -0
- package/dist/direct-registry.d.ts.map +1 -0
- package/dist/direct-registry.js +102 -0
- package/dist/direct-registry.js.map +1 -0
- package/dist/execution.d.ts +9 -0
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +105 -321
- package/dist/execution.js.map +1 -1
- package/dist/http-handler.d.ts +24 -17
- package/dist/http-handler.d.ts.map +1 -1
- package/dist/http-handler.js +282 -253
- package/dist/http-handler.js.map +1 -1
- package/dist/http-security.d.ts +23 -0
- package/dist/http-security.d.ts.map +1 -0
- package/dist/http-security.js +101 -0
- package/dist/http-security.js.map +1 -0
- package/dist/http-sessions.d.ts +33 -0
- package/dist/http-sessions.d.ts.map +1 -0
- package/dist/http-sessions.js +65 -0
- package/dist/http-sessions.js.map +1 -0
- package/dist/http-sse.d.ts +30 -0
- package/dist/http-sse.d.ts.map +1 -0
- package/dist/http-sse.js +70 -0
- package/dist/http-sse.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/json-rpc.d.ts +56 -0
- package/dist/json-rpc.d.ts.map +1 -0
- package/dist/json-rpc.js +73 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/lazy-tools.d.ts +2 -12
- package/dist/lazy-tools.d.ts.map +1 -1
- package/dist/lazy-tools.js +9 -14
- package/dist/lazy-tools.js.map +1 -1
- package/dist/meta-tools.d.ts +122 -0
- package/dist/meta-tools.d.ts.map +1 -0
- package/dist/meta-tools.js +156 -0
- package/dist/meta-tools.js.map +1 -0
- package/dist/middleware.d.ts +34 -7
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +82 -40
- package/dist/middleware.js.map +1 -1
- package/dist/schema.d.ts +27 -6
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +17 -12
- package/dist/schema.js.map +1 -1
- package/dist/server-types.d.ts +100 -13
- package/dist/server-types.d.ts.map +1 -1
- package/dist/server-types.js.map +1 -1
- package/dist/server.d.ts +10 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +165 -48
- package/dist/server.js.map +1 -1
- package/dist/tool-router.d.ts +6 -5
- package/dist/tool-router.d.ts.map +1 -1
- package/dist/tool-router.js +104 -120
- package/dist/tool-router.js.map +1 -1
- package/dist/tools.d.ts +10 -420
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +99 -208
- package/dist/tools.js.map +1 -1
- package/package.json +13 -8
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** HTTP request validation and bounded body parsing shared by all remote routes. */
|
|
2
|
+
import type { IncomingMessage } from 'node:http';
|
|
3
|
+
export declare class HttpRequestError extends Error {
|
|
4
|
+
readonly status: number;
|
|
5
|
+
/** JSON-RPC error code used when the route speaks JSON-RPC (default: -32000 server error). */
|
|
6
|
+
readonly rpcCode: number;
|
|
7
|
+
/** Recovery guidance; a generic one is used when omitted. */
|
|
8
|
+
readonly suggestion?: string;
|
|
9
|
+
constructor(status: number, message: string, options?: {
|
|
10
|
+
rpcCode?: number;
|
|
11
|
+
suggestion?: string;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export interface HttpSecurityOptions {
|
|
15
|
+
host: string;
|
|
16
|
+
devMode: boolean;
|
|
17
|
+
allowedHosts?: string[];
|
|
18
|
+
allowedOrigins?: string[];
|
|
19
|
+
maxBodyBytes?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function validateHttpRequest(req: IncomingMessage, options: HttpSecurityOptions): URL;
|
|
22
|
+
export declare function readJsonBody(req: IncomingMessage, maxBytes: number): Promise<unknown>;
|
|
23
|
+
//# sourceMappingURL=http-security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-security.d.ts","sourceRoot":"","sources":["../src/http-security.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGjD,qBAAa,gBAAiB,SAAQ,KAAK;IAOzC,QAAQ,CAAC,MAAM,EAAE,MAAM;IANxB,8FAA8F;IAC9F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAGnB,MAAM,EAAE,MAAM,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAO;CAMxD;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,mBAAmB,GAAG,GAAG,CAwC3F;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAiDrF"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { TLSSocket } from 'node:tls';
|
|
2
|
+
export class HttpRequestError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
/** JSON-RPC error code used when the route speaks JSON-RPC (default: -32000 server error). */
|
|
5
|
+
rpcCode;
|
|
6
|
+
/** Recovery guidance; a generic one is used when omitted. */
|
|
7
|
+
suggestion;
|
|
8
|
+
constructor(status, message, options = {}) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.rpcCode = options.rpcCode ?? -32000;
|
|
12
|
+
this.suggestion = options.suggestion;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function validateHttpRequest(req, options) {
|
|
16
|
+
const host = req.headers.host;
|
|
17
|
+
if (!host || /[\s/@\\?#]/.test(host))
|
|
18
|
+
throw new HttpRequestError(400, 'Invalid Host header');
|
|
19
|
+
let base;
|
|
20
|
+
try {
|
|
21
|
+
base = new URL(`${req.socket instanceof TLSSocket ? 'https' : 'http'}://${host}`);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new HttpRequestError(400, 'Invalid Host header');
|
|
25
|
+
}
|
|
26
|
+
const allowedHosts = options.allowedHosts ?? [options.host, 'localhost', '127.0.0.1', '[::1]'];
|
|
27
|
+
if (!allowedHosts.some((allowed) => allowed.toLowerCase() === base.hostname.toLowerCase())) {
|
|
28
|
+
throw new HttpRequestError(403, 'Host is not allowed; configure allowedHosts for this host');
|
|
29
|
+
}
|
|
30
|
+
const origin = req.headers.origin;
|
|
31
|
+
if (!options.devMode &&
|
|
32
|
+
origin &&
|
|
33
|
+
origin !== base.origin &&
|
|
34
|
+
!options.allowedOrigins?.includes(origin)) {
|
|
35
|
+
throw new HttpRequestError(403, 'Origin is not allowed; configure allowedOrigins for browser access');
|
|
36
|
+
}
|
|
37
|
+
// Covers navigation and no-cors GET requests that omit Origin, including legacy streams.
|
|
38
|
+
const fetchSite = req.headers['sec-fetch-site'];
|
|
39
|
+
if (!options.devMode &&
|
|
40
|
+
!origin &&
|
|
41
|
+
fetchSite &&
|
|
42
|
+
fetchSite !== 'same-origin' &&
|
|
43
|
+
fetchSite !== 'none') {
|
|
44
|
+
throw new HttpRequestError(403, 'Cross-origin browser requests require an allowed Origin');
|
|
45
|
+
}
|
|
46
|
+
const target = req.url ?? '/';
|
|
47
|
+
if (!target.startsWith('/') || target.startsWith('//'))
|
|
48
|
+
throw new HttpRequestError(400, 'Invalid request target');
|
|
49
|
+
return new URL(target, base);
|
|
50
|
+
}
|
|
51
|
+
export function readJsonBody(req, maxBytes) {
|
|
52
|
+
if (req.destroyed || req.aborted)
|
|
53
|
+
throw new HttpRequestError(400, 'Request body was interrupted');
|
|
54
|
+
if (req.headers['content-type']?.split(';')[0]?.trim().toLowerCase() !== 'application/json') {
|
|
55
|
+
throw new HttpRequestError(415, 'Content-Type must be application/json');
|
|
56
|
+
}
|
|
57
|
+
const length = req.headers['content-length'];
|
|
58
|
+
if (length && Number(length) > maxBytes)
|
|
59
|
+
throw new HttpRequestError(413, 'Request body is too large');
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const chunks = [];
|
|
62
|
+
let size = 0;
|
|
63
|
+
const cleanup = () => {
|
|
64
|
+
req.off('data', onData);
|
|
65
|
+
req.off('end', onEnd);
|
|
66
|
+
req.off('aborted', onAborted);
|
|
67
|
+
};
|
|
68
|
+
const fail = (error) => {
|
|
69
|
+
cleanup();
|
|
70
|
+
reject(error);
|
|
71
|
+
};
|
|
72
|
+
const onData = (chunk) => {
|
|
73
|
+
size += chunk.length;
|
|
74
|
+
if (size > maxBytes) {
|
|
75
|
+
fail(new HttpRequestError(413, 'Request body is too large'));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
chunks.push(chunk);
|
|
79
|
+
};
|
|
80
|
+
const onEnd = () => {
|
|
81
|
+
cleanup();
|
|
82
|
+
try {
|
|
83
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString('utf8')));
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
reject(new HttpRequestError(400, 'Request body must be valid JSON', {
|
|
87
|
+
rpcCode: -32700,
|
|
88
|
+
suggestion: 'Send a UTF-8 JSON body',
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const onError = () => fail(new HttpRequestError(400, 'Request body could not be read'));
|
|
93
|
+
const onAborted = () => fail(new HttpRequestError(400, 'Request body was interrupted'));
|
|
94
|
+
req.on('data', onData);
|
|
95
|
+
req.once('end', onEnd);
|
|
96
|
+
req.on('error', onError);
|
|
97
|
+
req.once('close', () => req.off('error', onError));
|
|
98
|
+
req.once('aborted', onAborted);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=http-security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-security.js","sourceRoot":"","sources":["../src/http-security.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAOhC;IANV,8FAA8F;IACrF,OAAO,CAAS;IACzB,6DAA6D;IACpD,UAAU,CAAU;IAE7B,YACU,MAAc,EACvB,OAAe,EACf,UAAqD,EAAE;QAEvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,WAAM,GAAN,MAAM,CAAQ;QAKvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACtC,CAAC;CACD;AAUD,MAAM,UAAU,mBAAmB,CAAC,GAAoB,EAAE,OAA4B;IACrF,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC9B,IAAI,CAAC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IAC7F,IAAI,IAAS,CAAC;IACd,IAAI,CAAC;QACJ,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,YAAY,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;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,SAAS,EAAE,SAAS,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Bounded store of HTTP MCP sessions and their context state.
|
|
3
|
+
*
|
|
4
|
+
* `initialize` creates a session and returns its ID in the `Mcp-Session-Id` response header.
|
|
5
|
+
* Later requests carrying that header share one context stack; requests without it are
|
|
6
|
+
* stateless. Sessions expire after an idle timeout, and the least recently used session is
|
|
7
|
+
* evicted when the store is full, so memory stays bounded however many clients connect.
|
|
8
|
+
*/
|
|
9
|
+
import { type ContextState } from './bootstrap/afd-context.js';
|
|
10
|
+
/** Default maximum number of live HTTP sessions. */
|
|
11
|
+
export declare const DEFAULT_MAX_SESSIONS = 1000;
|
|
12
|
+
/** Default idle time after which an HTTP session expires (30 minutes). */
|
|
13
|
+
export declare const DEFAULT_SESSION_IDLE_TIMEOUT_MS: number;
|
|
14
|
+
export interface SessionStoreOptions {
|
|
15
|
+
/** Maximum live sessions; the least recently used one is evicted beyond it. */
|
|
16
|
+
maxSessions?: number;
|
|
17
|
+
/** Idle time in milliseconds after which a session expires. */
|
|
18
|
+
idleTimeoutMs?: number;
|
|
19
|
+
/** Clock, for tests. */
|
|
20
|
+
now?: () => number;
|
|
21
|
+
}
|
|
22
|
+
export interface SessionStore {
|
|
23
|
+
/** Start a session and return its ID. */
|
|
24
|
+
create(): string;
|
|
25
|
+
/** The context state of a live session, refreshing its idle timer; `undefined` if unknown or expired. */
|
|
26
|
+
get(id: string): ContextState | undefined;
|
|
27
|
+
/** Number of live sessions (expired ones may still be counted until the next access). */
|
|
28
|
+
readonly size: number;
|
|
29
|
+
/** Drop every session. */
|
|
30
|
+
clear(): void;
|
|
31
|
+
}
|
|
32
|
+
export declare function createSessionStore(options?: SessionStoreOptions): SessionStore;
|
|
33
|
+
//# sourceMappingURL=http-sessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-sessions.d.ts","sourceRoot":"","sources":["../src/http-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,4BAA4B,CAAC;AAEnF,oDAAoD;AACpD,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC,0EAA0E;AAC1E,eAAO,MAAM,+BAA+B,QAAiB,CAAC;AAE9D,MAAM,WAAW,mBAAmB;IACnC,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wBAAwB;IACxB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC5B,yCAAyC;IACzC,MAAM,IAAI,MAAM,CAAC;IACjB,yGAAyG;IACzG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;IAC1C,yFAAyF;IACzF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0BAA0B;IAC1B,KAAK,IAAI,IAAI,CAAC;CACd;AAOD,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAmDlF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Bounded store of HTTP MCP sessions and their context state.
|
|
3
|
+
*
|
|
4
|
+
* `initialize` creates a session and returns its ID in the `Mcp-Session-Id` response header.
|
|
5
|
+
* Later requests carrying that header share one context stack; requests without it are
|
|
6
|
+
* stateless. Sessions expire after an idle timeout, and the least recently used session is
|
|
7
|
+
* evicted when the store is full, so memory stays bounded however many clients connect.
|
|
8
|
+
*/
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import { createContextState } from './bootstrap/afd-context.js';
|
|
11
|
+
/** Default maximum number of live HTTP sessions. */
|
|
12
|
+
export const DEFAULT_MAX_SESSIONS = 1000;
|
|
13
|
+
/** Default idle time after which an HTTP session expires (30 minutes). */
|
|
14
|
+
export const DEFAULT_SESSION_IDLE_TIMEOUT_MS = 30 * 60 * 1000;
|
|
15
|
+
export function createSessionStore(options = {}) {
|
|
16
|
+
const { maxSessions = DEFAULT_MAX_SESSIONS, idleTimeoutMs = DEFAULT_SESSION_IDLE_TIMEOUT_MS, now = Date.now, } = options;
|
|
17
|
+
if (!Number.isSafeInteger(maxSessions) || maxSessions <= 0) {
|
|
18
|
+
throw new Error('maxSessions must be a positive integer');
|
|
19
|
+
}
|
|
20
|
+
if (!Number.isFinite(idleTimeoutMs) || idleTimeoutMs <= 0) {
|
|
21
|
+
throw new Error('sessionIdleTimeoutMs must be a positive number');
|
|
22
|
+
}
|
|
23
|
+
// Map order is least recently used first: `get` moves a session to the end.
|
|
24
|
+
const sessions = new Map();
|
|
25
|
+
function sweep(at) {
|
|
26
|
+
for (const [id, session] of sessions) {
|
|
27
|
+
if (at - session.lastSeen < idleTimeoutMs)
|
|
28
|
+
return;
|
|
29
|
+
sessions.delete(id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
create() {
|
|
34
|
+
const at = now();
|
|
35
|
+
sweep(at);
|
|
36
|
+
for (const oldest of sessions.keys()) {
|
|
37
|
+
if (sessions.size < maxSessions)
|
|
38
|
+
break;
|
|
39
|
+
sessions.delete(oldest);
|
|
40
|
+
}
|
|
41
|
+
const id = randomUUID();
|
|
42
|
+
sessions.set(id, { state: createContextState(), lastSeen: at });
|
|
43
|
+
return id;
|
|
44
|
+
},
|
|
45
|
+
get(id) {
|
|
46
|
+
const session = sessions.get(id);
|
|
47
|
+
if (!session)
|
|
48
|
+
return undefined;
|
|
49
|
+
sessions.delete(id);
|
|
50
|
+
const at = now();
|
|
51
|
+
if (at - session.lastSeen >= idleTimeoutMs)
|
|
52
|
+
return undefined;
|
|
53
|
+
session.lastSeen = at;
|
|
54
|
+
sessions.set(id, session);
|
|
55
|
+
return session.state;
|
|
56
|
+
},
|
|
57
|
+
get size() {
|
|
58
|
+
return sessions.size;
|
|
59
|
+
},
|
|
60
|
+
clear() {
|
|
61
|
+
sessions.clear();
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=http-sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-sessions.js","sourceRoot":"","sources":["../src/http-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAqB,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEnF,oDAAoD;AACpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAEzC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AA2B9D,MAAM,UAAU,kBAAkB,CAAC,UAA+B,EAAE;IACnE,MAAM,EACL,WAAW,GAAG,oBAAoB,EAClC,aAAa,GAAG,+BAA+B,EAC/C,GAAG,GAAG,IAAI,CAAC,GAAG,GACd,GAAG,OAAO,CAAC;IACZ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACnE,CAAC;IACD,4EAA4E;IAC5E,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE5C,SAAS,KAAK,CAAC,EAAU;QACxB,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;YACtC,IAAI,EAAE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0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `/sse` connections: a concurrency cap, heartbeat comments and cleanup.
|
|
3
|
+
*/
|
|
4
|
+
import type { ServerResponse } from 'node:http';
|
|
5
|
+
/** Default maximum number of concurrent `/sse` connections. */
|
|
6
|
+
export declare const DEFAULT_MAX_SSE_CONNECTIONS = 100;
|
|
7
|
+
/** Default interval between SSE heartbeat comments (25 seconds). */
|
|
8
|
+
export declare const DEFAULT_SSE_HEARTBEAT_MS = 25000;
|
|
9
|
+
export interface SseClient {
|
|
10
|
+
id: string;
|
|
11
|
+
response: ServerResponse;
|
|
12
|
+
}
|
|
13
|
+
export interface SseHubOptions {
|
|
14
|
+
maxConnections?: number;
|
|
15
|
+
heartbeatMs?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Track open `/sse` responses. One shared timer writes a `: ping` comment to every client so
|
|
19
|
+
* proxies keep idle streams open and dead peers are detected; it runs only while clients exist.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createSseHub(options?: SseHubOptions): {
|
|
22
|
+
clients: Map<string, SseClient>;
|
|
23
|
+
/** Whether another connection would exceed the cap. */
|
|
24
|
+
isFull(): boolean;
|
|
25
|
+
/** Register an SSE response whose headers were sent; it is removed when it closes. */
|
|
26
|
+
add(response: ServerResponse): SseClient;
|
|
27
|
+
/** End every connection and stop the heartbeat. */
|
|
28
|
+
closeAll(): void;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=http-sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-sse.d.ts","sourceRoot":"","sources":["../src/http-sse.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,+DAA+D;AAC/D,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C,oEAAoE;AACpE,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,cAAc,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB;;IAkCtD,uDAAuD;cAC7C,OAAO;IAGjB,sFAAsF;kBACxE,cAAc,GAAG,SAAS;IAUxC,mDAAmD;gBACvC,IAAI;EAMjB"}
|
package/dist/http-sse.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `/sse` connections: a concurrency cap, heartbeat comments and cleanup.
|
|
3
|
+
*/
|
|
4
|
+
/** Default maximum number of concurrent `/sse` connections. */
|
|
5
|
+
export const DEFAULT_MAX_SSE_CONNECTIONS = 100;
|
|
6
|
+
/** Default interval between SSE heartbeat comments (25 seconds). */
|
|
7
|
+
export const DEFAULT_SSE_HEARTBEAT_MS = 25_000;
|
|
8
|
+
/**
|
|
9
|
+
* Track open `/sse` responses. One shared timer writes a `: ping` comment to every client so
|
|
10
|
+
* proxies keep idle streams open and dead peers are detected; it runs only while clients exist.
|
|
11
|
+
*/
|
|
12
|
+
export function createSseHub(options = {}) {
|
|
13
|
+
const maxConnections = options.maxConnections ?? DEFAULT_MAX_SSE_CONNECTIONS;
|
|
14
|
+
const heartbeatMs = options.heartbeatMs ?? DEFAULT_SSE_HEARTBEAT_MS;
|
|
15
|
+
if (!Number.isSafeInteger(maxConnections) || maxConnections <= 0) {
|
|
16
|
+
throw new Error('maxSseConnections must be a positive integer');
|
|
17
|
+
}
|
|
18
|
+
if (!Number.isFinite(heartbeatMs) || heartbeatMs <= 0) {
|
|
19
|
+
throw new Error('SSE heartbeat interval must be positive');
|
|
20
|
+
}
|
|
21
|
+
const clients = new Map();
|
|
22
|
+
let counter = 0;
|
|
23
|
+
let heartbeat;
|
|
24
|
+
function stopHeartbeat() {
|
|
25
|
+
if (heartbeat === undefined)
|
|
26
|
+
return;
|
|
27
|
+
clearInterval(heartbeat);
|
|
28
|
+
heartbeat = undefined;
|
|
29
|
+
}
|
|
30
|
+
function remove(id) {
|
|
31
|
+
clients.delete(id);
|
|
32
|
+
if (clients.size === 0)
|
|
33
|
+
stopHeartbeat();
|
|
34
|
+
}
|
|
35
|
+
function beat() {
|
|
36
|
+
for (const client of clients.values()) {
|
|
37
|
+
const { response } = client;
|
|
38
|
+
if (response.destroyed || response.writableEnded)
|
|
39
|
+
remove(client.id);
|
|
40
|
+
else
|
|
41
|
+
response.write(': ping\n\n');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
clients,
|
|
46
|
+
/** Whether another connection would exceed the cap. */
|
|
47
|
+
isFull() {
|
|
48
|
+
return clients.size >= maxConnections;
|
|
49
|
+
},
|
|
50
|
+
/** Register an SSE response whose headers were sent; it is removed when it closes. */
|
|
51
|
+
add(response) {
|
|
52
|
+
const client = { id: `client-${++counter}`, response };
|
|
53
|
+
clients.set(client.id, client);
|
|
54
|
+
response.once('close', () => remove(client.id));
|
|
55
|
+
if (heartbeat === undefined) {
|
|
56
|
+
heartbeat = setInterval(beat, heartbeatMs);
|
|
57
|
+
heartbeat.unref();
|
|
58
|
+
}
|
|
59
|
+
return client;
|
|
60
|
+
},
|
|
61
|
+
/** End every connection and stop the heartbeat. */
|
|
62
|
+
closeAll() {
|
|
63
|
+
for (const client of clients.values())
|
|
64
|
+
client.response.end();
|
|
65
|
+
clients.clear();
|
|
66
|
+
stopHeartbeat();
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=http-sse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-sse.js","sourceRoot":"","sources":["../src/http-sse.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,+DAA+D;AAC/D,MAAM,CAA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AAC;;gBAC/D,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;IAED,OAAO;QACN,OAAO;QACP,uDAAuD;QACvD,MAAM;YACL,OAAO,OAAO,CAAC,IAAI,IAAI,cAAc,CAAC;QACvC,CAAC;QACD,sFAAsF;QACtF,GAAG,CAAC,QAAwB;YAC3B,MAAM,MAAM,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC;YACvD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YAC/B,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAChD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC7B,SAAS,GAAG,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;gBAC3C,SAAS,CAAC,KAAK,EAAE,CAAC;YACnB,CAAC;YACD,OAAO,MAAM,CAAC;QACf,CAAC;QACD,mDAAmD;QACnD,QAAQ;YACP,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE;gBAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;YAC7D,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,aAAa,EAAE,CAAC;QACjB,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -46,11 +46,12 @@
|
|
|
46
46
|
* @packageDocumentation
|
|
47
47
|
*/
|
|
48
48
|
export type { CommandMiddleware, CreateHandoffOptions, ExposeOptions, HandoffCredentials, HandoffMetadata, HandoffProtocol, HandoffResult, ReconnectPolicy, TelemetryEvent, TelemetrySink, } from '@lushly-dev/afd-core';
|
|
49
|
-
export { createHandoff, createTelemetryEvent, defaultExpose, defaultReconnectPolicy, failure, getHandoffProtocol, isFailure, isHandoff, isHandoffCommand, isHandoffProtocol, isReconnectPolicy, isSuccess, isTelemetryEvent, success, } from '@lushly-dev/afd-core';
|
|
50
|
-
export { type ContextState, createAfdContextEnterCommand, createAfdContextExitCommand, createAfdContextListCommand, createAfdDocsCommand, createAfdHelpCommand, createAfdSchemaCommand, createContextState, getBootstrapCommands, } from './bootstrap/index.js';
|
|
49
|
+
export { createHandoff, createTelemetryEvent, defaultExpose, defaultReconnectPolicy, error, failure, getHandoffProtocol, isFailure, isHandoff, isHandoffCommand, isHandoffProtocol, isReconnectPolicy, isSuccess, isTelemetryEvent, success, } from '@lushly-dev/afd-core';
|
|
50
|
+
export { type ContextState, createAfdContextEnterCommand, createAfdContextExitCommand, createAfdContextListCommand, createAfdDocsCommand, createAfdHelpCommand, createAfdSchemaCommand, createContextState, type DescribedCommand, getBootstrapCommands, } from './bootstrap/index.js';
|
|
51
|
+
export { createDirectRegistry, type DirectCommandRegistry, type DirectRegistryCommand, type DirectRegistryOptions, type ExposeInterface, } from './direct-registry.js';
|
|
51
52
|
export { type HandoffCredentialsInput, type HandoffCredentialsOutput, HandoffCredentialsSchema, type HandoffMetadataInput, type HandoffMetadataOutput, HandoffMetadataSchema, type HandoffResultInput, type HandoffResultOutput, HandoffResultSchema, } from './handoff-schema.js';
|
|
52
53
|
export { ConsoleTelemetrySink, type ConsoleTelemetrySinkOptions, composeMiddleware, createAutoTraceIdMiddleware, createLoggingMiddleware, createRateLimitMiddleware, createRetryMiddleware, createTelemetryMiddleware, createTimingMiddleware, createTracingMiddleware, type DefaultMiddlewareOptions, defaultMiddleware, type LoggingOptions, type RateLimitOptions, type RetryOptions, type Span, type TelemetryOptions, type TimingOptions, type TraceIdOptions, type Tracer, type TracingOptions, } from './middleware.js';
|
|
53
|
-
export { defineCommand, getRequiredFields, isObjectSchema, type ZodCommandDefinition, type ZodCommandOptions, zodToJsonSchema, } from './schema.js';
|
|
54
|
-
export { type ContextConfig, createMcpServer, isStdinPiped, type McpServer, type McpServerOptions, type McpTransport, } from './server.js';
|
|
54
|
+
export { defineCommand, getRequiredFields, isObjectSchema, type ZodCommandDefinition, type ZodCommandOptions, type ZodToJsonSchemaOptions, zodToJsonSchema, } from './schema.js';
|
|
55
|
+
export { type ContextConfig, createMcpHandler, createMcpServer, isStdinPiped, type McpHandler, type McpHandlerOptions, type McpServer, type McpServerOptions, type McpTransport, } from './server.js';
|
|
55
56
|
export { type DateRange, type EnhancedValidationResult, formatEnhancedValidationError, formatValidationErrors, isValid, optional, type Pagination, type PaginationInput, patterns, type SchemaInfo, type Search, type Sorting, type SortingInput, type ValidationError, ValidationException, type ValidationResult, validateInput, validateInputEnhanced, validateOrThrow, withDefault, } from './validation.js';
|
|
56
57
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAKH,YAAY,EACX,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,cAAc,EACd,aAAa,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACtB,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,OAAO,GACP,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,KAAK,YAAY,EACjB,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,wBAAwB,EACxB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,oBAAoB,EACpB,KAAK,2BAA2B,EAChC,iBAAiB,EACjB,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,cAAc,GACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,eAAe,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,aAAa,EAClB,eAAe,EACf,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,YAAY,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,KAAK,SAAS,EACd,KAAK,wBAAwB,EAC7B,6BAA6B,EAC7B,sBAAsB,EACtB,OAAO,EACP,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,WAAW,GACX,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"m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,EACrB,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,cAAc,GACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,eAAe,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,aAAa,EAClB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,YAAY,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,KAAK,SAAS,EACd,KAAK,wBAAwB,EAC7B,6BAA6B,EAC7B,sBAAsB,EACtB,OAAO,EACP,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,WAAW,GACX,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -46,16 +46,18 @@
|
|
|
46
46
|
* @packageDocumentation
|
|
47
47
|
*/
|
|
48
48
|
// Re-export core helpers for convenience
|
|
49
|
-
export { createHandoff, createTelemetryEvent, defaultExpose, defaultReconnectPolicy, failure, getHandoffProtocol, isFailure, isHandoff, isHandoffCommand, isHandoffProtocol, isReconnectPolicy, isSuccess, isTelemetryEvent, success, } from '@lushly-dev/afd-core';
|
|
49
|
+
export { createHandoff, createTelemetryEvent, defaultExpose, defaultReconnectPolicy, error, failure, getHandoffProtocol, isFailure, isHandoff, isHandoffCommand, isHandoffProtocol, isReconnectPolicy, isSuccess, isTelemetryEvent, success, } from '@lushly-dev/afd-core';
|
|
50
50
|
// Bootstrap tools
|
|
51
51
|
export { createAfdContextEnterCommand, createAfdContextExitCommand, createAfdContextListCommand, createAfdDocsCommand, createAfdHelpCommand, createAfdSchemaCommand, createContextState, getBootstrapCommands, } from './bootstrap/index.js';
|
|
52
|
+
// Validating in-process registry for DirectClient
|
|
53
|
+
export { createDirectRegistry, } from './direct-registry.js';
|
|
52
54
|
// Handoff schemas
|
|
53
55
|
export { HandoffCredentialsSchema, HandoffMetadataSchema, HandoffResultSchema, } from './handoff-schema.js';
|
|
54
56
|
// Middleware
|
|
55
57
|
export { ConsoleTelemetrySink, composeMiddleware, createAutoTraceIdMiddleware, createLoggingMiddleware, createRateLimitMiddleware, createRetryMiddleware, createTelemetryMiddleware, createTimingMiddleware, createTracingMiddleware, defaultMiddleware, } from './middleware.js';
|
|
56
58
|
// Schema and command definition
|
|
57
59
|
export { defineCommand, getRequiredFields, isObjectSchema, zodToJsonSchema, } from './schema.js';
|
|
58
|
-
export { createMcpServer, isStdinPiped, } from './server.js';
|
|
60
|
+
export { createMcpHandler, createMcpServer, isStdinPiped, } from './server.js';
|
|
59
61
|
// Validation utilities
|
|
60
62
|
export { formatEnhancedValidationError, formatValidationErrors, isValid, optional, patterns, ValidationException, validateInput, validateInputEnhanced, validateOrThrow, withDefault, } from './validation.js';
|
|
61
63
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAiBH,yCAAyC;AACzC,OAAO,EACN,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACtB,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,OAAO,GACP,MAAM,sBAAsB,CAAC;AAC9B,kBAAkB;AAClB,OAAO,EAEN,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAiBH,yCAAyC;AACzC,OAAO,EACN,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACtB,KAAK,EACL,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,OAAO,GACP,MAAM,sBAAsB,CAAC;AAC9B,kBAAkB;AAClB,OAAO,EAEN,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAElB,oBAAoB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,kDAAkD;AAClD,OAAO,EACN,oBAAoB,GAKpB,MAAM,sBAAsB,CAAC;AAC9B,kBAAkB;AAClB,OAAO,EAGN,wBAAwB,EAGxB,qBAAqB,EAGrB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,aAAa;AACb,OAAO,EACN,oBAAoB,EAEpB,iBAAiB,EACjB,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EAEvB,iBAAiB,GAUjB,MAAM,iBAAiB,CAAC;AACzB,gCAAgC;AAChC,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,cAAc,EAId,eAAe,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAEN,gBAAgB,EAChB,eAAe,EACf,YAAY,GAMZ,MAAM,aAAa,CAAC;AACrB,uBAAuB;AACvB,OAAO,EAGN,6BAA6B,EAC7B,sBAAsB,EACtB,OAAO,EACP,QAAQ,EAGR,QAAQ,EAMR,mBAAmB,EAEnB,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,WAAW,GACX,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview JSON-RPC 2.0 envelopes for the HTTP `/message` and `/rpc` endpoints.
|
|
3
|
+
*/
|
|
4
|
+
/** JSON-RPC 2.0 error codes used by the HTTP transport. */
|
|
5
|
+
export declare const JsonRpcErrorCode: {
|
|
6
|
+
readonly PARSE_ERROR: -32700;
|
|
7
|
+
readonly INVALID_REQUEST: -32600;
|
|
8
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
9
|
+
readonly INVALID_PARAMS: -32602;
|
|
10
|
+
readonly INTERNAL_ERROR: -32603;
|
|
11
|
+
/** Transport-level rejection (Host, Origin, Content-Type, body size). */
|
|
12
|
+
readonly SERVER_ERROR: -32000;
|
|
13
|
+
/** The `Mcp-Session-Id` is unknown or expired. */
|
|
14
|
+
readonly SESSION_NOT_FOUND: -32001;
|
|
15
|
+
};
|
|
16
|
+
export type JsonRpcId = string | number | null;
|
|
17
|
+
/** A validated JSON-RPC request; `notification` is true when it has no `id` member. */
|
|
18
|
+
export interface JsonRpcMessage {
|
|
19
|
+
id: JsonRpcId;
|
|
20
|
+
method: string;
|
|
21
|
+
params: unknown;
|
|
22
|
+
notification: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** A JSON-RPC error to answer a valid request with (HTTP 200). */
|
|
25
|
+
export declare class JsonRpcError extends Error {
|
|
26
|
+
readonly code: number;
|
|
27
|
+
readonly suggestion: string;
|
|
28
|
+
constructor(code: number, message: string, suggestion: string);
|
|
29
|
+
}
|
|
30
|
+
export declare function jsonRpcResult(id: JsonRpcId, result: unknown): {
|
|
31
|
+
jsonrpc: "2.0";
|
|
32
|
+
id: JsonRpcId;
|
|
33
|
+
result: unknown;
|
|
34
|
+
};
|
|
35
|
+
export declare function jsonRpcError(id: JsonRpcId, code: number, message: string, suggestion: string): {
|
|
36
|
+
jsonrpc: "2.0";
|
|
37
|
+
id: JsonRpcId;
|
|
38
|
+
error: {
|
|
39
|
+
code: number;
|
|
40
|
+
message: string;
|
|
41
|
+
data: {
|
|
42
|
+
suggestion: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Validate a parsed body as one JSON-RPC 2.0 request or notification.
|
|
48
|
+
*
|
|
49
|
+
* `jsonrpc` may be omitted for compatibility with the simple `/rpc` format, but any other
|
|
50
|
+
* value than "2.0" is rejected. Batch arrays are not supported (MCP removed JSON-RPC batching).
|
|
51
|
+
*
|
|
52
|
+
* @throws HttpRequestError (HTTP 400, JSON-RPC -32600) when the body is not a valid request
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseJsonRpcMessage(body: unknown): JsonRpcMessage;
|
|
55
|
+
export declare function methodNotFound(method: string): JsonRpcError;
|
|
56
|
+
//# sourceMappingURL=json-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-rpc.d.ts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,2DAA2D;AAC3D,eAAO,MAAM,gBAAgB;;;;;;IAM5B,yEAAyE;;IAEzE,kDAAkD;;CAEzC,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/C,uFAAuF;AACvF,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,SAAS,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;CACtB;AAED,kEAAkE;AAClE,qBAAa,YAAa,SAAQ,KAAK;IAErC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,UAAU,EAAE,MAAM;gBAFlB,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACN,UAAU,EAAE,MAAM;CAI5B;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO;;;;EAE3D;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;;;;;;;;;;EAE5F;AAUD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAoBjE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAM3D"}
|
package/dist/json-rpc.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview JSON-RPC 2.0 envelopes for the HTTP `/message` and `/rpc` endpoints.
|
|
3
|
+
*/
|
|
4
|
+
import { truncateName } from '@lushly-dev/afd-core';
|
|
5
|
+
import { HttpRequestError } from './http-security.js';
|
|
6
|
+
/** JSON-RPC 2.0 error codes used by the HTTP transport. */
|
|
7
|
+
export const JsonRpcErrorCode = {
|
|
8
|
+
PARSE_ERROR: -32700,
|
|
9
|
+
INVALID_REQUEST: -32600,
|
|
10
|
+
METHOD_NOT_FOUND: -32601,
|
|
11
|
+
INVALID_PARAMS: -32602,
|
|
12
|
+
INTERNAL_ERROR: -32603,
|
|
13
|
+
/** Transport-level rejection (Host, Origin, Content-Type, body size). */
|
|
14
|
+
SERVER_ERROR: -32000,
|
|
15
|
+
/** The `Mcp-Session-Id` is unknown or expired. */
|
|
16
|
+
SESSION_NOT_FOUND: -32001,
|
|
17
|
+
};
|
|
18
|
+
/** A JSON-RPC error to answer a valid request with (HTTP 200). */
|
|
19
|
+
export class JsonRpcError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
suggestion;
|
|
22
|
+
constructor(code, message, suggestion) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.suggestion = suggestion;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function jsonRpcResult(id, result) {
|
|
29
|
+
return { jsonrpc: '2.0', id, result };
|
|
30
|
+
}
|
|
31
|
+
export function jsonRpcError(id, code, message, suggestion) {
|
|
32
|
+
return { jsonrpc: '2.0', id, error: { code, message, data: { suggestion } } };
|
|
33
|
+
}
|
|
34
|
+
function invalidRequest(message) {
|
|
35
|
+
return new HttpRequestError(400, message, {
|
|
36
|
+
rpcCode: JsonRpcErrorCode.INVALID_REQUEST,
|
|
37
|
+
suggestion: 'Send one JSON-RPC 2.0 request object: { "jsonrpc": "2.0", "id": 1, "method": "..." }',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate a parsed body as one JSON-RPC 2.0 request or notification.
|
|
42
|
+
*
|
|
43
|
+
* `jsonrpc` may be omitted for compatibility with the simple `/rpc` format, but any other
|
|
44
|
+
* value than "2.0" is rejected. Batch arrays are not supported (MCP removed JSON-RPC batching).
|
|
45
|
+
*
|
|
46
|
+
* @throws HttpRequestError (HTTP 400, JSON-RPC -32600) when the body is not a valid request
|
|
47
|
+
*/
|
|
48
|
+
export function parseJsonRpcMessage(body) {
|
|
49
|
+
if (Array.isArray(body)) {
|
|
50
|
+
throw invalidRequest('JSON-RPC batch arrays are not supported; send one request per HTTP call');
|
|
51
|
+
}
|
|
52
|
+
if (!body || typeof body !== 'object')
|
|
53
|
+
throw invalidRequest('Expected a JSON-RPC request object');
|
|
54
|
+
const request = body;
|
|
55
|
+
if (request.jsonrpc !== undefined && request.jsonrpc !== '2.0') {
|
|
56
|
+
throw invalidRequest('jsonrpc must be "2.0"');
|
|
57
|
+
}
|
|
58
|
+
// Only a message that declares JSON-RPC 2.0 can be a notification. The simple `/rpc` format
|
|
59
|
+
// without a `jsonrpc` member predates this and is always answered (`id: null` if omitted).
|
|
60
|
+
const notification = request.jsonrpc === '2.0' && !('id' in request);
|
|
61
|
+
const id = request.id ?? null;
|
|
62
|
+
if (id !== null && typeof id !== 'string' && typeof id !== 'number') {
|
|
63
|
+
throw invalidRequest('id must be a string, a number or null');
|
|
64
|
+
}
|
|
65
|
+
if (typeof request.method !== 'string' || !request.method) {
|
|
66
|
+
throw invalidRequest('Request method is required');
|
|
67
|
+
}
|
|
68
|
+
return { id, method: request.method, params: request.params, notification };
|
|
69
|
+
}
|
|
70
|
+
export function methodNotFound(method) {
|
|
71
|
+
return new JsonRpcError(JsonRpcErrorCode.METHOD_NOT_FOUND, `Method not found: ${truncateName(method)}`, 'Use initialize, ping, tools/list or tools/call');
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=json-rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-rpc.js","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,WAAW,EAAE,CAAC,KAAK;IACnB,eAAe,EAAE,CAAC,KAAK;IACvB,gBAAgB,EAAE,CAAC,KAAK;IACxB,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;IACtB,yEAAyE;IACzE,YAAY,EAAE,CAAC,KAAK;IACpB,kDAAkD;IAClD,iBAAiB,EAAE,CAAC,KAAK;CAChB,CAAC;AAYX,kEAAkE;AAClE,MAAM,OAAO,YAAa,SAAQ,KAAK;IAE5B;IAEA;IAHV,YACU,IAAY,EACrB,OAAe,EACN,UAAkB;QAE3B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,C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I,IAAI,CAAC;IAC9B,IAAI,EAAE,KAAK,IAAI,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;QACrE,MAAM,cAAc,CAAC,uCAAuC,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAC3D,MAAM,cAAc,CAAC,4BAA4B,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAc;IAC5C,OAAO,IAAI,YAAY,CACtB,gBAAgB,CAAC,gBAAgB,EACjC,qBAAqB,YAAY,CAAC,MAAM,CAAC,EAAE,EAC3C,gDAAgD,CAChD,CAAC;AACH,CAAC"}
|
package/dist/lazy-tools.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @fileoverview Lazy-loading discovery tools: afd-discover, afd-detail.
|
|
3
3
|
*/
|
|
4
4
|
import type { CommandResult, JsonSchema } from '@lushly-dev/afd-core';
|
|
5
|
+
import type { DetailInput, DiscoverInput } from './meta-tools.js';
|
|
5
6
|
import type { ZodCommandDefinition } from './schema.js';
|
|
6
7
|
interface CommandSummary {
|
|
7
8
|
name: string;
|
|
@@ -18,18 +19,6 @@ interface DiscoverResult {
|
|
|
18
19
|
availableCategories: string[];
|
|
19
20
|
availableTags: string[];
|
|
20
21
|
}
|
|
21
|
-
export interface DiscoverInput {
|
|
22
|
-
category?: string;
|
|
23
|
-
tag?: string | string[];
|
|
24
|
-
tagMode?: 'all' | 'any';
|
|
25
|
-
search?: string;
|
|
26
|
-
includeMutation?: boolean;
|
|
27
|
-
limit?: number;
|
|
28
|
-
offset?: number;
|
|
29
|
-
}
|
|
30
|
-
export interface DetailInput {
|
|
31
|
-
command: string | string[];
|
|
32
|
-
}
|
|
33
22
|
interface DetailResult {
|
|
34
23
|
name: string;
|
|
35
24
|
found: true;
|
|
@@ -49,6 +38,7 @@ interface DetailResult {
|
|
|
49
38
|
callable: boolean;
|
|
50
39
|
}
|
|
51
40
|
interface DetailError {
|
|
41
|
+
/** The requested name, cut to 128 characters plus `…` when longer. */
|
|
52
42
|
name: string;
|
|
53
43
|
found: false;
|
|
54
44
|
error: {
|
package/dist/lazy-tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-tools.d.ts","sourceRoot":"","sources":["../src/lazy-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"lazy-tools.d.ts","sourceRoot":"","sources":["../src/lazy-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGtE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAMxD,UAAU,cAAc;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,cAAc;IACvB,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,aAAa,EAAE,MAAM,EAAE,CA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