@ai-sdk/mcp 2.0.0-beta.5 → 2.0.0-beta.66
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/CHANGELOG.md +496 -8
- package/README.md +134 -0
- package/dist/index.d.ts +146 -1
- package/dist/index.js +764 -350
- package/dist/index.js.map +1 -1
- package/dist/mcp-stdio/index.d.ts +8 -0
- package/dist/mcp-stdio/index.js +170 -172
- package/dist/mcp-stdio/index.js.map +1 -1
- package/package.json +18 -19
- package/src/error/mcp-client-error.ts +40 -0
- package/src/index.ts +16 -1
- package/src/tool/index.ts +1 -0
- package/src/tool/json-rpc-message.ts +7 -0
- package/src/tool/mcp-apps.ts +254 -0
- package/src/tool/mcp-client.ts +128 -43
- package/src/tool/mcp-http-transport.ts +78 -23
- package/src/tool/mcp-sse-transport.ts +47 -15
- package/src/tool/mcp-stdio/create-child-process.ts +2 -2
- package/src/tool/mcp-stdio/mcp-stdio-transport.ts +17 -14
- package/src/tool/mcp-transport.ts +28 -2
- package/src/tool/mock-mcp-transport.ts +8 -9
- package/src/tool/oauth-types.ts +22 -18
- package/src/tool/oauth.ts +324 -37
- package/src/tool/types.ts +27 -3
- package/src/util/oauth-util.ts +13 -0
- package/dist/index.d.mts +0 -509
- package/dist/index.mjs +0 -2128
- package/dist/index.mjs.map +0 -1
- package/dist/mcp-stdio/index.d.mts +0 -89
- package/dist/mcp-stdio/index.mjs +0 -426
- package/dist/mcp-stdio/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,8 @@ declare const OAuthTokensSchema: z.ZodObject<{
|
|
|
77
77
|
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
78
78
|
scope: z.ZodOptional<z.ZodString>;
|
|
79
79
|
refresh_token: z.ZodOptional<z.ZodString>;
|
|
80
|
+
authorization_server: z.ZodOptional<z.ZodString>;
|
|
81
|
+
token_endpoint: z.ZodOptional<z.ZodString>;
|
|
80
82
|
}, z.core.$strip>;
|
|
81
83
|
declare const OAuthMetadataSchema: z.ZodObject<{
|
|
82
84
|
issuer: z.ZodString;
|
|
@@ -116,6 +118,8 @@ declare const OAuthClientInformationSchema: z.ZodObject<{
|
|
|
116
118
|
client_secret: z.ZodOptional<z.ZodString>;
|
|
117
119
|
client_id_issued_at: z.ZodOptional<z.ZodNumber>;
|
|
118
120
|
client_secret_expires_at: z.ZodOptional<z.ZodNumber>;
|
|
121
|
+
authorization_server: z.ZodOptional<z.ZodString>;
|
|
122
|
+
token_endpoint: z.ZodOptional<z.ZodString>;
|
|
119
123
|
}, z.core.$strip>;
|
|
120
124
|
declare const OAuthClientMetadataSchema: z.ZodObject<{
|
|
121
125
|
redirect_uris: z.ZodArray<z.ZodString>;
|
|
@@ -143,6 +147,10 @@ type AuthorizationServerMetadata = OAuthMetadata | OpenIdProviderDiscoveryMetada
|
|
|
143
147
|
type OAuthClientMetadata = z.infer<typeof OAuthClientMetadataSchema>;
|
|
144
148
|
|
|
145
149
|
type AuthResult = 'AUTHORIZED' | 'REDIRECT';
|
|
150
|
+
interface OAuthAuthorizationServerInformation {
|
|
151
|
+
authorizationServerUrl: string;
|
|
152
|
+
tokenEndpoint: string;
|
|
153
|
+
}
|
|
146
154
|
interface OAuthClientProvider {
|
|
147
155
|
/**
|
|
148
156
|
* Returns current access token if present; undefined otherwise.
|
|
@@ -181,6 +189,13 @@ interface OAuthClientProvider {
|
|
|
181
189
|
get clientMetadata(): OAuthClientMetadata;
|
|
182
190
|
clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
|
|
183
191
|
saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
|
|
192
|
+
authorizationServerInformation?(): OAuthAuthorizationServerInformation | undefined | Promise<OAuthAuthorizationServerInformation | undefined>;
|
|
193
|
+
saveAuthorizationServerInformation?(authorizationServerInformation: OAuthAuthorizationServerInformation): void | Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Validates an authorization server URL discovered from MCP protected resource
|
|
196
|
+
* metadata before the client fetches its OAuth metadata.
|
|
197
|
+
*/
|
|
198
|
+
validateAuthorizationServerURL?(serverUrl: string | URL, authorizationServerUrl: string | URL): void | Promise<void>;
|
|
184
199
|
state?(): string | Promise<string>;
|
|
185
200
|
saveState?(state: string): void | Promise<void>;
|
|
186
201
|
storedState?(): string | undefined | Promise<string | undefined>;
|
|
@@ -228,6 +243,14 @@ interface MCPTransport {
|
|
|
228
243
|
* Event handler for received messages
|
|
229
244
|
*/
|
|
230
245
|
onmessage?: (message: JSONRPCMessage) => void;
|
|
246
|
+
/**
|
|
247
|
+
* The protocol version negotiated during initialization.
|
|
248
|
+
*/
|
|
249
|
+
protocolVersion?: string;
|
|
250
|
+
/**
|
|
251
|
+
* Set the protocol version negotiated during initialization.
|
|
252
|
+
*/
|
|
253
|
+
setProtocolVersion?(version: string): void;
|
|
231
254
|
}
|
|
232
255
|
type MCPTransportConfig = {
|
|
233
256
|
type: 'sse' | 'http';
|
|
@@ -243,8 +266,27 @@ type MCPTransportConfig = {
|
|
|
243
266
|
* An optional OAuth client provider to use for authentication for MCP servers.
|
|
244
267
|
*/
|
|
245
268
|
authProvider?: OAuthClientProvider;
|
|
269
|
+
/**
|
|
270
|
+
* Controls how HTTP redirects are handled for transport requests.
|
|
271
|
+
* - `'follow'`: Follow redirects automatically (standard fetch behavior).
|
|
272
|
+
* - `'error'`: Reject any redirect response with an error.
|
|
273
|
+
* @default 'error'
|
|
274
|
+
*/
|
|
275
|
+
redirect?: 'follow' | 'error';
|
|
276
|
+
/**
|
|
277
|
+
* Optional custom fetch implementation to use for HTTP requests.
|
|
278
|
+
* Useful for runtimes that need a request-local fetch.
|
|
279
|
+
* @default globalThis.fetch
|
|
280
|
+
*/
|
|
281
|
+
fetch?: FetchFunction;
|
|
246
282
|
};
|
|
247
283
|
|
|
284
|
+
type McpProviderMetadata = {
|
|
285
|
+
clientName?: string;
|
|
286
|
+
title?: string;
|
|
287
|
+
toolName?: string;
|
|
288
|
+
app?: JSONObject;
|
|
289
|
+
};
|
|
248
290
|
/** MCP tool metadata - keys should follow MCP _meta key format specification */
|
|
249
291
|
declare const ToolMetaSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
250
292
|
type ToolMeta = z.infer<typeof ToolMetaSchema>;
|
|
@@ -267,6 +309,12 @@ type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS e
|
|
|
267
309
|
inputSchema: FlexibleSchema<infer INPUT>;
|
|
268
310
|
} ? McpToolBase<INPUT, CallToolResult> : never;
|
|
269
311
|
} : Record<string, McpToolBase<unknown, CallToolResult>>;
|
|
312
|
+
declare const ClientOrServerImplementationSchema: z.ZodObject<{
|
|
313
|
+
name: z.ZodString;
|
|
314
|
+
version: z.ZodString;
|
|
315
|
+
title: z.ZodOptional<z.ZodString>;
|
|
316
|
+
}, z.core.$loose>;
|
|
317
|
+
type Configuration = z.infer<typeof ClientOrServerImplementationSchema>;
|
|
270
318
|
declare const BaseParamsSchema: z.ZodObject<{
|
|
271
319
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
272
320
|
}, z.core.$loose>;
|
|
@@ -350,6 +398,12 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
350
398
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
351
399
|
blob: z.ZodBase64;
|
|
352
400
|
}, z.core.$loose>]>;
|
|
401
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
402
|
+
type: z.ZodLiteral<"resource_link">;
|
|
403
|
+
uri: z.ZodString;
|
|
404
|
+
name: z.ZodString;
|
|
405
|
+
description: z.ZodOptional<z.ZodString>;
|
|
406
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
353
407
|
}, z.core.$loose>]>>;
|
|
354
408
|
structuredContent: z.ZodOptional<z.ZodUnknown>;
|
|
355
409
|
isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
@@ -428,6 +482,12 @@ declare const GetPromptResultSchema: z.ZodObject<{
|
|
|
428
482
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
429
483
|
blob: z.ZodBase64;
|
|
430
484
|
}, z.core.$loose>]>;
|
|
485
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
486
|
+
type: z.ZodLiteral<"resource_link">;
|
|
487
|
+
uri: z.ZodString;
|
|
488
|
+
name: z.ZodString;
|
|
489
|
+
description: z.ZodOptional<z.ZodString>;
|
|
490
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
431
491
|
}, z.core.$loose>]>;
|
|
432
492
|
}, z.core.$loose>>;
|
|
433
493
|
}, z.core.$loose>;
|
|
@@ -454,6 +514,12 @@ interface MCPClientConfig {
|
|
|
454
514
|
/** Optional callback for uncaught errors */
|
|
455
515
|
onUncaughtError?: (error: unknown) => void;
|
|
456
516
|
/** Optional client name, defaults to 'ai-sdk-mcp-client' */
|
|
517
|
+
clientName?: string;
|
|
518
|
+
/**
|
|
519
|
+
* Optional client name, defaults to 'ai-sdk-mcp-client'
|
|
520
|
+
*
|
|
521
|
+
* @deprecated Use `clientName` instead.
|
|
522
|
+
*/
|
|
457
523
|
name?: string;
|
|
458
524
|
/** Optional client version, defaults to '1.0.0' */
|
|
459
525
|
version?: string;
|
|
@@ -466,6 +532,20 @@ interface MCPClientConfig {
|
|
|
466
532
|
}
|
|
467
533
|
declare function createMCPClient(config: MCPClientConfig): Promise<MCPClient>;
|
|
468
534
|
interface MCPClient {
|
|
535
|
+
/**
|
|
536
|
+
* Information about the connected MCP server, as reported during initialization.
|
|
537
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/schema#implementation
|
|
538
|
+
*/
|
|
539
|
+
readonly serverInfo: Configuration;
|
|
540
|
+
/**
|
|
541
|
+
* Optional instructions provided by the server during the initialize handshake.
|
|
542
|
+
*
|
|
543
|
+
* These describe how to use the server and its features, and can be used by clients
|
|
544
|
+
* to improve LLM interactions (e.g. by including them in the system prompt).
|
|
545
|
+
*
|
|
546
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/schema#initializeresult
|
|
547
|
+
*/
|
|
548
|
+
readonly instructions?: string;
|
|
469
549
|
tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
|
|
470
550
|
schemas?: TOOL_SCHEMAS;
|
|
471
551
|
}): Promise<McpToolSet<TOOL_SCHEMAS>>;
|
|
@@ -476,6 +556,14 @@ interface MCPClient {
|
|
|
476
556
|
params?: PaginatedRequest['params'];
|
|
477
557
|
options?: RequestOptions;
|
|
478
558
|
}): Promise<ListToolsResult>;
|
|
559
|
+
/**
|
|
560
|
+
* Calls a tool on the MCP server.
|
|
561
|
+
*/
|
|
562
|
+
callTool(args: {
|
|
563
|
+
name: string;
|
|
564
|
+
arguments?: Record<string, unknown>;
|
|
565
|
+
options?: RequestOptions;
|
|
566
|
+
}): Promise<CallToolResult>;
|
|
479
567
|
/**
|
|
480
568
|
* Creates AI SDK tools from tool definitions.
|
|
481
569
|
*/
|
|
@@ -506,4 +594,61 @@ interface MCPClient {
|
|
|
506
594
|
close: () => Promise<void>;
|
|
507
595
|
}
|
|
508
596
|
|
|
509
|
-
|
|
597
|
+
/**
|
|
598
|
+
* MIME type for HTML resources that are meant to be rendered as MCP Apps.
|
|
599
|
+
*/
|
|
600
|
+
declare const MCP_APP_MIME_TYPE: "text/html;profile=mcp-app";
|
|
601
|
+
/**
|
|
602
|
+
* Client capabilities to pass to `createMCPClient` when the host supports MCP Apps.
|
|
603
|
+
*/
|
|
604
|
+
declare const mcpAppClientCapabilities: {
|
|
605
|
+
readonly extensions: {
|
|
606
|
+
readonly "io.modelcontextprotocol/ui": {
|
|
607
|
+
readonly mimeTypes: readonly ["text/html;profile=mcp-app"];
|
|
608
|
+
};
|
|
609
|
+
};
|
|
610
|
+
};
|
|
611
|
+
/**
|
|
612
|
+
* Content security policy metadata requested by an MCP App resource.
|
|
613
|
+
*/
|
|
614
|
+
type MCPAppResourceCSP = {
|
|
615
|
+
connectDomains?: string[];
|
|
616
|
+
resourceDomains?: string[];
|
|
617
|
+
frameDomains?: string[];
|
|
618
|
+
[key: string]: unknown;
|
|
619
|
+
};
|
|
620
|
+
/**
|
|
621
|
+
* Host rendering metadata from an MCP App resource.
|
|
622
|
+
*/
|
|
623
|
+
type MCPAppResourceMeta = {
|
|
624
|
+
prefersBorder?: boolean;
|
|
625
|
+
csp?: MCPAppResourceCSP;
|
|
626
|
+
permissions?: Record<string, unknown>;
|
|
627
|
+
[key: string]: unknown;
|
|
628
|
+
};
|
|
629
|
+
/**
|
|
630
|
+
* HTML and metadata needed by a host to render an MCP App.
|
|
631
|
+
*/
|
|
632
|
+
type MCPAppResource = {
|
|
633
|
+
uri: string;
|
|
634
|
+
mimeType: typeof MCP_APP_MIME_TYPE;
|
|
635
|
+
html: string;
|
|
636
|
+
meta?: MCPAppResourceMeta;
|
|
637
|
+
};
|
|
638
|
+
/**
|
|
639
|
+
* Splits tool definitions into model-visible tools and app-visible tools.
|
|
640
|
+
*/
|
|
641
|
+
declare function splitMCPAppTools(definitions: ListToolsResult): {
|
|
642
|
+
modelVisible: ListToolsResult;
|
|
643
|
+
appVisible: ListToolsResult;
|
|
644
|
+
};
|
|
645
|
+
/**
|
|
646
|
+
* Reads a `ui://` resource from an MCP server and normalizes it for rendering.
|
|
647
|
+
*/
|
|
648
|
+
declare function readMCPAppResource({ client, uri, options, }: {
|
|
649
|
+
client: Pick<MCPClient, 'readResource'>;
|
|
650
|
+
uri: string;
|
|
651
|
+
options?: RequestOptions;
|
|
652
|
+
}): Promise<MCPAppResource>;
|
|
653
|
+
|
|
654
|
+
export { type CallToolResult, type Configuration, type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type ListToolsResult, type MCPAppResource, type MCPAppResourceCSP, type MCPAppResourceMeta, type MCPClient, type ClientCapabilities as MCPClientCapabilities, type MCPClientConfig, type MCPTransport, MCP_APP_MIME_TYPE, type McpProviderMetadata, type OAuthAuthorizationServerInformation, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, createMCPClient, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient, mcpAppClientCapabilities, readMCPAppResource, splitMCPAppTools };
|