@ai-sdk/mcp 0.0.7 → 0.0.9
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 +13 -0
- package/dist/index.d.mts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +112 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -8
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js +24 -1
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs +24 -1
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/mcp
|
|
2
2
|
|
|
3
|
+
## 0.0.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 89b59d7: feat(mcp): add client elicitation support
|
|
8
|
+
|
|
9
|
+
## 0.0.8
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [056c471]
|
|
14
|
+
- @ai-sdk/provider-utils@3.0.17
|
|
15
|
+
|
|
3
16
|
## 0.0.7
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -270,6 +270,12 @@ type RequestOptions = {
|
|
|
270
270
|
timeout?: number;
|
|
271
271
|
maxTotalTimeout?: number;
|
|
272
272
|
};
|
|
273
|
+
declare const ClientCapabilitiesSchema: z.ZodObject<{
|
|
274
|
+
elicitation: z.ZodOptional<z.ZodObject<{
|
|
275
|
+
applyDefaults: z.ZodOptional<z.ZodBoolean>;
|
|
276
|
+
}, z.core.$loose>>;
|
|
277
|
+
}, z.core.$loose>;
|
|
278
|
+
type ClientCapabilities = z.infer<typeof ClientCapabilitiesSchema>;
|
|
273
279
|
type PaginatedRequest = Request & {
|
|
274
280
|
params?: BaseParams & {
|
|
275
281
|
cursor?: string;
|
|
@@ -393,6 +399,21 @@ declare const GetPromptResultSchema: z.ZodObject<{
|
|
|
393
399
|
}, z.core.$loose>>;
|
|
394
400
|
}, z.core.$loose>;
|
|
395
401
|
type GetPromptResult = z.infer<typeof GetPromptResultSchema>;
|
|
402
|
+
declare const ElicitationRequestSchema: z.ZodObject<{
|
|
403
|
+
method: z.ZodLiteral<"elicitation/create">;
|
|
404
|
+
params: z.ZodObject<{
|
|
405
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
406
|
+
message: z.ZodString;
|
|
407
|
+
requestedSchema: z.ZodUnknown;
|
|
408
|
+
}, z.core.$loose>;
|
|
409
|
+
}, z.core.$strip>;
|
|
410
|
+
type ElicitationRequest = z.infer<typeof ElicitationRequestSchema>;
|
|
411
|
+
declare const ElicitResultSchema: z.ZodObject<{
|
|
412
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
413
|
+
action: z.ZodUnion<readonly [z.ZodLiteral<"accept">, z.ZodLiteral<"decline">, z.ZodLiteral<"cancel">]>;
|
|
414
|
+
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
415
|
+
}, z.core.$loose>;
|
|
416
|
+
type ElicitResult = z.infer<typeof ElicitResultSchema>;
|
|
396
417
|
|
|
397
418
|
interface MCPClientConfig {
|
|
398
419
|
/** Transport configuration for connecting to the MCP server */
|
|
@@ -401,6 +422,12 @@ interface MCPClientConfig {
|
|
|
401
422
|
onUncaughtError?: (error: unknown) => void;
|
|
402
423
|
/** Optional client name, defaults to 'ai-sdk-mcp-client' */
|
|
403
424
|
name?: string;
|
|
425
|
+
/**
|
|
426
|
+
* Optional client capabilities to advertise during initialization
|
|
427
|
+
*
|
|
428
|
+
* NOTE: It is up to the client application to handle the requests properly. This parameter just helps surface the request from the server
|
|
429
|
+
*/
|
|
430
|
+
capabilities?: ClientCapabilities;
|
|
404
431
|
}
|
|
405
432
|
declare function createMCPClient(config: MCPClientConfig): Promise<MCPClient>;
|
|
406
433
|
interface MCPClient {
|
|
@@ -427,7 +454,8 @@ interface MCPClient {
|
|
|
427
454
|
arguments?: Record<string, unknown>;
|
|
428
455
|
options?: RequestOptions;
|
|
429
456
|
}): Promise<GetPromptResult>;
|
|
457
|
+
onElicitationRequest(schema: typeof ElicitationRequestSchema, handler: (request: ElicitationRequest) => Promise<ElicitResult> | ElicitResult): void;
|
|
430
458
|
close: () => Promise<void>;
|
|
431
459
|
}
|
|
432
460
|
|
|
433
|
-
export { type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type MCPTransport, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, type MCPClient as experimental_MCPClient, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient };
|
|
461
|
+
export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type MCPTransport, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -270,6 +270,12 @@ type RequestOptions = {
|
|
|
270
270
|
timeout?: number;
|
|
271
271
|
maxTotalTimeout?: number;
|
|
272
272
|
};
|
|
273
|
+
declare const ClientCapabilitiesSchema: z.ZodObject<{
|
|
274
|
+
elicitation: z.ZodOptional<z.ZodObject<{
|
|
275
|
+
applyDefaults: z.ZodOptional<z.ZodBoolean>;
|
|
276
|
+
}, z.core.$loose>>;
|
|
277
|
+
}, z.core.$loose>;
|
|
278
|
+
type ClientCapabilities = z.infer<typeof ClientCapabilitiesSchema>;
|
|
273
279
|
type PaginatedRequest = Request & {
|
|
274
280
|
params?: BaseParams & {
|
|
275
281
|
cursor?: string;
|
|
@@ -393,6 +399,21 @@ declare const GetPromptResultSchema: z.ZodObject<{
|
|
|
393
399
|
}, z.core.$loose>>;
|
|
394
400
|
}, z.core.$loose>;
|
|
395
401
|
type GetPromptResult = z.infer<typeof GetPromptResultSchema>;
|
|
402
|
+
declare const ElicitationRequestSchema: z.ZodObject<{
|
|
403
|
+
method: z.ZodLiteral<"elicitation/create">;
|
|
404
|
+
params: z.ZodObject<{
|
|
405
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
406
|
+
message: z.ZodString;
|
|
407
|
+
requestedSchema: z.ZodUnknown;
|
|
408
|
+
}, z.core.$loose>;
|
|
409
|
+
}, z.core.$strip>;
|
|
410
|
+
type ElicitationRequest = z.infer<typeof ElicitationRequestSchema>;
|
|
411
|
+
declare const ElicitResultSchema: z.ZodObject<{
|
|
412
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
413
|
+
action: z.ZodUnion<readonly [z.ZodLiteral<"accept">, z.ZodLiteral<"decline">, z.ZodLiteral<"cancel">]>;
|
|
414
|
+
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
415
|
+
}, z.core.$loose>;
|
|
416
|
+
type ElicitResult = z.infer<typeof ElicitResultSchema>;
|
|
396
417
|
|
|
397
418
|
interface MCPClientConfig {
|
|
398
419
|
/** Transport configuration for connecting to the MCP server */
|
|
@@ -401,6 +422,12 @@ interface MCPClientConfig {
|
|
|
401
422
|
onUncaughtError?: (error: unknown) => void;
|
|
402
423
|
/** Optional client name, defaults to 'ai-sdk-mcp-client' */
|
|
403
424
|
name?: string;
|
|
425
|
+
/**
|
|
426
|
+
* Optional client capabilities to advertise during initialization
|
|
427
|
+
*
|
|
428
|
+
* NOTE: It is up to the client application to handle the requests properly. This parameter just helps surface the request from the server
|
|
429
|
+
*/
|
|
430
|
+
capabilities?: ClientCapabilities;
|
|
404
431
|
}
|
|
405
432
|
declare function createMCPClient(config: MCPClientConfig): Promise<MCPClient>;
|
|
406
433
|
interface MCPClient {
|
|
@@ -427,7 +454,8 @@ interface MCPClient {
|
|
|
427
454
|
arguments?: Record<string, unknown>;
|
|
428
455
|
options?: RequestOptions;
|
|
429
456
|
}): Promise<GetPromptResult>;
|
|
457
|
+
onElicitationRequest(schema: typeof ElicitationRequestSchema, handler: (request: ElicitationRequest) => Promise<ElicitResult> | ElicitResult): void;
|
|
430
458
|
close: () => Promise<void>;
|
|
431
459
|
}
|
|
432
460
|
|
|
433
|
-
export { type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type MCPTransport, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, type MCPClient as experimental_MCPClient, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient };
|
|
461
|
+
export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type MCPTransport, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient };
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
ElicitResultSchema: () => ElicitResultSchema,
|
|
34
|
+
ElicitationRequestSchema: () => ElicitationRequestSchema,
|
|
33
35
|
UnauthorizedError: () => UnauthorizedError,
|
|
34
36
|
auth: () => auth,
|
|
35
37
|
experimental_createMCPClient: () => createMCPClient
|
|
@@ -89,6 +91,9 @@ var RequestSchema = import_v4.z.object({
|
|
|
89
91
|
method: import_v4.z.string(),
|
|
90
92
|
params: import_v4.z.optional(BaseParamsSchema)
|
|
91
93
|
});
|
|
94
|
+
var ElicitationCapabilitySchema = import_v4.z.object({
|
|
95
|
+
applyDefaults: import_v4.z.optional(import_v4.z.boolean())
|
|
96
|
+
}).loose();
|
|
92
97
|
var ServerCapabilitiesSchema = import_v4.z.looseObject({
|
|
93
98
|
experimental: import_v4.z.optional(import_v4.z.object({}).loose()),
|
|
94
99
|
logging: import_v4.z.optional(import_v4.z.object({}).loose()),
|
|
@@ -107,8 +112,12 @@ var ServerCapabilitiesSchema = import_v4.z.looseObject({
|
|
|
107
112
|
import_v4.z.looseObject({
|
|
108
113
|
listChanged: import_v4.z.optional(import_v4.z.boolean())
|
|
109
114
|
})
|
|
110
|
-
)
|
|
115
|
+
),
|
|
116
|
+
elicitation: import_v4.z.optional(ElicitationCapabilitySchema)
|
|
111
117
|
});
|
|
118
|
+
var ClientCapabilitiesSchema = import_v4.z.object({
|
|
119
|
+
elicitation: import_v4.z.optional(ElicitationCapabilitySchema)
|
|
120
|
+
}).loose();
|
|
112
121
|
var InitializeResultSchema = ResultSchema.extend({
|
|
113
122
|
protocolVersion: import_v4.z.string(),
|
|
114
123
|
capabilities: ServerCapabilitiesSchema,
|
|
@@ -228,6 +237,22 @@ var GetPromptResultSchema = ResultSchema.extend({
|
|
|
228
237
|
description: import_v4.z.optional(import_v4.z.string()),
|
|
229
238
|
messages: import_v4.z.array(PromptMessageSchema)
|
|
230
239
|
});
|
|
240
|
+
var ElicitationRequestParamsSchema = BaseParamsSchema.extend({
|
|
241
|
+
message: import_v4.z.string(),
|
|
242
|
+
requestedSchema: import_v4.z.unknown()
|
|
243
|
+
});
|
|
244
|
+
var ElicitationRequestSchema = RequestSchema.extend({
|
|
245
|
+
method: import_v4.z.literal("elicitation/create"),
|
|
246
|
+
params: ElicitationRequestParamsSchema
|
|
247
|
+
});
|
|
248
|
+
var ElicitResultSchema = ResultSchema.extend({
|
|
249
|
+
action: import_v4.z.union([
|
|
250
|
+
import_v4.z.literal("accept"),
|
|
251
|
+
import_v4.z.literal("decline"),
|
|
252
|
+
import_v4.z.literal("cancel")
|
|
253
|
+
]),
|
|
254
|
+
content: import_v4.z.optional(import_v4.z.record(import_v4.z.string(), import_v4.z.unknown()))
|
|
255
|
+
});
|
|
231
256
|
|
|
232
257
|
// src/tool/json-rpc-message.ts
|
|
233
258
|
var JSONRPC_VERSION = "2.0";
|
|
@@ -1546,13 +1571,15 @@ var DefaultMCPClient = class {
|
|
|
1546
1571
|
constructor({
|
|
1547
1572
|
transport: transportConfig,
|
|
1548
1573
|
name: name3 = "ai-sdk-mcp-client",
|
|
1549
|
-
onUncaughtError
|
|
1574
|
+
onUncaughtError,
|
|
1575
|
+
capabilities
|
|
1550
1576
|
}) {
|
|
1551
1577
|
this.requestMessageId = 0;
|
|
1552
1578
|
this.responseHandlers = /* @__PURE__ */ new Map();
|
|
1553
1579
|
this.serverCapabilities = {};
|
|
1554
1580
|
this.isClosed = true;
|
|
1555
1581
|
this.onUncaughtError = onUncaughtError;
|
|
1582
|
+
this.clientCapabilities = capabilities != null ? capabilities : {};
|
|
1556
1583
|
if (isCustomMcpTransport(transportConfig)) {
|
|
1557
1584
|
this.transport = transportConfig;
|
|
1558
1585
|
} else {
|
|
@@ -1562,11 +1589,15 @@ var DefaultMCPClient = class {
|
|
|
1562
1589
|
this.transport.onerror = (error) => this.onError(error);
|
|
1563
1590
|
this.transport.onmessage = (message) => {
|
|
1564
1591
|
if ("method" in message) {
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1592
|
+
if ("id" in message) {
|
|
1593
|
+
this.onRequestMessage(message);
|
|
1594
|
+
} else {
|
|
1595
|
+
this.onError(
|
|
1596
|
+
new MCPClientError({
|
|
1597
|
+
message: "Unsupported message type"
|
|
1598
|
+
})
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
1570
1601
|
return;
|
|
1571
1602
|
}
|
|
1572
1603
|
this.onResponse(message);
|
|
@@ -1585,7 +1616,7 @@ var DefaultMCPClient = class {
|
|
|
1585
1616
|
method: "initialize",
|
|
1586
1617
|
params: {
|
|
1587
1618
|
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
1588
|
-
capabilities:
|
|
1619
|
+
capabilities: this.clientCapabilities,
|
|
1589
1620
|
clientInfo: this.clientInfo
|
|
1590
1621
|
}
|
|
1591
1622
|
},
|
|
@@ -1885,6 +1916,77 @@ var DefaultMCPClient = class {
|
|
|
1885
1916
|
}) {
|
|
1886
1917
|
return this.getPromptInternal({ name: name3, args, options });
|
|
1887
1918
|
}
|
|
1919
|
+
onElicitationRequest(schema, handler) {
|
|
1920
|
+
if (schema !== ElicitationRequestSchema) {
|
|
1921
|
+
throw new MCPClientError({
|
|
1922
|
+
message: "Unsupported request schema. Only ElicitationRequestSchema is supported."
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
this.elicitationRequestHandler = handler;
|
|
1926
|
+
}
|
|
1927
|
+
async onRequestMessage(request) {
|
|
1928
|
+
try {
|
|
1929
|
+
if (request.method !== "elicitation/create") {
|
|
1930
|
+
await this.transport.send({
|
|
1931
|
+
jsonrpc: "2.0",
|
|
1932
|
+
id: request.id,
|
|
1933
|
+
error: {
|
|
1934
|
+
code: -32601,
|
|
1935
|
+
message: `Unsupported request method: ${request.method}`
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1938
|
+
return;
|
|
1939
|
+
}
|
|
1940
|
+
if (!this.elicitationRequestHandler) {
|
|
1941
|
+
await this.transport.send({
|
|
1942
|
+
jsonrpc: "2.0",
|
|
1943
|
+
id: request.id,
|
|
1944
|
+
error: {
|
|
1945
|
+
code: -32601,
|
|
1946
|
+
message: "No elicitation handler registered on client"
|
|
1947
|
+
}
|
|
1948
|
+
});
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
|
+
const parsedRequest = ElicitationRequestSchema.safeParse({
|
|
1952
|
+
method: request.method,
|
|
1953
|
+
params: request.params
|
|
1954
|
+
});
|
|
1955
|
+
if (!parsedRequest.success) {
|
|
1956
|
+
await this.transport.send({
|
|
1957
|
+
jsonrpc: "2.0",
|
|
1958
|
+
id: request.id,
|
|
1959
|
+
error: {
|
|
1960
|
+
code: -32602,
|
|
1961
|
+
message: `Invalid elicitation request: ${parsedRequest.error.message}`,
|
|
1962
|
+
data: parsedRequest.error.issues
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1967
|
+
try {
|
|
1968
|
+
const result = await this.elicitationRequestHandler(parsedRequest.data);
|
|
1969
|
+
const validatedResult = ElicitResultSchema.parse(result);
|
|
1970
|
+
await this.transport.send({
|
|
1971
|
+
jsonrpc: "2.0",
|
|
1972
|
+
id: request.id,
|
|
1973
|
+
result: validatedResult
|
|
1974
|
+
});
|
|
1975
|
+
} catch (error) {
|
|
1976
|
+
await this.transport.send({
|
|
1977
|
+
jsonrpc: "2.0",
|
|
1978
|
+
id: request.id,
|
|
1979
|
+
error: {
|
|
1980
|
+
code: -32603,
|
|
1981
|
+
message: error instanceof Error ? error.message : "Failed to handle elicitation request"
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
this.onError(error);
|
|
1985
|
+
}
|
|
1986
|
+
} catch (error) {
|
|
1987
|
+
this.onError(error);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1888
1990
|
onClose() {
|
|
1889
1991
|
if (this.isClosed) return;
|
|
1890
1992
|
this.isClosed = true;
|
|
@@ -1924,6 +2026,8 @@ var DefaultMCPClient = class {
|
|
|
1924
2026
|
};
|
|
1925
2027
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1926
2028
|
0 && (module.exports = {
|
|
2029
|
+
ElicitResultSchema,
|
|
2030
|
+
ElicitationRequestSchema,
|
|
1927
2031
|
UnauthorizedError,
|
|
1928
2032
|
auth,
|
|
1929
2033
|
experimental_createMCPClient
|