@jangmanj/mcp 0.0.0-stage → 0.12.3
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 +337 -2
- package/adapters/pi/HOST-NOTES.md +65 -0
- package/adapters/pi/bridge.ts +721 -0
- package/adapters/pi/config.ts +364 -0
- package/adapters/pi/content-offloaded.ts +53 -0
- package/adapters/pi/content.ts +78 -0
- package/adapters/pi/diagnostics.ts +26 -0
- package/adapters/pi/elicitation.ts +133 -0
- package/adapters/pi/index.ts +210 -0
- package/adapters/pi/oauth.ts +219 -0
- package/adapters/pi/pi-api.ts +133 -0
- package/adapters/pi/resources.ts +177 -0
- package/adapters/pi/result-files.ts +32 -0
- package/adapters/pi/tasks.ts +49 -0
- package/dist/auth/client-credentials.d.ts +65 -0
- package/dist/auth/client-credentials.js +388 -0
- package/dist/auth/discovery.d.ts +28 -0
- package/dist/auth/discovery.js +125 -0
- package/dist/auth/index.d.ts +9 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/node-ports.d.ts +8 -0
- package/dist/auth/node-ports.js +67 -0
- package/dist/auth/protocol.d.ts +12 -0
- package/dist/auth/protocol.js +39 -0
- package/dist/auth/provider.d.ts +114 -0
- package/dist/auth/provider.js +407 -0
- package/dist/auth/safe-fetch.d.ts +14 -0
- package/dist/auth/safe-fetch.js +130 -0
- package/dist/client/events.d.ts +33 -0
- package/dist/client/events.js +84 -0
- package/dist/client/index.d.ts +65 -0
- package/dist/client/index.js +128 -0
- package/dist/core/auth-types.d.ts +36 -0
- package/dist/core/auth-types.js +11 -0
- package/dist/core/bearer-challenge.d.ts +3 -0
- package/dist/core/bearer-challenge.js +63 -0
- package/dist/core/cancel.d.ts +70 -0
- package/dist/core/cancel.js +177 -0
- package/dist/core/extension.d.ts +33 -0
- package/dist/core/extension.js +145 -0
- package/dist/core/index.d.ts +73 -0
- package/dist/core/index.js +129 -0
- package/dist/core/jsonrpc.d.ts +49 -0
- package/dist/core/jsonrpc.js +80 -0
- package/dist/core/lifecycle.d.ts +128 -0
- package/dist/core/lifecycle.js +251 -0
- package/dist/core/outcome.d.ts +98 -0
- package/dist/core/outcome.js +32 -0
- package/dist/core/ports.d.ts +144 -0
- package/dist/core/ports.js +67 -0
- package/dist/core/progress.d.ts +81 -0
- package/dist/core/progress.js +205 -0
- package/dist/core/request.d.ts +108 -0
- package/dist/core/request.js +578 -0
- package/dist/core/schema/index.d.ts +1 -0
- package/dist/core/schema/index.js +1 -0
- package/dist/core/schema/types.d.ts +4154 -0
- package/dist/core/schema/types.js +6 -0
- package/dist/core/telemetry.d.ts +25 -0
- package/dist/core/telemetry.js +37 -0
- package/dist/ext-events/index.d.ts +79 -0
- package/dist/ext-events/index.js +218 -0
- package/dist/ext-events/model.d.ts +10 -0
- package/dist/ext-events/model.js +6 -0
- package/dist/ext-events/push.d.ts +18 -0
- package/dist/ext-events/push.js +101 -0
- package/dist/ext-events/stream.d.ts +6 -0
- package/dist/ext-events/stream.js +60 -0
- package/dist/ext-server-cards/index.d.ts +107 -0
- package/dist/ext-server-cards/index.js +249 -0
- package/dist/ext-skills/cache.d.ts +20 -0
- package/dist/ext-skills/cache.js +101 -0
- package/dist/ext-skills/client.d.ts +82 -0
- package/dist/ext-skills/client.js +292 -0
- package/dist/ext-skills/extension.d.ts +16 -0
- package/dist/ext-skills/extension.js +29 -0
- package/dist/ext-skills/index.d.ts +4 -0
- package/dist/ext-skills/index.js +4 -0
- package/dist/ext-skills/verify.d.ts +57 -0
- package/dist/ext-skills/verify.js +168 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mrtr-cache/cache.d.ts +51 -0
- package/dist/mrtr-cache/cache.js +295 -0
- package/dist/mrtr-cache/client.d.ts +24 -0
- package/dist/mrtr-cache/client.js +44 -0
- package/dist/mrtr-cache/common.d.ts +10 -0
- package/dist/mrtr-cache/common.js +9 -0
- package/dist/mrtr-cache/elicitation.d.ts +42 -0
- package/dist/mrtr-cache/elicitation.js +221 -0
- package/dist/mrtr-cache/index.d.ts +9 -0
- package/dist/mrtr-cache/index.js +8 -0
- package/dist/mrtr-cache/mrtr.d.ts +37 -0
- package/dist/mrtr-cache/mrtr.js +250 -0
- package/dist/mrtr-cache/refresh.d.ts +8 -0
- package/dist/mrtr-cache/refresh.js +30 -0
- package/dist/mrtr-cache/stream.d.ts +5 -0
- package/dist/mrtr-cache/stream.js +18 -0
- package/dist/mrtr-cache/subscriptions.d.ts +96 -0
- package/dist/mrtr-cache/subscriptions.js +288 -0
- package/dist/mrtr-cache/tasks.d.ts +103 -0
- package/dist/mrtr-cache/tasks.js +444 -0
- package/dist/ops/common.d.ts +18 -0
- package/dist/ops/common.js +39 -0
- package/dist/ops/completion.d.ts +44 -0
- package/dist/ops/completion.js +65 -0
- package/dist/ops/content.d.ts +40 -0
- package/dist/ops/content.js +117 -0
- package/dist/ops/icons.d.ts +29 -0
- package/dist/ops/icons.js +82 -0
- package/dist/ops/index.d.ts +30 -0
- package/dist/ops/index.js +28 -0
- package/dist/ops/pagination.d.ts +32 -0
- package/dist/ops/pagination.js +65 -0
- package/dist/ops/prompts.d.ts +32 -0
- package/dist/ops/prompts.js +68 -0
- package/dist/ops/resources.d.ts +42 -0
- package/dist/ops/resources.js +104 -0
- package/dist/ops/schema.d.ts +39 -0
- package/dist/ops/schema.js +163 -0
- package/dist/ops/tools.d.ts +88 -0
- package/dist/ops/tools.js +169 -0
- package/dist/ops/uri-template.d.ts +3 -0
- package/dist/ops/uri-template.js +101 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +5 -0
- package/dist/server/mrtr.d.ts +38 -0
- package/dist/server/mrtr.js +99 -0
- package/dist/server/protocol.d.ts +21 -0
- package/dist/server/protocol.js +49 -0
- package/dist/server/server.d.ts +105 -0
- package/dist/server/server.js +383 -0
- package/dist/server/skills.d.ts +45 -0
- package/dist/server/skills.js +73 -0
- package/dist/server/uri.d.ts +2 -0
- package/dist/server/uri.js +27 -0
- package/dist/server-events/bus.d.ts +40 -0
- package/dist/server-events/bus.js +84 -0
- package/dist/server-events/events.d.ts +36 -0
- package/dist/server-events/events.js +108 -0
- package/dist/server-events/index.d.ts +6 -0
- package/dist/server-events/index.js +6 -0
- package/dist/server-events/notices.d.ts +24 -0
- package/dist/server-events/notices.js +31 -0
- package/dist/server-events/subscriptions.d.ts +33 -0
- package/dist/server-events/subscriptions.js +77 -0
- package/dist/server-events/tasks.d.ts +43 -0
- package/dist/server-events/tasks.js +101 -0
- package/dist/server-events/types.d.ts +25 -0
- package/dist/server-events/types.js +34 -0
- package/dist/server-transport/auth.d.ts +20 -0
- package/dist/server-transport/auth.js +29 -0
- package/dist/server-transport/channel.d.ts +17 -0
- package/dist/server-transport/channel.js +47 -0
- package/dist/server-transport/http.d.ts +19 -0
- package/dist/server-transport/http.js +209 -0
- package/dist/server-transport/index.d.ts +4 -0
- package/dist/server-transport/index.js +4 -0
- package/dist/server-transport/stdio.d.ts +16 -0
- package/dist/server-transport/stdio.js +83 -0
- package/dist/telemetry-otel/index.d.ts +64 -0
- package/dist/telemetry-otel/index.js +196 -0
- package/dist/testing/index.d.ts +36 -0
- package/dist/testing/index.js +140 -0
- package/dist/transport-http/headers.d.ts +24 -0
- package/dist/transport-http/headers.js +140 -0
- package/dist/transport-http/index.d.ts +3 -0
- package/dist/transport-http/index.js +3 -0
- package/dist/transport-http/sse.d.ts +33 -0
- package/dist/transport-http/sse.js +152 -0
- package/dist/transport-http/transport.d.ts +66 -0
- package/dist/transport-http/transport.js +854 -0
- package/dist/transport-stdio/framing.d.ts +50 -0
- package/dist/transport-stdio/framing.js +154 -0
- package/dist/transport-stdio/index.d.ts +4 -0
- package/dist/transport-stdio/index.js +4 -0
- package/dist/transport-stdio/stderr-ring.d.ts +27 -0
- package/dist/transport-stdio/stderr-ring.js +105 -0
- package/dist/transport-stdio/transport.d.ts +142 -0
- package/dist/transport-stdio/transport.js +743 -0
- package/dist/transport-stdio/write-queue.d.ts +48 -0
- package/dist/transport-stdio/write-queue.js +147 -0
- package/package.json +134 -4
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { type JsonRpcNotification, type JsonRpcRequest } from "./jsonrpc.js";
|
|
2
|
+
import { type JsonRpcRefinement, type Outcome } from "./outcome.js";
|
|
3
|
+
import type { ProgressRegistry } from "./progress.js";
|
|
4
|
+
import type { DiscoverResult } from "./schema/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Wire lifecycle helpers (WIRE-*, VER-*).
|
|
7
|
+
* Runtime-neutral: no node:* imports, no third-party dependencies.
|
|
8
|
+
*/
|
|
9
|
+
/** Library identity sent as io.modelcontextprotocol/clientInfo when the host supplies none (WIRE-META-3). */
|
|
10
|
+
export declare const LIBRARY_CLIENT_INFO: {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly version: string;
|
|
13
|
+
};
|
|
14
|
+
/** Deprecated logging key; never sent (WIRE-LOG-1). */
|
|
15
|
+
export declare const META_LOG_LEVEL: "io.modelcontextprotocol/logLevel";
|
|
16
|
+
/** Default timeout for the server/discover era probe. */
|
|
17
|
+
export declare const DISCOVER_PROBE_TIMEOUT_MS = 10000;
|
|
18
|
+
/** Max bytes of offending error text carried in a diagnostic. */
|
|
19
|
+
export declare const DIAGNOSTIC_EVIDENCE_MAX = 2048;
|
|
20
|
+
export type JsonRpcErrorCategory = "parse-error" | "invalid-request" | "method-not-found" | "invalid-params" | "internal-error" | "header-mismatch" | "missing-client-capability" | "unsupported-version" | "resource-not-found" | "unknown-reserved" | "server-error" | "application";
|
|
21
|
+
export interface UnsupportedVersionData {
|
|
22
|
+
readonly requested?: string;
|
|
23
|
+
readonly supported: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
export interface JsonRpcErrorClass {
|
|
26
|
+
readonly code: number;
|
|
27
|
+
readonly category: JsonRpcErrorCategory;
|
|
28
|
+
readonly refined?: JsonRpcRefinement;
|
|
29
|
+
/** -32022 data, when well-formed. */
|
|
30
|
+
readonly unsupported?: UnsupportedVersionData;
|
|
31
|
+
/** -32021 data.requiredCapabilities, when present (VER-7). */
|
|
32
|
+
readonly requiredCapabilities?: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Classifies a JSON-RPC error by code only (never by message). `data` is optional and untyped
|
|
36
|
+
* for every code except where noted (WIRE-ERR-4); unknown data fields are ignored.
|
|
37
|
+
*/
|
|
38
|
+
export declare function classifyJsonRpcError(code: number, data?: unknown): JsonRpcErrorClass;
|
|
39
|
+
export declare function parseUnsupportedVersionData(data: unknown): UnsupportedVersionData | undefined;
|
|
40
|
+
/** Picks the first version from our preference list that the server also supports (VER-2). */
|
|
41
|
+
export declare function selectProtocolVersion(ours: readonly string[], theirs: readonly string[]): string | undefined;
|
|
42
|
+
export interface UnsupportedVersionDiagnostic {
|
|
43
|
+
readonly binding: string;
|
|
44
|
+
readonly endpointOrCommand: string;
|
|
45
|
+
readonly requested: string;
|
|
46
|
+
readonly supported?: readonly string[];
|
|
47
|
+
readonly observed: "modern-error" | "other-error" | "timeout" | "http-status";
|
|
48
|
+
readonly evidence: string;
|
|
49
|
+
readonly advice: string;
|
|
50
|
+
}
|
|
51
|
+
export interface LifecycleContext {
|
|
52
|
+
readonly binding: string;
|
|
53
|
+
readonly endpointOrCommand: string;
|
|
54
|
+
readonly supportedVersions: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
export declare function buildUnsupportedVersionDiagnostic(ctx: LifecycleContext, observed: UnsupportedVersionDiagnostic["observed"], evidence: string, supported?: readonly string[]): UnsupportedVersionDiagnostic;
|
|
57
|
+
/**
|
|
58
|
+
* Default outcome mapping applied to every settled request:
|
|
59
|
+
* a -32022 that was not (or no longer) retryable becomes `unsupported-version` with a diagnostic
|
|
60
|
+
* (VER-3, VER-4). Everything else passes through.
|
|
61
|
+
*/
|
|
62
|
+
export declare function mapLifecycleOutcome<T>(outcome: Outcome<T>, ctx: LifecycleContext): Outcome<T>;
|
|
63
|
+
export type EraState = {
|
|
64
|
+
readonly era: "modern";
|
|
65
|
+
readonly version: string;
|
|
66
|
+
/** DiscoverResult when discover succeeded. serverInfo inside is display/log only (VER-6). */
|
|
67
|
+
readonly discover?: DiscoverResult;
|
|
68
|
+
readonly supported: readonly string[];
|
|
69
|
+
} | {
|
|
70
|
+
readonly era: "modern-no-mutual";
|
|
71
|
+
readonly diagnostic: UnsupportedVersionDiagnostic;
|
|
72
|
+
} | {
|
|
73
|
+
readonly era: "legacy-or-unresponsive";
|
|
74
|
+
readonly diagnostic: UnsupportedVersionDiagnostic;
|
|
75
|
+
} | {
|
|
76
|
+
readonly era: "unknown";
|
|
77
|
+
readonly outcome: Outcome<unknown>;
|
|
78
|
+
};
|
|
79
|
+
/** Whether an era verdict is cached; `unknown` (local cancel, transport fault) is not. */
|
|
80
|
+
export declare function isCacheableEra(state: EraState): boolean;
|
|
81
|
+
/** Classifies the outcome of a server/discover probe into an era verdict. Never branches on serverInfo. */
|
|
82
|
+
export declare function classifyDiscoverOutcome(outcome: Outcome<unknown>, ctx: LifecycleContext): EraState;
|
|
83
|
+
/**
|
|
84
|
+
* In-memory era cache keyed by server config key (VER-CACHE-1: never persisted).
|
|
85
|
+
* `resolve` is single-flight per key; uncacheable verdicts are returned but not stored.
|
|
86
|
+
*/
|
|
87
|
+
export declare class EraCache {
|
|
88
|
+
private readonly entries;
|
|
89
|
+
private readonly inflight;
|
|
90
|
+
get(key: string): EraState | undefined;
|
|
91
|
+
set(key: string, state: EraState): void;
|
|
92
|
+
delete(key: string): void;
|
|
93
|
+
clear(): void;
|
|
94
|
+
resolve(key: string, probe: () => Promise<EraState>): Promise<EraState>;
|
|
95
|
+
}
|
|
96
|
+
export type NotificationVerdict = "deliver" | "progress" | "drop-log" | "drop-cancelled" | "drop-other";
|
|
97
|
+
/**
|
|
98
|
+
* Default per-request notification policy:
|
|
99
|
+
* - notifications/progress goes to the progress registry (PROG-*)
|
|
100
|
+
* - notifications/message is dropped: logging is deprecated (WIRE-LOG-1, EDGE-33)
|
|
101
|
+
* - notifications/cancelled is accepted only for our subscriptions/listen request (WIRE-CANCEL-4)
|
|
102
|
+
* - anything else is delivered on the request's notification stream
|
|
103
|
+
*/
|
|
104
|
+
export declare function defaultNotificationFilter(n: JsonRpcNotification, req: JsonRpcRequest): NotificationVerdict;
|
|
105
|
+
export interface LifecycleHooks {
|
|
106
|
+
mapOutcome<T>(outcome: Outcome<T>, ctx: LifecycleContext): Outcome<T>;
|
|
107
|
+
classifyDiscover(outcome: Outcome<unknown>, ctx: LifecycleContext): EraState;
|
|
108
|
+
filterNotification(n: JsonRpcNotification, req: JsonRpcRequest): NotificationVerdict;
|
|
109
|
+
}
|
|
110
|
+
export declare const defaultLifecycleHooks: LifecycleHooks;
|
|
111
|
+
/** Helper for hosts: missing capabilities from a -32021 outcome (VER-7), else undefined. */
|
|
112
|
+
export declare function missingClientCapabilities(outcome: Outcome<unknown>): unknown;
|
|
113
|
+
export interface LifecyclePolicyOptions {
|
|
114
|
+
/** Replace individual lifecycle policies (outcome mapping, discover classification, notification filter). */
|
|
115
|
+
readonly hooks?: Partial<LifecycleHooks>;
|
|
116
|
+
/** Settle a request locally on abort/timeout when the transport does not. Default true. */
|
|
117
|
+
readonly settleOnAbort?: boolean;
|
|
118
|
+
/** Methods treated as read-only for uncertain-write classification. Default DEFAULT_READ_ONLY_METHODS. */
|
|
119
|
+
readonly readOnlyMethods?: readonly string[];
|
|
120
|
+
/** Progress registry (shared or custom). Default: one per client. */
|
|
121
|
+
readonly progressRegistry?: ProgressRegistry;
|
|
122
|
+
/** In-memory era cache (shared or custom). Default: one per client. Never persisted. */
|
|
123
|
+
readonly eraCache?: EraCache;
|
|
124
|
+
}
|
|
125
|
+
export interface ProbeOptions {
|
|
126
|
+
readonly timeoutMs?: number;
|
|
127
|
+
readonly signal?: AbortSignal;
|
|
128
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { SUPPORTED_PROTOCOL_VERSION, } from "./jsonrpc.js";
|
|
2
|
+
import { refineJsonRpcCode } from "./outcome.js";
|
|
3
|
+
/**
|
|
4
|
+
* Wire lifecycle helpers (WIRE-*, VER-*).
|
|
5
|
+
* Runtime-neutral: no node:* imports, no third-party dependencies.
|
|
6
|
+
*/
|
|
7
|
+
/** Library identity sent as io.modelcontextprotocol/clientInfo when the host supplies none (WIRE-META-3). */
|
|
8
|
+
export const LIBRARY_CLIENT_INFO = Object.freeze({
|
|
9
|
+
name: "@jangmanj/mcp",
|
|
10
|
+
version: "0.1.1",
|
|
11
|
+
});
|
|
12
|
+
/** Deprecated logging key; never sent (WIRE-LOG-1). */
|
|
13
|
+
export const META_LOG_LEVEL = "io.modelcontextprotocol/logLevel";
|
|
14
|
+
/** Default timeout for the server/discover era probe. */
|
|
15
|
+
export const DISCOVER_PROBE_TIMEOUT_MS = 10_000;
|
|
16
|
+
/** Max bytes of offending error text carried in a diagnostic. */
|
|
17
|
+
export const DIAGNOSTIC_EVIDENCE_MAX = 2048;
|
|
18
|
+
/**
|
|
19
|
+
* Classifies a JSON-RPC error by code only (never by message). `data` is optional and untyped
|
|
20
|
+
* for every code except where noted (WIRE-ERR-4); unknown data fields are ignored.
|
|
21
|
+
*/
|
|
22
|
+
export function classifyJsonRpcError(code, data) {
|
|
23
|
+
const refined = refineJsonRpcCode(code);
|
|
24
|
+
const base = { code, ...(refined ? { refined } : {}) };
|
|
25
|
+
switch (code) {
|
|
26
|
+
case -32700:
|
|
27
|
+
return { ...base, category: "parse-error" };
|
|
28
|
+
case -32600:
|
|
29
|
+
return { ...base, category: "invalid-request" };
|
|
30
|
+
case -32601:
|
|
31
|
+
return { ...base, category: "method-not-found" };
|
|
32
|
+
case -32602:
|
|
33
|
+
return { ...base, category: "invalid-params" };
|
|
34
|
+
case -32603:
|
|
35
|
+
return { ...base, category: "internal-error" };
|
|
36
|
+
case -32020:
|
|
37
|
+
return { ...base, category: "header-mismatch" };
|
|
38
|
+
case -32021: {
|
|
39
|
+
const rc = typeof data === "object" && data !== null ? data["requiredCapabilities"] : undefined;
|
|
40
|
+
return { ...base, category: "missing-client-capability", ...(rc !== undefined ? { requiredCapabilities: rc } : {}) };
|
|
41
|
+
}
|
|
42
|
+
case -32022: {
|
|
43
|
+
const parsed = parseUnsupportedVersionData(data);
|
|
44
|
+
return { ...base, category: "unsupported-version", ...(parsed ? { unsupported: parsed } : {}) };
|
|
45
|
+
}
|
|
46
|
+
case -32002:
|
|
47
|
+
return { ...base, category: "resource-not-found" };
|
|
48
|
+
default:
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
if (refined === "unknown-reserved")
|
|
52
|
+
return { ...base, category: "unknown-reserved" };
|
|
53
|
+
if (code <= -32000 && code >= -32099)
|
|
54
|
+
return { ...base, category: "server-error" };
|
|
55
|
+
return { ...base, category: "application" };
|
|
56
|
+
}
|
|
57
|
+
export function parseUnsupportedVersionData(data) {
|
|
58
|
+
if (typeof data !== "object" || data === null)
|
|
59
|
+
return undefined;
|
|
60
|
+
const rec = data;
|
|
61
|
+
const supported = rec["supported"];
|
|
62
|
+
if (!Array.isArray(supported) || !supported.every((v) => typeof v === "string"))
|
|
63
|
+
return undefined;
|
|
64
|
+
const requested = rec["requested"];
|
|
65
|
+
return {
|
|
66
|
+
supported: supported,
|
|
67
|
+
...(typeof requested === "string" ? { requested } : {}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Picks the first version from our preference list that the server also supports (VER-2). */
|
|
71
|
+
export function selectProtocolVersion(ours, theirs) {
|
|
72
|
+
return ours.find((v) => theirs.includes(v));
|
|
73
|
+
}
|
|
74
|
+
function clip(s) {
|
|
75
|
+
return s.length > DIAGNOSTIC_EVIDENCE_MAX ? s.slice(0, DIAGNOSTIC_EVIDENCE_MAX) : s;
|
|
76
|
+
}
|
|
77
|
+
export function buildUnsupportedVersionDiagnostic(ctx, observed, evidence, supported) {
|
|
78
|
+
const ours = ctx.supportedVersions.join(", ") || SUPPORTED_PROTOCOL_VERSION;
|
|
79
|
+
const advice = observed === "modern-error"
|
|
80
|
+
? `The server supports ${supported && supported.length > 0 ? supported.join(", ") : "no listed version"}; this client implements only ${ours}. Upgrade the server or use a client that implements one of its versions.`
|
|
81
|
+
: `The peer did not answer server/discover as a ${ours} server; this client implements only ${ours} and never falls back to initialize. Upgrade the server to a ${ours} release.`;
|
|
82
|
+
return {
|
|
83
|
+
binding: ctx.binding,
|
|
84
|
+
endpointOrCommand: ctx.endpointOrCommand,
|
|
85
|
+
requested: ctx.supportedVersions[0] ?? SUPPORTED_PROTOCOL_VERSION,
|
|
86
|
+
...(supported !== undefined ? { supported } : {}),
|
|
87
|
+
observed,
|
|
88
|
+
evidence: clip(evidence),
|
|
89
|
+
advice,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Default outcome mapping applied to every settled request:
|
|
94
|
+
* a -32022 that was not (or no longer) retryable becomes `unsupported-version` with a diagnostic
|
|
95
|
+
* (VER-3, VER-4). Everything else passes through.
|
|
96
|
+
*/
|
|
97
|
+
export function mapLifecycleOutcome(outcome, ctx) {
|
|
98
|
+
if (outcome.kind === "jsonrpc-error" && outcome.code === -32022) {
|
|
99
|
+
const parsed = parseUnsupportedVersionData(outcome.data);
|
|
100
|
+
return {
|
|
101
|
+
kind: "unsupported-version",
|
|
102
|
+
detail: buildUnsupportedVersionDiagnostic(ctx, "modern-error", `${outcome.code} ${outcome.message}`, parsed?.supported),
|
|
103
|
+
meta: outcome.meta,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return outcome;
|
|
107
|
+
}
|
|
108
|
+
/** Whether an era verdict is cached; `unknown` (local cancel, transport fault) is not. */
|
|
109
|
+
export function isCacheableEra(state) {
|
|
110
|
+
return state.era !== "unknown";
|
|
111
|
+
}
|
|
112
|
+
/** Classifies the outcome of a server/discover probe into an era verdict. Never branches on serverInfo. */
|
|
113
|
+
export function classifyDiscoverOutcome(outcome, ctx) {
|
|
114
|
+
if (outcome.kind === "ok") {
|
|
115
|
+
const value = outcome.value;
|
|
116
|
+
const supported = value?.["supportedVersions"];
|
|
117
|
+
if (!Array.isArray(supported) || !supported.every((v) => typeof v === "string")) {
|
|
118
|
+
return {
|
|
119
|
+
era: "legacy-or-unresponsive",
|
|
120
|
+
diagnostic: buildUnsupportedVersionDiagnostic(ctx, "other-error", `server/discover result has no supportedVersions string array: ${clip(JSON.stringify(value) ?? "")}`),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const version = selectProtocolVersion(ctx.supportedVersions, supported);
|
|
124
|
+
if (!version) {
|
|
125
|
+
return {
|
|
126
|
+
era: "modern-no-mutual",
|
|
127
|
+
diagnostic: buildUnsupportedVersionDiagnostic(ctx, "modern-error", `server/discover supportedVersions: ${JSON.stringify(supported)}`, supported),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return { era: "modern", version, supported: supported, discover: value };
|
|
131
|
+
}
|
|
132
|
+
if (outcome.kind === "unsupported-version") {
|
|
133
|
+
const d = outcome.detail;
|
|
134
|
+
const supported = d?.supported ?? [];
|
|
135
|
+
const version = selectProtocolVersion(ctx.supportedVersions, supported);
|
|
136
|
+
if (version)
|
|
137
|
+
return { era: "modern", version, supported };
|
|
138
|
+
return {
|
|
139
|
+
era: "modern-no-mutual",
|
|
140
|
+
diagnostic: buildUnsupportedVersionDiagnostic(ctx, "modern-error", d?.evidence ?? "-32022", supported),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (outcome.kind === "jsonrpc-error") {
|
|
144
|
+
if (outcome.code === -32022) {
|
|
145
|
+
const parsed = parseUnsupportedVersionData(outcome.data);
|
|
146
|
+
const version = parsed ? selectProtocolVersion(ctx.supportedVersions, parsed.supported) : undefined;
|
|
147
|
+
if (version && parsed)
|
|
148
|
+
return { era: "modern", version, supported: parsed.supported };
|
|
149
|
+
return {
|
|
150
|
+
era: "modern-no-mutual",
|
|
151
|
+
diagnostic: buildUnsupportedVersionDiagnostic(ctx, "modern-error", `${outcome.code} ${outcome.message}`, parsed?.supported),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const data = outcome.data !== undefined ? ` ${JSON.stringify(outcome.data)}` : "";
|
|
155
|
+
return {
|
|
156
|
+
era: "legacy-or-unresponsive",
|
|
157
|
+
diagnostic: buildUnsupportedVersionDiagnostic(ctx, "other-error", `${outcome.code} ${outcome.message}${data}`),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (outcome.kind === "transport-failure") {
|
|
161
|
+
if (outcome.failure.kind === "timeout") {
|
|
162
|
+
return {
|
|
163
|
+
era: "legacy-or-unresponsive",
|
|
164
|
+
diagnostic: buildUnsupportedVersionDiagnostic(ctx, "timeout", outcome.failure.message),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (outcome.failure.kind === "http-status" && outcome.failure.status !== undefined && outcome.failure.status >= 400 && outcome.failure.status < 500) {
|
|
168
|
+
return {
|
|
169
|
+
era: "legacy-or-unresponsive",
|
|
170
|
+
diagnostic: buildUnsupportedVersionDiagnostic(ctx, "http-status", `HTTP ${outcome.failure.status}: ${outcome.failure.message}`),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (outcome.kind === "protocol-violation") {
|
|
175
|
+
return {
|
|
176
|
+
era: "legacy-or-unresponsive",
|
|
177
|
+
diagnostic: buildUnsupportedVersionDiagnostic(ctx, "other-error", `protocol-violation ${JSON.stringify(outcome.detail)}`),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return { era: "unknown", outcome };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* In-memory era cache keyed by server config key (VER-CACHE-1: never persisted).
|
|
184
|
+
* `resolve` is single-flight per key; uncacheable verdicts are returned but not stored.
|
|
185
|
+
*/
|
|
186
|
+
export class EraCache {
|
|
187
|
+
entries = new Map();
|
|
188
|
+
inflight = new Map();
|
|
189
|
+
get(key) {
|
|
190
|
+
return this.entries.get(key);
|
|
191
|
+
}
|
|
192
|
+
set(key, state) {
|
|
193
|
+
if (isCacheableEra(state))
|
|
194
|
+
this.entries.set(key, state);
|
|
195
|
+
}
|
|
196
|
+
delete(key) {
|
|
197
|
+
this.entries.delete(key);
|
|
198
|
+
}
|
|
199
|
+
clear() {
|
|
200
|
+
this.entries.clear();
|
|
201
|
+
}
|
|
202
|
+
resolve(key, probe) {
|
|
203
|
+
const hit = this.get(key);
|
|
204
|
+
if (hit)
|
|
205
|
+
return Promise.resolve(hit);
|
|
206
|
+
const running = this.inflight.get(key);
|
|
207
|
+
if (running)
|
|
208
|
+
return running;
|
|
209
|
+
const p = probe().then((state) => {
|
|
210
|
+
this.inflight.delete(key);
|
|
211
|
+
this.set(key, state);
|
|
212
|
+
return state;
|
|
213
|
+
}, (err) => {
|
|
214
|
+
this.inflight.delete(key);
|
|
215
|
+
throw err;
|
|
216
|
+
});
|
|
217
|
+
this.inflight.set(key, p);
|
|
218
|
+
return p;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Default per-request notification policy:
|
|
223
|
+
* - notifications/progress goes to the progress registry (PROG-*)
|
|
224
|
+
* - notifications/message is dropped: logging is deprecated (WIRE-LOG-1, EDGE-33)
|
|
225
|
+
* - notifications/cancelled is accepted only for our subscriptions/listen request (WIRE-CANCEL-4)
|
|
226
|
+
* - anything else is delivered on the request's notification stream
|
|
227
|
+
*/
|
|
228
|
+
export function defaultNotificationFilter(n, req) {
|
|
229
|
+
if (n.method === "notifications/progress")
|
|
230
|
+
return "progress";
|
|
231
|
+
if (n.method === "notifications/message")
|
|
232
|
+
return "drop-log";
|
|
233
|
+
if (n.method === "notifications/cancelled") {
|
|
234
|
+
const rid = n.params?.["requestId"];
|
|
235
|
+
if (req.method === "subscriptions/listen" && rid === req.id)
|
|
236
|
+
return "deliver";
|
|
237
|
+
return "drop-cancelled";
|
|
238
|
+
}
|
|
239
|
+
return "deliver";
|
|
240
|
+
}
|
|
241
|
+
export const defaultLifecycleHooks = {
|
|
242
|
+
mapOutcome: mapLifecycleOutcome,
|
|
243
|
+
classifyDiscover: classifyDiscoverOutcome,
|
|
244
|
+
filterNotification: defaultNotificationFilter,
|
|
245
|
+
};
|
|
246
|
+
/** Helper for hosts: missing capabilities from a -32021 outcome (VER-7), else undefined. */
|
|
247
|
+
export function missingClientCapabilities(outcome) {
|
|
248
|
+
if (outcome.kind !== "jsonrpc-error" || outcome.code !== -32021)
|
|
249
|
+
return undefined;
|
|
250
|
+
return classifyJsonRpcError(outcome.code, outcome.data).requiredCapabilities;
|
|
251
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { RequestId } from "./schema/index.js";
|
|
2
|
+
export type TransportFailureKind = "connect" | "spawn" | "process-exit" | "stream-broken" | "http-status" | "closed" | "timeout" | "forbidden" | "auth-failure" | "auth-unavailable" | "too-large";
|
|
3
|
+
export interface TransportFailure {
|
|
4
|
+
readonly kind: TransportFailureKind;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
readonly status?: number;
|
|
7
|
+
readonly reason?: string;
|
|
8
|
+
readonly cause?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface UncertainWrite {
|
|
11
|
+
readonly requestId: RequestId;
|
|
12
|
+
readonly method: string;
|
|
13
|
+
readonly name?: string;
|
|
14
|
+
readonly argsDigest: string;
|
|
15
|
+
readonly sentAt: number;
|
|
16
|
+
readonly binding: string;
|
|
17
|
+
readonly evidence: "process-exit" | "eof-mid-line" | "cancelled" | "timeout" | "stream-broken" | "status-5xx" | "truncated-json";
|
|
18
|
+
/** HTTP-AMBIG-4: task handle observed on the stream before it broke; kept for the tasks extension to poll. */
|
|
19
|
+
readonly taskHandle?: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface MrtrRound {
|
|
22
|
+
readonly round: number;
|
|
23
|
+
readonly requestState?: string;
|
|
24
|
+
readonly action: "consent" | "auto" | "manual";
|
|
25
|
+
}
|
|
26
|
+
export interface OutcomeMeta {
|
|
27
|
+
readonly requestId: RequestId;
|
|
28
|
+
readonly method: string;
|
|
29
|
+
readonly binding: string;
|
|
30
|
+
readonly attempts: number;
|
|
31
|
+
/** HTTP-AMBIG-3: id of the original request this caller-opted re-issue duplicates. */
|
|
32
|
+
readonly retryOf?: RequestId;
|
|
33
|
+
readonly cache?: "hit" | "miss" | "stale" | "bypass";
|
|
34
|
+
readonly serverInfo?: {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly version: string;
|
|
37
|
+
readonly title?: string;
|
|
38
|
+
};
|
|
39
|
+
readonly trace?: readonly MrtrRound[];
|
|
40
|
+
}
|
|
41
|
+
export type JsonRpcRefinement = "resource-not-found" | "unsupported-version" | "missing-client-capability" | "header-mismatch" | "unknown-reserved";
|
|
42
|
+
export interface InputRequestsField {
|
|
43
|
+
readonly [key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
export type InputResponsesField = Record<string, unknown>;
|
|
46
|
+
export type Outcome<T> = {
|
|
47
|
+
readonly kind: "ok";
|
|
48
|
+
readonly value: T;
|
|
49
|
+
readonly meta: OutcomeMeta;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: "jsonrpc-error";
|
|
52
|
+
readonly code: number;
|
|
53
|
+
readonly message: string;
|
|
54
|
+
readonly data?: unknown;
|
|
55
|
+
readonly refined?: JsonRpcRefinement;
|
|
56
|
+
readonly meta: OutcomeMeta;
|
|
57
|
+
} | {
|
|
58
|
+
readonly kind: "transport-failure";
|
|
59
|
+
readonly failure: TransportFailure;
|
|
60
|
+
readonly safeToRetry: boolean;
|
|
61
|
+
readonly meta: OutcomeMeta;
|
|
62
|
+
} | {
|
|
63
|
+
readonly kind: "tool-isError";
|
|
64
|
+
readonly result: Record<string, unknown>;
|
|
65
|
+
readonly meta: OutcomeMeta;
|
|
66
|
+
} | {
|
|
67
|
+
readonly kind: "mrtr-interim";
|
|
68
|
+
readonly inputRequests?: InputRequestsField;
|
|
69
|
+
readonly requestState?: string;
|
|
70
|
+
readonly meta: OutcomeMeta;
|
|
71
|
+
} | {
|
|
72
|
+
readonly kind: "task-handle";
|
|
73
|
+
readonly handle: unknown;
|
|
74
|
+
readonly meta: OutcomeMeta;
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: "uncertain-write";
|
|
77
|
+
readonly uncertain: UncertainWrite;
|
|
78
|
+
readonly meta: OutcomeMeta;
|
|
79
|
+
} | {
|
|
80
|
+
readonly kind: "cancelled";
|
|
81
|
+
readonly wasSent: boolean;
|
|
82
|
+
readonly phase: "queue" | "wire" | "input";
|
|
83
|
+
readonly meta: OutcomeMeta;
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: "protocol-violation" | "capability-absent" | "invalid-arguments" | "invalid-schema" | "unsupported-version" | "auth-failure" | "auth-unavailable" | "limit-exceeded" | "local-error";
|
|
86
|
+
readonly detail: unknown;
|
|
87
|
+
readonly meta: OutcomeMeta;
|
|
88
|
+
};
|
|
89
|
+
export declare function refineJsonRpcCode(code: number): JsonRpcRefinement | undefined;
|
|
90
|
+
export declare class McpOutcomeError<T = unknown> extends Error {
|
|
91
|
+
readonly outcome: Exclude<Outcome<T>, {
|
|
92
|
+
readonly kind: "ok";
|
|
93
|
+
}>;
|
|
94
|
+
constructor(outcome: Exclude<Outcome<T>, {
|
|
95
|
+
readonly kind: "ok";
|
|
96
|
+
}>);
|
|
97
|
+
}
|
|
98
|
+
export declare function unwrapOutcome<T>(outcome: Outcome<T>): T;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function refineJsonRpcCode(code) {
|
|
2
|
+
if (code === -32020)
|
|
3
|
+
return "header-mismatch";
|
|
4
|
+
if (code === -32021)
|
|
5
|
+
return "missing-client-capability";
|
|
6
|
+
if (code === -32022)
|
|
7
|
+
return "unsupported-version";
|
|
8
|
+
if (code === -32002)
|
|
9
|
+
return "resource-not-found";
|
|
10
|
+
if (code <= -32023 && code >= -32099)
|
|
11
|
+
return "unknown-reserved";
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
export class McpOutcomeError extends Error {
|
|
15
|
+
outcome;
|
|
16
|
+
constructor(outcome) {
|
|
17
|
+
const label = outcome.kind === "jsonrpc-error"
|
|
18
|
+
? `MCP jsonrpc-error(${outcome.code}): ${outcome.message}`
|
|
19
|
+
: outcome.kind === "transport-failure"
|
|
20
|
+
? `MCP transport-failure(${outcome.failure.kind}): ${outcome.failure.message}`
|
|
21
|
+
: `MCP outcome: ${outcome.kind}`;
|
|
22
|
+
super(label);
|
|
23
|
+
this.name = "McpOutcomeError";
|
|
24
|
+
this.outcome = outcome;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function unwrapOutcome(outcome) {
|
|
28
|
+
if (outcome.kind === "ok") {
|
|
29
|
+
return outcome.value;
|
|
30
|
+
}
|
|
31
|
+
throw new McpOutcomeError(outcome);
|
|
32
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { JsonRpcErrorResponse, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse } from "./jsonrpc.js";
|
|
2
|
+
import type { TransportFailure } from "./outcome.js";
|
|
3
|
+
import type { TelemetryPort } from "./telemetry.js";
|
|
4
|
+
export interface TransportDiagnostic {
|
|
5
|
+
readonly kind: "stderr" | "noise" | "violation" | "lifecycle";
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly atMs: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_MAX_DIAGNOSTICS = 1000;
|
|
10
|
+
/**
|
|
11
|
+
* Bounded diagnostic ring buffer with AsyncIterable streaming (LIM-DIAG-1).
|
|
12
|
+
*/
|
|
13
|
+
export declare class DiagnosticChannel implements AsyncIterable<TransportDiagnostic> {
|
|
14
|
+
private readonly maxEvents;
|
|
15
|
+
private readonly ring;
|
|
16
|
+
private readonly liveQueue;
|
|
17
|
+
private readonly waiters;
|
|
18
|
+
private closed;
|
|
19
|
+
constructor(maxEvents?: number);
|
|
20
|
+
emit(diag: TransportDiagnostic): void;
|
|
21
|
+
snapshot(): readonly TransportDiagnostic[];
|
|
22
|
+
close(): void;
|
|
23
|
+
[Symbol.asyncIterator](): AsyncIterator<TransportDiagnostic>;
|
|
24
|
+
}
|
|
25
|
+
export interface TransportCall {
|
|
26
|
+
readonly signal: AbortSignal;
|
|
27
|
+
readonly idempotent: boolean;
|
|
28
|
+
readonly headersHint?: {
|
|
29
|
+
readonly name?: string;
|
|
30
|
+
readonly params?: Readonly<Record<string, string | number | boolean>>;
|
|
31
|
+
};
|
|
32
|
+
readonly timeoutMs: number;
|
|
33
|
+
readonly consent?: ConsentPort;
|
|
34
|
+
readonly serverLabel?: string;
|
|
35
|
+
}
|
|
36
|
+
export type ExchangeEnd = {
|
|
37
|
+
readonly kind: "response";
|
|
38
|
+
readonly message: JsonRpcResponse | JsonRpcErrorResponse;
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "failure";
|
|
41
|
+
readonly failure: TransportFailure;
|
|
42
|
+
readonly delivery: "not-sent" | "maybe-delivered" | "delivered-no-response";
|
|
43
|
+
};
|
|
44
|
+
export interface Exchange {
|
|
45
|
+
/** Current delivery evidence if interrupted before done settles. */
|
|
46
|
+
abortDelivery?(): Extract<ExchangeEnd, {
|
|
47
|
+
kind: "failure";
|
|
48
|
+
}>["delivery"];
|
|
49
|
+
readonly notifications: AsyncIterable<JsonRpcNotification>;
|
|
50
|
+
readonly done: Promise<ExchangeEnd>;
|
|
51
|
+
}
|
|
52
|
+
export interface Transport {
|
|
53
|
+
readonly binding: "stdio" | "streamable-http" | (string & {});
|
|
54
|
+
start(msg: JsonRpcRequest, ctx: TransportCall): Exchange;
|
|
55
|
+
notify(msg: JsonRpcNotification, ctx: TransportCall): Promise<void>;
|
|
56
|
+
close(opts?: {
|
|
57
|
+
readonly graceMs?: number;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
readonly diagnostics: AsyncIterable<TransportDiagnostic>;
|
|
60
|
+
}
|
|
61
|
+
export interface ProgressEvent {
|
|
62
|
+
readonly progressToken: string | number;
|
|
63
|
+
readonly progress: number;
|
|
64
|
+
readonly total?: number;
|
|
65
|
+
readonly message?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface Clock {
|
|
68
|
+
now(): number;
|
|
69
|
+
setTimeout(fn: () => void, ms: number): () => void;
|
|
70
|
+
}
|
|
71
|
+
export declare const systemClock: Clock;
|
|
72
|
+
export interface RandomPort {
|
|
73
|
+
bytes(len: number): Uint8Array;
|
|
74
|
+
}
|
|
75
|
+
export interface LoggerPort {
|
|
76
|
+
debug(msg: string, detail?: Record<string, unknown>): void;
|
|
77
|
+
warn(msg: string, detail?: Record<string, unknown>): void;
|
|
78
|
+
error(msg: string, detail?: Record<string, unknown>): void;
|
|
79
|
+
}
|
|
80
|
+
export interface ConsentPrompt {
|
|
81
|
+
readonly kind: "auth" | "authorize" | "client-info" | "url-elicitation" | "form-elicitation" | "tool-call";
|
|
82
|
+
readonly serverLabel: string;
|
|
83
|
+
readonly issuer?: string;
|
|
84
|
+
readonly issuerHost?: string;
|
|
85
|
+
readonly resource?: string;
|
|
86
|
+
readonly scopes?: readonly string[];
|
|
87
|
+
readonly redirectUri?: string;
|
|
88
|
+
readonly redirectHost?: string;
|
|
89
|
+
readonly localhostWarning?: boolean;
|
|
90
|
+
readonly url?: string;
|
|
91
|
+
readonly message?: string;
|
|
92
|
+
readonly schema?: Record<string, unknown>;
|
|
93
|
+
}
|
|
94
|
+
export type ConsentResult = {
|
|
95
|
+
readonly decision: "accept";
|
|
96
|
+
readonly content?: Record<string, unknown>;
|
|
97
|
+
} | {
|
|
98
|
+
readonly decision: "decline" | "cancel";
|
|
99
|
+
};
|
|
100
|
+
export interface ConsentPort {
|
|
101
|
+
request(prompt: ConsentPrompt, signal: AbortSignal): Promise<ConsentResult>;
|
|
102
|
+
}
|
|
103
|
+
export interface BrowserPort {
|
|
104
|
+
open(url: string, signal: AbortSignal): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
export interface RedirectPort {
|
|
107
|
+
awaitCallback(state: string, signal: AbortSignal): Promise<{
|
|
108
|
+
readonly code: string;
|
|
109
|
+
readonly state: string;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
export interface CredentialStore {
|
|
113
|
+
get(key: string): Promise<string | undefined>;
|
|
114
|
+
set(key: string, value: string): Promise<void>;
|
|
115
|
+
delete(key: string): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
export interface IdentityPort {
|
|
118
|
+
clientInfo(): {
|
|
119
|
+
readonly name: string;
|
|
120
|
+
readonly version: string;
|
|
121
|
+
readonly title?: string;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export interface FetchPort {
|
|
125
|
+
fetch(input: string, init: RequestInit): Promise<Response>;
|
|
126
|
+
}
|
|
127
|
+
export interface CacheStore {
|
|
128
|
+
get(key: string): Promise<unknown>;
|
|
129
|
+
set(key: string, value: unknown, ttlMs: number): Promise<void>;
|
|
130
|
+
delete(key: string): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
export interface PortRegistry {
|
|
133
|
+
readonly consent?: ConsentPort;
|
|
134
|
+
readonly browser?: BrowserPort;
|
|
135
|
+
readonly redirect?: RedirectPort;
|
|
136
|
+
readonly credentials?: CredentialStore;
|
|
137
|
+
readonly identity?: IdentityPort;
|
|
138
|
+
readonly fetch?: FetchPort;
|
|
139
|
+
readonly telemetry?: TelemetryPort;
|
|
140
|
+
readonly cache?: CacheStore;
|
|
141
|
+
readonly clock?: Clock;
|
|
142
|
+
readonly random?: RandomPort;
|
|
143
|
+
readonly logger?: LoggerPort;
|
|
144
|
+
}
|