@kodax-ai/kodax 0.7.46 → 0.7.48
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/CHANGELOG.md +37 -1
- package/dist/chunks/{chunk-2GEKCIIW.js → chunk-66B6ZOU7.js} +13 -13
- package/dist/chunks/{chunk-K4RBLNSY.js → chunk-6Z75SHX3.js} +1 -1
- package/dist/chunks/{chunk-Z4UT32NN.js → chunk-DEODZG6Q.js} +1 -1
- package/dist/chunks/chunk-EP46H5P3.js +415 -0
- package/dist/chunks/{chunk-XUEINS3X.js → chunk-LNJNRREL.js} +317 -263
- package/dist/chunks/{chunk-JRT447X5.js → chunk-UHAP234X.js} +244 -242
- package/dist/chunks/{compaction-config-PFTBIGQT.js → compaction-config-YWCHOP2U.js} +1 -1
- package/dist/chunks/{construction-bootstrap-2FKNOZZE.js → construction-bootstrap-AIWATBWW.js} +1 -1
- package/dist/chunks/dist-4WABQRJU.js +2 -0
- package/dist/chunks/{dist-QTV5M2JW.js → dist-IDNOAB4M.js} +1 -1
- package/dist/chunks/{utils-LY3LB65Z.js → utils-OG57XTPC.js} +1 -1
- package/dist/index.d.ts +10 -7
- package/dist/index.js +5 -5
- package/dist/kodax_cli.js +765 -719
- package/dist/provider-capabilities.json +3 -8
- package/dist/sdk-agent.d.ts +38 -7
- package/dist/sdk-agent.js +1 -1
- package/dist/sdk-coding.d.ts +102 -11
- package/dist/sdk-coding.js +1 -1
- package/dist/sdk-llm.js +1 -1
- package/dist/sdk-mcp.d.ts +3 -3
- package/dist/sdk-mcp.js +1 -1
- package/dist/sdk-repl.d.ts +10 -9
- package/dist/sdk-repl.js +1 -1
- package/dist/sdk-session.js +1 -1
- package/dist/sdk-skills.js +1 -1
- package/dist/types-chunks/{bash-prefix-extractor.d-BICYx8pt.d.ts → bash-prefix-extractor.d-DNO2-ycp.d.ts} +283 -31
- package/dist/types-chunks/{config.d-BfJUXxC0.d.ts → config.d-CJy1WENT.d.ts} +17 -7
- package/dist/types-chunks/{file-tracker.d-BNTIvsdb.d.ts → file-tracker.d-D7L_SbRm.d.ts} +1 -1
- package/dist/types-chunks/manager.d-DLmDhX3i.d.ts +696 -0
- package/dist/types-chunks/{types.d-D2RNa5Y7.d.ts → types.d-BCnbYG_A.d.ts} +68 -2
- package/dist/types-chunks/{utils.d-pzHPkrb8.d.ts → utils.d-Dgy5SVrq.d.ts} +1 -1
- package/package.json +2 -1
- package/dist/chunks/chunk-VBIVZOSD.js +0 -425
- package/dist/chunks/dist-JLMKDPEL.js +0 -2
- package/dist/types-chunks/manager.d-87belpiS.d.ts +0 -370
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
import { a as McpServerConfig, b as McpServersConfig, M as McpConnectMode } from './config.d-CJy1WENT.js';
|
|
2
|
+
import { a as CapabilityProvider, C as CapabilityKind, b as CapabilityResult } from './capability.d-3C62G8Eq.js';
|
|
3
|
+
|
|
4
|
+
type McpCapabilityKind = 'tool' | 'resource' | 'prompt';
|
|
5
|
+
type McpCapabilityRisk = 'read' | 'write' | 'network' | 'exec';
|
|
6
|
+
/** Per-tool task-augmentation support (2025-11-25 `execution.taskSupport`). */
|
|
7
|
+
type McpToolTaskSupport = 'forbidden' | 'optional' | 'required';
|
|
8
|
+
/** Icon metadata (2025-11-25) attached to tools / resources / prompts. */
|
|
9
|
+
interface McpIcon {
|
|
10
|
+
src: string;
|
|
11
|
+
mimeType?: string;
|
|
12
|
+
sizes?: string[];
|
|
13
|
+
theme?: 'light' | 'dark';
|
|
14
|
+
}
|
|
15
|
+
interface McpCatalogItem {
|
|
16
|
+
id: string;
|
|
17
|
+
serverId: string;
|
|
18
|
+
kind: McpCapabilityKind;
|
|
19
|
+
name: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
summary: string;
|
|
22
|
+
tags?: string[];
|
|
23
|
+
risk?: McpCapabilityRisk;
|
|
24
|
+
annotations?: Record<string, unknown>;
|
|
25
|
+
cachedAt: string;
|
|
26
|
+
}
|
|
27
|
+
interface McpCapabilityDescriptor extends McpCatalogItem {
|
|
28
|
+
inputSchema?: unknown;
|
|
29
|
+
outputSchema?: unknown;
|
|
30
|
+
promptArgsSchema?: unknown;
|
|
31
|
+
uri?: string;
|
|
32
|
+
mimeType?: string;
|
|
33
|
+
/** Sanitized icon metadata (unsafe-scheme icons dropped). */
|
|
34
|
+
icons?: McpIcon[];
|
|
35
|
+
/** Tool only — `execution.taskSupport`. Absent is treated as 'forbidden'. */
|
|
36
|
+
taskSupport?: McpToolTaskSupport;
|
|
37
|
+
}
|
|
38
|
+
interface McpServerCatalogSnapshot {
|
|
39
|
+
serverId: string;
|
|
40
|
+
items: McpCatalogItem[];
|
|
41
|
+
descriptors: McpCapabilityDescriptor[];
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
}
|
|
44
|
+
interface McpCatalogSearchOptions {
|
|
45
|
+
kind?: McpCapabilityKind;
|
|
46
|
+
limit?: number;
|
|
47
|
+
}
|
|
48
|
+
declare function defaultMcpCacheDir(): string;
|
|
49
|
+
declare function createMcpCapabilityId(serverId: string, kind: McpCapabilityKind, name: string): string;
|
|
50
|
+
declare function parseMcpCapabilityId(id: string): {
|
|
51
|
+
serverId: string;
|
|
52
|
+
kind: McpCapabilityKind;
|
|
53
|
+
name: string;
|
|
54
|
+
};
|
|
55
|
+
declare function searchMcpCatalog(items: readonly McpCatalogItem[], query: string, options?: McpCatalogSearchOptions): McpCatalogItem[];
|
|
56
|
+
declare function getMcpCachePaths(cacheDir: string, serverId: string): {
|
|
57
|
+
catalogDir: string;
|
|
58
|
+
indexPath: string;
|
|
59
|
+
itemsPath: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* FEATURE_222 — MCP 2025-11-25 reverse capabilities (server→client).
|
|
64
|
+
*
|
|
65
|
+
* KodaX's MCP client historically advertised `capabilities: {}` and answered
|
|
66
|
+
* every server→client request with `-32601`. This module is the host-injected
|
|
67
|
+
* seam that lets the client actually serve the reverse capabilities — roots,
|
|
68
|
+
* elicitation, sampling (and, later, tasks).
|
|
69
|
+
*
|
|
70
|
+
* Core principle (spec MUST: "both sides only use capabilities they
|
|
71
|
+
* negotiated"): a capability is advertised in `initialize.capabilities` ONLY
|
|
72
|
+
* when its handler is injected. An absent handler stays unadvertised, so a
|
|
73
|
+
* conformant server never sends the corresponding request. `buildInitialize-
|
|
74
|
+
* Capabilities` assembles that declaration from the handlers actually present,
|
|
75
|
+
* which is what makes the feature incrementally shippable, slice by slice.
|
|
76
|
+
*/
|
|
77
|
+
/** A workspace root exposed to a server. The spec requires a `file://` URI. */
|
|
78
|
+
interface McpRoot {
|
|
79
|
+
readonly uri: string;
|
|
80
|
+
readonly name?: string;
|
|
81
|
+
}
|
|
82
|
+
/** A server-initiated elicitation request (form mode now; url mode in Slice C). */
|
|
83
|
+
interface McpElicitRequest {
|
|
84
|
+
readonly mode: 'form' | 'url';
|
|
85
|
+
/** The MCP server making the request. The host MUST show this to the user so
|
|
86
|
+
* they know who is asking (anti-phishing). Enriched by the runtime. */
|
|
87
|
+
readonly serverId?: string;
|
|
88
|
+
readonly message?: string;
|
|
89
|
+
/** form mode: a flat object of primitive properties to collect. */
|
|
90
|
+
readonly requestedSchema?: Record<string, unknown>;
|
|
91
|
+
/** url mode: the URL the user must be shown + asked to consent to. */
|
|
92
|
+
readonly url?: string;
|
|
93
|
+
/** url mode: correlation id echoed in `notifications/elicitation/complete`. */
|
|
94
|
+
readonly elicitationId?: string;
|
|
95
|
+
}
|
|
96
|
+
/** The three-state elicitation response defined by the spec. */
|
|
97
|
+
type McpElicitResult = {
|
|
98
|
+
readonly action: 'accept';
|
|
99
|
+
readonly content: Record<string, unknown>;
|
|
100
|
+
} | {
|
|
101
|
+
readonly action: 'decline';
|
|
102
|
+
} | {
|
|
103
|
+
readonly action: 'cancel';
|
|
104
|
+
};
|
|
105
|
+
/** A server-initiated sampling request (`sampling/createMessage`). */
|
|
106
|
+
interface McpSamplingRequest {
|
|
107
|
+
readonly messages: readonly unknown[];
|
|
108
|
+
readonly systemPrompt?: string;
|
|
109
|
+
readonly maxTokens?: number;
|
|
110
|
+
readonly modelPreferences?: Record<string, unknown>;
|
|
111
|
+
/** The server id asking — for the host's user-visible prompt + guardrails. */
|
|
112
|
+
readonly serverId: string;
|
|
113
|
+
}
|
|
114
|
+
/** A sampling response bridged back from the user's LLM. */
|
|
115
|
+
interface McpSamplingResult {
|
|
116
|
+
readonly role: 'assistant';
|
|
117
|
+
readonly content: {
|
|
118
|
+
readonly type: 'text';
|
|
119
|
+
readonly text: string;
|
|
120
|
+
};
|
|
121
|
+
readonly model: string;
|
|
122
|
+
readonly stopReason?: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Host-injected reverse-capability handlers. Each present handler lights up its
|
|
126
|
+
* capability; an absent one stays unadvertised (server won't ask). Handlers are
|
|
127
|
+
* provided by the host (REPL / ACP / CLI) because only it owns the workspace,
|
|
128
|
+
* the user-interaction channel, and the LLM. A headless host injects nothing
|
|
129
|
+
* and the client behaves exactly as before (all reverse requests → -32601).
|
|
130
|
+
*/
|
|
131
|
+
interface McpReverseCapabilities {
|
|
132
|
+
/** Slice A — current workspace roots (a function so it reflects live state). */
|
|
133
|
+
readonly listRoots?: () => readonly McpRoot[] | Promise<readonly McpRoot[]>;
|
|
134
|
+
/** Whether to advertise `roots.listChanged` (default false). */
|
|
135
|
+
readonly rootsListChanged?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Slice B/C — ask the user (form or url elicitation). For `mode:'url'` the
|
|
138
|
+
* host MUST show the full URL + its domain, require explicit consent, and
|
|
139
|
+
* MUST NOT auto-open the browser or expose the URL/contents to the model
|
|
140
|
+
* (anti-phishing). It resolves `accept` when the user consents to open the
|
|
141
|
+
* URL; the server later signals completion via {@link onElicitationComplete}.
|
|
142
|
+
*/
|
|
143
|
+
readonly elicit?: (request: McpElicitRequest) => Promise<McpElicitResult>;
|
|
144
|
+
/** Which elicitation modes the injected `elicit` actually supports. Defaults
|
|
145
|
+
* to form-only (url is gated on the anti-phishing handler from Slice C). */
|
|
146
|
+
readonly elicitationModes?: {
|
|
147
|
+
readonly form?: boolean;
|
|
148
|
+
readonly url?: boolean;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Slice C — the server finished a url elicitation (the user completed the
|
|
152
|
+
* external flow in their browser); the host can dismiss its waiting state.
|
|
153
|
+
* Correlated by the `elicitationId` from the original url request.
|
|
154
|
+
*/
|
|
155
|
+
readonly onElicitationComplete?: (elicitationId: string) => void;
|
|
156
|
+
/** Slice D — run a sampling request via the user's LLM. Security-sensitive:
|
|
157
|
+
* the host injects this ONLY when the user opted in, and applies guardrails. */
|
|
158
|
+
readonly sample?: (request: McpSamplingRequest) => Promise<McpSamplingResult>;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Build the `initialize.capabilities` object from the injected handlers —
|
|
162
|
+
* advertise only what we can actually handle.
|
|
163
|
+
*/
|
|
164
|
+
declare function buildInitializeCapabilities(reverse: McpReverseCapabilities | undefined): Record<string, unknown>;
|
|
165
|
+
|
|
166
|
+
interface McpServerRuntimeDiagnostics {
|
|
167
|
+
serverId: string;
|
|
168
|
+
connect: 'lazy' | 'prewarm' | 'disabled';
|
|
169
|
+
status: 'idle' | 'connecting' | 'ready' | 'error' | 'disabled';
|
|
170
|
+
resolvedTransport?: string;
|
|
171
|
+
dirty: boolean;
|
|
172
|
+
lastError?: string;
|
|
173
|
+
cachedAt?: string;
|
|
174
|
+
tools: number;
|
|
175
|
+
resources: number;
|
|
176
|
+
prompts: number;
|
|
177
|
+
}
|
|
178
|
+
declare class McpServerRuntime {
|
|
179
|
+
private readonly serverId;
|
|
180
|
+
private readonly config;
|
|
181
|
+
private readonly cacheDir;
|
|
182
|
+
/** FEATURE_222 — host-injected server→client reverse capabilities. */
|
|
183
|
+
private readonly reverse?;
|
|
184
|
+
private transport?;
|
|
185
|
+
private readonly pending;
|
|
186
|
+
/** FEATURE_222 — resolvers awaiting notifications/elicitation/complete, keyed
|
|
187
|
+
* by elicitationId (used by the url-elicitation tool-retry closure). */
|
|
188
|
+
private readonly elicitationWaiters;
|
|
189
|
+
/** Completion notifications that arrived before the host finished consent. */
|
|
190
|
+
private readonly completedElicitations;
|
|
191
|
+
private nextRequestId;
|
|
192
|
+
private initialized;
|
|
193
|
+
private connectPromise?;
|
|
194
|
+
private catalog?;
|
|
195
|
+
private serverCapabilities?;
|
|
196
|
+
private cachedHttpTransport?;
|
|
197
|
+
private diagnostics;
|
|
198
|
+
constructor(serverId: string, config: McpServerConfig, cacheDir: string,
|
|
199
|
+
/** FEATURE_222 — host-injected server→client reverse capabilities. */
|
|
200
|
+
reverse?: McpReverseCapabilities | undefined);
|
|
201
|
+
getDiagnostics(): McpServerRuntimeDiagnostics;
|
|
202
|
+
prewarmIfNeeded(): Promise<void>;
|
|
203
|
+
/** Load catalog from memory or disk only — never triggers a lazy connection. */
|
|
204
|
+
getCachedCatalog(): Promise<McpServerCatalogSnapshot | undefined>;
|
|
205
|
+
getCatalog(forceRefresh?: boolean): Promise<McpServerCatalogSnapshot>;
|
|
206
|
+
describeCapability(capabilityId: string): Promise<McpCapabilityDescriptor | undefined>;
|
|
207
|
+
callTool(name: string, args: Record<string, unknown>): Promise<{
|
|
208
|
+
content?: string;
|
|
209
|
+
structuredContent?: unknown;
|
|
210
|
+
metadata?: Record<string, unknown>;
|
|
211
|
+
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Drive a url elicitation the server asked for before a tools/call can
|
|
214
|
+
* succeed: route it to the host (anti-phishing consent UI) and, on consent,
|
|
215
|
+
* wait for the server's completion notification. Returns false when the host
|
|
216
|
+
* cannot serve url elicitation or the user did not consent.
|
|
217
|
+
*/
|
|
218
|
+
private satisfyUrlElicitation;
|
|
219
|
+
/** Resolve when the server signals the url elicitation completed, or on timeout
|
|
220
|
+
* (a premature retry is harmless — the server re-requests and the loop caps). */
|
|
221
|
+
private waitForElicitationComplete;
|
|
222
|
+
readResource(name: string, options: Record<string, unknown>): Promise<{
|
|
223
|
+
content?: string;
|
|
224
|
+
structuredContent?: unknown;
|
|
225
|
+
metadata?: Record<string, unknown>;
|
|
226
|
+
}>;
|
|
227
|
+
getPrompt(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
228
|
+
refreshCatalog(forceReconnect?: boolean): Promise<void>;
|
|
229
|
+
/** Public teardown — clears everything including the connect lock. */
|
|
230
|
+
dispose(): Promise<void>;
|
|
231
|
+
/** Internal transport teardown — does NOT clear connectPromise so the
|
|
232
|
+
* retry loop inside doConnect() can safely call it between attempts. */
|
|
233
|
+
private resetTransport;
|
|
234
|
+
private connect;
|
|
235
|
+
private doConnect;
|
|
236
|
+
/** Initial Authorization header: a static-config token, or a cached token
|
|
237
|
+
* from a prior discovery-based login. Absent → connect unauthenticated. */
|
|
238
|
+
private resolveInitialAuthHeaders;
|
|
239
|
+
private handshakeWithFramings;
|
|
240
|
+
/**
|
|
241
|
+
* FEATURE_222 — discover + interactively log in to an authenticated MCP
|
|
242
|
+
* server. The authorization URL is shown through the host's url-elicitation
|
|
243
|
+
* consent (anti-phishing; never auto-opened). Returns undefined when the host
|
|
244
|
+
* has no url-consent surface, discovery fails, or the user declines.
|
|
245
|
+
*/
|
|
246
|
+
private runOAuthLogin;
|
|
247
|
+
private listDescriptors;
|
|
248
|
+
private request;
|
|
249
|
+
private sendRequest;
|
|
250
|
+
private notify;
|
|
251
|
+
private handleMessage;
|
|
252
|
+
/** Best-effort JSON-RPC response send (server times out on its own if closed). */
|
|
253
|
+
private sendResponse;
|
|
254
|
+
/** Best-effort JSON-RPC error send. */
|
|
255
|
+
private sendError;
|
|
256
|
+
/**
|
|
257
|
+
* FEATURE_222 — handle a server→client request for an advertised reverse
|
|
258
|
+
* capability. Each slice adds a case to {@link dispatchServerRequest};
|
|
259
|
+
* anything unhandled replies -32601, and a handler that throws replies
|
|
260
|
+
* -32603 so the server never hangs.
|
|
261
|
+
*/
|
|
262
|
+
private handleServerRequest;
|
|
263
|
+
/**
|
|
264
|
+
* Route a reverse request to its handler, or return the sentinel when the
|
|
265
|
+
* method is not an advertised capability. Slices add cases here.
|
|
266
|
+
*/
|
|
267
|
+
private dispatchServerRequest;
|
|
268
|
+
private failPending;
|
|
269
|
+
private applyCatalogSnapshot;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* `McpCapabilityProvider` — implements the Layer A `CapabilityProvider`
|
|
274
|
+
* contract for an MCP server fleet.
|
|
275
|
+
*
|
|
276
|
+
* FEATURE_082 (v0.7.24): moved from
|
|
277
|
+
* `@kodax-ai/coding/src/capabilities/providers/mcp/provider.ts` to this package.
|
|
278
|
+
* The coding-specific `registerConfiguredMcpCapabilityProvider` adapter (which
|
|
279
|
+
* pulls in `KodaXExtensionRuntime`) lives in
|
|
280
|
+
* `@kodax-ai/coding/src/capabilities/providers/mcp-adapter.ts`.
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
interface McpProviderOptions {
|
|
284
|
+
cacheDir?: string;
|
|
285
|
+
/**
|
|
286
|
+
* FEATURE_222 — host-injected server→client reverse capabilities (workspace
|
|
287
|
+
* roots / elicitation / sampling), applied to every server in this provider.
|
|
288
|
+
* Omitted in headless hosts, in which case reverse requests reply -32601.
|
|
289
|
+
*/
|
|
290
|
+
reverse?: McpReverseCapabilities;
|
|
291
|
+
}
|
|
292
|
+
declare class McpCapabilityProvider implements CapabilityProvider {
|
|
293
|
+
readonly id = "mcp";
|
|
294
|
+
readonly kinds: CapabilityProvider['kinds'];
|
|
295
|
+
private readonly runtimes;
|
|
296
|
+
private readonly cacheDir;
|
|
297
|
+
/**
|
|
298
|
+
* Construct an MCP capability provider.
|
|
299
|
+
*
|
|
300
|
+
* **Cache-dir capture warning (v0.7.35.1 FEATURE_145)** — when
|
|
301
|
+
* `options.cacheDir` is omitted, this constructor resolves
|
|
302
|
+
* `defaultMcpCacheDir()` ONCE at instantiation time and threads the
|
|
303
|
+
* result into every `McpServerRuntime` it spawns. If a substrate
|
|
304
|
+
* consumer plans to redirect the agent config home via
|
|
305
|
+
* `setAgentConfigHome()` from `@kodax-ai/agent`, that call MUST happen
|
|
306
|
+
* BEFORE constructing this provider. Late calls have no effect on
|
|
307
|
+
* already-constructed runtimes.
|
|
308
|
+
*
|
|
309
|
+
* To bypass the agent-home resolver entirely, pass
|
|
310
|
+
* `options.cacheDir` explicitly — that path wins unconditionally.
|
|
311
|
+
*/
|
|
312
|
+
constructor(servers: McpServersConfig | undefined, options?: McpProviderOptions);
|
|
313
|
+
hasActiveServers(): boolean;
|
|
314
|
+
/**
|
|
315
|
+
* v0.7.42 — read-only accessor for the enabled server id list.
|
|
316
|
+
* Used by {@link McpManager} to drive popout-shape `listServers /
|
|
317
|
+
* startServer / stopServer / logs / tools` operations without
|
|
318
|
+
* exposing the internal runtimes Map.
|
|
319
|
+
*/
|
|
320
|
+
getServerIds(): readonly string[];
|
|
321
|
+
/**
|
|
322
|
+
* v0.7.42 — single-server runtime accessor. Returns `undefined`
|
|
323
|
+
* for unknown / disabled servers. Use {@link McpManager} for
|
|
324
|
+
* higher-level lifecycle control.
|
|
325
|
+
*/
|
|
326
|
+
getRuntime(serverId: string): McpServerRuntime | undefined;
|
|
327
|
+
prewarm(): Promise<void>;
|
|
328
|
+
search(query: string, options?: {
|
|
329
|
+
kind?: CapabilityKind;
|
|
330
|
+
limit?: number;
|
|
331
|
+
server?: string;
|
|
332
|
+
}): Promise<unknown[]>;
|
|
333
|
+
describe(id: string): Promise<unknown>;
|
|
334
|
+
execute(id: string, input: Record<string, unknown>): Promise<CapabilityResult>;
|
|
335
|
+
read(id: string, options?: Record<string, unknown>): Promise<CapabilityResult>;
|
|
336
|
+
getPrompt(id: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
337
|
+
getPromptContext(): Promise<string | undefined>;
|
|
338
|
+
getDiagnostics(): Record<string, unknown> | undefined;
|
|
339
|
+
refresh(): Promise<void>;
|
|
340
|
+
dispose(): Promise<void>;
|
|
341
|
+
private collectCatalogItems;
|
|
342
|
+
private listServerDiagnostics;
|
|
343
|
+
private requireRuntime;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
interface McpTransportEvents {
|
|
347
|
+
/** Called with a complete JSON-RPC message (raw JSON string). */
|
|
348
|
+
onMessage(raw: string): void;
|
|
349
|
+
onError(error: Error): void;
|
|
350
|
+
onClose(reason: string): void;
|
|
351
|
+
}
|
|
352
|
+
interface McpTransport {
|
|
353
|
+
open(events: McpTransportEvents): Promise<void>;
|
|
354
|
+
/** Send a JSON string. The transport handles framing. */
|
|
355
|
+
send(json: string): Promise<void>;
|
|
356
|
+
setProtocolVersion?(version: string | undefined): void;
|
|
357
|
+
close(): Promise<void>;
|
|
358
|
+
readonly connected: boolean;
|
|
359
|
+
/** Effective transport after auto-detection (diagnostics only). */
|
|
360
|
+
readonly resolvedTransport?: string;
|
|
361
|
+
}
|
|
362
|
+
declare class McpExpiredSessionError extends Error {
|
|
363
|
+
constructor();
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* FEATURE_222 — the server demanded OAuth (401) or a stronger scope (403). It
|
|
367
|
+
* carries the `WWW-Authenticate` header so the connect flow can discover the
|
|
368
|
+
* authorization server (RFC 9728 pointer) or read the step-up scope.
|
|
369
|
+
*/
|
|
370
|
+
declare class McpAuthRequiredError extends Error {
|
|
371
|
+
readonly status: number;
|
|
372
|
+
readonly wwwAuthenticate?: string | undefined;
|
|
373
|
+
constructor(status: number, wwwAuthenticate?: string | undefined);
|
|
374
|
+
}
|
|
375
|
+
type StdioFraming = 'content-length' | 'ndjson';
|
|
376
|
+
interface McpTransportOptions {
|
|
377
|
+
stdioFraming?: StdioFraming;
|
|
378
|
+
httpResolvedTransport?: 'streamable-http' | 'sse';
|
|
379
|
+
}
|
|
380
|
+
declare function createMcpTransport(config: McpServerConfig, options?: McpTransportOptions): McpTransport;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* FEATURE_222 — MCP OAuth discovery (server→authorization-server resolution).
|
|
384
|
+
*
|
|
385
|
+
* The modern MCP auth flow does NOT require the user to hand-configure
|
|
386
|
+
* authorization/token endpoints. Instead the client discovers them at runtime:
|
|
387
|
+
*
|
|
388
|
+
* 401 WWW-Authenticate (resource_metadata=...) [RFC 9728 pointer]
|
|
389
|
+
* → GET /.well-known/oauth-protected-resource [RFC 9728 PRM]
|
|
390
|
+
* → authorization_servers[0]
|
|
391
|
+
* → GET /.well-known/oauth-authorization-server [RFC 8414]
|
|
392
|
+
* (fallback /.well-known/openid-configuration) [OIDC]
|
|
393
|
+
* → authorization_endpoint / token_endpoint / registration_endpoint
|
|
394
|
+
*
|
|
395
|
+
* This module is the pure-HTTP discovery layer (no PKCE, no browser, no token
|
|
396
|
+
* storage — those compose on top). The path-aware fallback ordering mirrors
|
|
397
|
+
* Claude Code's MCP client so KodaX resolves the same servers it does.
|
|
398
|
+
*/
|
|
399
|
+
interface WwwAuthenticateChallenge {
|
|
400
|
+
readonly scheme: string;
|
|
401
|
+
readonly params: Record<string, string>;
|
|
402
|
+
}
|
|
403
|
+
/** The RFC 9728 `resource_metadata` URL a 401 challenge points at, if any. */
|
|
404
|
+
declare function extractResourceMetadataUrl(header: string | undefined): string | undefined;
|
|
405
|
+
/**
|
|
406
|
+
* For a 403 `error="insufficient_scope"` challenge, the `scope` the server now
|
|
407
|
+
* requires (space-separated). Undefined when the challenge is not a step-up.
|
|
408
|
+
*/
|
|
409
|
+
declare function extractInsufficientScope(header: string | undefined): string | undefined;
|
|
410
|
+
interface ProtectedResourceMetadata {
|
|
411
|
+
readonly authorizationServers: string[];
|
|
412
|
+
readonly resource?: string;
|
|
413
|
+
readonly scopesSupported?: string[];
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Discover the protected-resource metadata for an MCP server URL. Prefers the
|
|
417
|
+
* `resource_metadata` URL from the 401 challenge; otherwise probes the
|
|
418
|
+
* path-specific then root `/.well-known/oauth-protected-resource`.
|
|
419
|
+
*/
|
|
420
|
+
declare function discoverProtectedResourceMetadata(options: {
|
|
421
|
+
serverUrl: string;
|
|
422
|
+
resourceMetadataUrl?: string;
|
|
423
|
+
fetchFn?: typeof fetch;
|
|
424
|
+
}): Promise<ProtectedResourceMetadata | undefined>;
|
|
425
|
+
interface AuthorizationServerMetadata {
|
|
426
|
+
readonly issuer?: string;
|
|
427
|
+
readonly authorizationEndpoint: string;
|
|
428
|
+
readonly tokenEndpoint: string;
|
|
429
|
+
readonly registrationEndpoint?: string;
|
|
430
|
+
readonly scopesSupported?: string[];
|
|
431
|
+
readonly codeChallengeMethodsSupported?: string[];
|
|
432
|
+
}
|
|
433
|
+
/** Discover an authorization server's endpoints. The first candidate returning
|
|
434
|
+
* both an authorization + token endpoint wins. */
|
|
435
|
+
declare function discoverAuthorizationServerMetadata(options: {
|
|
436
|
+
authorizationServerUrl: string;
|
|
437
|
+
fetchFn?: typeof fetch;
|
|
438
|
+
}): Promise<AuthorizationServerMetadata | undefined>;
|
|
439
|
+
/**
|
|
440
|
+
* End-to-end endpoint discovery: PRM → first authorization server → AS metadata.
|
|
441
|
+
* Returns the resolved endpoints plus the resource indicator (RFC 8707) and the
|
|
442
|
+
* scopes the resource advertises. Undefined when discovery fails at any step.
|
|
443
|
+
*/
|
|
444
|
+
interface DiscoveredOAuthEndpoints extends AuthorizationServerMetadata {
|
|
445
|
+
/** RFC 8707 resource indicator (the MCP server's canonical URL). */
|
|
446
|
+
readonly resource?: string;
|
|
447
|
+
/** Scopes from the protected-resource document, when the AS omits them. */
|
|
448
|
+
readonly resourceScopesSupported?: string[];
|
|
449
|
+
}
|
|
450
|
+
declare function discoverOAuthEndpoints(options: {
|
|
451
|
+
serverUrl: string;
|
|
452
|
+
resourceMetadataUrl?: string;
|
|
453
|
+
fetchFn?: typeof fetch;
|
|
454
|
+
}): Promise<DiscoveredOAuthEndpoints | undefined>;
|
|
455
|
+
|
|
456
|
+
interface OAuthToken {
|
|
457
|
+
readonly accessToken: string;
|
|
458
|
+
readonly refreshToken?: string;
|
|
459
|
+
readonly expiresAt?: number;
|
|
460
|
+
readonly tokenType?: string;
|
|
461
|
+
readonly scope?: string;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** A dynamically-registered (or pre-configured) OAuth client. */
|
|
465
|
+
interface OAuthClientInfo {
|
|
466
|
+
readonly clientId: string;
|
|
467
|
+
readonly clientSecret?: string;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* RFC 7591 Dynamic Client Registration. Registers a public client (PKCE, no
|
|
471
|
+
* secret) for the loopback redirect and returns the issued client_id.
|
|
472
|
+
*/
|
|
473
|
+
declare function registerOAuthClient(options: {
|
|
474
|
+
registrationEndpoint: string;
|
|
475
|
+
redirectUri: string;
|
|
476
|
+
clientName: string;
|
|
477
|
+
scope?: string;
|
|
478
|
+
fetchFn?: typeof fetch;
|
|
479
|
+
}): Promise<OAuthClientInfo>;
|
|
480
|
+
/**
|
|
481
|
+
* The host's consent gate for a login. Receives the authorization URL and must
|
|
482
|
+
* return true to proceed (the user will open it in their browser). Returning
|
|
483
|
+
* false aborts the login. KodaX never auto-opens the URL.
|
|
484
|
+
*/
|
|
485
|
+
type OAuthLoginConsent = (authorizationUrl: string) => Promise<boolean>;
|
|
486
|
+
interface PerformOAuthLoginOptions {
|
|
487
|
+
serverId: string;
|
|
488
|
+
/** The MCP server URL (resource) we are authenticating to. */
|
|
489
|
+
serverUrl: string;
|
|
490
|
+
/** resource_metadata URL from a 401 challenge, if one was seen. */
|
|
491
|
+
resourceMetadataUrl?: string;
|
|
492
|
+
/** A pre-configured client_id (skips dynamic registration). */
|
|
493
|
+
configuredClientId?: string;
|
|
494
|
+
/** Pre-configured scopes (override discovery). */
|
|
495
|
+
configuredScopes?: readonly string[];
|
|
496
|
+
/** For an insufficient_scope step-up: the elevated scope to request. */
|
|
497
|
+
stepUpScope?: string;
|
|
498
|
+
/** Host consent gate (anti-phishing) — receives the authorization URL. */
|
|
499
|
+
consent: OAuthLoginConsent;
|
|
500
|
+
/** Loopback callback port (defaults to {@link DEFAULT_OAUTH_REDIRECT_PORT}). */
|
|
501
|
+
redirectPort?: number;
|
|
502
|
+
fetchFn?: typeof fetch;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Run the full interactive login and persist the resulting token. Returns the
|
|
506
|
+
* token, or undefined when discovery fails, no client can be obtained, or the
|
|
507
|
+
* user declines consent. Throws only on a hard protocol error (bad exchange).
|
|
508
|
+
*/
|
|
509
|
+
declare function performOAuthLogin(options: PerformOAuthLoginOptions): Promise<OAuthToken | undefined>;
|
|
510
|
+
/**
|
|
511
|
+
* Return a still-valid cached token for a server, or undefined. (Discovery-based
|
|
512
|
+
* refresh on expiry is driven by the connect flow, which knows the endpoints.)
|
|
513
|
+
*/
|
|
514
|
+
declare function loadValidToken(serverId: string): Promise<OAuthToken | undefined>;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* McpManager — v0.7.42 (extends FEATURE_186 MCP popout surface).
|
|
518
|
+
*
|
|
519
|
+
* `McpCapabilityProvider` (`./provider.ts`) is the capability-provider-
|
|
520
|
+
* shaped object KodaX uses internally to plug MCP into the agent runtime
|
|
521
|
+
* — its public methods are `search` / `describe` / `execute` / `read` /
|
|
522
|
+
* `getPrompt` / `getDiagnostics` / `refresh` / `dispose`, which is the
|
|
523
|
+
* shape the substrate consumes but NOT the shape a popout UI wants.
|
|
524
|
+
*
|
|
525
|
+
* KodaX Space reported that `@kodax-ai/kodax/mcp` only exposed "types +
|
|
526
|
+
* helpers, no manager-shape API" — concretely they wanted a thin
|
|
527
|
+
* `listServers / startServer / stopServer / getServerLogs / listTools`
|
|
528
|
+
* surface to drive a popout panel:
|
|
529
|
+
*
|
|
530
|
+
* - One row per configured MCP server with live status
|
|
531
|
+
* - "Start" / "Stop" buttons that map to refreshCatalog(true) / dispose
|
|
532
|
+
* - Server logs (last error + status) so users can debug failures
|
|
533
|
+
* - Per-server tool list (filtered descriptors) for the "what does
|
|
534
|
+
* this MCP server expose" pane
|
|
535
|
+
*
|
|
536
|
+
* `McpManager` is the thin wrapper. It owns one `McpCapabilityProvider`
|
|
537
|
+
* instance internally, so all the existing lifecycle invariants
|
|
538
|
+
* (cache-dir capture, refresh, dispose, server-config validation) are
|
|
539
|
+
* preserved verbatim. The capability-provider-shaped methods stay
|
|
540
|
+
* available via `manager.provider()` as an escape hatch.
|
|
541
|
+
*
|
|
542
|
+
* Trust boundary: same as the rest of FEATURE_186 — KodaX is a
|
|
543
|
+
* single-user CLI, last-write-wins on the server-config-vs-active-
|
|
544
|
+
* runtime path; a Space popout that swaps configs hot would still need
|
|
545
|
+
* to construct a fresh `McpManager` (or call `dispose()` then
|
|
546
|
+
* `createMcpManager` again) to pick up the new wire.
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
interface McpServerStatus {
|
|
550
|
+
readonly serverId: string;
|
|
551
|
+
readonly config: McpServerConfig;
|
|
552
|
+
readonly connect: McpConnectMode;
|
|
553
|
+
readonly status: McpServerRuntimeDiagnostics['status'];
|
|
554
|
+
readonly resolvedTransport?: string;
|
|
555
|
+
readonly tools: number;
|
|
556
|
+
readonly resources: number;
|
|
557
|
+
readonly prompts: number;
|
|
558
|
+
readonly dirty: boolean;
|
|
559
|
+
readonly cachedAt?: string;
|
|
560
|
+
readonly lastError?: string;
|
|
561
|
+
}
|
|
562
|
+
interface McpServerLogs {
|
|
563
|
+
readonly serverId: string;
|
|
564
|
+
readonly status: McpServerRuntimeDiagnostics['status'];
|
|
565
|
+
readonly connect: McpConnectMode;
|
|
566
|
+
readonly resolvedTransport?: string;
|
|
567
|
+
readonly lastError?: string;
|
|
568
|
+
readonly cachedAt?: string;
|
|
569
|
+
}
|
|
570
|
+
interface McpServerToolList {
|
|
571
|
+
readonly serverId: string;
|
|
572
|
+
readonly tools: readonly McpCapabilityDescriptor[];
|
|
573
|
+
readonly cachedAt?: string;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Full catalog snapshot for a server — tools + resources + prompts.
|
|
577
|
+
* Use {@link McpManager.getCatalog} when the popout needs to render
|
|
578
|
+
* all three capability kinds (not just tools).
|
|
579
|
+
*
|
|
580
|
+
* `cachedAt` matches the naming used by {@link McpServerStatus},
|
|
581
|
+
* {@link McpServerLogs}, and {@link McpServerToolList} for consistency
|
|
582
|
+
* across the manager surface (all are renames of the underlying
|
|
583
|
+
* `McpServerCatalogSnapshot.updatedAt` field).
|
|
584
|
+
*/
|
|
585
|
+
interface McpServerCatalog {
|
|
586
|
+
readonly serverId: string;
|
|
587
|
+
readonly items: readonly McpCatalogItem[];
|
|
588
|
+
readonly descriptors: readonly McpCapabilityDescriptor[];
|
|
589
|
+
readonly cachedAt: string;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Manager-shape facade over {@link McpCapabilityProvider}. Construct
|
|
593
|
+
* via the {@link createMcpManager} factory or `new McpManager(...)`
|
|
594
|
+
* directly.
|
|
595
|
+
*/
|
|
596
|
+
declare class McpManager {
|
|
597
|
+
private readonly capabilityProvider;
|
|
598
|
+
private readonly serversConfig;
|
|
599
|
+
constructor(servers: McpServersConfig | undefined, options?: McpProviderOptions);
|
|
600
|
+
/**
|
|
601
|
+
* Escape hatch — returns the underlying {@link McpCapabilityProvider}
|
|
602
|
+
* for callers that need the search / describe / execute / read /
|
|
603
|
+
* getPrompt API (e.g. embedding into a custom agent runtime).
|
|
604
|
+
*/
|
|
605
|
+
provider(): McpCapabilityProvider;
|
|
606
|
+
/**
|
|
607
|
+
* One status row per configured server (lazy / prewarm / disabled
|
|
608
|
+
* all included). Returned objects are plain readonly snapshots —
|
|
609
|
+
* mutating them does NOT affect runtime state.
|
|
610
|
+
*/
|
|
611
|
+
listServers(): McpServerStatus[];
|
|
612
|
+
/**
|
|
613
|
+
* Force a connection + catalog refresh for `serverId`. Returns the
|
|
614
|
+
* post-start status row. Throws if `serverId` is not configured.
|
|
615
|
+
*
|
|
616
|
+
* For lazy servers, this is the explicit "connect now" trigger —
|
|
617
|
+
* useful when a popout user clicks "Start" before any tool call has
|
|
618
|
+
* forced the lazy connection.
|
|
619
|
+
*/
|
|
620
|
+
startServer(serverId: string): Promise<McpServerStatus>;
|
|
621
|
+
/**
|
|
622
|
+
* Disconnect `serverId` — closes the transport, drops the pending
|
|
623
|
+
* request queue, but keeps the server in the config so a subsequent
|
|
624
|
+
* `startServer` / `listTools` can reconnect. Returns the post-stop
|
|
625
|
+
* status (`status: 'idle'`).
|
|
626
|
+
*/
|
|
627
|
+
stopServer(serverId: string): Promise<McpServerStatus>;
|
|
628
|
+
/**
|
|
629
|
+
* Return the most recent runtime diagnostic envelope for `serverId`
|
|
630
|
+
* — status, last error, last cached timestamp. Designed as the data
|
|
631
|
+
* source for a popout "Logs" pane.
|
|
632
|
+
*
|
|
633
|
+
* Logs API is intentionally conservative in v0.7.42: only the last
|
|
634
|
+
* error message + status are exposed. A future iteration may add a
|
|
635
|
+
* ring buffer of recent events; the field shape will extend (add
|
|
636
|
+
* fields), never break (rename / remove).
|
|
637
|
+
*/
|
|
638
|
+
getServerLogs(serverId: string): McpServerLogs;
|
|
639
|
+
/**
|
|
640
|
+
* Return the tool descriptors for `serverId`. Triggers a lazy
|
|
641
|
+
* connect + catalog fetch if the catalog has not yet been built;
|
|
642
|
+
* pass `{ forceRefresh: true }` to force a fresh catalog regardless
|
|
643
|
+
* of cache state.
|
|
644
|
+
*
|
|
645
|
+
* Only `kind === 'tool'` descriptors are returned (filters out
|
|
646
|
+
* resources + prompts so popout consumers can render a clean
|
|
647
|
+
* "tools" table). Use the underlying `provider().describe(id)` for
|
|
648
|
+
* full descriptor introspection including resources + prompts.
|
|
649
|
+
*/
|
|
650
|
+
listTools(serverId: string, options?: {
|
|
651
|
+
forceRefresh?: boolean;
|
|
652
|
+
}): Promise<McpServerToolList>;
|
|
653
|
+
/**
|
|
654
|
+
* Return the full catalog snapshot for `serverId` — every tool,
|
|
655
|
+
* resource, and prompt the server exposes — plus lightweight catalog
|
|
656
|
+
* items for menu rendering. `listTools` is the tools-only fast path;
|
|
657
|
+
* use this when the popout needs to render resources / prompts panes
|
|
658
|
+
* alongside tools.
|
|
659
|
+
*
|
|
660
|
+
* Triggers a lazy connect + catalog fetch if the catalog has not yet
|
|
661
|
+
* been built; pass `{ forceRefresh: true }` to force a fresh catalog
|
|
662
|
+
* regardless of cache state.
|
|
663
|
+
*/
|
|
664
|
+
getCatalog(serverId: string, options?: {
|
|
665
|
+
forceRefresh?: boolean;
|
|
666
|
+
}): Promise<McpServerCatalog>;
|
|
667
|
+
/**
|
|
668
|
+
* Dispose all runtimes. After calling, the manager is no longer
|
|
669
|
+
* usable for `startServer` / `listTools` (they would reconnect, but
|
|
670
|
+
* the consumer should construct a fresh manager instead).
|
|
671
|
+
*/
|
|
672
|
+
dispose(): Promise<void>;
|
|
673
|
+
/** v0.7.42 — escape hatch for advanced uses; usually consumers use the typed methods above. */
|
|
674
|
+
search(query: string, options?: {
|
|
675
|
+
kind?: CapabilityKind;
|
|
676
|
+
limit?: number;
|
|
677
|
+
server?: string;
|
|
678
|
+
}): Promise<readonly McpCatalogItem[]>;
|
|
679
|
+
/** v0.7.42 — escape hatch for advanced uses; usually consumers use {@link listTools}. */
|
|
680
|
+
describe(id: string): Promise<McpCapabilityDescriptor | undefined>;
|
|
681
|
+
/** v0.7.42 — invoke a tool by capability id (`mcp://<serverId>/<kind>/<name>`). */
|
|
682
|
+
execute(id: string, input: Record<string, unknown>): Promise<CapabilityResult>;
|
|
683
|
+
/** v0.7.42 — read a resource by capability id. */
|
|
684
|
+
read(id: string, options?: Record<string, unknown>): Promise<CapabilityResult>;
|
|
685
|
+
private requireRuntime;
|
|
686
|
+
private buildStatus;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Convenience factory matching the rest of the FEATURE_186 surface
|
|
690
|
+
* naming (`createSessionControl`, etc.). Equivalent to
|
|
691
|
+
* `new McpManager(servers, options)`.
|
|
692
|
+
*/
|
|
693
|
+
declare function createMcpManager(servers: McpServersConfig | undefined, options?: McpProviderOptions): McpManager;
|
|
694
|
+
|
|
695
|
+
export { buildInitializeCapabilities as C, createMcpCapabilityId as E, createMcpManager as F, createMcpTransport as G, defaultMcpCacheDir as H, discoverAuthorizationServerMetadata as I, discoverOAuthEndpoints as J, discoverProtectedResourceMetadata as K, extractInsufficientScope as L, McpAuthRequiredError as M, extractResourceMetadataUrl as N, getMcpCachePaths as Q, loadValidToken as R, parseMcpCapabilityId as S, performOAuthLogin as T, registerOAuthClient as U, searchMcpCatalog as V, McpCapabilityProvider as c, McpExpiredSessionError as h, McpManager as j, McpServerRuntime as s };
|
|
696
|
+
export type { AuthorizationServerMetadata as A, ProtectedResourceMetadata as B, DiscoveredOAuthEndpoints as D, OAuthClientInfo as O, PerformOAuthLoginOptions as P, WwwAuthenticateChallenge as W, McpCapabilityDescriptor as a, McpCapabilityKind as b, McpCapabilityRisk as d, McpCatalogItem as e, McpElicitRequest as f, McpElicitResult as g, McpIcon as i, McpProviderOptions as k, McpReverseCapabilities as l, McpRoot as m, McpSamplingRequest as n, McpSamplingResult as o, McpServerCatalog as p, McpServerCatalogSnapshot as q, McpServerLogs as r, McpServerRuntimeDiagnostics as t, McpServerStatus as u, McpServerToolList as v, McpToolTaskSupport as w, McpTransport as x, McpTransportEvents as y, OAuthLoginConsent as z };
|