@ai-sdk/mcp 2.0.0-beta.9 → 2.0.0-canary.39
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 +253 -8
- package/dist/index.d.ts +27 -1
- package/dist/index.js +297 -282
- package/dist/index.js.map +1 -1
- package/dist/mcp-stdio/index.js +149 -170
- package/dist/mcp-stdio/index.js.map +1 -1
- package/package.json +14 -15
- package/src/index.ts +1 -0
- package/src/tool/json-rpc-message.ts +7 -0
- package/src/tool/mcp-client.ts +71 -33
- package/src/tool/mcp-http-transport.ts +19 -8
- package/src/tool/mcp-sse-transport.ts +17 -10
- 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 +10 -2
- package/src/tool/mock-mcp-transport.ts +6 -8
- package/src/tool/oauth.ts +17 -12
- package/src/tool/types.ts +4 -2
- 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/src/tool/oauth.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import pkceChallenge from 'pkce-challenge';
|
|
2
2
|
import {
|
|
3
|
-
OAuthTokens,
|
|
4
|
-
OAuthProtectedResourceMetadata,
|
|
5
3
|
OAuthProtectedResourceMetadataSchema,
|
|
6
4
|
OAuthMetadataSchema,
|
|
7
5
|
OpenIdProviderDiscoveryMetadataSchema,
|
|
8
|
-
AuthorizationServerMetadata,
|
|
9
|
-
OAuthClientInformation,
|
|
10
6
|
OAuthTokensSchema,
|
|
11
7
|
OAuthErrorResponseSchema,
|
|
12
|
-
OAuthClientMetadata,
|
|
13
|
-
OAuthClientInformationFull,
|
|
14
8
|
OAuthClientInformationFullSchema,
|
|
9
|
+
type OAuthTokens,
|
|
10
|
+
type OAuthProtectedResourceMetadata,
|
|
11
|
+
type AuthorizationServerMetadata,
|
|
12
|
+
type OAuthClientInformation,
|
|
13
|
+
type OAuthClientMetadata,
|
|
14
|
+
type OAuthClientInformationFull,
|
|
15
15
|
} from './oauth-types';
|
|
16
16
|
import {
|
|
17
17
|
MCPClientOAuthError,
|
|
@@ -24,10 +24,10 @@ import {
|
|
|
24
24
|
import {
|
|
25
25
|
resourceUrlFromServerUrl,
|
|
26
26
|
checkResourceAllowed,
|
|
27
|
+
resourceUrlStripSlash,
|
|
27
28
|
} from '../util/oauth-util';
|
|
28
29
|
import { LATEST_PROTOCOL_VERSION } from './types';
|
|
29
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
30
|
-
|
|
30
|
+
import { parseJSON, type FetchFunction } from '@ai-sdk/provider-utils';
|
|
31
31
|
export type AuthResult = 'AUTHORIZED' | 'REDIRECT';
|
|
32
32
|
|
|
33
33
|
export interface OAuthClientProvider {
|
|
@@ -451,7 +451,10 @@ export async function startAuthorization(
|
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
if (resource) {
|
|
454
|
-
authorizationUrl.searchParams.set(
|
|
454
|
+
authorizationUrl.searchParams.set(
|
|
455
|
+
'resource',
|
|
456
|
+
resourceUrlStripSlash(resource),
|
|
457
|
+
);
|
|
455
458
|
}
|
|
456
459
|
|
|
457
460
|
return { authorizationUrl, codeVerifier };
|
|
@@ -587,7 +590,9 @@ export async function parseErrorResponse(
|
|
|
587
590
|
const body = input instanceof Response ? await input.text() : input;
|
|
588
591
|
|
|
589
592
|
try {
|
|
590
|
-
const result = OAuthErrorResponseSchema.parse(
|
|
593
|
+
const result = OAuthErrorResponseSchema.parse(
|
|
594
|
+
await parseJSON({ text: body }),
|
|
595
|
+
);
|
|
591
596
|
const { error, error_description, error_uri } = result;
|
|
592
597
|
const errorClass = OAUTH_ERRORS[error] || ServerError;
|
|
593
598
|
return new errorClass({
|
|
@@ -675,7 +680,7 @@ export async function exchangeAuthorization(
|
|
|
675
680
|
}
|
|
676
681
|
|
|
677
682
|
if (resource) {
|
|
678
|
-
params.set('resource', resource
|
|
683
|
+
params.set('resource', resourceUrlStripSlash(resource));
|
|
679
684
|
}
|
|
680
685
|
|
|
681
686
|
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
|
@@ -762,7 +767,7 @@ export async function refreshAuthorization(
|
|
|
762
767
|
}
|
|
763
768
|
|
|
764
769
|
if (resource) {
|
|
765
|
-
params.set('resource', resource
|
|
770
|
+
params.set('resource', resourceUrlStripSlash(resource));
|
|
766
771
|
}
|
|
767
772
|
|
|
768
773
|
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
package/src/tool/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import { JSONObject } from '@ai-sdk/provider';
|
|
3
|
-
import { FlexibleSchema, Tool } from '@ai-sdk/provider-utils';
|
|
2
|
+
import type { JSONObject } from '@ai-sdk/provider';
|
|
3
|
+
import type { FlexibleSchema, Tool } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
5
|
export const LATEST_PROTOCOL_VERSION = '2025-11-25';
|
|
6
6
|
export const SUPPORTED_PROTOCOL_VERSIONS = [
|
|
@@ -56,8 +56,10 @@ export type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> =
|
|
|
56
56
|
const ClientOrServerImplementationSchema = z.looseObject({
|
|
57
57
|
name: z.string(),
|
|
58
58
|
version: z.string(),
|
|
59
|
+
title: z.optional(z.string()),
|
|
59
60
|
});
|
|
60
61
|
|
|
62
|
+
// Maps to `Implementation` in the MCP specification
|
|
61
63
|
export type Configuration = z.infer<typeof ClientOrServerImplementationSchema>;
|
|
62
64
|
|
|
63
65
|
export const BaseParamsSchema = z.looseObject({
|
package/src/util/oauth-util.ts
CHANGED
|
@@ -14,6 +14,19 @@ export function resourceUrlFromServerUrl(url: URL | string): URL {
|
|
|
14
14
|
return resourceURL;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Serializes a resource URL to a string, removing the trailing slash that
|
|
19
|
+
* URL.href adds to pathless URLs. Per the MCP spec, implementations SHOULD
|
|
20
|
+
* use the form without the trailing slash for better interoperability.
|
|
21
|
+
*/
|
|
22
|
+
export function resourceUrlStripSlash(resource: URL): string {
|
|
23
|
+
const href = resource.href;
|
|
24
|
+
if (resource.pathname === '/' && href.endsWith('/')) {
|
|
25
|
+
return href.slice(0, -1);
|
|
26
|
+
}
|
|
27
|
+
return href;
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
/**
|
|
18
31
|
* Checks if a requested resource URL matches a configured resource URL.
|
|
19
32
|
* A requested resource matches if it has the same scheme, domain, port,
|
package/dist/index.d.mts
DELETED
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod/v4';
|
|
2
|
-
import { FetchFunction, FlexibleSchema, Tool } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { JSONObject } from '@ai-sdk/provider';
|
|
4
|
-
|
|
5
|
-
declare const JSONRPCRequestSchema: z.ZodObject<{
|
|
6
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
7
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
8
|
-
method: z.ZodString;
|
|
9
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
10
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
11
|
-
}, z.core.$loose>>;
|
|
12
|
-
}, z.core.$strict>;
|
|
13
|
-
type JSONRPCRequest = z.infer<typeof JSONRPCRequestSchema>;
|
|
14
|
-
declare const JSONRPCResponseSchema: z.ZodObject<{
|
|
15
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
16
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
17
|
-
result: z.ZodObject<{
|
|
18
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
19
|
-
}, z.core.$loose>;
|
|
20
|
-
}, z.core.$strict>;
|
|
21
|
-
type JSONRPCResponse = z.infer<typeof JSONRPCResponseSchema>;
|
|
22
|
-
declare const JSONRPCErrorSchema: z.ZodObject<{
|
|
23
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
24
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
25
|
-
error: z.ZodObject<{
|
|
26
|
-
code: z.ZodNumber;
|
|
27
|
-
message: z.ZodString;
|
|
28
|
-
data: z.ZodOptional<z.ZodUnknown>;
|
|
29
|
-
}, z.core.$strip>;
|
|
30
|
-
}, z.core.$strict>;
|
|
31
|
-
type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
|
|
32
|
-
declare const JSONRPCNotificationSchema: z.ZodObject<{
|
|
33
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
34
|
-
method: z.ZodString;
|
|
35
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
36
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
37
|
-
}, z.core.$loose>>;
|
|
38
|
-
}, z.core.$strict>;
|
|
39
|
-
type JSONRPCNotification = z.infer<typeof JSONRPCNotificationSchema>;
|
|
40
|
-
declare const JSONRPCMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
41
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
42
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
43
|
-
method: z.ZodString;
|
|
44
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
45
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
46
|
-
}, z.core.$loose>>;
|
|
47
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
48
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
49
|
-
method: z.ZodString;
|
|
50
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
51
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
52
|
-
}, z.core.$loose>>;
|
|
53
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
54
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
55
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
56
|
-
result: z.ZodObject<{
|
|
57
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
58
|
-
}, z.core.$loose>;
|
|
59
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
60
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
61
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
62
|
-
error: z.ZodObject<{
|
|
63
|
-
code: z.ZodNumber;
|
|
64
|
-
message: z.ZodString;
|
|
65
|
-
data: z.ZodOptional<z.ZodUnknown>;
|
|
66
|
-
}, z.core.$strip>;
|
|
67
|
-
}, z.core.$strict>]>;
|
|
68
|
-
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* OAuth 2.1 token response
|
|
72
|
-
*/
|
|
73
|
-
declare const OAuthTokensSchema: z.ZodObject<{
|
|
74
|
-
access_token: z.ZodString;
|
|
75
|
-
id_token: z.ZodOptional<z.ZodString>;
|
|
76
|
-
token_type: z.ZodString;
|
|
77
|
-
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
78
|
-
scope: z.ZodOptional<z.ZodString>;
|
|
79
|
-
refresh_token: z.ZodOptional<z.ZodString>;
|
|
80
|
-
}, z.core.$strip>;
|
|
81
|
-
declare const OAuthMetadataSchema: z.ZodObject<{
|
|
82
|
-
issuer: z.ZodString;
|
|
83
|
-
authorization_endpoint: z.ZodString;
|
|
84
|
-
token_endpoint: z.ZodString;
|
|
85
|
-
registration_endpoint: z.ZodOptional<z.ZodString>;
|
|
86
|
-
scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
87
|
-
response_types_supported: z.ZodArray<z.ZodString>;
|
|
88
|
-
grant_types_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
89
|
-
code_challenge_methods_supported: z.ZodArray<z.ZodString>;
|
|
90
|
-
token_endpoint_auth_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
91
|
-
token_endpoint_auth_signing_alg_values_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
92
|
-
}, z.core.$loose>;
|
|
93
|
-
/**
|
|
94
|
-
* OpenID Connect Discovery metadata that may include OAuth 2.0 fields
|
|
95
|
-
* This schema represents the real-world scenario where OIDC providers
|
|
96
|
-
* return a mix of OpenID Connect and OAuth 2.0 metadata fields
|
|
97
|
-
*/
|
|
98
|
-
declare const OpenIdProviderDiscoveryMetadataSchema: z.ZodObject<{
|
|
99
|
-
issuer: z.ZodString;
|
|
100
|
-
authorization_endpoint: z.ZodString;
|
|
101
|
-
token_endpoint: z.ZodString;
|
|
102
|
-
userinfo_endpoint: z.ZodOptional<z.ZodString>;
|
|
103
|
-
jwks_uri: z.ZodString;
|
|
104
|
-
registration_endpoint: z.ZodOptional<z.ZodString>;
|
|
105
|
-
scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
106
|
-
response_types_supported: z.ZodArray<z.ZodString>;
|
|
107
|
-
grant_types_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
108
|
-
subject_types_supported: z.ZodArray<z.ZodString>;
|
|
109
|
-
id_token_signing_alg_values_supported: z.ZodArray<z.ZodString>;
|
|
110
|
-
claims_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
111
|
-
token_endpoint_auth_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
112
|
-
code_challenge_methods_supported: z.ZodArray<z.ZodString>;
|
|
113
|
-
}, z.core.$loose>;
|
|
114
|
-
declare const OAuthClientInformationSchema: z.ZodObject<{
|
|
115
|
-
client_id: z.ZodString;
|
|
116
|
-
client_secret: z.ZodOptional<z.ZodString>;
|
|
117
|
-
client_id_issued_at: z.ZodOptional<z.ZodNumber>;
|
|
118
|
-
client_secret_expires_at: z.ZodOptional<z.ZodNumber>;
|
|
119
|
-
}, z.core.$strip>;
|
|
120
|
-
declare const OAuthClientMetadataSchema: z.ZodObject<{
|
|
121
|
-
redirect_uris: z.ZodArray<z.ZodString>;
|
|
122
|
-
token_endpoint_auth_method: z.ZodOptional<z.ZodString>;
|
|
123
|
-
grant_types: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
124
|
-
response_types: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
125
|
-
client_name: z.ZodOptional<z.ZodString>;
|
|
126
|
-
client_uri: z.ZodOptional<z.ZodString>;
|
|
127
|
-
logo_uri: z.ZodOptional<z.ZodString>;
|
|
128
|
-
scope: z.ZodOptional<z.ZodString>;
|
|
129
|
-
contacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
130
|
-
tos_uri: z.ZodOptional<z.ZodString>;
|
|
131
|
-
policy_uri: z.ZodOptional<z.ZodString>;
|
|
132
|
-
jwks_uri: z.ZodOptional<z.ZodString>;
|
|
133
|
-
jwks: z.ZodOptional<z.ZodAny>;
|
|
134
|
-
software_id: z.ZodOptional<z.ZodString>;
|
|
135
|
-
software_version: z.ZodOptional<z.ZodString>;
|
|
136
|
-
software_statement: z.ZodOptional<z.ZodString>;
|
|
137
|
-
}, z.core.$strip>;
|
|
138
|
-
type OAuthMetadata = z.infer<typeof OAuthMetadataSchema>;
|
|
139
|
-
type OpenIdProviderDiscoveryMetadata = z.infer<typeof OpenIdProviderDiscoveryMetadataSchema>;
|
|
140
|
-
type OAuthTokens = z.infer<typeof OAuthTokensSchema>;
|
|
141
|
-
type OAuthClientInformation = z.infer<typeof OAuthClientInformationSchema>;
|
|
142
|
-
type AuthorizationServerMetadata = OAuthMetadata | OpenIdProviderDiscoveryMetadata;
|
|
143
|
-
type OAuthClientMetadata = z.infer<typeof OAuthClientMetadataSchema>;
|
|
144
|
-
|
|
145
|
-
type AuthResult = 'AUTHORIZED' | 'REDIRECT';
|
|
146
|
-
interface OAuthClientProvider {
|
|
147
|
-
/**
|
|
148
|
-
* Returns current access token if present; undefined otherwise.
|
|
149
|
-
*/
|
|
150
|
-
tokens(): OAuthTokens | undefined | Promise<OAuthTokens | undefined>;
|
|
151
|
-
saveTokens(tokens: OAuthTokens): void | Promise<void>;
|
|
152
|
-
redirectToAuthorization(authorizationUrl: URL): void | Promise<void>;
|
|
153
|
-
saveCodeVerifier(codeVerifier: string): void | Promise<void>;
|
|
154
|
-
codeVerifier(): string | Promise<string>;
|
|
155
|
-
/**
|
|
156
|
-
* Adds custom client authentication to OAuth token requests.
|
|
157
|
-
*
|
|
158
|
-
* This optional method allows implementations to customize how client credentials
|
|
159
|
-
* are included in token exchange and refresh requests. When provided, this method
|
|
160
|
-
* is called instead of the default authentication logic, giving full control over
|
|
161
|
-
* the authentication mechanism.
|
|
162
|
-
*
|
|
163
|
-
* Common use cases include:
|
|
164
|
-
* - Supporting authentication methods beyond the standard OAuth 2.0 methods
|
|
165
|
-
* - Adding custom headers for proprietary authentication schemes
|
|
166
|
-
* - Implementing client assertion-based authentication (e.g., JWT bearer tokens)
|
|
167
|
-
*
|
|
168
|
-
* @param headers - The request headers (can be modified to add authentication)
|
|
169
|
-
* @param params - The request body parameters (can be modified to add credentials)
|
|
170
|
-
* @param url - The token endpoint URL being called
|
|
171
|
-
* @param metadata - Optional OAuth metadata for the server, which may include supported authentication methods
|
|
172
|
-
*/
|
|
173
|
-
addClientAuthentication?(headers: Headers, params: URLSearchParams, url: string | URL, metadata?: AuthorizationServerMetadata): void | Promise<void>;
|
|
174
|
-
/**
|
|
175
|
-
* If implemented, provides a way for the client to invalidate (e.g. delete) the specified
|
|
176
|
-
* credentials, in the case where the server has indicated that they are no longer valid.
|
|
177
|
-
* This avoids requiring the user to intervene manually.
|
|
178
|
-
*/
|
|
179
|
-
invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier'): void | Promise<void>;
|
|
180
|
-
get redirectUrl(): string | URL;
|
|
181
|
-
get clientMetadata(): OAuthClientMetadata;
|
|
182
|
-
clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
|
|
183
|
-
saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
|
|
184
|
-
state?(): string | Promise<string>;
|
|
185
|
-
saveState?(state: string): void | Promise<void>;
|
|
186
|
-
storedState?(): string | undefined | Promise<string | undefined>;
|
|
187
|
-
validateResourceURL?(serverUrl: string | URL, resource?: string): Promise<URL | undefined>;
|
|
188
|
-
}
|
|
189
|
-
declare class UnauthorizedError extends Error {
|
|
190
|
-
constructor(message?: string);
|
|
191
|
-
}
|
|
192
|
-
declare function auth(provider: OAuthClientProvider, options: {
|
|
193
|
-
serverUrl: string | URL;
|
|
194
|
-
authorizationCode?: string;
|
|
195
|
-
callbackState?: string;
|
|
196
|
-
scope?: string;
|
|
197
|
-
resourceMetadataUrl?: URL;
|
|
198
|
-
fetchFn?: FetchFunction;
|
|
199
|
-
}): Promise<AuthResult>;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Transport interface for MCP (Model Context Protocol) communication.
|
|
203
|
-
* Maps to the `Transport` interface in the MCP spec.
|
|
204
|
-
*/
|
|
205
|
-
interface MCPTransport {
|
|
206
|
-
/**
|
|
207
|
-
* Initialize and start the transport
|
|
208
|
-
*/
|
|
209
|
-
start(): Promise<void>;
|
|
210
|
-
/**
|
|
211
|
-
* Send a JSON-RPC message through the transport
|
|
212
|
-
* @param message The JSON-RPC message to send
|
|
213
|
-
*/
|
|
214
|
-
send(message: JSONRPCMessage): Promise<void>;
|
|
215
|
-
/**
|
|
216
|
-
* Clean up and close the transport
|
|
217
|
-
*/
|
|
218
|
-
close(): Promise<void>;
|
|
219
|
-
/**
|
|
220
|
-
* Event handler for transport closure
|
|
221
|
-
*/
|
|
222
|
-
onclose?: () => void;
|
|
223
|
-
/**
|
|
224
|
-
* Event handler for transport errors
|
|
225
|
-
*/
|
|
226
|
-
onerror?: (error: Error) => void;
|
|
227
|
-
/**
|
|
228
|
-
* Event handler for received messages
|
|
229
|
-
*/
|
|
230
|
-
onmessage?: (message: JSONRPCMessage) => void;
|
|
231
|
-
}
|
|
232
|
-
type MCPTransportConfig = {
|
|
233
|
-
type: 'sse' | 'http';
|
|
234
|
-
/**
|
|
235
|
-
* The URL of the MCP server.
|
|
236
|
-
*/
|
|
237
|
-
url: string;
|
|
238
|
-
/**
|
|
239
|
-
* Additional HTTP headers to be sent with requests.
|
|
240
|
-
*/
|
|
241
|
-
headers?: Record<string, string>;
|
|
242
|
-
/**
|
|
243
|
-
* An optional OAuth client provider to use for authentication for MCP servers.
|
|
244
|
-
*/
|
|
245
|
-
authProvider?: OAuthClientProvider;
|
|
246
|
-
/**
|
|
247
|
-
* Controls how HTTP redirects are handled for transport requests.
|
|
248
|
-
* - `'follow'`: Follow redirects automatically (standard fetch behavior).
|
|
249
|
-
* - `'error'`: Reject any redirect response with an error.
|
|
250
|
-
* @default 'error'
|
|
251
|
-
*/
|
|
252
|
-
redirect?: 'follow' | 'error';
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
/** MCP tool metadata - keys should follow MCP _meta key format specification */
|
|
256
|
-
declare const ToolMetaSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
257
|
-
type ToolMeta = z.infer<typeof ToolMetaSchema>;
|
|
258
|
-
type ToolSchemas = Record<string, {
|
|
259
|
-
inputSchema: FlexibleSchema<JSONObject | unknown>;
|
|
260
|
-
outputSchema?: FlexibleSchema<JSONObject | unknown>;
|
|
261
|
-
}> | 'automatic' | undefined;
|
|
262
|
-
/** Base MCP tool type with execute and _meta */
|
|
263
|
-
type McpToolBase<INPUT = unknown, OUTPUT = CallToolResult> = Tool<INPUT, OUTPUT> & Required<Pick<Tool<INPUT, OUTPUT>, 'execute'>> & {
|
|
264
|
-
_meta?: ToolMeta;
|
|
265
|
-
};
|
|
266
|
-
type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS extends Record<string, {
|
|
267
|
-
inputSchema: FlexibleSchema<any>;
|
|
268
|
-
outputSchema?: FlexibleSchema<any>;
|
|
269
|
-
}> ? {
|
|
270
|
-
[K in keyof TOOL_SCHEMAS]: TOOL_SCHEMAS[K] extends {
|
|
271
|
-
inputSchema: FlexibleSchema<infer INPUT>;
|
|
272
|
-
outputSchema: FlexibleSchema<infer OUTPUT>;
|
|
273
|
-
} ? McpToolBase<INPUT, OUTPUT> : TOOL_SCHEMAS[K] extends {
|
|
274
|
-
inputSchema: FlexibleSchema<infer INPUT>;
|
|
275
|
-
} ? McpToolBase<INPUT, CallToolResult> : never;
|
|
276
|
-
} : Record<string, McpToolBase<unknown, CallToolResult>>;
|
|
277
|
-
declare const BaseParamsSchema: z.ZodObject<{
|
|
278
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
279
|
-
}, z.core.$loose>;
|
|
280
|
-
type BaseParams = z.infer<typeof BaseParamsSchema>;
|
|
281
|
-
declare const RequestSchema: z.ZodObject<{
|
|
282
|
-
method: z.ZodString;
|
|
283
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
284
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
285
|
-
}, z.core.$loose>>;
|
|
286
|
-
}, z.core.$strip>;
|
|
287
|
-
type Request = z.infer<typeof RequestSchema>;
|
|
288
|
-
type RequestOptions = {
|
|
289
|
-
signal?: AbortSignal;
|
|
290
|
-
timeout?: number;
|
|
291
|
-
maxTotalTimeout?: number;
|
|
292
|
-
};
|
|
293
|
-
declare const ClientCapabilitiesSchema: z.ZodObject<{
|
|
294
|
-
elicitation: z.ZodOptional<z.ZodObject<{
|
|
295
|
-
applyDefaults: z.ZodOptional<z.ZodBoolean>;
|
|
296
|
-
}, z.core.$loose>>;
|
|
297
|
-
}, z.core.$loose>;
|
|
298
|
-
type ClientCapabilities = z.infer<typeof ClientCapabilitiesSchema>;
|
|
299
|
-
type PaginatedRequest = Request & {
|
|
300
|
-
params?: BaseParams & {
|
|
301
|
-
cursor?: string;
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
declare const ListToolsResultSchema: z.ZodObject<{
|
|
305
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
306
|
-
nextCursor: z.ZodOptional<z.ZodString>;
|
|
307
|
-
tools: z.ZodArray<z.ZodObject<{
|
|
308
|
-
name: z.ZodString;
|
|
309
|
-
title: z.ZodOptional<z.ZodString>;
|
|
310
|
-
description: z.ZodOptional<z.ZodString>;
|
|
311
|
-
inputSchema: z.ZodObject<{
|
|
312
|
-
type: z.ZodLiteral<"object">;
|
|
313
|
-
properties: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
314
|
-
}, z.core.$loose>;
|
|
315
|
-
outputSchema: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
316
|
-
annotations: z.ZodOptional<z.ZodObject<{
|
|
317
|
-
title: z.ZodOptional<z.ZodString>;
|
|
318
|
-
}, z.core.$loose>>;
|
|
319
|
-
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
320
|
-
}, z.core.$loose>>;
|
|
321
|
-
}, z.core.$loose>;
|
|
322
|
-
type ListToolsResult = z.infer<typeof ListToolsResultSchema>;
|
|
323
|
-
declare const ListResourcesResultSchema: z.ZodObject<{
|
|
324
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
325
|
-
nextCursor: z.ZodOptional<z.ZodString>;
|
|
326
|
-
resources: z.ZodArray<z.ZodObject<{
|
|
327
|
-
uri: z.ZodString;
|
|
328
|
-
name: z.ZodString;
|
|
329
|
-
title: z.ZodOptional<z.ZodString>;
|
|
330
|
-
description: z.ZodOptional<z.ZodString>;
|
|
331
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
332
|
-
size: z.ZodOptional<z.ZodNumber>;
|
|
333
|
-
}, z.core.$loose>>;
|
|
334
|
-
}, z.core.$loose>;
|
|
335
|
-
type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>;
|
|
336
|
-
declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
|
|
337
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
338
|
-
content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
339
|
-
type: z.ZodLiteral<"text">;
|
|
340
|
-
text: z.ZodString;
|
|
341
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
342
|
-
type: z.ZodLiteral<"image">;
|
|
343
|
-
data: z.ZodBase64;
|
|
344
|
-
mimeType: z.ZodString;
|
|
345
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
346
|
-
type: z.ZodLiteral<"resource">;
|
|
347
|
-
resource: z.ZodUnion<readonly [z.ZodObject<{
|
|
348
|
-
uri: z.ZodString;
|
|
349
|
-
name: z.ZodOptional<z.ZodString>;
|
|
350
|
-
title: z.ZodOptional<z.ZodString>;
|
|
351
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
352
|
-
text: z.ZodString;
|
|
353
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
354
|
-
uri: z.ZodString;
|
|
355
|
-
name: z.ZodOptional<z.ZodString>;
|
|
356
|
-
title: z.ZodOptional<z.ZodString>;
|
|
357
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
358
|
-
blob: z.ZodBase64;
|
|
359
|
-
}, z.core.$loose>]>;
|
|
360
|
-
}, z.core.$loose>]>>;
|
|
361
|
-
structuredContent: z.ZodOptional<z.ZodUnknown>;
|
|
362
|
-
isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
363
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
364
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
365
|
-
toolResult: z.ZodUnknown;
|
|
366
|
-
}, z.core.$loose>]>;
|
|
367
|
-
type CallToolResult = z.infer<typeof CallToolResultSchema>;
|
|
368
|
-
declare const ListResourceTemplatesResultSchema: z.ZodObject<{
|
|
369
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
370
|
-
resourceTemplates: z.ZodArray<z.ZodObject<{
|
|
371
|
-
uriTemplate: z.ZodString;
|
|
372
|
-
name: z.ZodString;
|
|
373
|
-
title: z.ZodOptional<z.ZodString>;
|
|
374
|
-
description: z.ZodOptional<z.ZodString>;
|
|
375
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
376
|
-
}, z.core.$loose>>;
|
|
377
|
-
}, z.core.$loose>;
|
|
378
|
-
type ListResourceTemplatesResult = z.infer<typeof ListResourceTemplatesResultSchema>;
|
|
379
|
-
declare const ReadResourceResultSchema: z.ZodObject<{
|
|
380
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
381
|
-
contents: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
382
|
-
uri: z.ZodString;
|
|
383
|
-
name: z.ZodOptional<z.ZodString>;
|
|
384
|
-
title: z.ZodOptional<z.ZodString>;
|
|
385
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
386
|
-
text: z.ZodString;
|
|
387
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
388
|
-
uri: z.ZodString;
|
|
389
|
-
name: z.ZodOptional<z.ZodString>;
|
|
390
|
-
title: z.ZodOptional<z.ZodString>;
|
|
391
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
392
|
-
blob: z.ZodBase64;
|
|
393
|
-
}, z.core.$loose>]>>;
|
|
394
|
-
}, z.core.$loose>;
|
|
395
|
-
type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>;
|
|
396
|
-
declare const ListPromptsResultSchema: z.ZodObject<{
|
|
397
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
398
|
-
nextCursor: z.ZodOptional<z.ZodString>;
|
|
399
|
-
prompts: z.ZodArray<z.ZodObject<{
|
|
400
|
-
name: z.ZodString;
|
|
401
|
-
title: z.ZodOptional<z.ZodString>;
|
|
402
|
-
description: z.ZodOptional<z.ZodString>;
|
|
403
|
-
arguments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
404
|
-
name: z.ZodString;
|
|
405
|
-
description: z.ZodOptional<z.ZodString>;
|
|
406
|
-
required: z.ZodOptional<z.ZodBoolean>;
|
|
407
|
-
}, z.core.$loose>>>;
|
|
408
|
-
}, z.core.$loose>>;
|
|
409
|
-
}, z.core.$loose>;
|
|
410
|
-
type ListPromptsResult = z.infer<typeof ListPromptsResultSchema>;
|
|
411
|
-
declare const GetPromptResultSchema: z.ZodObject<{
|
|
412
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
413
|
-
description: z.ZodOptional<z.ZodString>;
|
|
414
|
-
messages: z.ZodArray<z.ZodObject<{
|
|
415
|
-
role: z.ZodUnion<readonly [z.ZodLiteral<"user">, z.ZodLiteral<"assistant">]>;
|
|
416
|
-
content: z.ZodUnion<readonly [z.ZodObject<{
|
|
417
|
-
type: z.ZodLiteral<"text">;
|
|
418
|
-
text: z.ZodString;
|
|
419
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
420
|
-
type: z.ZodLiteral<"image">;
|
|
421
|
-
data: z.ZodBase64;
|
|
422
|
-
mimeType: z.ZodString;
|
|
423
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
424
|
-
type: z.ZodLiteral<"resource">;
|
|
425
|
-
resource: z.ZodUnion<readonly [z.ZodObject<{
|
|
426
|
-
uri: z.ZodString;
|
|
427
|
-
name: z.ZodOptional<z.ZodString>;
|
|
428
|
-
title: z.ZodOptional<z.ZodString>;
|
|
429
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
430
|
-
text: z.ZodString;
|
|
431
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
432
|
-
uri: z.ZodString;
|
|
433
|
-
name: z.ZodOptional<z.ZodString>;
|
|
434
|
-
title: z.ZodOptional<z.ZodString>;
|
|
435
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
436
|
-
blob: z.ZodBase64;
|
|
437
|
-
}, z.core.$loose>]>;
|
|
438
|
-
}, z.core.$loose>]>;
|
|
439
|
-
}, z.core.$loose>>;
|
|
440
|
-
}, z.core.$loose>;
|
|
441
|
-
type GetPromptResult = z.infer<typeof GetPromptResultSchema>;
|
|
442
|
-
declare const ElicitationRequestSchema: z.ZodObject<{
|
|
443
|
-
method: z.ZodLiteral<"elicitation/create">;
|
|
444
|
-
params: z.ZodObject<{
|
|
445
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
446
|
-
message: z.ZodString;
|
|
447
|
-
requestedSchema: z.ZodUnknown;
|
|
448
|
-
}, z.core.$loose>;
|
|
449
|
-
}, z.core.$strip>;
|
|
450
|
-
type ElicitationRequest = z.infer<typeof ElicitationRequestSchema>;
|
|
451
|
-
declare const ElicitResultSchema: z.ZodObject<{
|
|
452
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
453
|
-
action: z.ZodUnion<readonly [z.ZodLiteral<"accept">, z.ZodLiteral<"decline">, z.ZodLiteral<"cancel">]>;
|
|
454
|
-
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
455
|
-
}, z.core.$loose>;
|
|
456
|
-
type ElicitResult = z.infer<typeof ElicitResultSchema>;
|
|
457
|
-
|
|
458
|
-
interface MCPClientConfig {
|
|
459
|
-
/** Transport configuration for connecting to the MCP server */
|
|
460
|
-
transport: MCPTransportConfig | MCPTransport;
|
|
461
|
-
/** Optional callback for uncaught errors */
|
|
462
|
-
onUncaughtError?: (error: unknown) => void;
|
|
463
|
-
/** Optional client name, defaults to 'ai-sdk-mcp-client' */
|
|
464
|
-
name?: string;
|
|
465
|
-
/** Optional client version, defaults to '1.0.0' */
|
|
466
|
-
version?: string;
|
|
467
|
-
/**
|
|
468
|
-
* Optional client capabilities to advertise during initialization
|
|
469
|
-
*
|
|
470
|
-
* NOTE: It is up to the client application to handle the requests properly. This parameter just helps surface the request from the server
|
|
471
|
-
*/
|
|
472
|
-
capabilities?: ClientCapabilities;
|
|
473
|
-
}
|
|
474
|
-
declare function createMCPClient(config: MCPClientConfig): Promise<MCPClient>;
|
|
475
|
-
interface MCPClient {
|
|
476
|
-
tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
|
|
477
|
-
schemas?: TOOL_SCHEMAS;
|
|
478
|
-
}): Promise<McpToolSet<TOOL_SCHEMAS>>;
|
|
479
|
-
/**
|
|
480
|
-
* Lists available tools from the MCP server.
|
|
481
|
-
*/
|
|
482
|
-
listTools(options?: {
|
|
483
|
-
params?: PaginatedRequest['params'];
|
|
484
|
-
options?: RequestOptions;
|
|
485
|
-
}): Promise<ListToolsResult>;
|
|
486
|
-
/**
|
|
487
|
-
* Creates AI SDK tools from tool definitions.
|
|
488
|
-
*/
|
|
489
|
-
toolsFromDefinitions<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(definitions: ListToolsResult, options?: {
|
|
490
|
-
schemas?: TOOL_SCHEMAS;
|
|
491
|
-
}): McpToolSet<TOOL_SCHEMAS>;
|
|
492
|
-
listResources(options?: {
|
|
493
|
-
params?: PaginatedRequest['params'];
|
|
494
|
-
options?: RequestOptions;
|
|
495
|
-
}): Promise<ListResourcesResult>;
|
|
496
|
-
readResource(args: {
|
|
497
|
-
uri: string;
|
|
498
|
-
options?: RequestOptions;
|
|
499
|
-
}): Promise<ReadResourceResult>;
|
|
500
|
-
listResourceTemplates(options?: {
|
|
501
|
-
options?: RequestOptions;
|
|
502
|
-
}): Promise<ListResourceTemplatesResult>;
|
|
503
|
-
experimental_listPrompts(options?: {
|
|
504
|
-
params?: PaginatedRequest['params'];
|
|
505
|
-
options?: RequestOptions;
|
|
506
|
-
}): Promise<ListPromptsResult>;
|
|
507
|
-
experimental_getPrompt(args: {
|
|
508
|
-
name: string;
|
|
509
|
-
arguments?: Record<string, unknown>;
|
|
510
|
-
options?: RequestOptions;
|
|
511
|
-
}): Promise<GetPromptResult>;
|
|
512
|
-
onElicitationRequest(schema: typeof ElicitationRequestSchema, handler: (request: ElicitationRequest) => Promise<ElicitResult> | ElicitResult): void;
|
|
513
|
-
close: () => Promise<void>;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type ListToolsResult, type MCPClient, type ClientCapabilities as MCPClientCapabilities, type MCPClientConfig, type MCPTransport, 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 };
|