@ai-sdk/mcp 1.0.0-beta.2 → 1.0.0-beta.4

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,19 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 1.0.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a755db5]
8
+ - @ai-sdk/provider@3.0.0-beta.9
9
+ - @ai-sdk/provider-utils@4.0.0-beta.23
10
+
11
+ ## 1.0.0-beta.3
12
+
13
+ ### Patch Changes
14
+
15
+ - 5939b92: feat(mcp): adding resources support to MCP client
16
+
3
17
  ## 1.0.0-beta.2
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -254,6 +254,40 @@ type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS e
254
254
  } : McpToolSet<Record<string, {
255
255
  inputSchema: FlexibleSchema<unknown>;
256
256
  }>>;
257
+ declare const BaseParamsSchema: z.ZodObject<{
258
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
259
+ }, z.core.$loose>;
260
+ type BaseParams = z.infer<typeof BaseParamsSchema>;
261
+ declare const RequestSchema: z.ZodObject<{
262
+ method: z.ZodString;
263
+ params: z.ZodOptional<z.ZodObject<{
264
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
265
+ }, z.core.$loose>>;
266
+ }, z.core.$strip>;
267
+ type Request = z.infer<typeof RequestSchema>;
268
+ type RequestOptions = {
269
+ signal?: AbortSignal;
270
+ timeout?: number;
271
+ maxTotalTimeout?: number;
272
+ };
273
+ type PaginatedRequest = Request & {
274
+ params?: BaseParams & {
275
+ cursor?: string;
276
+ };
277
+ };
278
+ declare const ListResourcesResultSchema: z.ZodObject<{
279
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
280
+ nextCursor: z.ZodOptional<z.ZodString>;
281
+ resources: z.ZodArray<z.ZodObject<{
282
+ uri: z.ZodString;
283
+ name: z.ZodString;
284
+ title: z.ZodOptional<z.ZodString>;
285
+ description: z.ZodOptional<z.ZodString>;
286
+ mimeType: z.ZodOptional<z.ZodString>;
287
+ size: z.ZodOptional<z.ZodNumber>;
288
+ }, z.core.$loose>>;
289
+ }, z.core.$loose>;
290
+ type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>;
257
291
  declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
258
292
  _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
259
293
  content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
@@ -267,10 +301,14 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
267
301
  type: z.ZodLiteral<"resource">;
268
302
  resource: z.ZodUnion<readonly [z.ZodObject<{
269
303
  uri: z.ZodString;
304
+ name: z.ZodOptional<z.ZodString>;
305
+ title: z.ZodOptional<z.ZodString>;
270
306
  mimeType: z.ZodOptional<z.ZodString>;
271
307
  text: z.ZodString;
272
308
  }, z.core.$loose>, z.ZodObject<{
273
309
  uri: z.ZodString;
310
+ name: z.ZodOptional<z.ZodString>;
311
+ title: z.ZodOptional<z.ZodString>;
274
312
  mimeType: z.ZodOptional<z.ZodString>;
275
313
  blob: z.ZodBase64;
276
314
  }, z.core.$loose>]>;
@@ -281,6 +319,34 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
281
319
  toolResult: z.ZodUnknown;
282
320
  }, z.core.$loose>]>;
283
321
  type CallToolResult = z.infer<typeof CallToolResultSchema>;
322
+ declare const ListResourceTemplatesResultSchema: z.ZodObject<{
323
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
324
+ resourceTemplates: z.ZodArray<z.ZodObject<{
325
+ uriTemplate: z.ZodString;
326
+ name: z.ZodString;
327
+ title: z.ZodOptional<z.ZodString>;
328
+ description: z.ZodOptional<z.ZodString>;
329
+ mimeType: z.ZodOptional<z.ZodString>;
330
+ }, z.core.$loose>>;
331
+ }, z.core.$loose>;
332
+ type ListResourceTemplatesResult = z.infer<typeof ListResourceTemplatesResultSchema>;
333
+ declare const ReadResourceResultSchema: z.ZodObject<{
334
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
335
+ contents: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
336
+ uri: z.ZodString;
337
+ name: z.ZodOptional<z.ZodString>;
338
+ title: z.ZodOptional<z.ZodString>;
339
+ mimeType: z.ZodOptional<z.ZodString>;
340
+ text: z.ZodString;
341
+ }, z.core.$loose>, z.ZodObject<{
342
+ uri: z.ZodString;
343
+ name: z.ZodOptional<z.ZodString>;
344
+ title: z.ZodOptional<z.ZodString>;
345
+ mimeType: z.ZodOptional<z.ZodString>;
346
+ blob: z.ZodBase64;
347
+ }, z.core.$loose>]>>;
348
+ }, z.core.$loose>;
349
+ type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>;
284
350
 
285
351
  interface MCPClientConfig {
286
352
  /** Transport configuration for connecting to the MCP server */
@@ -295,6 +361,17 @@ interface MCPClient {
295
361
  tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
296
362
  schemas?: TOOL_SCHEMAS;
297
363
  }): Promise<McpToolSet<TOOL_SCHEMAS>>;
364
+ listResources(options?: {
365
+ params?: PaginatedRequest['params'];
366
+ options?: RequestOptions;
367
+ }): Promise<ListResourcesResult>;
368
+ readResource(args: {
369
+ uri: string;
370
+ options?: RequestOptions;
371
+ }): Promise<ReadResourceResult>;
372
+ listResourceTemplates(options?: {
373
+ options?: RequestOptions;
374
+ }): Promise<ListResourceTemplatesResult>;
298
375
  close: () => Promise<void>;
299
376
  }
300
377
 
package/dist/index.d.ts CHANGED
@@ -254,6 +254,40 @@ type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS e
254
254
  } : McpToolSet<Record<string, {
255
255
  inputSchema: FlexibleSchema<unknown>;
256
256
  }>>;
257
+ declare const BaseParamsSchema: z.ZodObject<{
258
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
259
+ }, z.core.$loose>;
260
+ type BaseParams = z.infer<typeof BaseParamsSchema>;
261
+ declare const RequestSchema: z.ZodObject<{
262
+ method: z.ZodString;
263
+ params: z.ZodOptional<z.ZodObject<{
264
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
265
+ }, z.core.$loose>>;
266
+ }, z.core.$strip>;
267
+ type Request = z.infer<typeof RequestSchema>;
268
+ type RequestOptions = {
269
+ signal?: AbortSignal;
270
+ timeout?: number;
271
+ maxTotalTimeout?: number;
272
+ };
273
+ type PaginatedRequest = Request & {
274
+ params?: BaseParams & {
275
+ cursor?: string;
276
+ };
277
+ };
278
+ declare const ListResourcesResultSchema: z.ZodObject<{
279
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
280
+ nextCursor: z.ZodOptional<z.ZodString>;
281
+ resources: z.ZodArray<z.ZodObject<{
282
+ uri: z.ZodString;
283
+ name: z.ZodString;
284
+ title: z.ZodOptional<z.ZodString>;
285
+ description: z.ZodOptional<z.ZodString>;
286
+ mimeType: z.ZodOptional<z.ZodString>;
287
+ size: z.ZodOptional<z.ZodNumber>;
288
+ }, z.core.$loose>>;
289
+ }, z.core.$loose>;
290
+ type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>;
257
291
  declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
258
292
  _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
259
293
  content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
@@ -267,10 +301,14 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
267
301
  type: z.ZodLiteral<"resource">;
268
302
  resource: z.ZodUnion<readonly [z.ZodObject<{
269
303
  uri: z.ZodString;
304
+ name: z.ZodOptional<z.ZodString>;
305
+ title: z.ZodOptional<z.ZodString>;
270
306
  mimeType: z.ZodOptional<z.ZodString>;
271
307
  text: z.ZodString;
272
308
  }, z.core.$loose>, z.ZodObject<{
273
309
  uri: z.ZodString;
310
+ name: z.ZodOptional<z.ZodString>;
311
+ title: z.ZodOptional<z.ZodString>;
274
312
  mimeType: z.ZodOptional<z.ZodString>;
275
313
  blob: z.ZodBase64;
276
314
  }, z.core.$loose>]>;
@@ -281,6 +319,34 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
281
319
  toolResult: z.ZodUnknown;
282
320
  }, z.core.$loose>]>;
283
321
  type CallToolResult = z.infer<typeof CallToolResultSchema>;
322
+ declare const ListResourceTemplatesResultSchema: z.ZodObject<{
323
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
324
+ resourceTemplates: z.ZodArray<z.ZodObject<{
325
+ uriTemplate: z.ZodString;
326
+ name: z.ZodString;
327
+ title: z.ZodOptional<z.ZodString>;
328
+ description: z.ZodOptional<z.ZodString>;
329
+ mimeType: z.ZodOptional<z.ZodString>;
330
+ }, z.core.$loose>>;
331
+ }, z.core.$loose>;
332
+ type ListResourceTemplatesResult = z.infer<typeof ListResourceTemplatesResultSchema>;
333
+ declare const ReadResourceResultSchema: z.ZodObject<{
334
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
335
+ contents: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
336
+ uri: z.ZodString;
337
+ name: z.ZodOptional<z.ZodString>;
338
+ title: z.ZodOptional<z.ZodString>;
339
+ mimeType: z.ZodOptional<z.ZodString>;
340
+ text: z.ZodString;
341
+ }, z.core.$loose>, z.ZodObject<{
342
+ uri: z.ZodString;
343
+ name: z.ZodOptional<z.ZodString>;
344
+ title: z.ZodOptional<z.ZodString>;
345
+ mimeType: z.ZodOptional<z.ZodString>;
346
+ blob: z.ZodBase64;
347
+ }, z.core.$loose>]>>;
348
+ }, z.core.$loose>;
349
+ type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>;
284
350
 
285
351
  interface MCPClientConfig {
286
352
  /** Transport configuration for connecting to the MCP server */
@@ -295,6 +361,17 @@ interface MCPClient {
295
361
  tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
296
362
  schemas?: TOOL_SCHEMAS;
297
363
  }): Promise<McpToolSet<TOOL_SCHEMAS>>;
364
+ listResources(options?: {
365
+ params?: PaginatedRequest['params'];
366
+ options?: RequestOptions;
367
+ }): Promise<ListResourcesResult>;
368
+ readResource(args: {
369
+ uri: string;
370
+ options?: RequestOptions;
371
+ }): Promise<ReadResourceResult>;
372
+ listResourceTemplates(options?: {
373
+ options?: RequestOptions;
374
+ }): Promise<ListResourceTemplatesResult>;
298
375
  close: () => Promise<void>;
299
376
  }
300
377
 
package/dist/index.js CHANGED
@@ -143,11 +143,30 @@ var ImageContentSchema = import_v4.z.object({
143
143
  data: import_v4.z.base64(),
144
144
  mimeType: import_v4.z.string()
145
145
  }).loose();
146
+ var ResourceSchema = import_v4.z.object({
147
+ uri: import_v4.z.string(),
148
+ name: import_v4.z.string(),
149
+ title: import_v4.z.optional(import_v4.z.string()),
150
+ description: import_v4.z.optional(import_v4.z.string()),
151
+ mimeType: import_v4.z.optional(import_v4.z.string()),
152
+ size: import_v4.z.optional(import_v4.z.number())
153
+ }).loose();
154
+ var ListResourcesResultSchema = PaginatedResultSchema.extend({
155
+ resources: import_v4.z.array(ResourceSchema)
156
+ });
146
157
  var ResourceContentsSchema = import_v4.z.object({
147
158
  /**
148
159
  * The URI of this resource.
149
160
  */
150
161
  uri: import_v4.z.string(),
162
+ /**
163
+ * Optional display name of the resource content.
164
+ */
165
+ name: import_v4.z.optional(import_v4.z.string()),
166
+ /**
167
+ * Optional human readable title.
168
+ */
169
+ title: import_v4.z.optional(import_v4.z.string()),
151
170
  /**
152
171
  * The MIME type of this resource, if known.
153
172
  */
@@ -173,6 +192,21 @@ var CallToolResultSchema = ResultSchema.extend({
173
192
  toolResult: import_v4.z.unknown()
174
193
  })
175
194
  );
195
+ var ResourceTemplateSchema = import_v4.z.object({
196
+ uriTemplate: import_v4.z.string(),
197
+ name: import_v4.z.string(),
198
+ title: import_v4.z.optional(import_v4.z.string()),
199
+ description: import_v4.z.optional(import_v4.z.string()),
200
+ mimeType: import_v4.z.optional(import_v4.z.string())
201
+ }).loose();
202
+ var ListResourceTemplatesResultSchema = ResultSchema.extend({
203
+ resourceTemplates: import_v4.z.array(ResourceTemplateSchema)
204
+ });
205
+ var ReadResourceResultSchema = ResultSchema.extend({
206
+ contents: import_v4.z.array(
207
+ import_v4.z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
208
+ )
209
+ });
176
210
 
177
211
  // src/tool/json-rpc-message.ts
178
212
  var JSONRPC_VERSION = "2.0";
@@ -1574,6 +1608,15 @@ var DefaultMCPClient = class {
1574
1608
  });
1575
1609
  }
1576
1610
  break;
1611
+ case "resources/list":
1612
+ case "resources/read":
1613
+ case "resources/templates/list":
1614
+ if (!this.serverCapabilities.resources) {
1615
+ throw new MCPClientError({
1616
+ message: `Server does not support resources`
1617
+ });
1618
+ }
1619
+ break;
1577
1620
  default:
1578
1621
  throw new MCPClientError({
1579
1622
  message: `Unsupported method: ${method}`
@@ -1665,6 +1708,47 @@ var DefaultMCPClient = class {
1665
1708
  throw error;
1666
1709
  }
1667
1710
  }
1711
+ async listResourcesInternal({
1712
+ params,
1713
+ options
1714
+ } = {}) {
1715
+ try {
1716
+ return this.request({
1717
+ request: { method: "resources/list", params },
1718
+ resultSchema: ListResourcesResultSchema,
1719
+ options
1720
+ });
1721
+ } catch (error) {
1722
+ throw error;
1723
+ }
1724
+ }
1725
+ async readResourceInternal({
1726
+ uri,
1727
+ options
1728
+ }) {
1729
+ try {
1730
+ return this.request({
1731
+ request: { method: "resources/read", params: { uri } },
1732
+ resultSchema: ReadResourceResultSchema,
1733
+ options
1734
+ });
1735
+ } catch (error) {
1736
+ throw error;
1737
+ }
1738
+ }
1739
+ async listResourceTemplatesInternal({
1740
+ options
1741
+ } = {}) {
1742
+ try {
1743
+ return this.request({
1744
+ request: { method: "resources/templates/list" },
1745
+ resultSchema: ListResourceTemplatesResultSchema,
1746
+ options
1747
+ });
1748
+ } catch (error) {
1749
+ throw error;
1750
+ }
1751
+ }
1668
1752
  async notification(notification) {
1669
1753
  const jsonrpcNotification = {
1670
1754
  ...notification,
@@ -1721,6 +1805,23 @@ var DefaultMCPClient = class {
1721
1805
  throw error;
1722
1806
  }
1723
1807
  }
1808
+ listResources({
1809
+ params,
1810
+ options
1811
+ } = {}) {
1812
+ return this.listResourcesInternal({ params, options });
1813
+ }
1814
+ readResource({
1815
+ uri,
1816
+ options
1817
+ }) {
1818
+ return this.readResourceInternal({ uri, options });
1819
+ }
1820
+ listResourceTemplates({
1821
+ options
1822
+ } = {}) {
1823
+ return this.listResourceTemplatesInternal({ options });
1824
+ }
1724
1825
  onClose() {
1725
1826
  if (this.isClosed) return;
1726
1827
  this.isClosed = true;