@prefecthq/fastmcp-ts 0.0.2-alpha.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.
- package/README.md +309 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/cli/index.cjs +45522 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/client.d.ts +543 -0
- package/dist/client.js +1758 -0
- package/dist/client.js.map +1 -0
- package/dist/server.d.ts +1023 -0
- package/dist/server.js +2863 -0
- package/dist/server.js.map +1 -0
- package/dist/zod-P5QUYVPB.js +14015 -0
- package/dist/zod-P5QUYVPB.js.map +1 -0
- package/package.json +110 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import { CreateMessageResult, CreateMessageResultWithTools, ContentBlock, CreateMessageRequestParams, LoggingLevel, ElicitRequestParams, ElicitResult, Tool, Resource, Prompt, ResourceTemplate, ResourceContents, GetPromptResult, Root, ModelPreferences, SamplingMessage, ToolChoice } from '@modelcontextprotocol/sdk/types';
|
|
2
|
+
export { ContentBlock, CreateMessageRequestParams, CreateMessageResult, CreateMessageResultWithTools, ElicitRequestParams, ElicitResult, GetPromptResult, LoggingLevel, ModelPreferences, Prompt, PromptArgument, PromptMessage, Resource, ResourceContents, ResourceTemplate, Root, SamplingMessage, Tool, ToolChoice, ToolResultContent, ToolUseContent } from '@modelcontextprotocol/sdk/types';
|
|
3
|
+
import { OAuthClientProvider, OAuthDiscoveryState } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
4
|
+
import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
5
|
+
import { Transport } from '@modelcontextprotocol/sdk/shared/transport';
|
|
6
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
7
|
+
import OpenAI from 'openai';
|
|
8
|
+
import { GoogleGenAI } from '@google/genai';
|
|
9
|
+
|
|
10
|
+
/** Union of the two sampling result shapes the MCP protocol defines. */
|
|
11
|
+
type AnySamplingResult = CreateMessageResult | CreateMessageResultWithTools;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The SDK's CallToolResult with a typed generic for structuredContent.
|
|
15
|
+
* Use TData to get typed access to structured tool output.
|
|
16
|
+
*/
|
|
17
|
+
type CallToolResult<TData = unknown> = {
|
|
18
|
+
content: ContentBlock[];
|
|
19
|
+
structuredContent: TData | null;
|
|
20
|
+
isError: boolean;
|
|
21
|
+
};
|
|
22
|
+
type CompletionResult = {
|
|
23
|
+
values: string[];
|
|
24
|
+
total?: number;
|
|
25
|
+
hasMore?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type LogMessage = {
|
|
29
|
+
level: LoggingLevel;
|
|
30
|
+
logger?: string;
|
|
31
|
+
data: unknown;
|
|
32
|
+
};
|
|
33
|
+
type LogHandler = (message: LogMessage) => void | Promise<void>;
|
|
34
|
+
type ProgressHandler = (progress: number, total?: number, message?: string) => void | Promise<void>;
|
|
35
|
+
type SamplingHandler = (params: CreateMessageRequestParams) => AnySamplingResult | Promise<AnySamplingResult>;
|
|
36
|
+
type ElicitationHandler = (params: ElicitRequestParams) => ElicitResult | Promise<ElicitResult>;
|
|
37
|
+
type ResourceUpdateHandler = (uri: string) => void | Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Config for receiving server-initiated list-change notifications.
|
|
40
|
+
* Set debounceMs: 0 in tests for instant delivery.
|
|
41
|
+
*/
|
|
42
|
+
type ListChangedHandler<T> = {
|
|
43
|
+
onChanged: (error: Error | null, items: T[] | null) => void | Promise<void>;
|
|
44
|
+
/** Whether to auto-fetch the updated list before calling onChanged. Default: true. */
|
|
45
|
+
autoRefresh?: boolean;
|
|
46
|
+
/** Debounce window in ms. Default: 300. Set to 0 to disable. */
|
|
47
|
+
debounceMs?: number;
|
|
48
|
+
};
|
|
49
|
+
interface ClientHandlers {
|
|
50
|
+
log?: LogHandler;
|
|
51
|
+
progress?: ProgressHandler;
|
|
52
|
+
sampling?: SamplingHandler;
|
|
53
|
+
elicitation?: ElicitationHandler;
|
|
54
|
+
onToolsListChanged?: ListChangedHandler<Tool>;
|
|
55
|
+
onResourcesListChanged?: ListChangedHandler<Resource>;
|
|
56
|
+
onPromptsListChanged?: ListChangedHandler<Prompt>;
|
|
57
|
+
}
|
|
58
|
+
declare function defaultLogHandler(message: LogMessage): void;
|
|
59
|
+
declare function defaultProgressHandler(progress: number, total?: number, message?: string): void;
|
|
60
|
+
|
|
61
|
+
interface RequestOptions {
|
|
62
|
+
/** Per-request timeout in seconds. Overrides client-level defaultOptions. */
|
|
63
|
+
timeout?: number;
|
|
64
|
+
/** AbortSignal for caller-controlled cancellation. */
|
|
65
|
+
signal?: AbortSignal;
|
|
66
|
+
}
|
|
67
|
+
interface CallToolOptions extends RequestOptions {
|
|
68
|
+
/** Per-call progress handler, overrides the client-level handler for this call. */
|
|
69
|
+
onProgress?: ProgressHandler;
|
|
70
|
+
}
|
|
71
|
+
interface IToolsClient {
|
|
72
|
+
listTools(options?: RequestOptions): Promise<Tool[]>;
|
|
73
|
+
callTool<TData = unknown>(name: string, args?: Record<string, unknown>, options?: CallToolOptions): Promise<CallToolResult<TData>>;
|
|
74
|
+
}
|
|
75
|
+
interface IResourcesClient {
|
|
76
|
+
listResources(options?: RequestOptions): Promise<Resource[]>;
|
|
77
|
+
listResourceTemplates(options?: RequestOptions): Promise<ResourceTemplate[]>;
|
|
78
|
+
readResource(uri: string, options?: RequestOptions): Promise<ResourceContents[]>;
|
|
79
|
+
subscribeResource(uri: string, handler: ResourceUpdateHandler, options?: RequestOptions): Promise<void>;
|
|
80
|
+
unsubscribeResource(uri: string, options?: RequestOptions): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
interface IPromptsClient {
|
|
83
|
+
listPrompts(options?: RequestOptions): Promise<Prompt[]>;
|
|
84
|
+
getPrompt(name: string, args?: Record<string, string>, options?: RequestOptions): Promise<GetPromptResult>;
|
|
85
|
+
}
|
|
86
|
+
interface IClient extends IToolsClient, IResourcesClient, IPromptsClient {
|
|
87
|
+
connect(): Promise<void>;
|
|
88
|
+
close(): Promise<void>;
|
|
89
|
+
isConnected(): boolean;
|
|
90
|
+
ping(options?: RequestOptions): Promise<boolean>;
|
|
91
|
+
complete(ref: {
|
|
92
|
+
type: 'ref/prompt';
|
|
93
|
+
name: string;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'ref/resource';
|
|
96
|
+
uri: string;
|
|
97
|
+
}, argument: {
|
|
98
|
+
name: string;
|
|
99
|
+
value: string;
|
|
100
|
+
}, context?: {
|
|
101
|
+
arguments?: Record<string, string>;
|
|
102
|
+
}, options?: RequestOptions): Promise<CompletionResult>;
|
|
103
|
+
setLogLevel(level: LoggingLevel, options?: RequestOptions): Promise<void>;
|
|
104
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type OAuthToken = {
|
|
108
|
+
access_token: string;
|
|
109
|
+
token_type?: string;
|
|
110
|
+
refresh_token?: string;
|
|
111
|
+
/** Unix timestamp in milliseconds (normalized internally). */
|
|
112
|
+
expires_at?: number;
|
|
113
|
+
/** Seconds until expiry — used to compute expires_at on receipt. */
|
|
114
|
+
expires_in?: number;
|
|
115
|
+
scope?: string;
|
|
116
|
+
};
|
|
117
|
+
type KeyValueStore = {
|
|
118
|
+
get(key: string): Promise<string | null>;
|
|
119
|
+
set(key: string, value: string): Promise<void>;
|
|
120
|
+
delete(key: string): Promise<void>;
|
|
121
|
+
};
|
|
122
|
+
declare class InMemoryStore implements KeyValueStore {
|
|
123
|
+
private readonly _map;
|
|
124
|
+
get(key: string): Promise<string | null>;
|
|
125
|
+
set(key: string, value: string): Promise<void>;
|
|
126
|
+
delete(key: string): Promise<void>;
|
|
127
|
+
}
|
|
128
|
+
declare class FileTokenStorage implements KeyValueStore {
|
|
129
|
+
private readonly _path;
|
|
130
|
+
constructor(path?: string);
|
|
131
|
+
private _readAll;
|
|
132
|
+
private _writeAll;
|
|
133
|
+
get(key: string): Promise<string | null>;
|
|
134
|
+
set(key: string, value: string): Promise<void>;
|
|
135
|
+
delete(key: string): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
interface OAuthOptions {
|
|
138
|
+
/** Pre-registered client ID. When set, Dynamic Client Registration is skipped. */
|
|
139
|
+
clientId?: string;
|
|
140
|
+
/** Pre-registered client secret. */
|
|
141
|
+
clientSecret?: string;
|
|
142
|
+
/** Requested OAuth scopes (space-separated string or array). */
|
|
143
|
+
scopes?: string | string[];
|
|
144
|
+
/** Client name used in Dynamic Client Registration. Default: "FastMCP Client". */
|
|
145
|
+
clientName?: string;
|
|
146
|
+
/** Persistent key-value store for tokens, client info, and discovery state. Default: in-memory. */
|
|
147
|
+
store?: KeyValueStore;
|
|
148
|
+
/**
|
|
149
|
+
* Port for the local OAuth callback server. Default: 8765.
|
|
150
|
+
* The port must be consistent across calls because it is registered as the
|
|
151
|
+
* redirect_uri during Dynamic Client Registration.
|
|
152
|
+
*/
|
|
153
|
+
callbackPort?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Override how the authorization URL is opened. When not provided the
|
|
156
|
+
* system browser is launched. Inject a no-op or mock here for testing.
|
|
157
|
+
*/
|
|
158
|
+
onRedirect?: (url: URL) => void | Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
declare class OAuth implements OAuthClientProvider {
|
|
161
|
+
private _serverUrl;
|
|
162
|
+
private readonly _clientId?;
|
|
163
|
+
private readonly _clientSecret?;
|
|
164
|
+
private readonly _scopes?;
|
|
165
|
+
private readonly _clientName;
|
|
166
|
+
private readonly _store;
|
|
167
|
+
private readonly _callbackPort;
|
|
168
|
+
private readonly _onRedirect?;
|
|
169
|
+
private _codeVerifier;
|
|
170
|
+
private _callbackPromise;
|
|
171
|
+
private _callbackResolve;
|
|
172
|
+
private _callbackReject;
|
|
173
|
+
private _callbackServer;
|
|
174
|
+
private _actualCallbackPort;
|
|
175
|
+
constructor(options?: OAuthOptions);
|
|
176
|
+
/**
|
|
177
|
+
* Binds the MCP server URL so that all storage keys are namespaced by it.
|
|
178
|
+
* Called by Client before connecting.
|
|
179
|
+
*/
|
|
180
|
+
_bind(serverUrl: string): void;
|
|
181
|
+
get redirectUrl(): string | URL;
|
|
182
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
183
|
+
clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
|
|
184
|
+
saveClientInformation(info: OAuthClientInformationMixed): Promise<void>;
|
|
185
|
+
tokens(): Promise<OAuthTokens | undefined>;
|
|
186
|
+
saveTokens(tokens: OAuthTokens): Promise<void>;
|
|
187
|
+
redirectToAuthorization(authorizationUrl: URL): Promise<void>;
|
|
188
|
+
saveCodeVerifier(codeVerifier: string): void;
|
|
189
|
+
codeVerifier(): string;
|
|
190
|
+
invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): Promise<void>;
|
|
191
|
+
saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
|
|
192
|
+
discoveryState(): Promise<OAuthDiscoveryState | undefined>;
|
|
193
|
+
/**
|
|
194
|
+
* Returns the actual port the callback server bound to.
|
|
195
|
+
* Only populated after redirectToAuthorization() has been called.
|
|
196
|
+
*/
|
|
197
|
+
get callbackServerPort(): number | null;
|
|
198
|
+
/**
|
|
199
|
+
* Waits for the OAuth authorization code to arrive via the callback server,
|
|
200
|
+
* then stops the server and resolves with the code.
|
|
201
|
+
*
|
|
202
|
+
* Must be called after the UnauthorizedError thrown by connect() is caught.
|
|
203
|
+
*/
|
|
204
|
+
waitForCallback(timeoutMs?: number): Promise<string>;
|
|
205
|
+
private _key;
|
|
206
|
+
private _startCallbackServer;
|
|
207
|
+
private _stopCallbackServer;
|
|
208
|
+
}
|
|
209
|
+
declare class BearerAuth {
|
|
210
|
+
private readonly _token;
|
|
211
|
+
constructor(token: string);
|
|
212
|
+
getHeaders(): Record<string, string>;
|
|
213
|
+
}
|
|
214
|
+
interface ClientCredentialsOptions {
|
|
215
|
+
tokenEndpoint: string;
|
|
216
|
+
clientId: string;
|
|
217
|
+
clientSecret: string;
|
|
218
|
+
scope?: string;
|
|
219
|
+
store?: KeyValueStore;
|
|
220
|
+
/** How many seconds before expiry to proactively re-fetch. Default: 60. */
|
|
221
|
+
refreshBufferSeconds?: number;
|
|
222
|
+
}
|
|
223
|
+
declare class ClientCredentials {
|
|
224
|
+
readonly kind: "client_credentials";
|
|
225
|
+
private readonly _tokenEndpoint;
|
|
226
|
+
private readonly _clientId;
|
|
227
|
+
private readonly _clientSecret;
|
|
228
|
+
private readonly _scope?;
|
|
229
|
+
private readonly _store;
|
|
230
|
+
private readonly _bufferMs;
|
|
231
|
+
private _fetchPromise;
|
|
232
|
+
constructor(options: ClientCredentialsOptions);
|
|
233
|
+
getHeaders(): Promise<Record<string, string>>;
|
|
234
|
+
private get _tokenKey();
|
|
235
|
+
private _getValidToken;
|
|
236
|
+
private _doFetch;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
interface McpServerLike {
|
|
240
|
+
connect(transport: Transport): Promise<void>;
|
|
241
|
+
}
|
|
242
|
+
type McpServerEntry = {
|
|
243
|
+
url: string;
|
|
244
|
+
headers?: Record<string, string>;
|
|
245
|
+
auth?: BearerAuth | OAuth | ClientCredentials | string;
|
|
246
|
+
} | {
|
|
247
|
+
command: string;
|
|
248
|
+
args?: string[];
|
|
249
|
+
env?: Record<string, string>;
|
|
250
|
+
auth?: BearerAuth | OAuth | ClientCredentials | string;
|
|
251
|
+
};
|
|
252
|
+
/** Values accepted in mcpServers: either a config object or an in-process server. */
|
|
253
|
+
type McpServerValue = McpServerEntry | McpServerLike;
|
|
254
|
+
type McpConfig = {
|
|
255
|
+
mcpServers: Record<string, McpServerValue>;
|
|
256
|
+
};
|
|
257
|
+
declare class StdioTransport {
|
|
258
|
+
readonly command: string;
|
|
259
|
+
readonly args: string[];
|
|
260
|
+
readonly env?: Record<string, string>;
|
|
261
|
+
readonly cwd?: string;
|
|
262
|
+
constructor(command: string, args?: string[], options?: {
|
|
263
|
+
env?: Record<string, string>;
|
|
264
|
+
cwd?: string;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
type ClientTransportInput = string | McpServerLike | McpConfig | StdioTransport | Transport;
|
|
268
|
+
|
|
269
|
+
interface MultiServerOptions {
|
|
270
|
+
handlers?: ClientHandlers;
|
|
271
|
+
/** file:// URIs to advertise to all servers as accessible roots. */
|
|
272
|
+
roots?: string[];
|
|
273
|
+
defaultOptions?: ClientDefaultOptions;
|
|
274
|
+
}
|
|
275
|
+
declare class MultiServerClient implements IClient {
|
|
276
|
+
private _clients;
|
|
277
|
+
private _connectPromise;
|
|
278
|
+
private _connected;
|
|
279
|
+
/** URI (or namespaced template URI) → server name, populated by list calls */
|
|
280
|
+
private _uriMap;
|
|
281
|
+
private readonly _config;
|
|
282
|
+
private readonly _handlers;
|
|
283
|
+
private readonly _roots;
|
|
284
|
+
private readonly _defaultOptions;
|
|
285
|
+
private _resourceSubscriptions;
|
|
286
|
+
constructor(config: McpConfig, options?: MultiServerOptions);
|
|
287
|
+
connect(): Promise<void>;
|
|
288
|
+
private _doConnect;
|
|
289
|
+
close(): Promise<void>;
|
|
290
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
291
|
+
isConnected(): boolean;
|
|
292
|
+
static connect(config: McpConfig, options?: MultiServerOptions): Promise<MultiServerClient>;
|
|
293
|
+
ping(options?: RequestOptions): Promise<boolean>;
|
|
294
|
+
listTools(options?: RequestOptions): Promise<Tool[]>;
|
|
295
|
+
callTool<TData = unknown>(name: string, args?: Record<string, unknown>, options?: CallToolOptions): Promise<CallToolResult<TData>>;
|
|
296
|
+
callToolRaw<TData = unknown>(name: string, args?: Record<string, unknown>, options?: CallToolOptions): Promise<CallToolResult<TData>>;
|
|
297
|
+
listResources(options?: RequestOptions): Promise<Resource[]>;
|
|
298
|
+
listResourceTemplates(options?: RequestOptions): Promise<ResourceTemplate[]>;
|
|
299
|
+
readResource(uri: string, options?: RequestOptions): Promise<ResourceContents[]>;
|
|
300
|
+
listPrompts(options?: RequestOptions): Promise<Prompt[]>;
|
|
301
|
+
getPrompt(name: string, args?: Record<string, string>, options?: RequestOptions): Promise<GetPromptResult>;
|
|
302
|
+
subscribeResource(uri: string, handler: ResourceUpdateHandler, options?: RequestOptions): Promise<void>;
|
|
303
|
+
unsubscribeResource(uri: string, options?: RequestOptions): Promise<void>;
|
|
304
|
+
complete(ref: {
|
|
305
|
+
type: 'ref/prompt';
|
|
306
|
+
name: string;
|
|
307
|
+
} | {
|
|
308
|
+
type: 'ref/resource';
|
|
309
|
+
uri: string;
|
|
310
|
+
}, argument: {
|
|
311
|
+
name: string;
|
|
312
|
+
value: string;
|
|
313
|
+
}, context?: {
|
|
314
|
+
arguments?: Record<string, string>;
|
|
315
|
+
}, options?: RequestOptions): Promise<CompletionResult>;
|
|
316
|
+
setLogLevel(level: LoggingLevel, options?: RequestOptions): Promise<void>;
|
|
317
|
+
private _assertConnected;
|
|
318
|
+
private _parseNamespacedName;
|
|
319
|
+
private _sdkForServer;
|
|
320
|
+
private _buildSdkClient;
|
|
321
|
+
private _buildCapabilities;
|
|
322
|
+
private _registerHandlers;
|
|
323
|
+
private _toSdkOptions;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
declare class ToolCallError extends Error {
|
|
327
|
+
readonly content: ContentBlock[];
|
|
328
|
+
constructor(message: string, content: ContentBlock[]);
|
|
329
|
+
}
|
|
330
|
+
interface ClientDefaultOptions {
|
|
331
|
+
/** Global fallback timeout in seconds for all requests. */
|
|
332
|
+
timeout?: number;
|
|
333
|
+
tool?: {
|
|
334
|
+
timeout?: number;
|
|
335
|
+
};
|
|
336
|
+
resource?: {
|
|
337
|
+
timeout?: number;
|
|
338
|
+
};
|
|
339
|
+
prompt?: {
|
|
340
|
+
timeout?: number;
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
/** A single element of the roots option: a URI string or a full Root object. */
|
|
344
|
+
type RootInput = string | Root;
|
|
345
|
+
/**
|
|
346
|
+
* Static list of roots, or an async callback invoked on each roots/list request.
|
|
347
|
+
* URI strings are normalised to file:// URIs automatically; relative paths are
|
|
348
|
+
* resolved against process.cwd().
|
|
349
|
+
*/
|
|
350
|
+
type RootsValue = RootInput[] | (() => RootInput[] | Promise<RootInput[]>);
|
|
351
|
+
interface ClientOptions {
|
|
352
|
+
/**
|
|
353
|
+
* Authentication to attach to HTTP requests.
|
|
354
|
+
* A plain string is treated as a Bearer token.
|
|
355
|
+
*/
|
|
356
|
+
auth?: BearerAuth | OAuth | ClientCredentials | string;
|
|
357
|
+
handlers?: ClientHandlers;
|
|
358
|
+
/**
|
|
359
|
+
* Filesystem roots to advertise to the server.
|
|
360
|
+
* Accepts a static array of strings / Root objects, or an async callback
|
|
361
|
+
* invoked on each roots/list request (useful for dynamic root sets).
|
|
362
|
+
*/
|
|
363
|
+
roots?: RootsValue;
|
|
364
|
+
/**
|
|
365
|
+
* When true (default), the MCP initialize handshake is performed
|
|
366
|
+
* automatically inside connect().
|
|
367
|
+
*/
|
|
368
|
+
autoInitialize?: boolean;
|
|
369
|
+
defaultOptions?: ClientDefaultOptions;
|
|
370
|
+
}
|
|
371
|
+
declare class Client implements IClient {
|
|
372
|
+
private _sdkClient;
|
|
373
|
+
private _refCount;
|
|
374
|
+
private _connectPromise;
|
|
375
|
+
private readonly _resourceSubscriptions;
|
|
376
|
+
private readonly _input;
|
|
377
|
+
private readonly _auth;
|
|
378
|
+
private readonly _handlers;
|
|
379
|
+
private readonly _roots;
|
|
380
|
+
private readonly _autoInitialize;
|
|
381
|
+
private readonly _defaultOptions;
|
|
382
|
+
constructor(input: ClientTransportInput, options?: ClientOptions);
|
|
383
|
+
connect(): Promise<void>;
|
|
384
|
+
private _doConnect;
|
|
385
|
+
private _extractServerUrl;
|
|
386
|
+
close(): Promise<void>;
|
|
387
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
388
|
+
isConnected(): boolean;
|
|
389
|
+
/** Creates a connected MultiServerClient when given a multi-entry McpConfig. */
|
|
390
|
+
static connect(input: McpConfig, options?: MultiServerOptions): Promise<MultiServerClient>;
|
|
391
|
+
/** Creates a connected Client for a single-server transport. Use with `await using` for automatic cleanup. */
|
|
392
|
+
static connect(input: ClientTransportInput, options?: ClientOptions): Promise<Client>;
|
|
393
|
+
ping(options?: RequestOptions): Promise<boolean>;
|
|
394
|
+
listTools(options?: RequestOptions): Promise<Tool[]>;
|
|
395
|
+
callTool<TData = unknown>(name: string, args?: Record<string, unknown>, options?: CallToolOptions): Promise<CallToolResult<TData>>;
|
|
396
|
+
/** Returns the full result including isError without throwing. */
|
|
397
|
+
callToolRaw<TData = unknown>(name: string, args?: Record<string, unknown>, options?: CallToolOptions): Promise<CallToolResult<TData>>;
|
|
398
|
+
listResources(options?: RequestOptions): Promise<Resource[]>;
|
|
399
|
+
listResourceTemplates(options?: RequestOptions): Promise<ResourceTemplate[]>;
|
|
400
|
+
readResource(uri: string, options?: RequestOptions): Promise<ResourceContents[]>;
|
|
401
|
+
/** Returns the raw SDK ReadResourceResult without unwrapping. */
|
|
402
|
+
readResourceRaw(uri: string, options?: RequestOptions): Promise<{
|
|
403
|
+
[x: string]: unknown;
|
|
404
|
+
contents: ({
|
|
405
|
+
uri: string;
|
|
406
|
+
text: string;
|
|
407
|
+
mimeType?: string | undefined;
|
|
408
|
+
_meta?: Record<string, unknown> | undefined;
|
|
409
|
+
} | {
|
|
410
|
+
uri: string;
|
|
411
|
+
blob: string;
|
|
412
|
+
mimeType?: string | undefined;
|
|
413
|
+
_meta?: Record<string, unknown> | undefined;
|
|
414
|
+
})[];
|
|
415
|
+
_meta?: {
|
|
416
|
+
[x: string]: unknown;
|
|
417
|
+
progressToken?: string | number | undefined;
|
|
418
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
419
|
+
taskId: string;
|
|
420
|
+
} | undefined;
|
|
421
|
+
} | undefined;
|
|
422
|
+
}>;
|
|
423
|
+
subscribeResource(uri: string, handler: ResourceUpdateHandler, options?: RequestOptions): Promise<void>;
|
|
424
|
+
unsubscribeResource(uri: string, options?: RequestOptions): Promise<void>;
|
|
425
|
+
listPrompts(options?: RequestOptions): Promise<Prompt[]>;
|
|
426
|
+
getPrompt(name: string, args?: Record<string, string>, options?: RequestOptions): Promise<GetPromptResult>;
|
|
427
|
+
complete(ref: {
|
|
428
|
+
type: 'ref/prompt';
|
|
429
|
+
name: string;
|
|
430
|
+
} | {
|
|
431
|
+
type: 'ref/resource';
|
|
432
|
+
uri: string;
|
|
433
|
+
}, argument: {
|
|
434
|
+
name: string;
|
|
435
|
+
value: string;
|
|
436
|
+
}, context?: {
|
|
437
|
+
arguments?: Record<string, string>;
|
|
438
|
+
}, options?: RequestOptions): Promise<CompletionResult>;
|
|
439
|
+
setLogLevel(level: LoggingLevel, options?: RequestOptions): Promise<void>;
|
|
440
|
+
private _sdk;
|
|
441
|
+
private _toSdkOptions;
|
|
442
|
+
private _buildCapabilities;
|
|
443
|
+
private _buildListChangedConfig;
|
|
444
|
+
private _registerHandlers;
|
|
445
|
+
/**
|
|
446
|
+
* Notify the connected server that the client's roots list has changed.
|
|
447
|
+
* The server should re-issue a roots/list request to get the updated list.
|
|
448
|
+
*/
|
|
449
|
+
notifyRootsChanged(): Promise<void>;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
type Result<T, E = Error> = {
|
|
453
|
+
ok: true;
|
|
454
|
+
value: T;
|
|
455
|
+
} | {
|
|
456
|
+
ok: false;
|
|
457
|
+
error: E;
|
|
458
|
+
};
|
|
459
|
+
declare function toResult<T, E = Error>(fn: Promise<T> | (() => Promise<T>)): Promise<Result<T, E>>;
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Resolve a concrete model name from the server's modelPreferences.
|
|
463
|
+
* A plain string always uses that model; a function inspects the preferences.
|
|
464
|
+
*/
|
|
465
|
+
type ModelSelector = string | ((prefs: ModelPreferences | undefined) => string);
|
|
466
|
+
/** Called with each text token as it is streamed from the provider. */
|
|
467
|
+
type OnTokenCallback = (token: string) => void;
|
|
468
|
+
interface SamplingAdapterOptions {
|
|
469
|
+
/** Override or replace the model selection logic. */
|
|
470
|
+
modelSelector?: ModelSelector;
|
|
471
|
+
/** Fired for each streamed text token. Tool-use deltas are not surfaced. */
|
|
472
|
+
onToken?: OnTokenCallback;
|
|
473
|
+
}
|
|
474
|
+
/** Implemented by all sampling adapters. */
|
|
475
|
+
interface SamplingAdapter {
|
|
476
|
+
asHandler(): SamplingHandler;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
interface GenericCompletionParams {
|
|
480
|
+
model: string;
|
|
481
|
+
messages: SamplingMessage[];
|
|
482
|
+
system?: string;
|
|
483
|
+
/** Defaulted to 1024 when absent in the original request. */
|
|
484
|
+
maxTokens: number;
|
|
485
|
+
temperature?: number;
|
|
486
|
+
stopSequences?: string[];
|
|
487
|
+
tools?: Tool[];
|
|
488
|
+
toolChoice?: ToolChoice;
|
|
489
|
+
onToken?: OnTokenCallback;
|
|
490
|
+
}
|
|
491
|
+
type GenericCompletionFn = (params: GenericCompletionParams) => Promise<AnySamplingResult>;
|
|
492
|
+
/**
|
|
493
|
+
* Contribution template. Wraps any async function into a SamplingHandler.
|
|
494
|
+
*
|
|
495
|
+
* The adapter resolves the model from modelPreferences, defaults maxTokens,
|
|
496
|
+
* and threads onToken through. Message format conversion, tool translation,
|
|
497
|
+
* and streaming are the caller's responsibility.
|
|
498
|
+
*
|
|
499
|
+
* Example:
|
|
500
|
+
* ```ts
|
|
501
|
+
* const adapter = new GenericSamplingAdapter(async ({ model, messages }) => {
|
|
502
|
+
* const text = await myLlm.complete(model, messages)
|
|
503
|
+
* return { role: 'assistant', content: { type: 'text', text }, model, stopReason: 'endTurn' }
|
|
504
|
+
* })
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
declare class GenericSamplingAdapter implements SamplingAdapter {
|
|
508
|
+
private readonly _fn;
|
|
509
|
+
private readonly _options;
|
|
510
|
+
constructor(fn: GenericCompletionFn, options?: SamplingAdapterOptions & {
|
|
511
|
+
defaultModel?: string;
|
|
512
|
+
});
|
|
513
|
+
asHandler(): SamplingHandler;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
declare class AnthropicSamplingAdapter implements SamplingAdapter {
|
|
517
|
+
private readonly _client;
|
|
518
|
+
private readonly _options;
|
|
519
|
+
constructor(client: Anthropic, options?: SamplingAdapterOptions & {
|
|
520
|
+
defaultModel?: string;
|
|
521
|
+
});
|
|
522
|
+
asHandler(): SamplingHandler;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
declare class OpenAISamplingAdapter implements SamplingAdapter {
|
|
526
|
+
private readonly _client;
|
|
527
|
+
private readonly _options;
|
|
528
|
+
constructor(client: OpenAI, options?: SamplingAdapterOptions & {
|
|
529
|
+
defaultModel?: string;
|
|
530
|
+
});
|
|
531
|
+
asHandler(): SamplingHandler;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
declare class GoogleSamplingAdapter implements SamplingAdapter {
|
|
535
|
+
private readonly _client;
|
|
536
|
+
private readonly _options;
|
|
537
|
+
constructor(client: GoogleGenAI, options?: SamplingAdapterOptions & {
|
|
538
|
+
defaultModel?: string;
|
|
539
|
+
});
|
|
540
|
+
asHandler(): SamplingHandler;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export { AnthropicSamplingAdapter, type AnySamplingResult, BearerAuth, type CallToolOptions, type CallToolResult, Client, ClientCredentials, type ClientCredentialsOptions, type ClientDefaultOptions, type ClientHandlers, type ClientOptions, type ClientTransportInput, type CompletionResult, type ElicitationHandler, FileTokenStorage, type GenericCompletionFn, type GenericCompletionParams, GenericSamplingAdapter, GoogleSamplingAdapter, type IClient, type IPromptsClient, type IResourcesClient, type IToolsClient, InMemoryStore, type KeyValueStore, type ListChangedHandler, type LogHandler, type LogMessage, type McpConfig, type McpServerEntry, type McpServerLike, type McpServerValue, type ModelSelector, MultiServerClient, type MultiServerOptions, OAuth, type OAuthOptions, type OAuthToken, type OnTokenCallback, OpenAISamplingAdapter, type ProgressHandler, type RequestOptions, type ResourceUpdateHandler, type Result, type RootInput, type RootsValue, type SamplingAdapter, type SamplingAdapterOptions, type SamplingHandler, StdioTransport, ToolCallError, defaultLogHandler, defaultProgressHandler, toResult };
|