@mcp-use/client 2.2.4 → 2.2.5
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/dist/.tsbuildinfo +1 -0
- package/dist/auth/browser.d.ts +218 -0
- package/dist/auth/browser.d.ts.map +1 -0
- package/dist/auth/callback.d.ts +9 -0
- package/dist/auth/callback.d.ts.map +1 -0
- package/dist/auth/flow.d.ts +32 -0
- package/dist/auth/flow.d.ts.map +1 -0
- package/dist/auth/node.d.ts +212 -0
- package/dist/auth/node.d.ts.map +1 -0
- package/dist/auth/popup.d.ts +67 -0
- package/dist/auth/popup.d.ts.map +1 -0
- package/dist/auth/session-store.d.ts +125 -0
- package/dist/auth/session-store.d.ts.map +1 -0
- package/dist/auth/storage-file.d.ts +18 -0
- package/dist/auth/storage-file.d.ts.map +1 -0
- package/dist/auth/storage.d.ts +34 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/url.d.ts +17 -0
- package/dist/auth/url.d.ts.map +1 -0
- package/dist/code-mode/connector.d.ts +27 -0
- package/dist/code-mode/connector.d.ts.map +1 -0
- package/dist/code-mode/executor-e2b.d.ts +46 -0
- package/dist/code-mode/executor-e2b.d.ts.map +1 -0
- package/dist/code-mode/executor-vm.d.ts +39 -0
- package/dist/code-mode/executor-vm.d.ts.map +1 -0
- package/dist/code-mode/executor.d.ts +81 -0
- package/dist/code-mode/executor.d.ts.map +1 -0
- package/dist/core/base.d.ts +423 -0
- package/dist/core/base.d.ts.map +1 -0
- package/dist/core/browser.d.ts +32 -0
- package/dist/core/browser.d.ts.map +1 -0
- package/dist/core/config.d.ts +225 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/node.d.ts +437 -0
- package/dist/core/node.d.ts.map +1 -0
- package/dist/core/session.d.ts +792 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/skills.d.ts +47 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/index-browser.d.ts +26 -0
- package/dist/index-browser.d.ts.map +1 -0
- package/dist/index-browser.js +4767 -0
- package/dist/index-browser.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6113 -0
- package/dist/index.js.map +1 -0
- package/dist/react/McpClientProvider.d.ts +254 -0
- package/dist/react/McpClientProvider.d.ts.map +1 -0
- package/dist/react/index.d.ts +39 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9444 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/rpc-logger.d.ts +47 -0
- package/dist/react/rpc-logger.d.ts.map +1 -0
- package/dist/react/storage.d.ts +98 -0
- package/dist/react/storage.d.ts.map +1 -0
- package/dist/react/token-expiry.d.ts +9 -0
- package/dist/react/token-expiry.d.ts.map +1 -0
- package/dist/react/types.d.ts +727 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/useMcp-helpers.d.ts +99 -0
- package/dist/react/useMcp-helpers.d.ts.map +1 -0
- package/dist/react/useMcp-operations.d.ts +180 -0
- package/dist/react/useMcp-operations.d.ts.map +1 -0
- package/dist/react/useMcp.d.ts +48 -0
- package/dist/react/useMcp.d.ts.map +1 -0
- package/dist/react/useMcpServerQueues.d.ts +403 -0
- package/dist/react/useMcpServerQueues.d.ts.map +1 -0
- package/dist/react/view/ViewRenderer.d.ts +20 -0
- package/dist/react/view/ViewRenderer.d.ts.map +1 -0
- package/dist/react/view/ext-apps-bridge.d.ts +3 -0
- package/dist/react/view/ext-apps-bridge.d.ts.map +1 -0
- package/dist/react/view/initialized-sync.d.ts +13 -0
- package/dist/react/view/initialized-sync.d.ts.map +1 -0
- package/dist/react/view/inject-openai-file-apis.d.ts +9 -0
- package/dist/react/view/inject-openai-file-apis.d.ts.map +1 -0
- package/dist/react/view/parse-custom-props.d.ts +10 -0
- package/dist/react/view/parse-custom-props.d.ts.map +1 -0
- package/dist/react/view/resolve-view-resource.d.ts +22 -0
- package/dist/react/view/resolve-view-resource.d.ts.map +1 -0
- package/dist/react/view/sandbox-blob-url.d.ts +27 -0
- package/dist/react/view/sandbox-blob-url.d.ts.map +1 -0
- package/dist/react/view/types.d.ts +220 -0
- package/dist/react/view/types.d.ts.map +1 -0
- package/dist/react/view/use-display-mode.d.ts +19 -0
- package/dist/react/view/use-display-mode.d.ts.map +1 -0
- package/dist/react/view/view-detection.d.ts +22 -0
- package/dist/react/view/view-detection.d.ts.map +1 -0
- package/dist/react/view/view-host-policy.d.ts +61 -0
- package/dist/react/view/view-host-policy.d.ts.map +1 -0
- package/dist/sandbox.d.ts +2 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +288 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/telemetry/client-telemetry.d.ts +13 -0
- package/dist/telemetry/client-telemetry.d.ts.map +1 -0
- package/dist/telemetry/configure-browser.d.ts +2 -0
- package/dist/telemetry/configure-browser.d.ts.map +1 -0
- package/dist/telemetry/configure-node.d.ts +2 -0
- package/dist/telemetry/configure-node.d.ts.map +1 -0
- package/dist/telemetry/connector-telemetry.d.ts +8 -0
- package/dist/telemetry/connector-telemetry.d.ts.map +1 -0
- package/dist/telemetry/events.d.ts +91 -0
- package/dist/telemetry/events.d.ts.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/tel-fetch.d.ts +19 -0
- package/dist/telemetry/tel-fetch.d.ts.map +1 -0
- package/dist/telemetry/telemetry-browser.d.ts +6 -0
- package/dist/telemetry/telemetry-browser.d.ts.map +1 -0
- package/dist/telemetry/telemetry-node.d.ts +8 -0
- package/dist/telemetry/telemetry-node.d.ts.map +1 -0
- package/dist/telemetry/telemetry.d.ts +75 -0
- package/dist/telemetry/telemetry.d.ts.map +1 -0
- package/dist/transport/base.d.ts +656 -0
- package/dist/transport/base.d.ts.map +1 -0
- package/dist/transport/connection-manager.d.ts +59 -0
- package/dist/transport/connection-manager.d.ts.map +1 -0
- package/dist/transport/http.d.ts +137 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/stdio.d.ts +97 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/utils/elicitation.d.ts +54 -0
- package/dist/utils/elicitation.d.ts.map +1 -0
- package/dist/utils/favicon.d.ts +6 -0
- package/dist/utils/favicon.d.ts.map +1 -0
- package/dist/utils/json-schema-validator.d.ts +13 -0
- package/dist/utils/json-schema-validator.d.ts.map +1 -0
- package/dist/utils/logging.d.ts +33 -0
- package/dist/utils/logging.d.ts.map +1 -0
- package/dist/utils/version.d.ts +9 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,212 @@
|
|
|
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
|
+
/** Configures OAuth authorization for Node.js and CLI clients. */
|
|
5
|
+
export interface NodeOAuthOptions extends OAuthSessionStoreOptions {
|
|
6
|
+
/** Preferred loopback port. Default 33418. Walks up by `portRange` on EADDRINUSE. */
|
|
7
|
+
preferredPort?: number;
|
|
8
|
+
/** Number of consecutive loopback ports to try. Defaults to `10`. */
|
|
9
|
+
portRange?: number;
|
|
10
|
+
/** Override the on-disk store directory (mostly for tests). */
|
|
11
|
+
baseDir?: string;
|
|
12
|
+
/** Override KV store entirely (mostly for tests). */
|
|
13
|
+
kvStore?: KVStore;
|
|
14
|
+
/** Loopback wait timeout. Default 5 minutes. */
|
|
15
|
+
authTimeoutMs?: number;
|
|
16
|
+
/** Suppress the default `open(url)` browser launch (test hook). */
|
|
17
|
+
openBrowser?: (url: string) => Promise<void> | void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error reported by the local OAuth callback flow.
|
|
21
|
+
*
|
|
22
|
+
* The {@link OAuthFlowError.code} value is a stable OAuth or local-flow error
|
|
23
|
+
* code such as `"timeout"` or `"cancelled"`.
|
|
24
|
+
*/
|
|
25
|
+
export declare class OAuthFlowError extends Error {
|
|
26
|
+
/** OAuth or local-flow error code. */
|
|
27
|
+
readonly code: string;
|
|
28
|
+
/** Optional human-readable error description. */
|
|
29
|
+
readonly description?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an OAuth flow error.
|
|
32
|
+
*
|
|
33
|
+
* @param code - OAuth or local-flow error code.
|
|
34
|
+
* @param description - Optional human-readable description.
|
|
35
|
+
*/
|
|
36
|
+
constructor(code: string, description?: string);
|
|
37
|
+
}
|
|
38
|
+
/** Authorization response captured by the Node loopback callback. */
|
|
39
|
+
export interface NodeOAuthAuthorizationResponse {
|
|
40
|
+
/** Authorization code returned by the authorization server. */
|
|
41
|
+
code: string;
|
|
42
|
+
/** RFC 9207 authorization-server issuer, when present in the callback. */
|
|
43
|
+
iss?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Node/CLI OAuth client provider for MCP. Owns a localhost loopback callback
|
|
47
|
+
* server, opens the user's browser, and resolves the authorization code via
|
|
48
|
+
* `getAuthorizationCode()` — designed for the orchestrator pattern in
|
|
49
|
+
* `useMcp.ts:1121-1145`.
|
|
50
|
+
*
|
|
51
|
+
* Use the static `create()` factory; the constructor is internal because
|
|
52
|
+
* port reservation is async.
|
|
53
|
+
*/
|
|
54
|
+
export declare class NodeOAuthClientProvider implements OAuthClientProvider {
|
|
55
|
+
/** Protected MCP server URL associated with this provider. */
|
|
56
|
+
readonly serverUrl: string;
|
|
57
|
+
/** Reserved localhost callback port. */
|
|
58
|
+
readonly port: number;
|
|
59
|
+
private session;
|
|
60
|
+
private kv;
|
|
61
|
+
private authTimeoutMs;
|
|
62
|
+
private openBrowserOverride?;
|
|
63
|
+
/** Whether the selected callback port still needs to be written to storage. */
|
|
64
|
+
private shouldPersistSelectedPort;
|
|
65
|
+
private server;
|
|
66
|
+
/** Provider authorization URL, exposed only through the local redirect route. */
|
|
67
|
+
private authorizationUrl;
|
|
68
|
+
/** Currently in-flight deferred — used to prevent overlapping flows. */
|
|
69
|
+
private pending;
|
|
70
|
+
/** Latest deferred (settled or in-flight) for the loopback response. */
|
|
71
|
+
private lastFlow;
|
|
72
|
+
private pendingTimer;
|
|
73
|
+
private constructor();
|
|
74
|
+
/**
|
|
75
|
+
* Creates a Node OAuth provider and reserves a localhost callback port.
|
|
76
|
+
*
|
|
77
|
+
* @param serverUrl - Protected MCP server URL.
|
|
78
|
+
* @param options - OAuth metadata, storage, loopback, and browser options.
|
|
79
|
+
* @returns A provider ready to participate in the SDK OAuth flow.
|
|
80
|
+
*/
|
|
81
|
+
static create(serverUrl: string, options?: NodeOAuthOptions): Promise<NodeOAuthClientProvider>;
|
|
82
|
+
/** Prefix used for persisted OAuth session keys. */
|
|
83
|
+
get storageKeyPrefix(): string;
|
|
84
|
+
/** Stable hash of the protected server URL used to namespace storage. */
|
|
85
|
+
get serverUrlHash(): string;
|
|
86
|
+
/** Loopback redirect URL registered for this provider. */
|
|
87
|
+
get redirectUrl(): string;
|
|
88
|
+
/** OAuth client metadata presented during registration. */
|
|
89
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
90
|
+
/** OAuth Client ID Metadata Document URL, when configured. */
|
|
91
|
+
get clientMetadataUrl(): string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Loads saved OAuth tokens.
|
|
94
|
+
*
|
|
95
|
+
* @param ctx - Optional client registration context.
|
|
96
|
+
* @returns Saved tokens, or `undefined` when none exist.
|
|
97
|
+
*/
|
|
98
|
+
tokens(ctx?: OAuthClientInformationContext): Promise<OAuthTokens | undefined>;
|
|
99
|
+
/**
|
|
100
|
+
* Persists OAuth tokens.
|
|
101
|
+
*
|
|
102
|
+
* @param tokens - Tokens to save.
|
|
103
|
+
* @param ctx - Optional client registration context.
|
|
104
|
+
*/
|
|
105
|
+
saveTokens(tokens: OAuthTokens, ctx?: OAuthClientInformationContext): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Loads saved OAuth client registration information.
|
|
108
|
+
*
|
|
109
|
+
* @param ctx - Optional registration context.
|
|
110
|
+
* @returns Saved registration information, or `undefined`.
|
|
111
|
+
*/
|
|
112
|
+
clientInformation(ctx?: OAuthClientInformationContext): Promise<OAuthClientInformation | undefined>;
|
|
113
|
+
/**
|
|
114
|
+
* Persists OAuth client registration information.
|
|
115
|
+
*
|
|
116
|
+
* @param info - Client information to save.
|
|
117
|
+
* @param ctx - Optional registration context.
|
|
118
|
+
*/
|
|
119
|
+
saveClientInformation(info: OAuthClientInformation, ctx?: OAuthClientInformationContext): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Loads the saved PKCE code verifier.
|
|
122
|
+
*
|
|
123
|
+
* @returns The saved verifier.
|
|
124
|
+
*/
|
|
125
|
+
codeVerifier(): Promise<string>;
|
|
126
|
+
/**
|
|
127
|
+
* Persists a PKCE code verifier.
|
|
128
|
+
*
|
|
129
|
+
* @param codeVerifier - Verifier to save.
|
|
130
|
+
*/
|
|
131
|
+
saveCodeVerifier(codeVerifier: string): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Invalidates selected persisted OAuth credentials.
|
|
134
|
+
*
|
|
135
|
+
* @param scope - Credential group to remove.
|
|
136
|
+
*/
|
|
137
|
+
invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Persists OAuth discovery state.
|
|
140
|
+
*
|
|
141
|
+
* @param state - Discovery state to save.
|
|
142
|
+
*/
|
|
143
|
+
saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Returns previously saved OAuth discovery state.
|
|
146
|
+
*
|
|
147
|
+
* @returns Saved discovery state, or `undefined`.
|
|
148
|
+
*/
|
|
149
|
+
discoveryState(): Promise<OAuthDiscoveryState | undefined>;
|
|
150
|
+
/**
|
|
151
|
+
* Bind the loopback server, set up the pending-code deferred, and ask the
|
|
152
|
+
* platform to open the user's browser. Does NOT await the code; the
|
|
153
|
+
* orchestrator awaits via `getAuthorizationCode()`.
|
|
154
|
+
*
|
|
155
|
+
* @param authorizationUrl - Authorization URL generated by the SDK.
|
|
156
|
+
* @returns A promise that resolves once the loopback listener is ready and
|
|
157
|
+
* the browser-open attempt completes.
|
|
158
|
+
*/
|
|
159
|
+
redirectToAuthorization(authorizationUrl: URL): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Resolves with the authorization code captured by the loopback callback.
|
|
162
|
+
*
|
|
163
|
+
* @remarks This compatibility method omits the RFC 9207 issuer. OAuth flow
|
|
164
|
+
* orchestrators should use {@link getAuthorizationResponse} when available.
|
|
165
|
+
* Must be called after `redirectToAuthorization()`. Returns the same
|
|
166
|
+
* promise whether the callback has fired or not — callers may subscribe
|
|
167
|
+
* before or after.
|
|
168
|
+
*
|
|
169
|
+
* @returns The authorization code received by the loopback callback.
|
|
170
|
+
*/
|
|
171
|
+
getAuthorizationCode(): Promise<string>;
|
|
172
|
+
/**
|
|
173
|
+
* Resolves with the authorization code and RFC 9207 issuer captured by the
|
|
174
|
+
* loopback callback.
|
|
175
|
+
*
|
|
176
|
+
* @returns The loopback authorization response.
|
|
177
|
+
* @throws When called before {@link NodeOAuthClientProvider.redirectToAuthorization}.
|
|
178
|
+
*/
|
|
179
|
+
getAuthorizationResponse(): Promise<NodeOAuthAuthorizationResponse>;
|
|
180
|
+
/**
|
|
181
|
+
* Cancel an in-progress flow (timeout, SIGINT, etc.) and close the loopback.
|
|
182
|
+
*
|
|
183
|
+
* Pending calls to {@link NodeOAuthClientProvider.getAuthorizationResponse}
|
|
184
|
+
* reject with an {@link OAuthFlowError} whose code is `"cancelled"`.
|
|
185
|
+
*/
|
|
186
|
+
dispose(): void;
|
|
187
|
+
/** Local callback port, useful for status output and tests. */
|
|
188
|
+
get callbackPort(): number;
|
|
189
|
+
/**
|
|
190
|
+
* True if `redirectToAuthorization()` has been called and we're awaiting
|
|
191
|
+
* a callback (loopback bound, browser opened). Lets orchestrators detect
|
|
192
|
+
* when the SDK transport has already kicked off the flow on a 401, so they
|
|
193
|
+
* can skip straight to `getAuthorizationCode()` instead of calling `auth()`
|
|
194
|
+
* again (which would throw "already in progress").
|
|
195
|
+
*/
|
|
196
|
+
get hasPendingFlow(): boolean;
|
|
197
|
+
private startLoopback;
|
|
198
|
+
private stopLoopback;
|
|
199
|
+
private resolvePending;
|
|
200
|
+
private rejectPending;
|
|
201
|
+
private handleCallback;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Creates a Node OAuth provider for an MCP server.
|
|
205
|
+
*
|
|
206
|
+
* @param serverUrl - Protected MCP server URL.
|
|
207
|
+
* @param options - OAuth metadata, storage, loopback, and browser options.
|
|
208
|
+
* @returns A provider compatible with the MCP SDK OAuth flow.
|
|
209
|
+
*/
|
|
210
|
+
export declare function createOAuthProvider(serverUrl: string, options?: NodeOAuthOptions): Promise<OAuthClientProvider>;
|
|
211
|
+
export type { NodeOAuthOptions as OAuthProviderOptions };
|
|
212
|
+
//# 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,kEAAkE;AAClE,MAAM,WAAW,gBAAiB,SAAQ,wBAAwB;IAChE,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,OA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AAG,SAAS,CAAC;IAI1D;;;;;;;;OAQG;IACG,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAmDnE;;;;;;;;;;OAUG;IACH,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC;;;;;;OAMG;IACH,wBAAwB,IAAI,OAAO,CAAC,8BAA8B,CAAC;IAWnE;;;;;OAKG;IACH,OAAO,IAAI,IAAI;IAQf,+DAA+D;IAC/D,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;;;;;OAMG;IACH,IAAI,cAAc,IAAI,OAAO,CAE5B;YAIa,aAAa;IAwB3B,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,cAAc;CAoDvB;AAmBD;;;;;;GAMG;AACH,wBAAsB,mBAAmB,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,125 @@
|
|
|
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
|
+
/** Prefix used for persisted OAuth keys. */
|
|
31
|
+
storageKeyPrefix?: string;
|
|
32
|
+
/** Human-readable OAuth client name. */
|
|
33
|
+
clientName?: string;
|
|
34
|
+
/** Public website describing the OAuth client. */
|
|
35
|
+
clientUri?: string;
|
|
36
|
+
/** Public OAuth client logo URL. */
|
|
37
|
+
logoUri?: string;
|
|
38
|
+
/** OAuth redirect URI. */
|
|
39
|
+
callbackUrl?: string;
|
|
40
|
+
/** OAuth Client ID Metadata Document URL. */
|
|
41
|
+
clientMetadataUrl?: string;
|
|
42
|
+
/** Whether this platform may persist confidential-client credentials. */
|
|
43
|
+
allowClientSecret?: boolean;
|
|
44
|
+
/** OAuth scope string forwarded to the SDK via clientMetadata.scope. */
|
|
45
|
+
scope?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options passed by the platform provider when persisting an authorization
|
|
49
|
+
* request prior to redirecting the user agent.
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
interface StoreAuthorizationStateOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Platform-specific provider options that should round-trip through the
|
|
56
|
+
* stored state so the callback handler can rebuild the provider.
|
|
57
|
+
*/
|
|
58
|
+
extraProviderOptions?: Record<string, unknown>;
|
|
59
|
+
flowType?: "popup" | "redirect";
|
|
60
|
+
returnUrl?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Platform-neutral helper that owns OAuth session persistence and refresh
|
|
64
|
+
* logic. Used by `BrowserOAuthClientProvider` and `NodeOAuthClientProvider`
|
|
65
|
+
* — each platform provider implements `OAuthClientProvider` directly and
|
|
66
|
+
* delegates the generic methods here.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export declare class OAuthSessionStore {
|
|
71
|
+
readonly serverUrl: string;
|
|
72
|
+
readonly storageKeyPrefix: string;
|
|
73
|
+
readonly serverUrlHash: string;
|
|
74
|
+
readonly clientName: string;
|
|
75
|
+
readonly clientUri: string;
|
|
76
|
+
readonly logoUri: string;
|
|
77
|
+
readonly callbackUrl: string;
|
|
78
|
+
readonly clientMetadataUrl?: string;
|
|
79
|
+
readonly scope?: string;
|
|
80
|
+
private store;
|
|
81
|
+
private allowClientSecret;
|
|
82
|
+
constructor(serverUrl: string, options: OAuthSessionStoreOptions, store: KVStore);
|
|
83
|
+
getKey(keySuffix: string): string;
|
|
84
|
+
static hashString(str: string): string;
|
|
85
|
+
get redirectUrl(): string;
|
|
86
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
87
|
+
private credentialKey;
|
|
88
|
+
private readCredential;
|
|
89
|
+
tokens(ctx?: OAuthClientInformationContext): Promise<StoredOAuthTokens | undefined>;
|
|
90
|
+
saveTokens(tokens: StoredOAuthTokens, ctx?: OAuthClientInformationContext): Promise<void>;
|
|
91
|
+
clientInformation(ctx?: OAuthClientInformationContext): Promise<OAuthClientInformation | undefined>;
|
|
92
|
+
saveClientInformation(clientInformation: OAuthClientInformation, ctx?: OAuthClientInformationContext): Promise<void>;
|
|
93
|
+
saveCodeVerifier(codeVerifier: string): Promise<void>;
|
|
94
|
+
codeVerifier(): Promise<string>;
|
|
95
|
+
invalidateCredentials(scope: "all" | "registration" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Persist the OAuth discovery state (authorization-server metadata resolved
|
|
98
|
+
* during the auth flow). Stored with the same durability as the code
|
|
99
|
+
* verifier so the callback leg can verify it is exchanging the code at the
|
|
100
|
+
* same authorization server the redirect targeted (SEP-2352 mix-up defense).
|
|
101
|
+
*/
|
|
102
|
+
saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
|
|
103
|
+
/** Return the previously saved discovery state, or `undefined`. */
|
|
104
|
+
discoveryState(): Promise<OAuthDiscoveryState | undefined>;
|
|
105
|
+
/**
|
|
106
|
+
* Generates and persists `StoredState` for an authorization request,
|
|
107
|
+
* appends the `state` query param to the URL, and persists the sanitized
|
|
108
|
+
* URL to `last_auth_url` so it can be replayed on popup-blocker fallback.
|
|
109
|
+
*
|
|
110
|
+
* @returns The sanitized authorization URL string with the `state` param appended.
|
|
111
|
+
*/
|
|
112
|
+
storeAuthorizationState(authorizationUrl: URL, opts?: StoreAuthorizationStateOptions): Promise<string>;
|
|
113
|
+
/**
|
|
114
|
+
* Return the token endpoint from SDK-managed discovery state. The SDK
|
|
115
|
+
* persists this state during `auth()`, avoiding a second discovery flow.
|
|
116
|
+
*/
|
|
117
|
+
getTokenEndpoint(): Promise<string | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Return the protected-resource URL selected during OAuth discovery.
|
|
120
|
+
* Consumers can persist it and reuse it for server-side refresh exchanges.
|
|
121
|
+
*/
|
|
122
|
+
getResource(): Promise<string | null>;
|
|
123
|
+
}
|
|
124
|
+
export {};
|
|
125
|
+
//# 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;QACzB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,gBAAgB,CAAC,EAAE,sBAAsB,CAA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EAAE,GAAG,EACrB,IAAI,GAAE,8BAAmC,GACxC,OAAO,CAAC,MAAM,CAAC;IAqClB;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAOhD;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAI5C"}
|
|
@@ -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;IAOnD,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,34 @@
|
|
|
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
|
+
* Encrypted `KVStore` backed by `globalThis.localStorage`.
|
|
16
|
+
*
|
|
17
|
+
* Values use AES-256-GCM with a non-extractable origin key held by IndexedDB.
|
|
18
|
+
* Legacy plaintext values are encrypted on first read. When durable browser
|
|
19
|
+
* cryptography is unavailable, the store removes plaintext and falls back to
|
|
20
|
+
* memory for the lifetime of this instance.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare class LocalStorageKVStore implements KVStore {
|
|
25
|
+
private readonly fallback;
|
|
26
|
+
private keyPromise;
|
|
27
|
+
private durable;
|
|
28
|
+
get(key: string): Promise<string | null>;
|
|
29
|
+
set(key: string, value: string): Promise<void>;
|
|
30
|
+
remove(key: string): void;
|
|
31
|
+
keys(): string[];
|
|
32
|
+
private getCryptoKey;
|
|
33
|
+
}
|
|
34
|
+
//# 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;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,YAAW,OAAO;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,OAAO,CAAQ;IAEjB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAoCxC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqCpD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IASzB,IAAI,IAAI,MAAM,EAAE;IAehB,OAAO,CAAC,YAAY;CAIrB"}
|
|
@@ -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;AAKF;;;;;;;;;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;CAyC3B"}
|
|
@@ -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;IAoGpB;;;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"}
|