@mcp-use/client 0.0.0-bootstrap.0 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +127 -4
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/auth/browser.d.ts +149 -0
  4. package/dist/auth/browser.d.ts.map +1 -0
  5. package/dist/auth/callback.d.ts +9 -0
  6. package/dist/auth/callback.d.ts.map +1 -0
  7. package/dist/auth/flow.d.ts +23 -0
  8. package/dist/auth/flow.d.ts.map +1 -0
  9. package/dist/auth/node.d.ts +100 -0
  10. package/dist/auth/node.d.ts.map +1 -0
  11. package/dist/auth/popup.d.ts +67 -0
  12. package/dist/auth/popup.d.ts.map +1 -0
  13. package/dist/auth/session-store.d.ts +114 -0
  14. package/dist/auth/session-store.d.ts.map +1 -0
  15. package/dist/auth/storage-file.d.ts +18 -0
  16. package/dist/auth/storage-file.d.ts.map +1 -0
  17. package/dist/auth/storage.d.ts +25 -0
  18. package/dist/auth/storage.d.ts.map +1 -0
  19. package/dist/auth/url.d.ts +17 -0
  20. package/dist/auth/url.d.ts.map +1 -0
  21. package/dist/code-mode/connector.d.ts +27 -0
  22. package/dist/code-mode/connector.d.ts.map +1 -0
  23. package/dist/code-mode/executor-e2b.d.ts +46 -0
  24. package/dist/code-mode/executor-e2b.d.ts.map +1 -0
  25. package/dist/code-mode/executor-vm.d.ts +39 -0
  26. package/dist/code-mode/executor-vm.d.ts.map +1 -0
  27. package/dist/code-mode/executor.d.ts +66 -0
  28. package/dist/code-mode/executor.d.ts.map +1 -0
  29. package/dist/core/base.d.ts +418 -0
  30. package/dist/core/base.d.ts.map +1 -0
  31. package/dist/core/browser.d.ts +20 -0
  32. package/dist/core/browser.d.ts.map +1 -0
  33. package/dist/core/config.d.ts +149 -0
  34. package/dist/core/config.d.ts.map +1 -0
  35. package/dist/core/node.d.ts +441 -0
  36. package/dist/core/node.d.ts.map +1 -0
  37. package/dist/core/session.d.ts +683 -0
  38. package/dist/core/session.d.ts.map +1 -0
  39. package/dist/index-browser.d.ts +25 -0
  40. package/dist/index-browser.d.ts.map +1 -0
  41. package/dist/index-browser.js +4150 -0
  42. package/dist/index-browser.js.map +1 -0
  43. package/dist/index.d.ts +23 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +5598 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/react/McpClientProvider.d.ts +242 -0
  48. package/dist/react/McpClientProvider.d.ts.map +1 -0
  49. package/dist/react/index.d.ts +33 -0
  50. package/dist/react/index.d.ts.map +1 -0
  51. package/dist/react/index.js +7922 -0
  52. package/dist/react/index.js.map +1 -0
  53. package/dist/react/rpc-logger.d.ts +42 -0
  54. package/dist/react/rpc-logger.d.ts.map +1 -0
  55. package/dist/react/storage.d.ts +51 -0
  56. package/dist/react/storage.d.ts.map +1 -0
  57. package/dist/react/types.d.ts +596 -0
  58. package/dist/react/types.d.ts.map +1 -0
  59. package/dist/react/useMcp-helpers.d.ts +99 -0
  60. package/dist/react/useMcp-helpers.d.ts.map +1 -0
  61. package/dist/react/useMcp-operations.d.ts +156 -0
  62. package/dist/react/useMcp-operations.d.ts.map +1 -0
  63. package/dist/react/useMcp.d.ts +48 -0
  64. package/dist/react/useMcp.d.ts.map +1 -0
  65. package/dist/react/useMcpServerQueues.d.ts +376 -0
  66. package/dist/react/useMcpServerQueues.d.ts.map +1 -0
  67. package/dist/react/view/ViewRenderer.d.ts +12 -0
  68. package/dist/react/view/ViewRenderer.d.ts.map +1 -0
  69. package/dist/react/view/ext-apps-bridge.d.ts +3 -0
  70. package/dist/react/view/ext-apps-bridge.d.ts.map +1 -0
  71. package/dist/react/view/parse-custom-props.d.ts +2 -0
  72. package/dist/react/view/parse-custom-props.d.ts.map +1 -0
  73. package/dist/react/view/resolve-view-resource.d.ts +12 -0
  74. package/dist/react/view/resolve-view-resource.d.ts.map +1 -0
  75. package/dist/react/view/sandbox-blob-url.d.ts +25 -0
  76. package/dist/react/view/sandbox-blob-url.d.ts.map +1 -0
  77. package/dist/react/view/types.d.ts +97 -0
  78. package/dist/react/view/types.d.ts.map +1 -0
  79. package/dist/react/view/use-display-mode.d.ts +18 -0
  80. package/dist/react/view/use-display-mode.d.ts.map +1 -0
  81. package/dist/react/view/view-detection.d.ts +4 -0
  82. package/dist/react/view/view-detection.d.ts.map +1 -0
  83. package/dist/telemetry/client-telemetry.d.ts +13 -0
  84. package/dist/telemetry/client-telemetry.d.ts.map +1 -0
  85. package/dist/telemetry/configure-browser.d.ts +2 -0
  86. package/dist/telemetry/configure-browser.d.ts.map +1 -0
  87. package/dist/telemetry/configure-node.d.ts +2 -0
  88. package/dist/telemetry/configure-node.d.ts.map +1 -0
  89. package/dist/telemetry/connector-telemetry.d.ts +8 -0
  90. package/dist/telemetry/connector-telemetry.d.ts.map +1 -0
  91. package/dist/telemetry/events.d.ts +91 -0
  92. package/dist/telemetry/events.d.ts.map +1 -0
  93. package/dist/telemetry/index.d.ts +3 -0
  94. package/dist/telemetry/index.d.ts.map +1 -0
  95. package/dist/telemetry/tel-fetch.d.ts +25 -0
  96. package/dist/telemetry/tel-fetch.d.ts.map +1 -0
  97. package/dist/telemetry/telemetry-browser.d.ts +6 -0
  98. package/dist/telemetry/telemetry-browser.d.ts.map +1 -0
  99. package/dist/telemetry/telemetry-node.d.ts +8 -0
  100. package/dist/telemetry/telemetry-node.d.ts.map +1 -0
  101. package/dist/telemetry/telemetry.d.ts +79 -0
  102. package/dist/telemetry/telemetry.d.ts.map +1 -0
  103. package/dist/transport/base.d.ts +505 -0
  104. package/dist/transport/base.d.ts.map +1 -0
  105. package/dist/transport/connection-manager.d.ts +55 -0
  106. package/dist/transport/connection-manager.d.ts.map +1 -0
  107. package/dist/transport/http.d.ts +74 -0
  108. package/dist/transport/http.d.ts.map +1 -0
  109. package/dist/transport/stdio.d.ts +48 -0
  110. package/dist/transport/stdio.d.ts.map +1 -0
  111. package/dist/utils/elicitation.d.ts +52 -0
  112. package/dist/utils/elicitation.d.ts.map +1 -0
  113. package/dist/utils/favicon.d.ts +6 -0
  114. package/dist/utils/favicon.d.ts.map +1 -0
  115. package/dist/utils/json-schema-validator.d.ts +13 -0
  116. package/dist/utils/json-schema-validator.d.ts.map +1 -0
  117. package/dist/utils/logging.d.ts +32 -0
  118. package/dist/utils/logging.d.ts.map +1 -0
  119. package/dist/utils/version.d.ts +3 -0
  120. package/dist/utils/version.d.ts.map +1 -0
  121. package/package.json +77 -8
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Completes the browser OAuth callback once per page load.
3
+ *
4
+ * This host validates the CSRF state and restores the browser provider. The MCP
5
+ * SDK transport owns callback parameter parsing, issuer validation, OAuth error
6
+ * handling, and the authorization-code exchange.
7
+ */
8
+ export declare function onMcpAuthorization(): Promise<void>;
9
+ //# sourceMappingURL=callback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../../src/auth/callback.ts"],"names":[],"mappings":"AA4MA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAGlD"}
@@ -0,0 +1,23 @@
1
+ import { type OAuthClientProvider } from "@modelcontextprotocol/client";
2
+ /**
3
+ * True if the error (or a wrapped cause) is an HTTP 401 / UnauthorizedError
4
+ * that should trigger the OAuth completion dance.
5
+ */
6
+ export declare function isUnauthorized(err: unknown, depth?: number): boolean;
7
+ /**
8
+ * Complete an in-progress or required OAuth authorization for `provider`.
9
+ *
10
+ * - Node loopback providers expose `getAuthorizationCode()`; we await the
11
+ * code and finish the token exchange.
12
+ * - Browser providers open a popup/redirect; we wait for the callback page
13
+ * (`onMcpAuthorization`) to exchange the code and signal success over
14
+ * `BroadcastChannel` / `postMessage`.
15
+ *
16
+ * Safe to call when the SDK transport already invoked `auth()` on a 401
17
+ * (Node: `hasPendingFlow`; we skip a duplicate `auth()` in that case).
18
+ */
19
+ export declare function completeOAuthFlow(provider: OAuthClientProvider, serverUrl: string, options?: {
20
+ timeoutMs?: number;
21
+ fetchFn?: typeof fetch;
22
+ }): Promise<void>;
23
+ //# sourceMappingURL=flow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/auth/flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,8BAA8B,CAAC;AAgBtC;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAgB/D;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,mBAAmB,EAC7B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GAC3D,OAAO,CAAC,IAAI,CAAC,CAyBf"}
@@ -0,0 +1,100 @@
1
+ import type { OAuthClientInformation, OAuthClientInformationContext, OAuthClientMetadata, OAuthClientProvider, OAuthDiscoveryState, OAuthTokens } from "@modelcontextprotocol/client";
2
+ import type { KVStore } from "./storage.js";
3
+ import { type OAuthSessionStoreOptions } from "./session-store.js";
4
+ export interface NodeOAuthOptions extends OAuthSessionStoreOptions {
5
+ /** Preferred loopback port. Default 33418. Walks up by `portRange` on EADDRINUSE. */
6
+ preferredPort?: number;
7
+ portRange?: number;
8
+ /** Override the on-disk store directory (mostly for tests). */
9
+ baseDir?: string;
10
+ /** Override KV store entirely (mostly for tests). */
11
+ kvStore?: KVStore;
12
+ /** Loopback wait timeout. Default 5 minutes. */
13
+ authTimeoutMs?: number;
14
+ /** Suppress the default `open(url)` browser launch (test hook). */
15
+ openBrowser?: (url: string) => Promise<void> | void;
16
+ }
17
+ export declare class OAuthFlowError extends Error {
18
+ readonly code: string;
19
+ readonly description?: string;
20
+ constructor(code: string, description?: string);
21
+ }
22
+ /**
23
+ * Node/CLI OAuth client provider for MCP. Owns a localhost loopback callback
24
+ * server, opens the user's browser, and resolves the authorization code via
25
+ * `getAuthorizationCode()` — designed for the orchestrator pattern in
26
+ * `useMcp.ts:1121-1145`.
27
+ *
28
+ * Use the static `create()` factory; the constructor is internal because
29
+ * port reservation is async.
30
+ */
31
+ export declare class NodeOAuthClientProvider implements OAuthClientProvider {
32
+ readonly serverUrl: string;
33
+ readonly port: number;
34
+ private session;
35
+ private kv;
36
+ private authTimeoutMs;
37
+ private openBrowserOverride?;
38
+ private server;
39
+ /** Currently in-flight deferred — used to prevent overlapping flows. */
40
+ private pending;
41
+ /** Latest deferred (settled or in-flight) — what `getAuthorizationCode()` returns. */
42
+ private lastFlow;
43
+ private pendingTimer;
44
+ private constructor();
45
+ static create(serverUrl: string, options?: NodeOAuthOptions): Promise<NodeOAuthClientProvider>;
46
+ get storageKeyPrefix(): string;
47
+ get serverUrlHash(): string;
48
+ get redirectUrl(): string;
49
+ get clientMetadata(): OAuthClientMetadata;
50
+ get clientMetadataUrl(): string | undefined;
51
+ tokens(ctx?: OAuthClientInformationContext): Promise<OAuthTokens | undefined>;
52
+ saveTokens(tokens: OAuthTokens, ctx?: OAuthClientInformationContext): Promise<void>;
53
+ clientInformation(ctx?: OAuthClientInformationContext): Promise<OAuthClientInformation | undefined>;
54
+ saveClientInformation(info: OAuthClientInformation, ctx?: OAuthClientInformationContext): Promise<void>;
55
+ codeVerifier(): Promise<string>;
56
+ saveCodeVerifier(codeVerifier: string): Promise<void>;
57
+ invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
58
+ /** Persist OAuth discovery state (SEP-2352). Delegated to the session store. */
59
+ saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
60
+ /** Return previously saved OAuth discovery state, or `undefined`. */
61
+ discoveryState(): Promise<OAuthDiscoveryState | undefined>;
62
+ /**
63
+ * Bind the loopback server, set up the pending-code deferred, and ask the
64
+ * platform to open the user's browser. Does NOT await the code; the
65
+ * orchestrator awaits via `getAuthorizationCode()`.
66
+ */
67
+ redirectToAuthorization(authorizationUrl: URL): Promise<void>;
68
+ /**
69
+ * Resolves with the authorization code captured by the loopback callback.
70
+ * Must be called after `redirectToAuthorization()`. Returns the same
71
+ * promise whether the callback has fired or not — callers may subscribe
72
+ * before or after.
73
+ */
74
+ getAuthorizationCode(): Promise<string>;
75
+ /**
76
+ * Cancel an in-progress flow (timeout, SIGINT, etc.) and close the loopback.
77
+ */
78
+ dispose(): void;
79
+ /** Best-effort port for tests / status output. */
80
+ get callbackPort(): number;
81
+ /**
82
+ * True if `redirectToAuthorization()` has been called and we're awaiting
83
+ * a callback (loopback bound, browser opened). Lets orchestrators detect
84
+ * when the SDK transport has already kicked off the flow on a 401, so they
85
+ * can skip straight to `getAuthorizationCode()` instead of calling `auth()`
86
+ * again (which would throw "already in progress").
87
+ */
88
+ get hasPendingFlow(): boolean;
89
+ private startLoopback;
90
+ private stopLoopback;
91
+ private resolvePending;
92
+ private rejectPending;
93
+ private handleCallback;
94
+ }
95
+ /**
96
+ * Creates the Node OAuth provider used by the root client entry.
97
+ */
98
+ export declare function createOAuthProvider(serverUrl: string, options?: NodeOAuthOptions): Promise<OAuthClientProvider>;
99
+ export type { NodeOAuthOptions as OAuthProviderOptions };
100
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/auth/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,6BAA6B,EAC7B,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACZ,MAAM,8BAA8B,CAAC;AAItC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,oBAAoB,CAAC;AAM5B,MAAM,WAAW,gBAAiB,SAAQ,wBAAwB;IAChE,qFAAqF;IACrF,aAAa,CAAC,EAAE,M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AAmB,CACvC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAE9B;AAED,YAAY,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,67 @@
1
+ /** Channel name shared by the popup callback notifier and every listener. */
2
+ export declare const MCP_AUTH_BROADCAST_CHANNEL = "mcp_auth_callback";
3
+ /** Result message type posted by the OAuth callback page. */
4
+ export declare const MCP_AUTH_CALLBACK_MESSAGE_TYPE = "mcp_auth_callback";
5
+ /**
6
+ * Payload shape posted by the OAuth callback page over `postMessage` /
7
+ * `BroadcastChannel`. `state` and `serverUrlHash` are used to scope a result
8
+ * to the flow / server that initiated it; both are optional for backward
9
+ * compatibility with callback pages built against older versions.
10
+ */
11
+ export interface McpAuthCallbackMessage {
12
+ type?: string;
13
+ success?: boolean;
14
+ error?: string;
15
+ /** OAuth `state` parameter of the originating authorization request. */
16
+ state?: string;
17
+ /** Hash of the server URL the flow authenticated against. */
18
+ serverUrlHash?: string;
19
+ }
20
+ /** Terminal outcome of an opener-owned popup flow. */
21
+ type AuthPopupResult = {
22
+ kind: "success";
23
+ } | {
24
+ kind: "error";
25
+ error: string;
26
+ } | {
27
+ kind: "cancelled";
28
+ } | {
29
+ kind: "timeout";
30
+ };
31
+ interface RunAuthPopupOptions {
32
+ /**
33
+ * The popup window handle returned by `window.open`. May be `null` when the
34
+ * popup was blocked or opened out-of-band (e.g. a manual fallback link); the
35
+ * runner then relies on the message / storage / timeout signals only.
36
+ */
37
+ popup: globalThis.Window | null;
38
+ /** OAuth `state` parameter for this flow. Used to ignore unrelated results. */
39
+ state: string | null;
40
+ /** localStorage key under which the flow's tokens are persisted on success. */
41
+ tokensKey: string;
42
+ /** Overall flow timeout. Default 5 minutes. */
43
+ timeoutMs?: number;
44
+ /** Interval for the `popup.closed` poll. Default 1s (matches auth0-spa-js). */
45
+ closePollMs?: number;
46
+ /**
47
+ * How long to keep waiting for a result after the popup reports closed
48
+ * without tokens, before settling `cancelled`. COOP browsing-context-group
49
+ * swaps (popup navigating cross-origin) make `popup.closed` report `true`
50
+ * while the real window is still open mid-flow, so a closed signal is only
51
+ * a soft hint — message/storage listeners stay alive during this grace
52
+ * window and can still settle `success`. Default 20s.
53
+ */
54
+ closeGraceMs?: number;
55
+ /**
56
+ * Origin to accept `postMessage` results from. Defaults to the current
57
+ * window origin. BroadcastChannel results are same-origin by definition.
58
+ */
59
+ expectedOrigin?: string;
60
+ }
61
+ /**
62
+ * Run an opener-owned OAuth popup flow and resolve once it reaches a terminal
63
+ * outcome. Never rejects — all failure modes map to an {@link AuthPopupResult}.
64
+ */
65
+ export declare function runAuthPopup({ popup, state, tokensKey, timeoutMs, closePollMs, closeGraceMs, expectedOrigin, }: RunAuthPopupOptions): Promise<AuthPopupResult>;
66
+ export {};
67
+ //# sourceMappingURL=popup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"popup.d.ts","sourceRoot":"","sources":["../../src/auth/popup.ts"],"names":[],"mappings":"AAsBA,6EAA6E;AAC7E,eAAO,MAAM,0BAA0B,sBAAsB,CAAC;AAE9D,6DAA6D;AAC7D,eAAO,MAAM,8BAA8B,sBAAsB,CAAC;AAElE;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,sDAAsD;AACtD,KAAK,eAAe,GAChB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAExB,UAAU,mBAAmB;IAC3B;;;;OAIG;IACH,KAAK,EAAE,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC;IAChC,+EAA+E;IAC/E,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,+EAA+E;IAC/E,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAYD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,SAAS,EACT,SAAsB,EACtB,WAAkB,EAClB,YAAqB,EACrB,cAA4E,GAC7E,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC,CAoIhD"}
@@ -0,0 +1,114 @@
1
+ import type { OAuthClientInformation, OAuthClientInformationContext, OAuthClientMetadata, OAuthDiscoveryState, StoredOAuthTokens } from "@modelcontextprotocol/client";
2
+ import type { KVStore } from "./storage.js";
3
+ /**
4
+ * Internal type for storing OAuth state during the OAuth flow.
5
+ * @internal
6
+ */
7
+ export interface StoredState {
8
+ expiry: number;
9
+ serverUrlHash: string;
10
+ providerOptions: {
11
+ serverUrl: string;
12
+ storageKeyPrefix: string;
13
+ clientName: string;
14
+ clientUri: string;
15
+ callbackUrl: string;
16
+ oauthProxyUrl?: string;
17
+ clientMetadataUrl?: string;
18
+ staticClientInfo?: OAuthClientInformation;
19
+ scope?: string;
20
+ };
21
+ flowType?: "popup" | "redirect";
22
+ returnUrl?: string;
23
+ }
24
+ /**
25
+ * Common options for OAuthSessionStore.
26
+ *
27
+ * @internal
28
+ */
29
+ export interface OAuthSessionStoreOptions {
30
+ storageKeyPrefix?: string;
31
+ clientName?: string;
32
+ clientUri?: string;
33
+ logoUri?: string;
34
+ callbackUrl?: string;
35
+ clientMetadataUrl?: string;
36
+ /** Whether this platform may persist confidential-client credentials. */
37
+ allowClientSecret?: boolean;
38
+ /** OAuth scope string forwarded to the SDK via clientMetadata.scope. */
39
+ scope?: string;
40
+ }
41
+ /**
42
+ * Options passed by the platform provider when persisting an authorization
43
+ * request prior to redirecting the user agent.
44
+ *
45
+ * @internal
46
+ */
47
+ interface StoreAuthorizationStateOptions {
48
+ /**
49
+ * Platform-specific provider options that should round-trip through the
50
+ * stored state so the callback handler can rebuild the provider.
51
+ */
52
+ extraProviderOptions?: Record<string, unknown>;
53
+ flowType?: "popup" | "redirect";
54
+ returnUrl?: string;
55
+ }
56
+ /**
57
+ * Platform-neutral helper that owns OAuth session persistence and refresh
58
+ * logic. Used by `BrowserOAuthClientProvider` and `NodeOAuthClientProvider`
59
+ * — each platform provider implements `OAuthClientProvider` directly and
60
+ * delegates the generic methods here.
61
+ *
62
+ * @internal
63
+ */
64
+ export declare class OAuthSessionStore {
65
+ readonly serverUrl: string;
66
+ readonly storageKeyPrefix: string;
67
+ readonly serverUrlHash: string;
68
+ readonly clientName: string;
69
+ readonly clientUri: string;
70
+ readonly logoUri: string;
71
+ readonly callbackUrl: string;
72
+ readonly clientMetadataUrl?: string;
73
+ readonly scope?: string;
74
+ private store;
75
+ private allowClientSecret;
76
+ constructor(serverUrl: string, options: OAuthSessionStoreOptions, store: KVStore);
77
+ getKey(keySuffix: string): string;
78
+ static hashString(str: string): string;
79
+ get redirectUrl(): string;
80
+ get clientMetadata(): OAuthClientMetadata;
81
+ private credentialKey;
82
+ private readCredential;
83
+ tokens(ctx?: OAuthClientInformationContext): Promise<StoredOAuthTokens | undefined>;
84
+ saveTokens(tokens: StoredOAuthTokens, ctx?: OAuthClientInformationContext): Promise<void>;
85
+ clientInformation(ctx?: OAuthClientInformationContext): Promise<OAuthClientInformation | undefined>;
86
+ saveClientInformation(clientInformation: OAuthClientInformation, ctx?: OAuthClientInformationContext): Promise<void>;
87
+ saveCodeVerifier(codeVerifier: string): Promise<void>;
88
+ codeVerifier(): Promise<string>;
89
+ invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
90
+ /**
91
+ * Persist the OAuth discovery state (authorization-server metadata resolved
92
+ * during the auth flow). Stored with the same durability as the code
93
+ * verifier so the callback leg can verify it is exchanging the code at the
94
+ * same authorization server the redirect targeted (SEP-2352 mix-up defense).
95
+ */
96
+ saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
97
+ /** Return the previously saved discovery state, or `undefined`. */
98
+ discoveryState(): Promise<OAuthDiscoveryState | undefined>;
99
+ /**
100
+ * Generates and persists `StoredState` for an authorization request,
101
+ * appends the `state` query param to the URL, and persists the sanitized
102
+ * URL to `last_auth_url` so it can be replayed on popup-blocker fallback.
103
+ *
104
+ * @returns The sanitized authorization URL string with the `state` param appended.
105
+ */
106
+ storeAuthorizationState(authorizationUrl: URL, opts?: StoreAuthorizationStateOptions): Promise<string>;
107
+ /**
108
+ * Return the token endpoint from SDK-managed discovery state. The SDK
109
+ * persists this state during `auth()`, avoiding a second discovery flow.
110
+ */
111
+ getTokenEndpoint(): Promise<string | null>;
112
+ }
113
+ export {};
114
+ //# sourceMappingURL=session-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../src/auth/session-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,6BAA6B,EAC7B,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,EAAE,MAAM,CAAC;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AAmE;IAC7D,cAAc,IAAI,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAahE;;;;;;OAMG;IACG,uBAAuB,CAC3B,gBAAgB,EAAE,GAAG,EACrB,IAAI,GAAE,8BAAmC,GACxC,OAAO,CAAC,MAAM,CAAC;IAiClB;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAMjD"}
@@ -0,0 +1,18 @@
1
+ import type { KVStore } from "./storage.js";
2
+ /**
3
+ * `KVStore` implementation backed by `~/.mcp-use/oauth/<serverUrlHash>/`.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare class FileKVStore implements KVStore {
8
+ readonly dir: string;
9
+ constructor(serverUrlHash: string, baseDir?: string);
10
+ private ensureDir;
11
+ private sanitize;
12
+ private pathFor;
13
+ get(key: string): string | null;
14
+ set(key: string, value: string): void;
15
+ remove(key: string): void;
16
+ keys(): string[];
17
+ }
18
+ //# sourceMappingURL=storage-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-file.d.ts","sourceRoot":"","sources":["../../src/auth/storage-file.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C;;;;GAIG;AACH,qBAAa,WAAY,YAAW,OAAO;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAMnD,OAAO,CAAC,SAAS;IAajB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,OAAO;IAIf,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAU/B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAerC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAOzB,IAAI,IAAI,MAAM,EAAE;CAIjB"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Minimal key/value storage abstraction used by OAuthSessionStore.
3
+ *
4
+ * Browser-safe module — Node filesystem KV lives in `storage-file.ts`.
5
+ *
6
+ * @internal
7
+ */
8
+ export interface KVStore {
9
+ get(key: string): Promise<string | null> | string | null;
10
+ set(key: string, value: string): Promise<void> | void;
11
+ remove(key: string): Promise<void> | void;
12
+ keys(): Promise<string[]> | string[];
13
+ }
14
+ /**
15
+ * `KVStore` implementation backed by `globalThis.localStorage`.
16
+ *
17
+ * @internal
18
+ */
19
+ export declare class LocalStorageKVStore implements KVStore {
20
+ get(key: string): string | null;
21
+ set(key: string, value: string): void;
22
+ remove(key: string): void;
23
+ keys(): string[];
24
+ }
25
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/auth/storage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IACzD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACtD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1C,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC;CACtC;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,OAAO;IACjD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI/B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIrC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIzB,IAAI,IAAI,MAAM,EAAE;CAQjB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * URL sanitization utility
3
+ *
4
+ * Sanitizes URLs to prevent security issues by:
5
+ * - Restricting to http/https protocols only
6
+ * - Encoding URL components properly
7
+ * - Validating hostnames
8
+ */
9
+ /**
10
+ * Sanitizes a URL string by encoding all components and validating the protocol.
11
+ *
12
+ * @param raw - The raw URL string to sanitize
13
+ * @returns The sanitized URL as a string
14
+ * @throws Error if the URL is invalid or uses an unsupported protocol
15
+ */
16
+ export declare function sanitizeUrl(raw: string): string;
17
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/auth/url.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA+B/C"}
@@ -0,0 +1,27 @@
1
+ import type { CallToolResult, Tool } from "@modelcontextprotocol/client";
2
+ import type { MCPClient } from "../core/node.js";
3
+ import { BaseConnector } from "../transport/base.js";
4
+ export declare const CODE_MODE_AGENT_PROMPT = "\n## MCP Code Mode Tool Usage Guide\n\nYou have access to an MCP Code Mode Client that allows you to execute JavaScript/TypeScript code with access to registered tools. Follow this workflow:\n\n### 1. Tool Discovery Phase\n**Always start by discovering available tools:**\n- Tools are organized by server namespace (e.g., `server_name.tool_name`)\n- Use the `search_tools(query, detail_level)` function to find available tools\n- You can access `__tool_namespaces` to see all available server namespaces\n\n```javascript\n// Find all GitHub-related tools\nconst tools = await search_tools(\"github\");\nfor (const tool of tools) {\n console.log(`${tool.server}.${tool.name}: ${tool.description}`);\n}\n\n// Get only tool names for quick overview\nconst tools = await search_tools(\"\", \"names\");\n```\n\n### 2. Interface Introspection\n**Understand tool contracts before using them:**\n- Use `search_tools` to get tool descriptions and input schemas\n- Look for \"Access as: server.tool(args)\" patterns in descriptions\n\n### 3. Code Execution Guidelines\n**When writing code:**\n- Use `await server.tool({ param: value })` syntax for all tool calls\n- Tools are async functions that return promises\n- You have access to standard JavaScript globals: `console`, `JSON`, `Math`, `Date`, etc.\n- All console output (`console.log`, `console.error`, etc.) is automatically captured and returned\n- Build properly structured input objects based on interface definitions\n- Handle errors appropriately with try/catch blocks\n- Chain tool calls by using results from previous calls\n\n### 4. Best Practices\n- **Discover first, code second**: Always explore available tools before writing execution code\n- **Respect namespaces**: Use full `server.tool` names to avoid conflicts\n- **Minimize Context**: Process large data in code, return only essential results\n- **Error handling**: Wrap tool calls in try/catch for robustness\n- **Data flow**: Chain tools by passing outputs as inputs to subsequent tools\n\n### 5. Available Runtime Context\n- `search_tools(query, detail_level)`: Function to discover tools\n- `__tool_namespaces`: Array of available server namespaces\n- All registered tools as `server.tool` functions\n- Standard JavaScript built-ins for data processing\n\n### Example Workflow\n\n```javascript\n// 1. Discover available tools\nconst github_tools = await search_tools(\"github pull request\");\nconsole.log(`Available GitHub PR tools: ${github_tools.map(t => t.name)}`);\n\n// 2. Call tools with proper parameters\nconst pr = await github.get_pull_request({\n owner: \"facebook\",\n repo: \"react\",\n number: 12345\n});\n\n// 3. Process results\nlet result;\nif (pr.state === 'open' && pr.labels.some(l => l.name === 'bug')) {\n // 4. Chain with other tools\n await slack.post_message({\n channel: \"#bugs\",\n text: `\uD83D\uDC1B Bug PR needs review: ${pr.title}`\n });\n result = \"Notification sent\";\n} else {\n result = \"No action needed\";\n}\n\n// 5. Return structured results\nreturn {\n pr_number: pr.number,\n pr_title: pr.title,\n action_taken: result\n};\n```\n\nRemember: Always discover and understand available tools before attempting to use them in code execution.\n";
5
+ /**
6
+ * CodeModeConnector provides a special "code mode" interface for executing JavaScript/TypeScript
7
+ * code with access to MCP tools. Unlike other connectors, it doesn't establish its own external
8
+ * connection - instead, it wraps an already-connected BaseMCPClient and exposes special tools
9
+ * (execute_code, search_tools) on top of it.
10
+ *
11
+ * Since there's no connection phase to perform, the connector is immediately ready to use
12
+ * (connected=true) upon construction. The connect() and disconnect() methods exist for
13
+ * lifecycle compatibility with the BaseConnector interface but don't manage actual connections.
14
+ */
15
+ export declare class CodeModeConnector extends BaseConnector {
16
+ private mcpClient;
17
+ private _tools;
18
+ constructor(client: MCPClient);
19
+ connect(): Promise<void>;
20
+ disconnect(): Promise<void>;
21
+ get publicIdentifier(): Record<string, string>;
22
+ private _createToolsList;
23
+ get tools(): Tool[];
24
+ initialize(): Promise<any>;
25
+ callTool(name: string, args: Record<string, any>): Promise<CallToolResult>;
26
+ }
27
+ //# sourceMappingURL=connector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/code-mode/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,eAAO,MAAM,sBAAsB,0rGAsFlC,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,SAAS;IAOvB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,IAAI,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE7C;IAED,OAAO,CAAC,gBAAgB;IA4DxB,IAAI,KAAK,IAAI,IAAI,EAAE,CAElB;IAEK,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IAK1B,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACxB,OAAO,CAAC,cAAc,CAAC;CA2C3B"}
@@ -0,0 +1,46 @@
1
+ import type { E2BExecutorOptions, MCPClient } from "../core/node.js";
2
+ import { BaseCodeExecutor, type ExecutionResult } from "./executor.js";
3
+ /**
4
+ * E2B-based code executor using remote sandboxes.
5
+ * Executes code in an E2B sandbox with tool calls proxied back to the host.
6
+ */
7
+ export declare class E2BCodeExecutor extends BaseCodeExecutor {
8
+ private e2bApiKey;
9
+ private codeExecSandbox;
10
+ private SandboxClass;
11
+ private timeoutMs;
12
+ constructor(client: MCPClient, options: E2BExecutorOptions);
13
+ /**
14
+ * Lazy load E2B Sandbox class.
15
+ * This allows the library to work without E2B installed.
16
+ */
17
+ private ensureSandboxClass;
18
+ /**
19
+ * Get or create a dedicated sandbox for code execution.
20
+ */
21
+ private getOrCreateCodeExecSandbox;
22
+ /**
23
+ * Generate the shim code that exposes tools to the sandbox environment.
24
+ * Creates a bridge that intercepts tool calls and sends them back to host.
25
+ */
26
+ private generateShim;
27
+ /**
28
+ * Build the tool catalog for the shim.
29
+ * Returns a map of server names to their available tools.
30
+ */
31
+ private buildToolCatalog;
32
+ /**
33
+ * Execute JavaScript/TypeScript code in an E2B sandbox with MCP tool access.
34
+ * Tool calls are proxied back to the host via the bridge pattern.
35
+ *
36
+ * @param code - Code to execute
37
+ * @param timeout - Execution timeout in milliseconds (default: 30000)
38
+ */
39
+ execute(code: string, timeout?: number): Promise<ExecutionResult>;
40
+ /**
41
+ * Clean up the E2B sandbox.
42
+ * Should be called when the executor is no longer needed.
43
+ */
44
+ cleanup(): Promise<void>;
45
+ }
46
+ //# sourceMappingURL=executor-e2b.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor-e2b.d.ts","sourceRoot":"","sources":["../../src/code-mode/executor-e2b.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAKvE;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,gBAAgB;IACnD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB;IAM1D;;;OAGG;YACW,kBAAkB;IAgBhC;;OAEG;YACW,0BAA0B;IAcxC;;;OAGG;IACH,OAAO,CAAC,YAAY;IA6FpB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;;;;;OAMG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,SAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAwKtE;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAW/B"}
@@ -0,0 +1,39 @@
1
+ import type { MCPClient, VMExecutorOptions } from "../core/node.js";
2
+ import { BaseCodeExecutor, type ExecutionResult } from "./executor.js";
3
+ /**
4
+ * Check if VM executor is available in the current environment
5
+ * This is a synchronous check that returns true if vm was already loaded
6
+ */
7
+ export declare function isVMAvailable(): boolean;
8
+ /**
9
+ * VM-based code executor using Node.js vm module.
10
+ * Executes code in an isolated V8 context with access to MCP tools.
11
+ */
12
+ export declare class VMCodeExecutor extends BaseCodeExecutor {
13
+ private defaultTimeout;
14
+ private memoryLimitMb?;
15
+ constructor(client: MCPClient, options?: VMExecutorOptions);
16
+ /**
17
+ * Ensure VM module is loaded before execution
18
+ */
19
+ private ensureVMLoaded;
20
+ /**
21
+ * Execute JavaScript/TypeScript code with access to MCP tools.
22
+ *
23
+ * @param code - Code to execute
24
+ * @param timeout - Execution timeout in milliseconds (default: configured timeout or 30000)
25
+ */
26
+ execute(code: string, timeout?: number): Promise<ExecutionResult>;
27
+ /**
28
+ * Build the VM execution context with MCP tools and standard globals.
29
+ *
30
+ * @param logs - Array to capture console output
31
+ */
32
+ private _buildContext;
33
+ /**
34
+ * Clean up resources.
35
+ * VM executor doesn't need cleanup, but method kept for interface consistency.
36
+ */
37
+ cleanup(): Promise<void>;
38
+ }
39
+ //# sourceMappingURL=executor-vm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor-vm.d.ts","sourceRoot":"","sources":["../../src/code-mode/executor-vm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAsEvE;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAGvC;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,gBAAgB;IAClD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,aAAa,CAAC,CAAS;gBAEnB,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,iBAAiB;IAS1D;;OAEG;YACW,cAAc;IAc5B;;;;;OAKG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAsEvE;;;;OAIG;YACW,aAAa;IA6F3B;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
@@ -0,0 +1,66 @@
1
+ import type { Tool } from "@modelcontextprotocol/client";
2
+ import type { MCPClient } from "../core/node.js";
3
+ export interface ExecutionResult {
4
+ result: unknown;
5
+ logs: string[];
6
+ error: string | null;
7
+ execution_time: number;
8
+ }
9
+ interface ToolSearchResult {
10
+ name: string;
11
+ server: string;
12
+ description?: string;
13
+ input_schema?: Tool["inputSchema"];
14
+ }
15
+ interface ToolSearchMeta {
16
+ total_tools: number;
17
+ namespaces: string[];
18
+ result_count: number;
19
+ }
20
+ export interface ToolSearchResponse {
21
+ meta: ToolSearchMeta;
22
+ results: ToolSearchResult[];
23
+ }
24
+ type SearchToolsFunction = (query?: string, detailLevel?: "names" | "descriptions" | "full") => Promise<ToolSearchResponse>;
25
+ interface ToolNamespaceInfo {
26
+ serverName: string;
27
+ tools: Tool[];
28
+ session: any;
29
+ }
30
+ /**
31
+ * Abstract base class for code executors.
32
+ * Provides shared functionality for connecting to MCP servers and building tool contexts.
33
+ */
34
+ export declare abstract class BaseCodeExecutor {
35
+ protected client: MCPClient;
36
+ protected _connecting: boolean;
37
+ constructor(client: MCPClient);
38
+ /**
39
+ * Execute code with access to MCP tools.
40
+ * @param code - The code to execute
41
+ * @param timeout - Execution timeout in milliseconds
42
+ */
43
+ abstract execute(code: string, timeout?: number): Promise<ExecutionResult>;
44
+ /**
45
+ * Clean up resources used by the executor.
46
+ * Should be called when the executor is no longer needed.
47
+ */
48
+ abstract cleanup(): Promise<void>;
49
+ /**
50
+ * Ensure all configured MCP servers are connected before execution.
51
+ * Prevents race conditions with a connection lock.
52
+ */
53
+ protected ensureServersConnected(): Promise<void>;
54
+ /**
55
+ * Get tool namespace information from all active MCP sessions.
56
+ * Filters out the internal code_mode server.
57
+ */
58
+ protected getToolNamespaces(): ToolNamespaceInfo[];
59
+ /**
60
+ * Create a search function for discovering available MCP tools.
61
+ * Used by code execution environments to find tools at runtime.
62
+ */
63
+ createSearchToolsFunction(): SearchToolsFunction;
64
+ }
65
+ export {};
66
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/code-mode/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAA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