@ai-sdk/mcp 2.0.2 → 2.0.3

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 2.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 68a739a: feat(mcp): allow MCP client to use server completions
8
+ - Updated dependencies [6a436e3]
9
+ - @ai-sdk/provider-utils@5.0.1
10
+
3
11
  ## 2.0.2
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -374,6 +374,7 @@ declare const InitializeResultSchema: z.ZodObject<{
374
374
  capabilities: z.ZodObject<{
375
375
  experimental: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
376
376
  logging: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
377
+ completions: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
377
378
  prompts: z.ZodOptional<z.ZodObject<{
378
379
  listChanged: z.ZodOptional<z.ZodBoolean>;
379
380
  }, z.core.$loose>>;
@@ -499,6 +500,33 @@ declare const ReadResourceResultSchema: z.ZodObject<{
499
500
  }, z.core.$loose>]>>;
500
501
  }, z.core.$loose>;
501
502
  type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>;
503
+ declare const CompleteRequestParamsSchema: z.ZodObject<{
504
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
505
+ ref: z.ZodUnion<readonly [z.ZodObject<{
506
+ type: z.ZodLiteral<"ref/prompt">;
507
+ name: z.ZodString;
508
+ }, z.core.$loose>, z.ZodObject<{
509
+ type: z.ZodLiteral<"ref/resource">;
510
+ uri: z.ZodString;
511
+ }, z.core.$loose>]>;
512
+ argument: z.ZodObject<{
513
+ name: z.ZodString;
514
+ value: z.ZodString;
515
+ }, z.core.$loose>;
516
+ context: z.ZodOptional<z.ZodObject<{
517
+ arguments: z.ZodRecord<z.ZodString, z.ZodString>;
518
+ }, z.core.$loose>>;
519
+ }, z.core.$loose>;
520
+ type CompleteRequestParams = z.infer<typeof CompleteRequestParamsSchema>;
521
+ declare const CompleteResultSchema: z.ZodObject<{
522
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
523
+ completion: z.ZodObject<{
524
+ values: z.ZodArray<z.ZodString>;
525
+ total: z.ZodOptional<z.ZodNumber>;
526
+ hasMore: z.ZodOptional<z.ZodBoolean>;
527
+ }, z.core.$loose>;
528
+ }, z.core.$loose>;
529
+ type CompleteResult = z.infer<typeof CompleteResultSchema>;
502
530
  declare const ListPromptsResultSchema: z.ZodObject<{
503
531
  _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
504
532
  nextCursor: z.ZodOptional<z.ZodString>;
@@ -660,6 +688,9 @@ interface MCPClient {
660
688
  arguments?: Record<string, unknown>;
661
689
  options?: RequestOptions;
662
690
  }): Promise<GetPromptResult>;
691
+ complete(args: CompleteRequestParams & {
692
+ options?: RequestOptions;
693
+ }): Promise<CompleteResult>;
663
694
  onElicitationRequest(schema: typeof ElicitationRequestSchema, handler: (request: ElicitationRequest) => Promise<ElicitResult> | ElicitResult): void;
664
695
  close: () => Promise<void>;
665
696
  }
@@ -721,4 +752,4 @@ declare function readMCPAppResource({ client, uri, options, }: {
721
752
  options?: RequestOptions;
722
753
  }): Promise<MCPAppResource>;
723
754
 
724
- export { type CallToolResult, type Configuration, type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type InitializeResult, 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 };
755
+ export { type CallToolResult, type CompleteRequestParams, type CompleteResult, type Configuration, type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type InitializeResult, 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 };
package/dist/index.js CHANGED
@@ -78,6 +78,7 @@ var ElicitationCapabilitySchema = z.object({
78
78
  var ServerCapabilitiesSchema = z.looseObject({
79
79
  experimental: z.optional(z.object({}).loose()),
80
80
  logging: z.optional(z.object({}).loose()),
81
+ completions: z.optional(z.object({}).loose()),
81
82
  prompts: z.optional(
82
83
  z.looseObject({
83
84
  listChanged: z.optional(z.boolean())
@@ -222,6 +223,34 @@ var ReadResourceResultSchema = ResultSchema.extend({
222
223
  z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
223
224
  )
224
225
  });
226
+ var PromptReferenceSchema = z.object({
227
+ type: z.literal("ref/prompt"),
228
+ name: z.string()
229
+ }).loose();
230
+ var ResourceReferenceSchema = z.object({
231
+ type: z.literal("ref/resource"),
232
+ uri: z.string()
233
+ }).loose();
234
+ var CompletionArgumentSchema = z.object({
235
+ name: z.string(),
236
+ value: z.string()
237
+ }).loose();
238
+ var CompleteRequestParamsSchema = BaseParamsSchema.extend({
239
+ ref: z.union([PromptReferenceSchema, ResourceReferenceSchema]),
240
+ argument: CompletionArgumentSchema,
241
+ context: z.optional(
242
+ z.object({
243
+ arguments: z.record(z.string(), z.string())
244
+ }).loose()
245
+ )
246
+ });
247
+ var CompleteResultSchema = ResultSchema.extend({
248
+ completion: z.object({
249
+ values: z.array(z.string()).max(100),
250
+ total: z.optional(z.number().int()),
251
+ hasMore: z.optional(z.boolean())
252
+ }).loose()
253
+ });
225
254
  var PromptArgumentSchema = z.object({
226
255
  name: z.string(),
227
256
  description: z.optional(z.string()),
@@ -2164,6 +2193,13 @@ var DefaultMCPClient = class {
2164
2193
  switch (method) {
2165
2194
  case "initialize":
2166
2195
  break;
2196
+ case "completion/complete":
2197
+ if (!this.serverCapabilities.completions) {
2198
+ throw new MCPClientError({
2199
+ message: `Server does not support completions`
2200
+ });
2201
+ }
2202
+ break;
2167
2203
  case "tools/list":
2168
2204
  case "tools/call":
2169
2205
  if (!this.serverCapabilities.tools) {
@@ -2344,6 +2380,16 @@ var DefaultMCPClient = class {
2344
2380
  throw error;
2345
2381
  }
2346
2382
  }
2383
+ async completeInternal({
2384
+ options,
2385
+ ...params
2386
+ }) {
2387
+ return this.request({
2388
+ request: { method: "completion/complete", params },
2389
+ resultSchema: CompleteResultSchema,
2390
+ options
2391
+ });
2392
+ }
2347
2393
  async notification(notification) {
2348
2394
  const jsonrpcNotification = {
2349
2395
  ...notification,
@@ -2503,6 +2549,9 @@ var DefaultMCPClient = class {
2503
2549
  }) {
2504
2550
  return this.getPromptInternal({ name: name3, args, options });
2505
2551
  }
2552
+ complete(args) {
2553
+ return this.completeInternal(args);
2554
+ }
2506
2555
  onElicitationRequest(schema, handler) {
2507
2556
  if (schema !== ElicitationRequestSchema) {
2508
2557
  throw new MCPClientError({