@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,792 @@
|
|
|
1
|
+
import type { CallToolResult, CompleteRequestParams, CompleteResult, MetaObject, Notification, ProtocolEra, RequestOptions, Root, Tool } from "@modelcontextprotocol/client";
|
|
2
|
+
import type { BaseConnector, NotificationHandler } from "../transport/base.js";
|
|
3
|
+
/** Negotiated protocol era: `"legacy"` or `"modern"`. */
|
|
4
|
+
export type MCPProtocolEra = ProtocolEra;
|
|
5
|
+
/** OAuth availability inferred after an anonymous MCP connection succeeds. */
|
|
6
|
+
export interface MCPAuthorizationInfo {
|
|
7
|
+
/** Mixed auth means public MCP operations succeeded while OAuth is available. */
|
|
8
|
+
mode: "mixed";
|
|
9
|
+
/** Whether this client currently has OAuth access tokens. */
|
|
10
|
+
authenticated: boolean;
|
|
11
|
+
/** Canonical protected-resource identifier from RFC 9728 metadata. */
|
|
12
|
+
resource?: string;
|
|
13
|
+
/** Scopes advertised by the protected resource, when provided. */
|
|
14
|
+
scopesSupported?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Server information normalized across legacy sessionful and modern sessionless
|
|
18
|
+
* MCP protocols.
|
|
19
|
+
*/
|
|
20
|
+
export interface MCPServerInfo {
|
|
21
|
+
/** Stable server name. */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Server version reported during initialization. */
|
|
24
|
+
version?: string;
|
|
25
|
+
/** Optional human-readable server title. */
|
|
26
|
+
title?: string;
|
|
27
|
+
/** Optional human-readable server description. */
|
|
28
|
+
description?: string;
|
|
29
|
+
/** Public website describing the server. */
|
|
30
|
+
websiteUrl?: string;
|
|
31
|
+
/** Icons advertised by the server. */
|
|
32
|
+
icons?: Array<{
|
|
33
|
+
/** Icon URL. */
|
|
34
|
+
src: string;
|
|
35
|
+
/** Icon media type. */
|
|
36
|
+
mimeType?: string;
|
|
37
|
+
/** Supported icon sizes, such as `"48x48"`. */
|
|
38
|
+
sizes?: string[];
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Connection metadata available after the MCP SDK has negotiated a protocol.
|
|
43
|
+
*
|
|
44
|
+
* `extensions` retains protocol-specific extensions without requiring
|
|
45
|
+
* callers to branch on the negotiated era.
|
|
46
|
+
*/
|
|
47
|
+
export interface MCPConnectionInfo {
|
|
48
|
+
/** Negotiated protocol era. */
|
|
49
|
+
protocolEra: MCPProtocolEra;
|
|
50
|
+
/** Negotiated MCP protocol version. */
|
|
51
|
+
protocolVersion: string;
|
|
52
|
+
/** Server identity reported during negotiation, when provided. */
|
|
53
|
+
server?: MCPServerInfo;
|
|
54
|
+
/** Capabilities advertised by the server. */
|
|
55
|
+
capabilities: Record<string, unknown>;
|
|
56
|
+
/** Instructions advertised by the server. */
|
|
57
|
+
instructions?: string;
|
|
58
|
+
/** Protocol extension metadata advertised by the server. */
|
|
59
|
+
extensions: Record<string, unknown>;
|
|
60
|
+
/** Optional OAuth state discovered without forcing authentication. */
|
|
61
|
+
authorization?: MCPAuthorizationInfo;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A ready connection to an MCP server.
|
|
65
|
+
*
|
|
66
|
+
* The connection has the same public API for legacy, sessionful MCP servers
|
|
67
|
+
* and modern, sessionless MCP servers. The underlying SDK owns the lifecycle
|
|
68
|
+
* distinction and protocol negotiation.
|
|
69
|
+
*
|
|
70
|
+
* Sessions handle:
|
|
71
|
+
* - Connection lifecycle (connect, disconnect, initialize)
|
|
72
|
+
* - Tool invocation
|
|
73
|
+
* - Resource access
|
|
74
|
+
* - Prompt retrieval
|
|
75
|
+
* - Notification handling
|
|
76
|
+
* - Root directory management
|
|
77
|
+
*
|
|
78
|
+
* Sessions are typically created by `MCPClient.createSession()` rather than
|
|
79
|
+
* being instantiated directly.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Create via client
|
|
84
|
+
* const client = new MCPClient('./config.json');
|
|
85
|
+
* const session = await client.createSession('my-server');
|
|
86
|
+
*
|
|
87
|
+
* // Use the session
|
|
88
|
+
* const tools = await session.listTools();
|
|
89
|
+
* const result = await session.callTool('my-tool', { arg: 'value' });
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Manual creation (advanced)
|
|
95
|
+
* import { StdioConnector } from "@mcp-use/client";
|
|
96
|
+
*
|
|
97
|
+
* const connector = new StdioConnector({
|
|
98
|
+
* command: 'node',
|
|
99
|
+
* args: ['server.js']
|
|
100
|
+
* });
|
|
101
|
+
* const session = new MCPSession(connector);
|
|
102
|
+
* await session.initialize();
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @see {@link BaseConnector} for connector implementations
|
|
106
|
+
*/
|
|
107
|
+
export declare class MCPConnection {
|
|
108
|
+
/**
|
|
109
|
+
* The underlying connector managing the transport layer.
|
|
110
|
+
* This is the Stdio, HTTP, or WebSocket connector handling actual communication.
|
|
111
|
+
*/
|
|
112
|
+
readonly connector: BaseConnector;
|
|
113
|
+
/**
|
|
114
|
+
* Whether to automatically connect when initializing.
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
private autoConnect;
|
|
118
|
+
/**
|
|
119
|
+
* Creates a new MCP session.
|
|
120
|
+
*
|
|
121
|
+
* @param connector - The connector to use for communication (Stdio, HTTP, WebSocket)
|
|
122
|
+
* @param autoConnect - Whether to automatically connect during initialization (default: true)
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const connector = new HttpConnector({ url: 'http://localhost:3000/mcp' });
|
|
127
|
+
* const session = new MCPSession(connector);
|
|
128
|
+
* await session.initialize(); // Auto-connects and initializes
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Manual connection control
|
|
134
|
+
* const session = new MCPSession(connector, false);
|
|
135
|
+
* await session.connect();
|
|
136
|
+
* await session.initialize();
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
constructor(connector: BaseConnector, autoConnect?: boolean);
|
|
140
|
+
/**
|
|
141
|
+
* Establishes the connection to the MCP server.
|
|
142
|
+
*
|
|
143
|
+
* This method starts the underlying transport (spawns process for Stdio,
|
|
144
|
+
* opens WebSocket, etc.) but does not perform the MCP initialization
|
|
145
|
+
* handshake. Call {@link initialize} after connecting.
|
|
146
|
+
*
|
|
147
|
+
* @returns Promise that resolves when connected
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* await session.connect();
|
|
152
|
+
* await session.initialize();
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @see {@link initialize} for performing the MCP handshake
|
|
156
|
+
* @see {@link disconnect} for closing the connection
|
|
157
|
+
*/
|
|
158
|
+
connect(): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Closes the connection to the MCP server.
|
|
161
|
+
*
|
|
162
|
+
* This method gracefully shuts down the transport and cleans up resources.
|
|
163
|
+
* After disconnecting, the session cannot be used until reconnected.
|
|
164
|
+
*
|
|
165
|
+
* @returns Promise that resolves when disconnected
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* await session.disconnect();
|
|
170
|
+
* console.log('Session closed');
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @see {@link connect} for establishing connections
|
|
174
|
+
*/
|
|
175
|
+
disconnect(): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Initializes the MCP session with the server.
|
|
178
|
+
*
|
|
179
|
+
* This method performs the MCP initialization handshake, exchanging
|
|
180
|
+
* capabilities and metadata with the server. If `autoConnect` is true
|
|
181
|
+
* and the session is not yet connected, it will connect first.
|
|
182
|
+
*
|
|
183
|
+
* After initialization, you can list and call tools, read resources, etc.
|
|
184
|
+
*
|
|
185
|
+
* @returns Promise that resolves when initialized
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const session = await client.createSession('my-server', false);
|
|
190
|
+
* await session.connect();
|
|
191
|
+
* await session.initialize();
|
|
192
|
+
* // Now ready to use
|
|
193
|
+
* const tools = await session.listTools();
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @see {@link connect} for establishing the connection first
|
|
197
|
+
*/
|
|
198
|
+
initialize(): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Checks if the session is currently connected to the server.
|
|
201
|
+
*
|
|
202
|
+
* @returns True if connected, false otherwise
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* if (session.isConnected) {
|
|
207
|
+
* const tools = await session.listTools();
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
get isConnected(): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Register an event handler for session events
|
|
214
|
+
*
|
|
215
|
+
* @param event - The event type to listen for
|
|
216
|
+
* @param handler - The handler function to call when the event occurs
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* session.on("notification", async (notification) => {
|
|
221
|
+
* console.log(`Received: ${notification.method}`, notification.params);
|
|
222
|
+
*
|
|
223
|
+
* if (notification.method === "notifications/tools/list_changed") {
|
|
224
|
+
* // Refresh tools list
|
|
225
|
+
* }
|
|
226
|
+
* });
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
on(event: "notification", handler: NotificationHandler): void;
|
|
230
|
+
/**
|
|
231
|
+
* Set roots and notify the server.
|
|
232
|
+
* Roots represent directories or files that the client has access to.
|
|
233
|
+
*
|
|
234
|
+
* @param roots - Array of Root objects with `uri` (must start with "file://") and optional `name`
|
|
235
|
+
*
|
|
236
|
+
* @deprecated Roots are a v1 compatibility feature and are not part of the
|
|
237
|
+
* sessionless v2 protocol.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* await session.setRoots([
|
|
242
|
+
* { uri: "file:///home/user/project", name: "My Project" },
|
|
243
|
+
* { uri: "file:///home/user/data" }
|
|
244
|
+
* ]);
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
setRoots(roots: Root[]): Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* Gets the current roots advertised to the server.
|
|
250
|
+
*
|
|
251
|
+
* Roots represent directories or files that the client has provided access to.
|
|
252
|
+
* The server may use this information to scope its operations.
|
|
253
|
+
*
|
|
254
|
+
* @returns Array of Root objects
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const roots = session.getRoots();
|
|
259
|
+
* console.log(`Current roots: ${roots.map(r => r.uri).join(', ')}`);
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @see {@link setRoots} for updating roots
|
|
263
|
+
*/
|
|
264
|
+
getRoots(): Root[];
|
|
265
|
+
/**
|
|
266
|
+
* Get the cached list of tools from the server.
|
|
267
|
+
*
|
|
268
|
+
* @returns Array of available tools
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const tools = session.tools;
|
|
273
|
+
* console.log(`Available tools: ${tools.map(t => t.name).join(", ")}`);
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
get tools(): Tool[];
|
|
277
|
+
/**
|
|
278
|
+
* List all available tools from the MCP server.
|
|
279
|
+
* This method fetches fresh tools from the server, unlike the `tools` getter which returns cached tools.
|
|
280
|
+
*
|
|
281
|
+
* @param options - Optional request options
|
|
282
|
+
* @returns Array of available tools
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const tools = await session.listTools();
|
|
287
|
+
* console.log(`Available tools: ${tools.map(t => t.name).join(", ")}`);
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
listTools(options?: RequestOptions): Promise<Tool[]>;
|
|
291
|
+
/**
|
|
292
|
+
* Get the server capabilities advertised during initialization.
|
|
293
|
+
*
|
|
294
|
+
* @returns Server capabilities object
|
|
295
|
+
*/
|
|
296
|
+
get serverCapabilities(): Record<string, unknown>;
|
|
297
|
+
/**
|
|
298
|
+
* Get the server information (name and version).
|
|
299
|
+
*
|
|
300
|
+
* @returns Server info object or null if not available
|
|
301
|
+
*/
|
|
302
|
+
get serverInfo(): MCPServerInfo | null;
|
|
303
|
+
/** OAuth state discovered for this connection, when available. */
|
|
304
|
+
get authorization(): MCPAuthorizationInfo | undefined;
|
|
305
|
+
/** Discover optional OAuth metadata without delaying MCP readiness. */
|
|
306
|
+
discoverAuthorization(): Promise<MCPAuthorizationInfo | undefined>;
|
|
307
|
+
/** Authenticate an already-connected mixed-auth server. */
|
|
308
|
+
authenticate(): Promise<void>;
|
|
309
|
+
/**
|
|
310
|
+
* The negotiated protocol era for this session's connection:
|
|
311
|
+
* `"legacy"` (2025-era) or `"modern"` (2026-07-28-era).
|
|
312
|
+
* `undefined` before the connection has negotiated.
|
|
313
|
+
*/
|
|
314
|
+
get protocolEra(): MCPProtocolEra | undefined;
|
|
315
|
+
/** The negotiated protocol version string for this session's connection. */
|
|
316
|
+
get negotiatedProtocolVersion(): string | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* Normalized server metadata for this ready connection.
|
|
319
|
+
*
|
|
320
|
+
* @throws When called before protocol negotiation completes.
|
|
321
|
+
*/
|
|
322
|
+
get info(): MCPConnectionInfo;
|
|
323
|
+
/**
|
|
324
|
+
* Whether the server advertised a named MCP capability.
|
|
325
|
+
*
|
|
326
|
+
* @param capability - A top-level capability name such as `"tools"` or
|
|
327
|
+
* `"resources"`.
|
|
328
|
+
*/
|
|
329
|
+
supports(capability: string): boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Call a tool on the server.
|
|
332
|
+
*
|
|
333
|
+
* @param name - Name of the tool to call
|
|
334
|
+
* @param args - Arguments to pass to the tool (defaults to empty object)
|
|
335
|
+
* @param options - Optional request options (timeout, progress handlers, etc.)
|
|
336
|
+
* @returns Result from the tool execution
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* const result = await session.callTool("add", { a: 5, b: 3 });
|
|
341
|
+
* console.log(`Result: ${result.content[0].text}`);
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
callTool(name: string, args?: Record<string, any>, options?: RequestOptions): Promise<CallToolResult>;
|
|
345
|
+
/**
|
|
346
|
+
* List resources from the server with optional pagination.
|
|
347
|
+
*
|
|
348
|
+
* @param cursor - Optional cursor for pagination
|
|
349
|
+
* @param options - Request options
|
|
350
|
+
* @returns Resource list with optional nextCursor for pagination
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* const result = await session.listResources();
|
|
355
|
+
* console.log(`Found ${result.resources.length} resources`);
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
listResources(cursor?: string, options?: RequestOptions): Promise<{
|
|
359
|
+
[x: string]: unknown;
|
|
360
|
+
resources: {
|
|
361
|
+
uri: string;
|
|
362
|
+
name: string;
|
|
363
|
+
description?: string | undefined;
|
|
364
|
+
mimeType?: string | undefined;
|
|
365
|
+
size?: number | undefined;
|
|
366
|
+
annotations?: {
|
|
367
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
368
|
+
priority?: number | undefined;
|
|
369
|
+
lastModified?: string | undefined;
|
|
370
|
+
} | undefined;
|
|
371
|
+
_meta?: {
|
|
372
|
+
[x: string]: unknown;
|
|
373
|
+
} | undefined;
|
|
374
|
+
icons?: {
|
|
375
|
+
src: string;
|
|
376
|
+
mimeType?: string | undefined;
|
|
377
|
+
sizes?: string[] | undefined;
|
|
378
|
+
theme?: "light" | "dark" | undefined;
|
|
379
|
+
}[] | undefined;
|
|
380
|
+
title?: string | undefined;
|
|
381
|
+
}[];
|
|
382
|
+
_meta?: {
|
|
383
|
+
[x: string]: unknown;
|
|
384
|
+
"io.modelcontextprotocol/serverInfo"?: {
|
|
385
|
+
version: string;
|
|
386
|
+
name: string;
|
|
387
|
+
websiteUrl?: string | undefined;
|
|
388
|
+
description?: string | undefined;
|
|
389
|
+
icons?: {
|
|
390
|
+
src: string;
|
|
391
|
+
mimeType?: string | undefined;
|
|
392
|
+
sizes?: string[] | undefined;
|
|
393
|
+
theme?: "light" | "dark" | undefined;
|
|
394
|
+
}[] | undefined;
|
|
395
|
+
title?: string | undefined;
|
|
396
|
+
} | undefined;
|
|
397
|
+
} | undefined;
|
|
398
|
+
nextCursor?: string | undefined;
|
|
399
|
+
}>;
|
|
400
|
+
/**
|
|
401
|
+
* List all resources from the server, automatically handling pagination.
|
|
402
|
+
*
|
|
403
|
+
* @param options - Request options
|
|
404
|
+
* @returns Complete list of all resources
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```typescript
|
|
408
|
+
* const result = await session.listAllResources();
|
|
409
|
+
* console.log(`Total resources: ${result.resources.length}`);
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
listAllResources(options?: RequestOptions): Promise<{
|
|
413
|
+
resources: any[];
|
|
414
|
+
}>;
|
|
415
|
+
/**
|
|
416
|
+
* List resource templates from the server.
|
|
417
|
+
*
|
|
418
|
+
* @param options - Request options
|
|
419
|
+
* @returns List of available resource templates
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```typescript
|
|
423
|
+
* const result = await session.listResourceTemplates();
|
|
424
|
+
* console.log(`Available templates: ${result.resourceTemplates.length}`);
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
listResourceTemplates(options?: RequestOptions): Promise<{
|
|
428
|
+
[x: string]: unknown;
|
|
429
|
+
resourceTemplates: {
|
|
430
|
+
uriTemplate: string;
|
|
431
|
+
name: string;
|
|
432
|
+
description?: string | undefined;
|
|
433
|
+
mimeType?: string | undefined;
|
|
434
|
+
annotations?: {
|
|
435
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
436
|
+
priority?: number | undefined;
|
|
437
|
+
lastModified?: string | undefined;
|
|
438
|
+
} | undefined;
|
|
439
|
+
_meta?: {
|
|
440
|
+
[x: string]: unknown;
|
|
441
|
+
} | undefined;
|
|
442
|
+
icons?: {
|
|
443
|
+
src: string;
|
|
444
|
+
mimeType?: string | undefined;
|
|
445
|
+
sizes?: string[] | undefined;
|
|
446
|
+
theme?: "light" | "dark" | undefined;
|
|
447
|
+
}[] | undefined;
|
|
448
|
+
title?: string | undefined;
|
|
449
|
+
}[];
|
|
450
|
+
_meta?: {
|
|
451
|
+
[x: string]: unknown;
|
|
452
|
+
"io.modelcontextprotocol/serverInfo"?: {
|
|
453
|
+
version: string;
|
|
454
|
+
name: string;
|
|
455
|
+
websiteUrl?: string | undefined;
|
|
456
|
+
description?: string | undefined;
|
|
457
|
+
icons?: {
|
|
458
|
+
src: string;
|
|
459
|
+
mimeType?: string | undefined;
|
|
460
|
+
sizes?: string[] | undefined;
|
|
461
|
+
theme?: "light" | "dark" | undefined;
|
|
462
|
+
}[] | undefined;
|
|
463
|
+
title?: string | undefined;
|
|
464
|
+
} | undefined;
|
|
465
|
+
} | undefined;
|
|
466
|
+
nextCursor?: string | undefined;
|
|
467
|
+
}>;
|
|
468
|
+
/**
|
|
469
|
+
* Request completion suggestions for a prompt or resource template argument.
|
|
470
|
+
*
|
|
471
|
+
* @param params - Completion request parameters
|
|
472
|
+
* @param options - Request options
|
|
473
|
+
* @returns Completion suggestions from the server
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* // Complete a prompt argument
|
|
478
|
+
* const result = await session.complete({
|
|
479
|
+
* ref: { type: "ref/prompt", name: "my-prompt" },
|
|
480
|
+
* argument: { name: "language", value: "py" }
|
|
481
|
+
* });
|
|
482
|
+
* console.log(result.completion.values); // ["python"]
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
485
|
+
complete(params: CompleteRequestParams, options?: RequestOptions): Promise<CompleteResult>;
|
|
486
|
+
/**
|
|
487
|
+
* Read a resource by URI.
|
|
488
|
+
*
|
|
489
|
+
* @param uri - URI of the resource to read
|
|
490
|
+
* @param options - Request options
|
|
491
|
+
* @returns Resource content
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```typescript
|
|
495
|
+
* const resource = await session.readResource("file:///path/to/file.txt");
|
|
496
|
+
* console.log(resource.contents);
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
readResource(uri: string, options?: RequestOptions): Promise<{
|
|
500
|
+
[x: string]: unknown;
|
|
501
|
+
contents: ({
|
|
502
|
+
uri: string;
|
|
503
|
+
text: string;
|
|
504
|
+
mimeType?: string | undefined;
|
|
505
|
+
_meta?: {
|
|
506
|
+
[x: string]: unknown;
|
|
507
|
+
} | undefined;
|
|
508
|
+
} | {
|
|
509
|
+
uri: string;
|
|
510
|
+
blob: string;
|
|
511
|
+
mimeType?: string | undefined;
|
|
512
|
+
_meta?: {
|
|
513
|
+
[x: string]: unknown;
|
|
514
|
+
} | undefined;
|
|
515
|
+
})[];
|
|
516
|
+
_meta?: {
|
|
517
|
+
[x: string]: unknown;
|
|
518
|
+
"io.modelcontextprotocol/serverInfo"?: {
|
|
519
|
+
version: string;
|
|
520
|
+
name: string;
|
|
521
|
+
websiteUrl?: string | undefined;
|
|
522
|
+
description?: string | undefined;
|
|
523
|
+
icons?: {
|
|
524
|
+
src: string;
|
|
525
|
+
mimeType?: string | undefined;
|
|
526
|
+
sizes?: string[] | undefined;
|
|
527
|
+
theme?: "light" | "dark" | undefined;
|
|
528
|
+
}[] | undefined;
|
|
529
|
+
title?: string | undefined;
|
|
530
|
+
} | undefined;
|
|
531
|
+
} | undefined;
|
|
532
|
+
}>;
|
|
533
|
+
/**
|
|
534
|
+
* Subscribe to resource updates.
|
|
535
|
+
*
|
|
536
|
+
* @param uri - URI of the resource to subscribe to
|
|
537
|
+
* @param options - Request options
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```typescript
|
|
541
|
+
* await session.subscribeToResource("file:///path/to/file.txt");
|
|
542
|
+
* // Now you'll receive notifications when this resource changes
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
subscribeToResource(uri: string, options?: RequestOptions): Promise<{
|
|
546
|
+
_meta?: {
|
|
547
|
+
[x: string]: unknown;
|
|
548
|
+
"io.modelcontextprotocol/serverInfo"?: {
|
|
549
|
+
version: string;
|
|
550
|
+
name: string;
|
|
551
|
+
websiteUrl?: string | undefined;
|
|
552
|
+
description?: string | undefined;
|
|
553
|
+
icons?: {
|
|
554
|
+
src: string;
|
|
555
|
+
mimeType?: string | undefined;
|
|
556
|
+
sizes?: string[] | undefined;
|
|
557
|
+
theme?: "light" | "dark" | undefined;
|
|
558
|
+
}[] | undefined;
|
|
559
|
+
title?: string | undefined;
|
|
560
|
+
} | undefined;
|
|
561
|
+
} | undefined;
|
|
562
|
+
}>;
|
|
563
|
+
/**
|
|
564
|
+
* Unsubscribe from resource updates.
|
|
565
|
+
*
|
|
566
|
+
* @param uri - URI of the resource to unsubscribe from
|
|
567
|
+
* @param options - Request options
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* ```typescript
|
|
571
|
+
* await session.unsubscribeFromResource("file:///path/to/file.txt");
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
unsubscribeFromResource(uri: string, options?: RequestOptions): Promise<{
|
|
575
|
+
_meta?: {
|
|
576
|
+
[x: string]: unknown;
|
|
577
|
+
"io.modelcontextprotocol/serverInfo"?: {
|
|
578
|
+
version: string;
|
|
579
|
+
name: string;
|
|
580
|
+
websiteUrl?: string | undefined;
|
|
581
|
+
description?: string | undefined;
|
|
582
|
+
icons?: {
|
|
583
|
+
src: string;
|
|
584
|
+
mimeType?: string | undefined;
|
|
585
|
+
sizes?: string[] | undefined;
|
|
586
|
+
theme?: "light" | "dark" | undefined;
|
|
587
|
+
}[] | undefined;
|
|
588
|
+
title?: string | undefined;
|
|
589
|
+
} | undefined;
|
|
590
|
+
} | undefined;
|
|
591
|
+
}>;
|
|
592
|
+
/**
|
|
593
|
+
* List available prompts from the server.
|
|
594
|
+
*
|
|
595
|
+
* @returns List of available prompts
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* const result = await session.listPrompts();
|
|
600
|
+
* console.log(`Available prompts: ${result.prompts.length}`);
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
listPrompts(): Promise<{
|
|
604
|
+
[x: string]: unknown;
|
|
605
|
+
prompts: {
|
|
606
|
+
name: string;
|
|
607
|
+
description?: string | undefined;
|
|
608
|
+
arguments?: {
|
|
609
|
+
name: string;
|
|
610
|
+
description?: string | undefined;
|
|
611
|
+
required?: boolean | undefined;
|
|
612
|
+
}[] | undefined;
|
|
613
|
+
_meta?: {
|
|
614
|
+
[x: string]: unknown;
|
|
615
|
+
} | undefined;
|
|
616
|
+
icons?: {
|
|
617
|
+
src: string;
|
|
618
|
+
mimeType?: string | undefined;
|
|
619
|
+
sizes?: string[] | undefined;
|
|
620
|
+
theme?: "light" | "dark" | undefined;
|
|
621
|
+
}[] | undefined;
|
|
622
|
+
title?: string | undefined;
|
|
623
|
+
}[];
|
|
624
|
+
_meta?: {
|
|
625
|
+
[x: string]: unknown;
|
|
626
|
+
"io.modelcontextprotocol/serverInfo"?: {
|
|
627
|
+
version: string;
|
|
628
|
+
name: string;
|
|
629
|
+
websiteUrl?: string | undefined;
|
|
630
|
+
description?: string | undefined;
|
|
631
|
+
icons?: {
|
|
632
|
+
src: string;
|
|
633
|
+
mimeType?: string | undefined;
|
|
634
|
+
sizes?: string[] | undefined;
|
|
635
|
+
theme?: "light" | "dark" | undefined;
|
|
636
|
+
}[] | undefined;
|
|
637
|
+
title?: string | undefined;
|
|
638
|
+
} | undefined;
|
|
639
|
+
} | undefined;
|
|
640
|
+
nextCursor?: string | undefined;
|
|
641
|
+
}>;
|
|
642
|
+
/**
|
|
643
|
+
* Get a specific prompt with arguments.
|
|
644
|
+
*
|
|
645
|
+
* @param name - Name of the prompt to get
|
|
646
|
+
* @param args - Arguments for the prompt
|
|
647
|
+
* @param options - Per-request timeout, cancellation, and progress options
|
|
648
|
+
* @returns Prompt result
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* ```typescript
|
|
652
|
+
* const prompt = await session.getPrompt("greeting", { name: "Alice" });
|
|
653
|
+
* console.log(prompt.messages);
|
|
654
|
+
* ```
|
|
655
|
+
*/
|
|
656
|
+
getPrompt(name: string, args: Record<string, any>, options?: RequestOptions): Promise<{
|
|
657
|
+
[x: string]: unknown;
|
|
658
|
+
messages: {
|
|
659
|
+
role: "user" | "assistant";
|
|
660
|
+
content: {
|
|
661
|
+
type: "text";
|
|
662
|
+
text: string;
|
|
663
|
+
annotations?: {
|
|
664
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
665
|
+
priority?: number | undefined;
|
|
666
|
+
lastModified?: string | undefined;
|
|
667
|
+
} | undefined;
|
|
668
|
+
_meta?: {
|
|
669
|
+
[x: string]: unknown;
|
|
670
|
+
} | undefined;
|
|
671
|
+
} | {
|
|
672
|
+
type: "image";
|
|
673
|
+
data: string;
|
|
674
|
+
mimeType: string;
|
|
675
|
+
annotations?: {
|
|
676
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
677
|
+
priority?: number | undefined;
|
|
678
|
+
lastModified?: string | undefined;
|
|
679
|
+
} | undefined;
|
|
680
|
+
_meta?: {
|
|
681
|
+
[x: string]: unknown;
|
|
682
|
+
} | undefined;
|
|
683
|
+
} | {
|
|
684
|
+
type: "audio";
|
|
685
|
+
data: string;
|
|
686
|
+
mimeType: string;
|
|
687
|
+
annotations?: {
|
|
688
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
689
|
+
priority?: number | undefined;
|
|
690
|
+
lastModified?: string | undefined;
|
|
691
|
+
} | undefined;
|
|
692
|
+
_meta?: {
|
|
693
|
+
[x: string]: unknown;
|
|
694
|
+
} | undefined;
|
|
695
|
+
} | {
|
|
696
|
+
uri: string;
|
|
697
|
+
name: string;
|
|
698
|
+
type: "resource_link";
|
|
699
|
+
description?: string | undefined;
|
|
700
|
+
mimeType?: string | undefined;
|
|
701
|
+
size?: number | undefined;
|
|
702
|
+
annotations?: {
|
|
703
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
704
|
+
priority?: number | undefined;
|
|
705
|
+
lastModified?: string | undefined;
|
|
706
|
+
} | undefined;
|
|
707
|
+
_meta?: {
|
|
708
|
+
[x: string]: unknown;
|
|
709
|
+
} | undefined;
|
|
710
|
+
icons?: {
|
|
711
|
+
src: string;
|
|
712
|
+
mimeType?: string | undefined;
|
|
713
|
+
sizes?: string[] | undefined;
|
|
714
|
+
theme?: "light" | "dark" | undefined;
|
|
715
|
+
}[] | undefined;
|
|
716
|
+
title?: string | undefined;
|
|
717
|
+
} | {
|
|
718
|
+
type: "resource";
|
|
719
|
+
resource: {
|
|
720
|
+
uri: string;
|
|
721
|
+
text: string;
|
|
722
|
+
mimeType?: string | undefined;
|
|
723
|
+
_meta?: {
|
|
724
|
+
[x: string]: unknown;
|
|
725
|
+
} | undefined;
|
|
726
|
+
} | {
|
|
727
|
+
uri: string;
|
|
728
|
+
blob: string;
|
|
729
|
+
mimeType?: string | undefined;
|
|
730
|
+
_meta?: {
|
|
731
|
+
[x: string]: unknown;
|
|
732
|
+
} | undefined;
|
|
733
|
+
};
|
|
734
|
+
annotations?: {
|
|
735
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
736
|
+
priority?: number | undefined;
|
|
737
|
+
lastModified?: string | undefined;
|
|
738
|
+
} | undefined;
|
|
739
|
+
_meta?: {
|
|
740
|
+
[x: string]: unknown;
|
|
741
|
+
} | undefined;
|
|
742
|
+
};
|
|
743
|
+
}[];
|
|
744
|
+
_meta?: {
|
|
745
|
+
[x: string]: unknown;
|
|
746
|
+
"io.modelcontextprotocol/serverInfo"?: {
|
|
747
|
+
version: string;
|
|
748
|
+
name: string;
|
|
749
|
+
websiteUrl?: string | undefined;
|
|
750
|
+
description?: string | undefined;
|
|
751
|
+
icons?: {
|
|
752
|
+
src: string;
|
|
753
|
+
mimeType?: string | undefined;
|
|
754
|
+
sizes?: string[] | undefined;
|
|
755
|
+
theme?: "light" | "dark" | undefined;
|
|
756
|
+
}[] | undefined;
|
|
757
|
+
title?: string | undefined;
|
|
758
|
+
} | undefined;
|
|
759
|
+
} | undefined;
|
|
760
|
+
description?: string | undefined;
|
|
761
|
+
}>;
|
|
762
|
+
/**
|
|
763
|
+
* Send a raw request through the client.
|
|
764
|
+
*
|
|
765
|
+
* @param method - MCP method name
|
|
766
|
+
* @param params - Request parameters
|
|
767
|
+
* @param options - Request options
|
|
768
|
+
* @returns Response from the server
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
* ```typescript
|
|
772
|
+
* const result = await session.request("custom/method", { key: "value" });
|
|
773
|
+
* ```
|
|
774
|
+
*/
|
|
775
|
+
request(method: string, params?: Record<string, any> | null, options?: RequestOptions): Promise<unknown>;
|
|
776
|
+
/** List one page of skills advertised through the experimental extension. */
|
|
777
|
+
listSkills(cursor?: string, options?: RequestOptions): Promise<import("./skills.js").SkillsListResult>;
|
|
778
|
+
/** List the complete skill catalog, following pagination defensively. */
|
|
779
|
+
listAllSkills(options?: RequestOptions): Promise<{
|
|
780
|
+
skills: import("./skills.js").Skill[];
|
|
781
|
+
}>;
|
|
782
|
+
/** Get one skill by its canonical `SKILL.md` URI. */
|
|
783
|
+
getSkill(uri: string, options?: RequestOptions): Promise<import("./skills.js").SkillGetResult>;
|
|
784
|
+
/** Read one non-recursive skill directory. */
|
|
785
|
+
readResourceDirectory(uri: string, cursor?: string, options?: RequestOptions): Promise<import("./skills.js").SkillDirectoryReadResult>;
|
|
786
|
+
}
|
|
787
|
+
/** @deprecated Use {@link MCPConnection}. */
|
|
788
|
+
export { MCPConnection as MCPSession };
|
|
789
|
+
export type { CallToolResult, MetaObject, Notification, Root, Tool };
|
|
790
|
+
export type { Skill, SkillDirectoryEntry, SkillDirectoryReadResult, SkillGetResult, SkillResource, SkillsListResult, } from "./skills.js";
|
|
791
|
+
export { SKILLS_EXTENSION_ID } from "./skills.js";
|
|
792
|
+
//# sourceMappingURL=session.d.ts.map
|