@embassys/ambassador 0.0.0 → 0.2.7
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/LICENSE +21 -0
- package/README.md +69 -2
- package/dist/agent-capabilities.d.ts +35 -0
- package/dist/agent-capabilities.js +221 -0
- package/dist/agent-capabilities.js.map +1 -0
- package/dist/ambassador-options.d.ts +6 -0
- package/dist/ambassador-options.js +13 -0
- package/dist/ambassador-options.js.map +1 -0
- package/dist/central-credential.d.ts +41 -0
- package/dist/central-credential.js +355 -0
- package/dist/central-credential.js.map +1 -0
- package/dist/central-enrollment.d.ts +31 -0
- package/dist/central-enrollment.js +278 -0
- package/dist/central-enrollment.js.map +1 -0
- package/dist/central-json.d.ts +8 -0
- package/dist/central-json.js +259 -0
- package/dist/central-json.js.map +1 -0
- package/dist/central-protected-transport.d.ts +21 -0
- package/dist/central-protected-transport.js +217 -0
- package/dist/central-protected-transport.js.map +1 -0
- package/dist/central-rest.d.ts +50 -0
- package/dist/central-rest.js +401 -0
- package/dist/central-rest.js.map +1 -0
- package/dist/cli.d.ts +26 -0
- package/dist/cli.js +129 -0
- package/dist/cli.js.map +1 -0
- package/dist/credential-store.d.ts +18 -0
- package/dist/credential-store.js +617 -0
- package/dist/credential-store.js.map +1 -0
- package/dist/delivery-profile.d.ts +43 -0
- package/dist/delivery-profile.js +253 -0
- package/dist/delivery-profile.js.map +1 -0
- package/dist/direct-delivery.d.ts +37 -0
- package/dist/direct-delivery.js +312 -0
- package/dist/direct-delivery.js.map +1 -0
- package/dist/dpop.d.ts +28 -0
- package/dist/dpop.js +119 -0
- package/dist/dpop.js.map +1 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -0
- package/dist/gateway-application.d.ts +32 -0
- package/dist/gateway-application.js +255 -0
- package/dist/gateway-application.js.map +1 -0
- package/dist/gateway-paths.d.ts +11 -0
- package/dist/gateway-paths.js +29 -0
- package/dist/gateway-paths.js.map +1 -0
- package/dist/guided-registration.d.ts +23 -0
- package/dist/guided-registration.js +117 -0
- package/dist/guided-registration.js.map +1 -0
- package/dist/identity.d.ts +20 -0
- package/dist/identity.js +54 -0
- package/dist/identity.js.map +1 -0
- package/dist/local-mcp.d.ts +28 -0
- package/dist/local-mcp.js +410 -0
- package/dist/local-mcp.js.map +1 -0
- package/dist/local-tool-result.d.ts +4 -0
- package/dist/local-tool-result.js +17 -0
- package/dist/local-tool-result.js.map +1 -0
- package/dist/mcp-contract.d.ts +10 -0
- package/dist/mcp-contract.js +63 -0
- package/dist/mcp-contract.js.map +1 -0
- package/dist/notification-journal.d.ts +24 -0
- package/dist/notification-journal.js +194 -0
- package/dist/notification-journal.js.map +1 -0
- package/dist/notification-relay.d.ts +31 -0
- package/dist/notification-relay.js +203 -0
- package/dist/notification-relay.js.map +1 -0
- package/dist/process-lock.d.ts +8 -0
- package/dist/process-lock.js +122 -0
- package/dist/process-lock.js.map +1 -0
- package/dist/sqlite-artifact.d.ts +7 -0
- package/dist/sqlite-artifact.js +121 -0
- package/dist/sqlite-artifact.js.map +1 -0
- package/dist/webhook-delivery.d.ts +23 -0
- package/dist/webhook-delivery.js +122 -0
- package/dist/webhook-delivery.js.map +1 -0
- package/docs/getting-started-claude.md +33 -0
- package/docs/getting-started-codex.md +36 -0
- package/docs/getting-started-gemini.md +31 -0
- package/docs/getting-started-hermes.md +47 -0
- package/docs/getting-started-openclaw.md +48 -0
- package/docs/live-qualification.md +174 -0
- package/package.json +48 -7
- package/index.js +0 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { PRODUCTION_AGENT_CAPABILITIES, resolveAgentCapability, } from "./agent-capabilities.js";
|
|
2
|
+
import { createDeliveryProfile, } from "./delivery-profile.js";
|
|
3
|
+
export class GuidedRegistrationError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code) {
|
|
6
|
+
super("Guided registration failed");
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.name = "GuidedRegistrationError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/u;
|
|
12
|
+
function invalid() {
|
|
13
|
+
return new GuidedRegistrationError("invalid_arguments");
|
|
14
|
+
}
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
function exactKeys(value, required, optional = []) {
|
|
19
|
+
const allowed = new Set([...required, ...optional]);
|
|
20
|
+
return (required.every((key) => Object.hasOwn(value, key)) &&
|
|
21
|
+
Object.keys(value).every((key) => allowed.has(key)));
|
|
22
|
+
}
|
|
23
|
+
function centralArguments(value) {
|
|
24
|
+
if (typeof value.email !== "string" || value.email.length > 254 || !EMAIL.test(value.email)) {
|
|
25
|
+
throw invalid();
|
|
26
|
+
}
|
|
27
|
+
if (value.display_name !== undefined &&
|
|
28
|
+
(typeof value.display_name !== "string" ||
|
|
29
|
+
value.display_name.length < 1 ||
|
|
30
|
+
value.display_name.length > 128)) {
|
|
31
|
+
throw invalid();
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
email: value.email,
|
|
35
|
+
...(value.display_name === undefined ? {} : { display_name: value.display_name }),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function deliveryInput(value) {
|
|
39
|
+
if (!isRecord(value) || typeof value.mode !== "string")
|
|
40
|
+
throw invalid();
|
|
41
|
+
if (value.mode === "direct" && exactKeys(value, ["mode"]))
|
|
42
|
+
return { mode: "direct" };
|
|
43
|
+
if (value.mode === "webhook" &&
|
|
44
|
+
exactKeys(value, ["mode", "url", "secret_env"]) &&
|
|
45
|
+
typeof value.url === "string" &&
|
|
46
|
+
typeof value.secret_env === "string") {
|
|
47
|
+
return { mode: "webhook", url: value.url, secret_env: value.secret_env };
|
|
48
|
+
}
|
|
49
|
+
throw invalid();
|
|
50
|
+
}
|
|
51
|
+
export class GuidedRegistration {
|
|
52
|
+
#registry;
|
|
53
|
+
#profileStore;
|
|
54
|
+
#workingDirectory;
|
|
55
|
+
#environment;
|
|
56
|
+
#registerCentral;
|
|
57
|
+
constructor(options) {
|
|
58
|
+
this.#registry = options.registry ?? PRODUCTION_AGENT_CAPABILITIES;
|
|
59
|
+
this.#profileStore = options.profileStore;
|
|
60
|
+
this.#workingDirectory = options.workingDirectory;
|
|
61
|
+
this.#environment = options.environment;
|
|
62
|
+
this.#registerCentral = options.registerCentral;
|
|
63
|
+
}
|
|
64
|
+
async register(untrustedArguments, clientInfo, signal) {
|
|
65
|
+
const resolution = resolveAgentCapability(clientInfo, this.#registry);
|
|
66
|
+
if (resolution.status === "unsupported") {
|
|
67
|
+
return {
|
|
68
|
+
status: "unsupported_agent",
|
|
69
|
+
message: "This MCP client is not supported by this Ambassador version.",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (!isRecord(untrustedArguments) ||
|
|
73
|
+
!exactKeys(untrustedArguments, ["email"], ["display_name", "delivery"])) {
|
|
74
|
+
throw invalid();
|
|
75
|
+
}
|
|
76
|
+
const registration = centralArguments(untrustedArguments);
|
|
77
|
+
const capability = resolution.profile;
|
|
78
|
+
const suppliedDelivery = untrustedArguments.delivery === undefined
|
|
79
|
+
? undefined
|
|
80
|
+
: deliveryInput(untrustedArguments.delivery);
|
|
81
|
+
let delivery;
|
|
82
|
+
if (suppliedDelivery === undefined) {
|
|
83
|
+
if (capability.modes.length !== 1 || capability.modes[0] !== "direct") {
|
|
84
|
+
return {
|
|
85
|
+
status: "input_required",
|
|
86
|
+
prompt: "How should incoming requests reach this agent?",
|
|
87
|
+
required: ["delivery"],
|
|
88
|
+
default: "direct",
|
|
89
|
+
choices: [
|
|
90
|
+
{
|
|
91
|
+
value: "direct",
|
|
92
|
+
label: `Send directly to this ${capability.displayName} agent`,
|
|
93
|
+
},
|
|
94
|
+
{ value: "webhook", label: "Send to a webhook" },
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
delivery = { mode: "direct" };
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
delivery = suppliedDelivery;
|
|
102
|
+
}
|
|
103
|
+
if (!capability.modes.includes(delivery.mode))
|
|
104
|
+
throw invalid();
|
|
105
|
+
try {
|
|
106
|
+
const profile = await createDeliveryProfile(capability, delivery, this.#workingDirectory, this.#environment);
|
|
107
|
+
await this.#profileStore.save(profile);
|
|
108
|
+
return await this.#registerCentral(registration, signal);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (error instanceof GuidedRegistrationError)
|
|
112
|
+
throw error;
|
|
113
|
+
throw new GuidedRegistrationError("registration_failed");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=guided-registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guided-registration.js","sourceRoot":"","sources":["../src/guided-registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,qBAAqB,GAGtB,MAAM,uBAAuB,CAAC;AAI/B,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAC3B,IAAI;IAAzB,YAAqB,IAAiC;QACpD,KAAK,CAAC,4BAA4B,CAAC,CAAC;oBADjB,IAAI;QAEvB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAkBD,MAAM,KAAK,GAAG,6BAA6B,CAAC;AAE5C,SAAS,OAAO;IACd,OAAO,IAAI,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,SAAS,CAChB,KAA8B,EAC9B,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C,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,MAAM,OAAO,EAAE,CAAC;QAC/D,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,qBAAqB,CACzC,UAAU,EACV,QAAQ,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,YAAY,CAClB,CAAC;YACF,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvC,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,uBAAuB;gBAAE,MAAM,KAAK,CAAC;YAC1D,MAAM,IAAI,uBAAuB,CAAC,qBAAqB,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type CentralCredentialRecord, type LoadedCentralCredential } from "./central-credential.js";
|
|
2
|
+
import type { CredentialStore } from "./credential-store.js";
|
|
3
|
+
export type { CredentialStore } from "./credential-store.js";
|
|
4
|
+
export declare class IdentityError extends Error {
|
|
5
|
+
readonly code: "already_enrolled" | "not_enrolled" | "verification_busy";
|
|
6
|
+
constructor(code: "already_enrolled" | "not_enrolled" | "verification_busy");
|
|
7
|
+
}
|
|
8
|
+
export declare class GatewayIdentity {
|
|
9
|
+
#private;
|
|
10
|
+
private readonly store;
|
|
11
|
+
private readonly nowSeconds;
|
|
12
|
+
private constructor();
|
|
13
|
+
static open(store: CredentialStore, nowSeconds?: () => number): Promise<GatewayIdentity>;
|
|
14
|
+
get enrolled(): boolean;
|
|
15
|
+
credential(): LoadedCentralCredential;
|
|
16
|
+
enroll<T>(operation: () => Promise<{
|
|
17
|
+
readonly credential: CentralCredentialRecord;
|
|
18
|
+
readonly localResult: T;
|
|
19
|
+
}>): Promise<T>;
|
|
20
|
+
}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { parseCentralCredential, serializeCentralCredential, } from "./central-credential.js";
|
|
2
|
+
export class IdentityError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code) {
|
|
5
|
+
super(code);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = "IdentityError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class GatewayIdentity {
|
|
11
|
+
store;
|
|
12
|
+
nowSeconds;
|
|
13
|
+
#credential;
|
|
14
|
+
#commitBusy = false;
|
|
15
|
+
constructor(store, nowSeconds, credential) {
|
|
16
|
+
this.store = store;
|
|
17
|
+
this.nowSeconds = nowSeconds;
|
|
18
|
+
this.#credential = credential;
|
|
19
|
+
}
|
|
20
|
+
static async open(store, nowSeconds = () => Date.now() / 1_000) {
|
|
21
|
+
const stored = await store.load();
|
|
22
|
+
return new GatewayIdentity(store, nowSeconds, stored === undefined ? undefined : parseCentralCredential(stored, nowSeconds));
|
|
23
|
+
}
|
|
24
|
+
get enrolled() {
|
|
25
|
+
return this.#credential !== undefined;
|
|
26
|
+
}
|
|
27
|
+
credential() {
|
|
28
|
+
if (this.#credential === undefined)
|
|
29
|
+
throw new IdentityError("not_enrolled");
|
|
30
|
+
if (this.#credential.token.expiresAt <= Math.floor(this.nowSeconds())) {
|
|
31
|
+
throw new IdentityError("not_enrolled");
|
|
32
|
+
}
|
|
33
|
+
return this.#credential;
|
|
34
|
+
}
|
|
35
|
+
async enroll(operation) {
|
|
36
|
+
if (this.#credential !== undefined)
|
|
37
|
+
throw new IdentityError("already_enrolled");
|
|
38
|
+
if (this.#commitBusy)
|
|
39
|
+
throw new IdentityError("verification_busy");
|
|
40
|
+
this.#commitBusy = true;
|
|
41
|
+
try {
|
|
42
|
+
const result = await operation();
|
|
43
|
+
const serialized = serializeCentralCredential(result.credential);
|
|
44
|
+
const loaded = parseCentralCredential(serialized, this.nowSeconds);
|
|
45
|
+
await this.store.save(serialized);
|
|
46
|
+
this.#credential = loaded;
|
|
47
|
+
return result.localResult;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
this.#commitBusy = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,yBAAyB,CAAC;AAKjC,MAAM,OAAO,aAAc,SAAQ,KAAK;IACjB,IAAI;IAAzB,YAAqB,IAA+D;QAClF,KAAK,CAAC,IAAI,CAAC,CAAC;oBADO,IAAI;QAEvB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,eAAe;IAKP,KAAK;IACL,UAAU;IAL7B,WAAW,CAAsC;IACjD,WAAW,GAAG,KAAK,CAAC;IAEpB,YACmB,KAAsB,EACtB,UAAwB,EACzC,UAAoC;qBAFnB,KAAK;0BACL,UAAU;QAG3B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,KAAsB,EACtB,UAAU,GAAiB,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;QAEnD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QAClC,OAAO,IAAI,eAAe,CACxB,KAAK,EACL,UAAU,EACV,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,sBAAsB,CAAC,MAAM,EAAE,UAAU,CAAC,CAC9E,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC;IACxC,CAAC;IAED,UAAU;QACR,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS;YAAE,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,CAAC;QAC5E,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,MAAM,CACV,SAGE;QAEF,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS;YAAE,MAAM,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAAC;QAChF,IAAI,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,aAAa,CAAC,mBAAmB,CAAC,CAAC;QACnE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;YACjC,MAAM,UAAU,GAAG,0BAA0B,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACjE,MAAM,MAAM,GAAG,sBAAsB,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACnE,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAClC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;YAC1B,OAAO,MAAM,CAAC,WAAW,CAAC;QAC5B,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC3B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CentralToolDefinition } from "./mcp-contract.js";
|
|
2
|
+
export interface LocalMcpRouter {
|
|
3
|
+
listTools(): Promise<CentralToolDefinition[]>;
|
|
4
|
+
callTool(name: string, arguments_: Record<string, unknown>, signal: AbortSignal, clientInfo: LocalMcpClientInfo | undefined): Promise<Record<string, unknown>>;
|
|
5
|
+
}
|
|
6
|
+
export interface LocalMcpClientInfo {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly version: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class LocalMcpToolError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly retryAfterMs?: number | null | undefined;
|
|
13
|
+
constructor(code: string, retryAfterMs?: number | null | undefined);
|
|
14
|
+
get data(): Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface LocalMcpServerOptions {
|
|
17
|
+
port?: number;
|
|
18
|
+
requestTimeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class LocalMcpServer {
|
|
21
|
+
#private;
|
|
22
|
+
private readonly router;
|
|
23
|
+
constructor(router: LocalMcpRouter, options?: LocalMcpServerOptions);
|
|
24
|
+
get endpoint(): string;
|
|
25
|
+
listen(): Promise<void>;
|
|
26
|
+
sendToolListChanged(): Promise<void>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { once } from "node:events";
|
|
3
|
+
import { createServer as createHttpServer, } from "node:http";
|
|
4
|
+
import { toWebRequest } from "@modelcontextprotocol/node";
|
|
5
|
+
import { ProtocolError, Server, WebStandardStreamableHTTPServerTransport, } from "@modelcontextprotocol/server";
|
|
6
|
+
import { serializeLocalToolResult } from "./local-tool-result.js";
|
|
7
|
+
const MAX_REQUEST_BYTES = 1024 * 1024;
|
|
8
|
+
const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
9
|
+
const MAX_HEADERS_BYTES = 16 * 1024;
|
|
10
|
+
const MAX_SESSIONS = 32;
|
|
11
|
+
const MAX_CONCURRENT_TOOL_CALLS = 8;
|
|
12
|
+
const LOCAL_REQUEST_TIMEOUT_MS = 35_000;
|
|
13
|
+
const PROTOCOL_VERSION = "2025-06-18";
|
|
14
|
+
export class LocalMcpToolError extends Error {
|
|
15
|
+
code;
|
|
16
|
+
retryAfterMs;
|
|
17
|
+
constructor(code, retryAfterMs) {
|
|
18
|
+
super("Tool call failed");
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.retryAfterMs = retryAfterMs;
|
|
21
|
+
this.name = "LocalMcpToolError";
|
|
22
|
+
}
|
|
23
|
+
get data() {
|
|
24
|
+
return {
|
|
25
|
+
code: this.code,
|
|
26
|
+
...(this.retryAfterMs === undefined ? {} : { retry_after_ms: this.retryAfterMs }),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class RequestBodyTooLarge extends Error {
|
|
31
|
+
}
|
|
32
|
+
class ResponseBodyTooLarge extends Error {
|
|
33
|
+
}
|
|
34
|
+
function safeHttpError(response, status) {
|
|
35
|
+
if (!response.headersSent) {
|
|
36
|
+
response.writeHead(status, {
|
|
37
|
+
"cache-control": "no-store",
|
|
38
|
+
"content-type": "text/plain; charset=utf-8",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
response.end("Request rejected\n");
|
|
42
|
+
}
|
|
43
|
+
function readJsonBody(request) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const chunks = [];
|
|
46
|
+
let size = 0;
|
|
47
|
+
let settled = false;
|
|
48
|
+
request.on("data", (chunk) => {
|
|
49
|
+
if (settled)
|
|
50
|
+
return;
|
|
51
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
52
|
+
size += bytes.byteLength;
|
|
53
|
+
if (size > MAX_REQUEST_BYTES) {
|
|
54
|
+
settled = true;
|
|
55
|
+
request.pause();
|
|
56
|
+
reject(new RequestBodyTooLarge());
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
chunks.push(bytes);
|
|
60
|
+
});
|
|
61
|
+
request.once("end", () => {
|
|
62
|
+
if (settled)
|
|
63
|
+
return;
|
|
64
|
+
settled = true;
|
|
65
|
+
try {
|
|
66
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
reject(new Error("Invalid request body"));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
request.once("aborted", () => {
|
|
73
|
+
if (settled)
|
|
74
|
+
return;
|
|
75
|
+
settled = true;
|
|
76
|
+
reject(new Error("Request aborted"));
|
|
77
|
+
});
|
|
78
|
+
request.once("error", () => {
|
|
79
|
+
if (settled)
|
|
80
|
+
return;
|
|
81
|
+
settled = true;
|
|
82
|
+
reject(new Error("Request failed"));
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function isObject(value) {
|
|
87
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
88
|
+
}
|
|
89
|
+
function isInitializeRequest(value) {
|
|
90
|
+
return isObject(value) && value.method === "initialize";
|
|
91
|
+
}
|
|
92
|
+
function sessionId(request) {
|
|
93
|
+
const value = request.headers["mcp-session-id"];
|
|
94
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
95
|
+
}
|
|
96
|
+
function responseHeaders(response) {
|
|
97
|
+
return Object.fromEntries(response.headers.entries());
|
|
98
|
+
}
|
|
99
|
+
async function readBoundedResponse(response) {
|
|
100
|
+
const declared = response.headers.get("content-length");
|
|
101
|
+
if (declared !== null && /^\d+$/u.test(declared) && Number(declared) > MAX_RESPONSE_BYTES) {
|
|
102
|
+
await response.body?.cancel().catch(() => undefined);
|
|
103
|
+
throw new ResponseBodyTooLarge();
|
|
104
|
+
}
|
|
105
|
+
if (response.body === null)
|
|
106
|
+
return new Uint8Array();
|
|
107
|
+
const reader = response.body.getReader();
|
|
108
|
+
const chunks = [];
|
|
109
|
+
let total = 0;
|
|
110
|
+
try {
|
|
111
|
+
while (true) {
|
|
112
|
+
const item = await reader.read();
|
|
113
|
+
if (item.done)
|
|
114
|
+
break;
|
|
115
|
+
total += item.value.byteLength;
|
|
116
|
+
if (total > MAX_RESPONSE_BYTES) {
|
|
117
|
+
await reader.cancel().catch(() => undefined);
|
|
118
|
+
throw new ResponseBodyTooLarge();
|
|
119
|
+
}
|
|
120
|
+
chunks.push(item.value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error instanceof ResponseBodyTooLarge)
|
|
125
|
+
throw error;
|
|
126
|
+
throw new Error("MCP response failed");
|
|
127
|
+
}
|
|
128
|
+
const bytes = new Uint8Array(total);
|
|
129
|
+
let offset = 0;
|
|
130
|
+
for (const chunk of chunks) {
|
|
131
|
+
bytes.set(chunk, offset);
|
|
132
|
+
offset += chunk.byteLength;
|
|
133
|
+
}
|
|
134
|
+
return bytes;
|
|
135
|
+
}
|
|
136
|
+
async function writeWebResponse(request, response, webResponse) {
|
|
137
|
+
if (request.method !== "GET") {
|
|
138
|
+
const bytes = await readBoundedResponse(webResponse);
|
|
139
|
+
response.writeHead(webResponse.status, responseHeaders(webResponse));
|
|
140
|
+
response.end(bytes);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
response.writeHead(webResponse.status, responseHeaders(webResponse));
|
|
144
|
+
if (webResponse.body === null) {
|
|
145
|
+
response.end();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const reader = webResponse.body.getReader();
|
|
149
|
+
let total = 0;
|
|
150
|
+
const cancel = () => {
|
|
151
|
+
void reader.cancel().catch(() => undefined);
|
|
152
|
+
};
|
|
153
|
+
response.once("close", cancel);
|
|
154
|
+
try {
|
|
155
|
+
while (!response.destroyed) {
|
|
156
|
+
const item = await reader.read();
|
|
157
|
+
if (item.done)
|
|
158
|
+
break;
|
|
159
|
+
total += item.value.byteLength;
|
|
160
|
+
if (total > MAX_RESPONSE_BYTES) {
|
|
161
|
+
await reader.cancel().catch(() => undefined);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
if (!response.write(item.value))
|
|
165
|
+
await once(response, "drain");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
response.off("close", cancel);
|
|
170
|
+
if (!response.destroyed)
|
|
171
|
+
response.end();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export class LocalMcpServer {
|
|
175
|
+
router;
|
|
176
|
+
#http;
|
|
177
|
+
#requestTimeoutMs;
|
|
178
|
+
#port;
|
|
179
|
+
#sessions = new Map();
|
|
180
|
+
#sessionRecords = new Set();
|
|
181
|
+
#activeToolCalls = 0;
|
|
182
|
+
#accepting = false;
|
|
183
|
+
#endpoint;
|
|
184
|
+
constructor(router, options = {}) {
|
|
185
|
+
this.router = router;
|
|
186
|
+
this.#port = options.port ?? 8787;
|
|
187
|
+
this.#requestTimeoutMs = options.requestTimeoutMs ?? LOCAL_REQUEST_TIMEOUT_MS;
|
|
188
|
+
if (!Number.isInteger(this.#port) || this.#port < 0 || this.#port > 65_535) {
|
|
189
|
+
throw new Error("Invalid MCP listener port");
|
|
190
|
+
}
|
|
191
|
+
if (!Number.isFinite(this.#requestTimeoutMs) || this.#requestTimeoutMs <= 0) {
|
|
192
|
+
throw new Error("Invalid MCP request timeout");
|
|
193
|
+
}
|
|
194
|
+
this.#http = createHttpServer({ maxHeaderSize: MAX_HEADERS_BYTES, requestTimeout: this.#requestTimeoutMs }, (request, response) => {
|
|
195
|
+
void this.#handleRequest(request, response);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
get endpoint() {
|
|
199
|
+
if (this.#endpoint === undefined)
|
|
200
|
+
throw new Error("MCP listener is not bound");
|
|
201
|
+
return this.#endpoint;
|
|
202
|
+
}
|
|
203
|
+
async listen() {
|
|
204
|
+
if (this.#accepting || this.#endpoint !== undefined) {
|
|
205
|
+
throw new Error("MCP listener is already bound");
|
|
206
|
+
}
|
|
207
|
+
await new Promise((resolve, reject) => {
|
|
208
|
+
const onError = () => reject(new Error("MCP listener failed to bind"));
|
|
209
|
+
this.#http.once("error", onError);
|
|
210
|
+
this.#http.listen(this.#port, "127.0.0.1", () => {
|
|
211
|
+
this.#http.off("error", onError);
|
|
212
|
+
resolve();
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
const address = this.#http.address();
|
|
216
|
+
this.#endpoint = `http://127.0.0.1:${address.port}/mcp`;
|
|
217
|
+
this.#accepting = true;
|
|
218
|
+
}
|
|
219
|
+
async sendToolListChanged() {
|
|
220
|
+
await Promise.all([...this.#sessionRecords].map((record) => record.sdk.sendToolListChanged()));
|
|
221
|
+
}
|
|
222
|
+
async close() {
|
|
223
|
+
this.#accepting = false;
|
|
224
|
+
const closed = new Promise((resolve) => {
|
|
225
|
+
if (!this.#http.listening) {
|
|
226
|
+
resolve();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.#http.close(() => resolve());
|
|
230
|
+
});
|
|
231
|
+
await Promise.all([...this.#sessionRecords].map((record) => this.#closeSession(record)));
|
|
232
|
+
this.#http.closeAllConnections();
|
|
233
|
+
await closed;
|
|
234
|
+
}
|
|
235
|
+
#createSdk() {
|
|
236
|
+
const sdk = new Server({ name: "ambassador", version: "1" }, {
|
|
237
|
+
capabilities: { tools: { listChanged: true } },
|
|
238
|
+
supportedProtocolVersions: [PROTOCOL_VERSION],
|
|
239
|
+
debouncedNotificationMethods: ["notifications/tools/list_changed"],
|
|
240
|
+
});
|
|
241
|
+
sdk.onerror = () => undefined;
|
|
242
|
+
sdk.setRequestHandler("tools/list", async () => {
|
|
243
|
+
const tools = await this.router.listTools();
|
|
244
|
+
return { tools: tools };
|
|
245
|
+
});
|
|
246
|
+
sdk.setRequestHandler("tools/call", async (request, context) => {
|
|
247
|
+
if (this.#activeToolCalls >= MAX_CONCURRENT_TOOL_CALLS) {
|
|
248
|
+
throw new Error("Tool call capacity reached");
|
|
249
|
+
}
|
|
250
|
+
const arguments_ = request.params.arguments;
|
|
251
|
+
if (arguments_ !== undefined && !isObject(arguments_)) {
|
|
252
|
+
throw new Error("Invalid tool arguments");
|
|
253
|
+
}
|
|
254
|
+
this.#activeToolCalls += 1;
|
|
255
|
+
try {
|
|
256
|
+
const signal = AbortSignal.any([
|
|
257
|
+
context.mcpReq.signal,
|
|
258
|
+
AbortSignal.timeout(this.#requestTimeoutMs),
|
|
259
|
+
]);
|
|
260
|
+
const version = sdk.getClientVersion();
|
|
261
|
+
const clientInfo = version !== undefined &&
|
|
262
|
+
typeof version.name === "string" &&
|
|
263
|
+
typeof version.version === "string"
|
|
264
|
+
? { name: version.name, version: version.version }
|
|
265
|
+
: undefined;
|
|
266
|
+
const result = await this.router.callTool(request.params.name, arguments_ ?? {}, signal, clientInfo);
|
|
267
|
+
const serialized = serializeLocalToolResult(result);
|
|
268
|
+
return sdk.projectCallToolResult({
|
|
269
|
+
content: [{ type: "text", text: serialized }],
|
|
270
|
+
structuredContent: result,
|
|
271
|
+
}, undefined);
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
if (error instanceof LocalMcpToolError) {
|
|
275
|
+
throw new ProtocolError(-32_002, "Tool call failed", error.data);
|
|
276
|
+
}
|
|
277
|
+
throw new Error("Tool call failed");
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
this.#activeToolCalls -= 1;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
return sdk;
|
|
284
|
+
}
|
|
285
|
+
async #createSession() {
|
|
286
|
+
if (this.#sessionRecords.size >= MAX_SESSIONS) {
|
|
287
|
+
throw new Error("MCP session capacity reached");
|
|
288
|
+
}
|
|
289
|
+
const sdk = this.#createSdk();
|
|
290
|
+
let record;
|
|
291
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
292
|
+
sessionIdGenerator: randomUUID,
|
|
293
|
+
keepAliveMs: 15_000,
|
|
294
|
+
onsessioninitialized: (id) => {
|
|
295
|
+
if (this.#sessions.has(id))
|
|
296
|
+
throw new Error("Duplicate MCP session");
|
|
297
|
+
record.id = id;
|
|
298
|
+
this.#sessions.set(id, record);
|
|
299
|
+
},
|
|
300
|
+
onsessionclosed: (id) => {
|
|
301
|
+
this.#sessions.delete(id);
|
|
302
|
+
void this.#closeSession(record);
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
record = { sdk, transport, closing: false };
|
|
306
|
+
this.#sessionRecords.add(record);
|
|
307
|
+
try {
|
|
308
|
+
await sdk.connect(transport);
|
|
309
|
+
return record;
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
this.#sessionRecords.delete(record);
|
|
313
|
+
await sdk.close().catch(() => undefined);
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async #closeSession(record) {
|
|
318
|
+
if (record.closing)
|
|
319
|
+
return;
|
|
320
|
+
record.closing = true;
|
|
321
|
+
if (record.id !== undefined)
|
|
322
|
+
this.#sessions.delete(record.id);
|
|
323
|
+
this.#sessionRecords.delete(record);
|
|
324
|
+
await record.sdk.close().catch(() => undefined);
|
|
325
|
+
}
|
|
326
|
+
async #handleRequest(request, response) {
|
|
327
|
+
if (!this.#accepting) {
|
|
328
|
+
safeHttpError(response, 503);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (request.url !== "/mcp") {
|
|
332
|
+
safeHttpError(response, 404);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const address = this.#http.address();
|
|
336
|
+
if (request.headers.host !== `127.0.0.1:${address.port}`) {
|
|
337
|
+
safeHttpError(response, 421);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const origin = request.headers.origin;
|
|
341
|
+
if (origin !== undefined && origin !== `http://127.0.0.1:${address.port}`) {
|
|
342
|
+
safeHttpError(response, 403);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (request.headers.authorization !== undefined) {
|
|
346
|
+
safeHttpError(response, 400);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const controller = new AbortController();
|
|
350
|
+
const timeout = setTimeout(() => controller.abort(), this.#requestTimeoutMs);
|
|
351
|
+
const onResponseClose = () => {
|
|
352
|
+
if (!response.writableEnded)
|
|
353
|
+
controller.abort();
|
|
354
|
+
};
|
|
355
|
+
response.once("close", onResponseClose);
|
|
356
|
+
let record;
|
|
357
|
+
let transientSession = false;
|
|
358
|
+
try {
|
|
359
|
+
const parsedBody = request.method === "POST" ? await readJsonBody(request) : undefined;
|
|
360
|
+
if (Array.isArray(parsedBody)) {
|
|
361
|
+
safeHttpError(response, 400);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const id = sessionId(request);
|
|
365
|
+
if (id === undefined) {
|
|
366
|
+
if (request.method !== "POST" || !isInitializeRequest(parsedBody)) {
|
|
367
|
+
safeHttpError(response, 400);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
try {
|
|
371
|
+
record = await this.#createSession();
|
|
372
|
+
transientSession = true;
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
safeHttpError(response, 503);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
record = this.#sessions.get(id);
|
|
381
|
+
if (record === undefined) {
|
|
382
|
+
safeHttpError(response, 404);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const webRequest = await toWebRequest(request, parsedBody, { signal: controller.signal });
|
|
387
|
+
const webResponse = await record.transport.handleRequest(webRequest, { parsedBody });
|
|
388
|
+
await writeWebResponse(request, response, webResponse);
|
|
389
|
+
if (transientSession && record.id === undefined)
|
|
390
|
+
await this.#closeSession(record);
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
if (transientSession && record !== undefined && record.id === undefined) {
|
|
394
|
+
await this.#closeSession(record);
|
|
395
|
+
}
|
|
396
|
+
if (error instanceof RequestBodyTooLarge) {
|
|
397
|
+
request.resume();
|
|
398
|
+
safeHttpError(response, 413);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (!response.headersSent)
|
|
402
|
+
safeHttpError(response, 400);
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
clearTimeout(timeout);
|
|
406
|
+
response.off("close", onResponseClose);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
//# sourceMappingURL=local-mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-mcp.js","sourceRoot":"","sources":["../src/local-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EACL,YAAY,IAAI,gBAAgB,GAIjC,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,MAAM,EAEN,wCAAwC,GACzC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,MAAM,iBAAiB,GAAG,IAAI,GAAG,IAAI,CAAC;AACtC,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3C,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC;AACpC,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,yBAAyB,GAAG,CAAC,CAAC;AACpC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AACxC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAiBtC,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAE/B,IAAI;IACJ,YAAY;IAFvB,YACW,IAAY,EACZ,YAA4B;QAErC,KAAK,CAAC,kBAAkB,CAAC,CAAC;oBAHjB,IAAI;4BACJ,YAAY;QAGrB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;IAED,IAAI,IAAI;QACN,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,CAAC,IAAI,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CA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