@fitchmultz/pi-mcp-adapter 8.0.1 → 8.0.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +3 -3
  3. package/dist/app-bridge.bundle.js +13 -13
  4. package/dist/client-operations.d.ts +5 -0
  5. package/dist/client-operations.js +19 -0
  6. package/dist/commands.d.ts +1 -1
  7. package/dist/commands.js +3 -1
  8. package/dist/connection-runtime.d.ts +503 -0
  9. package/dist/connection-runtime.js +98 -0
  10. package/dist/direct-tools.js +1 -1
  11. package/dist/host-html-template.js +24 -12
  12. package/dist/index.js +36 -29
  13. package/dist/init.d.ts +1 -1
  14. package/dist/init.js +66 -38
  15. package/dist/lifecycle.d.ts +1 -1
  16. package/dist/lifecycle.js +1 -1
  17. package/dist/mcp-auth-flow.d.ts +2 -43
  18. package/dist/mcp-auth-flow.js +3 -138
  19. package/dist/mcp-callback-server.js +1 -1
  20. package/dist/mcp-code.d.ts +0 -1
  21. package/dist/mcp-code.js +20 -7
  22. package/dist/mcp-oauth-callback-config.d.ts +8 -0
  23. package/dist/mcp-oauth-callback-config.js +28 -0
  24. package/dist/mcp-oauth-provider.d.ts +1 -8
  25. package/dist/mcp-oauth-provider.js +2 -28
  26. package/dist/mcp-oauth-runtime.d.ts +83 -0
  27. package/dist/mcp-oauth-runtime.js +145 -0
  28. package/dist/mcp-output-guard.d.ts +1 -1
  29. package/dist/mcp-output-guard.js +5 -108
  30. package/dist/mcp-output-preview.d.ts +29 -0
  31. package/dist/mcp-output-preview.js +220 -0
  32. package/dist/mcp-panel.js +1 -2
  33. package/dist/mcp-script-worker.mjs +14 -2
  34. package/dist/metadata-cache.d.ts +1 -1
  35. package/dist/metadata-cache.js +56 -14
  36. package/dist/plain-result-reader.d.ts +7 -0
  37. package/dist/plain-result-reader.js +201 -0
  38. package/dist/prompts.js +1 -1
  39. package/dist/proxy-modes.d.ts +1 -1
  40. package/dist/proxy-modes.js +14 -5
  41. package/dist/public-types.d.ts +2 -0
  42. package/dist/public-types.js +2 -0
  43. package/dist/resource-tools.d.ts +0 -1
  44. package/dist/resource-tools.js +0 -13
  45. package/dist/server-manager.d.ts +4 -4
  46. package/dist/server-manager.js +25 -125
  47. package/dist/tool-loader.js +10 -4
  48. package/dist/tool-metadata.js +20 -3
  49. package/dist/tool-result-renderer.d.ts +1 -1
  50. package/dist/tool-result-renderer.js +10 -3
  51. package/dist/types.d.ts +1 -1
  52. package/dist/types.js +0 -3
  53. package/dist/ui-message-history.js +3 -2
  54. package/dist/ui-resource-handler.d.ts +2 -1
  55. package/dist/ui-resource-handler.js +4 -3
  56. package/dist/ui-server.js +2 -1
  57. package/dist/ui-session.js +2 -1
  58. package/dist/utils.d.ts +1 -0
  59. package/dist/utils.js +1 -0
  60. package/package.json +7 -7
@@ -0,0 +1,5 @@
1
+ import type { Client } from "@modelcontextprotocol/client";
2
+ export type ClientOperation = "request/refresh" | "sampling callback" | "elicitation callback" | "subscription";
3
+ export declare const clientOperations: WeakMap<Client, Map<Promise<unknown>, ClientOperation>>;
4
+ export declare function drainClientCallbacks(client: Client): Promise<void>;
5
+ export declare function drainClientOperations(client: Client): Promise<void>;
@@ -0,0 +1,19 @@
1
+ export const clientOperations = new WeakMap();
2
+ export async function drainClientCallbacks(client) {
3
+ for (;;) {
4
+ const pending = [...(clientOperations.get(client) ?? [])]
5
+ .filter(([, kind]) => kind === "sampling callback" || kind === "elicitation callback")
6
+ .map(([operation]) => operation);
7
+ if (!pending.length)
8
+ return;
9
+ await Promise.allSettled(pending);
10
+ }
11
+ }
12
+ export async function drainClientOperations(client) {
13
+ for (;;) {
14
+ const pending = [...(clientOperations.get(client)?.keys() ?? [])];
15
+ if (!pending.length)
16
+ return;
17
+ await Promise.allSettled(pending);
18
+ }
19
+ }
@@ -1,7 +1,7 @@
1
1
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import type { McpExtensionState } from "./state.ts";
3
3
  import { type McpAuthResult, type McpConfig } from "./types.ts";
4
- import { type McpOAuthRuntime } from "./mcp-auth-flow.ts";
4
+ import { type McpOAuthRuntime } from "./mcp-oauth-runtime.ts";
5
5
  export declare function showStatus(state: McpExtensionState, ctx: ExtensionContext): Promise<void>;
6
6
  export declare function showPrompts(state: McpExtensionState, ctx: ExtensionContext): Promise<void>;
7
7
  export declare function showTools(state: McpExtensionState, ctx: ExtensionContext): Promise<void>;
package/dist/commands.js CHANGED
@@ -3,7 +3,7 @@ import { ensureCompatibilityImports, getMcpDiscoverySummary, getProjectConfigPat
3
3
  import { markKeepAliveAfterConnect, notifyToolMetadataUpdated, updateMetadataCache, updateStatusBar, getFailureAgeSeconds, getFailureMessage, clearFailure, recordFailure } from "./init.js";
4
4
  import { loadMetadataCache, reconstructPromptMetadata } from "./metadata-cache.js";
5
5
  import { buildToolMetadata } from "./tool-metadata.js";
6
- import { supportsOAuth, authenticate, removeAuth } from "./mcp-auth-flow.js";
6
+ import { supportsOAuth } from "./mcp-oauth-runtime.js";
7
7
  import { getAuthStorageOptions, inspectAuthForUrl } from "./mcp-auth.js";
8
8
  import { loadOnboardingState, markSetupCompleted as persistSetupCompleted, markSharedConfigHintShown } from "./onboarding-state.js";
9
9
  import { openPath, resolveServerUrl, sanitizeTerminalText } from "./utils.js";
@@ -229,6 +229,7 @@ export async function authenticateServer(serverName, config, ctx, signal, runtim
229
229
  }
230
230
  ui.setStatus("mcp-auth", `Authenticating ${serverName}...`);
231
231
  const authStorageOptions = getAuthStorageOptions(config.settings?.oauthDir, cwd);
232
+ const { authenticate } = await import("./mcp-auth-flow.js");
232
233
  const status = await authenticate(serverName, serverUrl, definition, {
233
234
  ...(authStorageOptions.baseDir ? { authStorageOptions } : {}),
234
235
  onAuthorizationUrl: (authorizationUrl) => {
@@ -272,6 +273,7 @@ export async function logoutServer(serverName, state, ctx) {
272
273
  }
273
274
  const signal = state.owner?.signal;
274
275
  try {
276
+ const { removeAuth } = await import("./mcp-auth-flow.js");
275
277
  await removeAuth(serverName, { authStorageOptions: state.authStorageOptions, signal, runtime: state.oauthRuntime });
276
278
  }
277
279
  catch (error) {
@@ -0,0 +1,503 @@
1
+ import { Client } from "@modelcontextprotocol/client";
2
+ import type { McpOAuthProvider } from "./mcp-oauth-provider.ts";
3
+ export declare class ManagedClient extends Client {
4
+ serverName: string;
5
+ oauthProvider: McpOAuthProvider | undefined;
6
+ private own;
7
+ ownNative<T>(run: () => Promise<T>): Promise<T>;
8
+ ownSend(run: () => Promise<void>): Promise<void>;
9
+ ownCallback<T>(kind: "sampling callback" | "elicitation callback", run: () => Promise<T>): Promise<T>;
10
+ private track;
11
+ callTool(...args: Parameters<Client["callTool"]>): Promise<{
12
+ [x: string]: unknown;
13
+ _meta?: {
14
+ [x: string]: unknown;
15
+ "io.modelcontextprotocol/serverInfo"?: {
16
+ version: string;
17
+ websiteUrl?: string | undefined;
18
+ description?: string | undefined;
19
+ icons?: {
20
+ src: string;
21
+ mimeType?: string | undefined;
22
+ sizes?: string[] | undefined;
23
+ theme?: "dark" | "light" | undefined;
24
+ }[] | undefined;
25
+ name: string;
26
+ title?: string | undefined;
27
+ } | undefined;
28
+ } | undefined;
29
+ content: ({
30
+ type: "text";
31
+ text: string;
32
+ annotations?: {
33
+ audience?: ("assistant" | "user")[] | undefined;
34
+ priority?: number | undefined;
35
+ lastModified?: string | undefined;
36
+ } | undefined;
37
+ _meta?: {
38
+ [x: string]: unknown;
39
+ } | undefined;
40
+ } | {
41
+ type: "image";
42
+ data: string;
43
+ mimeType: string;
44
+ annotations?: {
45
+ audience?: ("assistant" | "user")[] | undefined;
46
+ priority?: number | undefined;
47
+ lastModified?: string | undefined;
48
+ } | undefined;
49
+ _meta?: {
50
+ [x: string]: unknown;
51
+ } | undefined;
52
+ } | {
53
+ type: "audio";
54
+ data: string;
55
+ mimeType: string;
56
+ annotations?: {
57
+ audience?: ("assistant" | "user")[] | undefined;
58
+ priority?: number | undefined;
59
+ lastModified?: string | undefined;
60
+ } | undefined;
61
+ _meta?: {
62
+ [x: string]: unknown;
63
+ } | undefined;
64
+ } | {
65
+ uri: string;
66
+ description?: string | undefined;
67
+ mimeType?: string | undefined;
68
+ size?: number | undefined;
69
+ annotations?: {
70
+ audience?: ("assistant" | "user")[] | undefined;
71
+ priority?: number | undefined;
72
+ lastModified?: string | undefined;
73
+ } | undefined;
74
+ _meta?: {
75
+ [x: string]: unknown;
76
+ } | undefined;
77
+ icons?: {
78
+ src: string;
79
+ mimeType?: string | undefined;
80
+ sizes?: string[] | undefined;
81
+ theme?: "dark" | "light" | undefined;
82
+ }[] | undefined;
83
+ name: string;
84
+ title?: string | undefined;
85
+ type: "resource_link";
86
+ } | {
87
+ type: "resource";
88
+ resource: {
89
+ uri: string;
90
+ mimeType?: string | undefined;
91
+ _meta?: {
92
+ [x: string]: unknown;
93
+ } | undefined;
94
+ text: string;
95
+ } | {
96
+ uri: string;
97
+ mimeType?: string | undefined;
98
+ _meta?: {
99
+ [x: string]: unknown;
100
+ } | undefined;
101
+ blob: string;
102
+ };
103
+ annotations?: {
104
+ audience?: ("assistant" | "user")[] | undefined;
105
+ priority?: number | undefined;
106
+ lastModified?: string | undefined;
107
+ } | undefined;
108
+ _meta?: {
109
+ [x: string]: unknown;
110
+ } | undefined;
111
+ })[];
112
+ structuredContent?: unknown;
113
+ isError?: boolean | undefined;
114
+ }>;
115
+ readResource(...args: Parameters<Client["readResource"]>): Promise<{
116
+ [x: string]: unknown;
117
+ _meta?: {
118
+ [x: string]: unknown;
119
+ "io.modelcontextprotocol/serverInfo"?: {
120
+ version: string;
121
+ websiteUrl?: string | undefined;
122
+ description?: string | undefined;
123
+ icons?: {
124
+ src: string;
125
+ mimeType?: string | undefined;
126
+ sizes?: string[] | undefined;
127
+ theme?: "dark" | "light" | undefined;
128
+ }[] | undefined;
129
+ name: string;
130
+ title?: string | undefined;
131
+ } | undefined;
132
+ } | undefined;
133
+ contents: ({
134
+ uri: string;
135
+ mimeType?: string | undefined;
136
+ _meta?: {
137
+ [x: string]: unknown;
138
+ } | undefined;
139
+ text: string;
140
+ } | {
141
+ uri: string;
142
+ mimeType?: string | undefined;
143
+ _meta?: {
144
+ [x: string]: unknown;
145
+ } | undefined;
146
+ blob: string;
147
+ })[];
148
+ }>;
149
+ getPrompt(...args: Parameters<Client["getPrompt"]>): Promise<{
150
+ [x: string]: unknown;
151
+ _meta?: {
152
+ [x: string]: unknown;
153
+ "io.modelcontextprotocol/serverInfo"?: {
154
+ version: string;
155
+ websiteUrl?: string | undefined;
156
+ description?: string | undefined;
157
+ icons?: {
158
+ src: string;
159
+ mimeType?: string | undefined;
160
+ sizes?: string[] | undefined;
161
+ theme?: "dark" | "light" | undefined;
162
+ }[] | undefined;
163
+ name: string;
164
+ title?: string | undefined;
165
+ } | undefined;
166
+ } | undefined;
167
+ description?: string | undefined;
168
+ messages: {
169
+ role: "assistant" | "user";
170
+ content: {
171
+ type: "text";
172
+ text: string;
173
+ annotations?: {
174
+ audience?: ("assistant" | "user")[] | undefined;
175
+ priority?: number | undefined;
176
+ lastModified?: string | undefined;
177
+ } | undefined;
178
+ _meta?: {
179
+ [x: string]: unknown;
180
+ } | undefined;
181
+ } | {
182
+ type: "image";
183
+ data: string;
184
+ mimeType: string;
185
+ annotations?: {
186
+ audience?: ("assistant" | "user")[] | undefined;
187
+ priority?: number | undefined;
188
+ lastModified?: string | undefined;
189
+ } | undefined;
190
+ _meta?: {
191
+ [x: string]: unknown;
192
+ } | undefined;
193
+ } | {
194
+ type: "audio";
195
+ data: string;
196
+ mimeType: string;
197
+ annotations?: {
198
+ audience?: ("assistant" | "user")[] | undefined;
199
+ priority?: number | undefined;
200
+ lastModified?: string | undefined;
201
+ } | undefined;
202
+ _meta?: {
203
+ [x: string]: unknown;
204
+ } | undefined;
205
+ } | {
206
+ uri: string;
207
+ description?: string | undefined;
208
+ mimeType?: string | undefined;
209
+ size?: number | undefined;
210
+ annotations?: {
211
+ audience?: ("assistant" | "user")[] | undefined;
212
+ priority?: number | undefined;
213
+ lastModified?: string | undefined;
214
+ } | undefined;
215
+ _meta?: {
216
+ [x: string]: unknown;
217
+ } | undefined;
218
+ icons?: {
219
+ src: string;
220
+ mimeType?: string | undefined;
221
+ sizes?: string[] | undefined;
222
+ theme?: "dark" | "light" | undefined;
223
+ }[] | undefined;
224
+ name: string;
225
+ title?: string | undefined;
226
+ type: "resource_link";
227
+ } | {
228
+ type: "resource";
229
+ resource: {
230
+ uri: string;
231
+ mimeType?: string | undefined;
232
+ _meta?: {
233
+ [x: string]: unknown;
234
+ } | undefined;
235
+ text: string;
236
+ } | {
237
+ uri: string;
238
+ mimeType?: string | undefined;
239
+ _meta?: {
240
+ [x: string]: unknown;
241
+ } | undefined;
242
+ blob: string;
243
+ };
244
+ annotations?: {
245
+ audience?: ("assistant" | "user")[] | undefined;
246
+ priority?: number | undefined;
247
+ lastModified?: string | undefined;
248
+ } | undefined;
249
+ _meta?: {
250
+ [x: string]: unknown;
251
+ } | undefined;
252
+ };
253
+ }[];
254
+ }>;
255
+ listTools(...args: Parameters<Client["listTools"]>): Promise<{
256
+ [x: string]: unknown;
257
+ _meta?: {
258
+ [x: string]: unknown;
259
+ "io.modelcontextprotocol/serverInfo"?: {
260
+ version: string;
261
+ websiteUrl?: string | undefined;
262
+ description?: string | undefined;
263
+ icons?: {
264
+ src: string;
265
+ mimeType?: string | undefined;
266
+ sizes?: string[] | undefined;
267
+ theme?: "dark" | "light" | undefined;
268
+ }[] | undefined;
269
+ name: string;
270
+ title?: string | undefined;
271
+ } | undefined;
272
+ } | undefined;
273
+ nextCursor?: string | undefined;
274
+ tools: {
275
+ description?: string | undefined;
276
+ inputSchema: {
277
+ [x: string]: unknown;
278
+ type: "object";
279
+ properties?: {
280
+ [x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | {
281
+ [x: string]: string | number | boolean | /*elided*/ any | /*elided*/ any | null;
282
+ } | null)[] | {
283
+ [x: string]: string | number | boolean | any | any | null;
284
+ } | null)[] | {
285
+ [x: string]: string | number | boolean | any | any | null;
286
+ } | null)[] | {
287
+ [x: string]: string | number | boolean | any | any | null;
288
+ } | null)[] | {
289
+ [x: string]: string | number | boolean | any | any | null;
290
+ } | null)[] | {
291
+ [x: string]: string | number | boolean | any | any | null;
292
+ } | null)[] | {
293
+ [x: string]: string | number | boolean | any | any | null;
294
+ } | null)[] | {
295
+ [x: string]: string | number | boolean | any | any | null;
296
+ } | null)[] | {
297
+ [x: string]: string | number | boolean | any | any | null;
298
+ } | null)[] | {
299
+ [x: string]: string | number | boolean | any | any | null;
300
+ } | null)[] | {
301
+ [x: string]: string | number | boolean | any | any | null;
302
+ } | null;
303
+ } | undefined;
304
+ required?: string[] | undefined;
305
+ };
306
+ outputSchema?: {
307
+ [x: string]: unknown;
308
+ $schema?: string | undefined;
309
+ } | undefined;
310
+ annotations?: {
311
+ title?: string | undefined;
312
+ readOnlyHint?: boolean | undefined;
313
+ destructiveHint?: boolean | undefined;
314
+ idempotentHint?: boolean | undefined;
315
+ openWorldHint?: boolean | undefined;
316
+ } | undefined;
317
+ execution?: {
318
+ taskSupport?: "forbidden" | "optional" | "required" | undefined;
319
+ } | undefined;
320
+ _meta?: {
321
+ [x: string]: unknown;
322
+ } | undefined;
323
+ icons?: {
324
+ src: string;
325
+ mimeType?: string | undefined;
326
+ sizes?: string[] | undefined;
327
+ theme?: "dark" | "light" | undefined;
328
+ }[] | undefined;
329
+ name: string;
330
+ title?: string | undefined;
331
+ }[];
332
+ }>;
333
+ listResources(...args: Parameters<Client["listResources"]>): Promise<{
334
+ [x: string]: unknown;
335
+ _meta?: {
336
+ [x: string]: unknown;
337
+ "io.modelcontextprotocol/serverInfo"?: {
338
+ version: string;
339
+ websiteUrl?: string | undefined;
340
+ description?: string | undefined;
341
+ icons?: {
342
+ src: string;
343
+ mimeType?: string | undefined;
344
+ sizes?: string[] | undefined;
345
+ theme?: "dark" | "light" | undefined;
346
+ }[] | undefined;
347
+ name: string;
348
+ title?: string | undefined;
349
+ } | undefined;
350
+ } | undefined;
351
+ nextCursor?: string | undefined;
352
+ resources: {
353
+ uri: string;
354
+ description?: string | undefined;
355
+ mimeType?: string | undefined;
356
+ size?: number | undefined;
357
+ annotations?: {
358
+ audience?: ("assistant" | "user")[] | undefined;
359
+ priority?: number | undefined;
360
+ lastModified?: string | undefined;
361
+ } | undefined;
362
+ _meta?: {
363
+ [x: string]: unknown;
364
+ } | undefined;
365
+ icons?: {
366
+ src: string;
367
+ mimeType?: string | undefined;
368
+ sizes?: string[] | undefined;
369
+ theme?: "dark" | "light" | undefined;
370
+ }[] | undefined;
371
+ name: string;
372
+ title?: string | undefined;
373
+ }[];
374
+ }>;
375
+ listPrompts(...args: Parameters<Client["listPrompts"]>): Promise<{
376
+ [x: string]: unknown;
377
+ _meta?: {
378
+ [x: string]: unknown;
379
+ "io.modelcontextprotocol/serverInfo"?: {
380
+ version: string;
381
+ websiteUrl?: string | undefined;
382
+ description?: string | undefined;
383
+ icons?: {
384
+ src: string;
385
+ mimeType?: string | undefined;
386
+ sizes?: string[] | undefined;
387
+ theme?: "dark" | "light" | undefined;
388
+ }[] | undefined;
389
+ name: string;
390
+ title?: string | undefined;
391
+ } | undefined;
392
+ } | undefined;
393
+ nextCursor?: string | undefined;
394
+ prompts: {
395
+ description?: string | undefined;
396
+ arguments?: {
397
+ name: string;
398
+ description?: string | undefined;
399
+ required?: boolean | undefined;
400
+ }[] | undefined;
401
+ _meta?: {
402
+ [x: string]: unknown;
403
+ } | undefined;
404
+ icons?: {
405
+ src: string;
406
+ mimeType?: string | undefined;
407
+ sizes?: string[] | undefined;
408
+ theme?: "dark" | "light" | undefined;
409
+ }[] | undefined;
410
+ name: string;
411
+ title?: string | undefined;
412
+ }[];
413
+ }>;
414
+ complete(...args: Parameters<Client["complete"]>): Promise<{
415
+ [x: string]: unknown;
416
+ _meta?: {
417
+ [x: string]: unknown;
418
+ "io.modelcontextprotocol/serverInfo"?: {
419
+ version: string;
420
+ websiteUrl?: string | undefined;
421
+ description?: string | undefined;
422
+ icons?: {
423
+ src: string;
424
+ mimeType?: string | undefined;
425
+ sizes?: string[] | undefined;
426
+ theme?: "dark" | "light" | undefined;
427
+ }[] | undefined;
428
+ name: string;
429
+ title?: string | undefined;
430
+ } | undefined;
431
+ } | undefined;
432
+ completion: {
433
+ [x: string]: unknown;
434
+ values: string[];
435
+ total?: number | undefined;
436
+ hasMore?: boolean | undefined;
437
+ };
438
+ }>;
439
+ setLoggingLevel(...args: Parameters<Client["setLoggingLevel"]>): Promise<{
440
+ _meta?: {
441
+ [x: string]: unknown;
442
+ "io.modelcontextprotocol/serverInfo"?: {
443
+ version: string;
444
+ websiteUrl?: string | undefined;
445
+ description?: string | undefined;
446
+ icons?: {
447
+ src: string;
448
+ mimeType?: string | undefined;
449
+ sizes?: string[] | undefined;
450
+ theme?: "dark" | "light" | undefined;
451
+ }[] | undefined;
452
+ name: string;
453
+ title?: string | undefined;
454
+ } | undefined;
455
+ } | undefined;
456
+ }>;
457
+ listen(...args: Parameters<Client["listen"]>): Promise<import("@modelcontextprotocol/client").McpSubscription>;
458
+ subscribeResource(...args: Parameters<Client["subscribeResource"]>): Promise<{
459
+ _meta?: {
460
+ [x: string]: unknown;
461
+ "io.modelcontextprotocol/serverInfo"?: {
462
+ version: string;
463
+ websiteUrl?: string | undefined;
464
+ description?: string | undefined;
465
+ icons?: {
466
+ src: string;
467
+ mimeType?: string | undefined;
468
+ sizes?: string[] | undefined;
469
+ theme?: "dark" | "light" | undefined;
470
+ }[] | undefined;
471
+ name: string;
472
+ title?: string | undefined;
473
+ } | undefined;
474
+ } | undefined;
475
+ }>;
476
+ unsubscribeResource(...args: Parameters<Client["unsubscribeResource"]>): Promise<{
477
+ _meta?: {
478
+ [x: string]: unknown;
479
+ "io.modelcontextprotocol/serverInfo"?: {
480
+ version: string;
481
+ websiteUrl?: string | undefined;
482
+ description?: string | undefined;
483
+ icons?: {
484
+ src: string;
485
+ mimeType?: string | undefined;
486
+ sizes?: string[] | undefined;
487
+ theme?: "dark" | "light" | undefined;
488
+ }[] | undefined;
489
+ name: string;
490
+ title?: string | undefined;
491
+ } | undefined;
492
+ } | undefined;
493
+ }>;
494
+ }
495
+ export { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
496
+ export { SdkHttpError, StreamableHTTPClientTransport, SSEClientTransport, auth, extractWWWAuthenticateParams, UnauthorizedError } from "@modelcontextprotocol/client";
497
+ export { UnixSocketClientTransport } from "./unix-socket-transport.ts";
498
+ export { trackToolTransport, trackToolTransportFailure } from "./session-recovery.ts";
499
+ export { McpOAuthProvider } from "./mcp-oauth-provider.ts";
500
+ export { extractOAuthConfig, isOAuthChallenge, recordOAuthChallenge, getOAuthRequest, bindOAuthRequestIssuer } from "./mcp-auth-flow.ts";
501
+ export { registerSamplingHandler } from "./sampling-handler.ts";
502
+ export { registerElicitationHandler } from "./elicitation-handler.ts";
503
+ export { serverStreamResultPatchNotificationSchema } from "./ui-stream-types.ts";
@@ -0,0 +1,98 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { Client } from "@modelcontextprotocol/client";
3
+ import { clientOperations } from "./client-operations.js";
4
+ import { throwIfAborted } from "./abort.js";
5
+ // Track complete SDK operations, including pagination and pre-request cache awaits.
6
+ export class ManagedClient extends Client {
7
+ serverName = "";
8
+ oauthProvider;
9
+ own(operation, kind) {
10
+ let pending = clientOperations.get(this);
11
+ if (!pending)
12
+ clientOperations.set(this, pending = new Map());
13
+ pending.set(operation, kind);
14
+ const settled = () => { pending.delete(operation); };
15
+ void operation.then(settled, settled);
16
+ return operation;
17
+ }
18
+ ownNative(run) {
19
+ return this.own(run(), "request/refresh");
20
+ }
21
+ ownSend(run) {
22
+ // SDK-generated callback replies also perform HTTP/auth work, without calling callTool().
23
+ return this.own(Promise.resolve().then(run), "request/refresh");
24
+ }
25
+ ownCallback(kind, run) {
26
+ // Insert before dispatch. Cancellation/close of the SDK response does not settle this promise.
27
+ return this.own(Promise.resolve().then(run), kind);
28
+ }
29
+ async track(start, signal) {
30
+ const controller = this.oauthProvider ? new AbortController() : undefined;
31
+ let removeAbortListener = () => { };
32
+ const operation = this.oauthProvider
33
+ ? this.oauthProvider.runWithSignal(controller.signal, () => {
34
+ // Native legacy cancellation notifications must retain their operation's auth context.
35
+ const abort = AsyncLocalStorage.bind(() => controller.abort(signal?.reason));
36
+ if (signal?.aborted)
37
+ abort();
38
+ else
39
+ signal?.addEventListener("abort", abort, { once: true });
40
+ removeAbortListener = () => signal?.removeEventListener("abort", abort);
41
+ return start(controller.signal);
42
+ })
43
+ : start(signal);
44
+ void operation.then(removeAbortListener, () => { controller?.abort(); removeAbortListener(); });
45
+ return this.own(operation, "request/refresh");
46
+ }
47
+ callTool(...args) {
48
+ return this.track(signal => super.callTool(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
49
+ }
50
+ readResource(...args) {
51
+ return this.track(signal => super.readResource(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
52
+ }
53
+ getPrompt(...args) {
54
+ return this.track(signal => super.getPrompt(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
55
+ }
56
+ listTools(...args) {
57
+ return this.track(signal => super.listTools(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
58
+ }
59
+ listResources(...args) {
60
+ return this.track(signal => super.listResources(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
61
+ }
62
+ listPrompts(...args) {
63
+ return this.track(signal => super.listPrompts(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
64
+ }
65
+ complete(...args) {
66
+ return this.track(signal => super.complete(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
67
+ }
68
+ setLoggingLevel(...args) {
69
+ return this.track(signal => super.setLoggingLevel(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
70
+ }
71
+ listen(...args) {
72
+ return this.track(async (signal) => {
73
+ const subscription = await super.listen(args[0], { ...args[1], ...(signal ? { signal } : {}) });
74
+ this.own(subscription.closed, "subscription");
75
+ return subscription;
76
+ }, args[1]?.signal);
77
+ }
78
+ subscribeResource(...args) {
79
+ return this.track(async (signal) => {
80
+ throwIfAborted(signal);
81
+ return super.subscribeResource(args[0], { ...args[1], ...(signal ? { signal } : {}) });
82
+ }, args[1]?.signal);
83
+ }
84
+ unsubscribeResource(...args) {
85
+ return this.track(signal => super.unsubscribeResource(args[0], { ...args[1], ...(signal ? { signal } : {}) }), args[1]?.signal);
86
+ }
87
+ }
88
+ // Loaded only by the manager's connection path. Keep native constructors and
89
+ // synchronous connection setup together, after the one asynchronous import.
90
+ export { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
91
+ export { SdkHttpError, StreamableHTTPClientTransport, SSEClientTransport, auth, extractWWWAuthenticateParams, UnauthorizedError } from "@modelcontextprotocol/client";
92
+ export { UnixSocketClientTransport } from "./unix-socket-transport.js";
93
+ export { trackToolTransport, trackToolTransportFailure } from "./session-recovery.js";
94
+ export { McpOAuthProvider } from "./mcp-oauth-provider.js";
95
+ export { extractOAuthConfig, isOAuthChallenge, recordOAuthChallenge, getOAuthRequest, bindOAuthRequestIssuer } from "./mcp-auth-flow.js";
96
+ export { registerSamplingHandler } from "./sampling-handler.js";
97
+ export { registerElicitationHandler } from "./elicitation-handler.js";
98
+ export { serverStreamResultPatchNotificationSchema } from "./ui-stream-types.js";
@@ -1,7 +1,6 @@
1
1
  import { abortable, throwIfAborted } from "./abort.js";
2
2
  import { parseDirectToolSelectors } from "./metadata-cache.js";
3
3
  export { getMissingConfiguredDirectToolServers } from "./metadata-cache.js";
4
- import { executeCall } from "./proxy-modes.js";
5
4
  import { isServerDisabled } from "./types.js";
6
5
  import { nativeMcpResult } from "./tool-registrar.js";
7
6
  export function directToolSelection(config, serverName, envOverride) {
@@ -46,6 +45,7 @@ export function createDirectToolExecutor(getState, getInitPromise, spec, beforeE
46
45
  details: { error: "not_initialized" },
47
46
  }, !!spec.outputSchema);
48
47
  }
48
+ const { executeCall } = await import("./proxy-modes.js");
49
49
  const result = await executeCall(state, spec.originalName, params, spec.serverName, undefined, signal, { toolCallId }, beforeExecute ? (callSignal, operation) => beforeExecute(toolCallId, { ...ctx, signal: callSignal }, operation) : undefined, { exactOriginalName: true, ...(spec.resourceUri ? { resourceUri: spec.resourceUri } : {}) });
50
50
  const { mode: _mode, ...details } = result.details;
51
51
  return nativeMcpResult({ ...result, details }, !!spec.outputSchema);