@ai-sdk/mcp 2.0.0-beta.6 → 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 +490 -8
- package/README.md +134 -0
- package/dist/index.d.ts +140 -2
- package/dist/index.js +750 -345
- 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 +72 -24
- package/src/tool/mcp-sse-transport.ts +42 -16
- 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 +21 -3
- 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 -516
- package/dist/index.mjs +0 -2137
- 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';
|
|
@@ -247,11 +270,23 @@ type MCPTransportConfig = {
|
|
|
247
270
|
* Controls how HTTP redirects are handled for transport requests.
|
|
248
271
|
* - `'follow'`: Follow redirects automatically (standard fetch behavior).
|
|
249
272
|
* - `'error'`: Reject any redirect response with an error.
|
|
250
|
-
* @default '
|
|
273
|
+
* @default 'error'
|
|
251
274
|
*/
|
|
252
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;
|
|
253
282
|
};
|
|
254
283
|
|
|
284
|
+
type McpProviderMetadata = {
|
|
285
|
+
clientName?: string;
|
|
286
|
+
title?: string;
|
|
287
|
+
toolName?: string;
|
|
288
|
+
app?: JSONObject;
|
|
289
|
+
};
|
|
255
290
|
/** MCP tool metadata - keys should follow MCP _meta key format specification */
|
|
256
291
|
declare const ToolMetaSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
257
292
|
type ToolMeta = z.infer<typeof ToolMetaSchema>;
|
|
@@ -274,6 +309,12 @@ type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS e
|
|
|
274
309
|
inputSchema: FlexibleSchema<infer INPUT>;
|
|
275
310
|
} ? McpToolBase<INPUT, CallToolResult> : never;
|
|
276
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>;
|
|
277
318
|
declare const BaseParamsSchema: z.ZodObject<{
|
|
278
319
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
279
320
|
}, z.core.$loose>;
|
|
@@ -357,6 +398,12 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
357
398
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
358
399
|
blob: z.ZodBase64;
|
|
359
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>;
|
|
360
407
|
}, z.core.$loose>]>>;
|
|
361
408
|
structuredContent: z.ZodOptional<z.ZodUnknown>;
|
|
362
409
|
isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
@@ -435,6 +482,12 @@ declare const GetPromptResultSchema: z.ZodObject<{
|
|
|
435
482
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
436
483
|
blob: z.ZodBase64;
|
|
437
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>;
|
|
438
491
|
}, z.core.$loose>]>;
|
|
439
492
|
}, z.core.$loose>>;
|
|
440
493
|
}, z.core.$loose>;
|
|
@@ -461,6 +514,12 @@ interface MCPClientConfig {
|
|
|
461
514
|
/** Optional callback for uncaught errors */
|
|
462
515
|
onUncaughtError?: (error: unknown) => void;
|
|
463
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
|
+
*/
|
|
464
523
|
name?: string;
|
|
465
524
|
/** Optional client version, defaults to '1.0.0' */
|
|
466
525
|
version?: string;
|
|
@@ -473,6 +532,20 @@ interface MCPClientConfig {
|
|
|
473
532
|
}
|
|
474
533
|
declare function createMCPClient(config: MCPClientConfig): Promise<MCPClient>;
|
|
475
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;
|
|
476
549
|
tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
|
|
477
550
|
schemas?: TOOL_SCHEMAS;
|
|
478
551
|
}): Promise<McpToolSet<TOOL_SCHEMAS>>;
|
|
@@ -483,6 +556,14 @@ interface MCPClient {
|
|
|
483
556
|
params?: PaginatedRequest['params'];
|
|
484
557
|
options?: RequestOptions;
|
|
485
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>;
|
|
486
567
|
/**
|
|
487
568
|
* Creates AI SDK tools from tool definitions.
|
|
488
569
|
*/
|
|
@@ -513,4 +594,61 @@ interface MCPClient {
|
|
|
513
594
|
close: () => Promise<void>;
|
|
514
595
|
}
|
|
515
596
|
|
|
516
|
-
|
|
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 };
|