@ai-sdk/mcp 0.0.1 → 0.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,18 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - f796ddc: feat(mcp): adding resources support to MCP client
8
+
9
+ ## 0.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [1e05490]
14
+ - @ai-sdk/provider-utils@3.0.13
15
+
3
16
  ## 0.0.1
4
17
 
5
18
  ### 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
@@ -138,11 +138,30 @@ var ImageContentSchema = import_v4.z.object({
138
138
  data: import_v4.z.base64(),
139
139
  mimeType: import_v4.z.string()
140
140
  }).loose();
141
+ var ResourceSchema = import_v4.z.object({
142
+ uri: import_v4.z.string(),
143
+ name: import_v4.z.string(),
144
+ title: import_v4.z.optional(import_v4.z.string()),
145
+ description: import_v4.z.optional(import_v4.z.string()),
146
+ mimeType: import_v4.z.optional(import_v4.z.string()),
147
+ size: import_v4.z.optional(import_v4.z.number())
148
+ }).loose();
149
+ var ListResourcesResultSchema = PaginatedResultSchema.extend({
150
+ resources: import_v4.z.array(ResourceSchema)
151
+ });
141
152
  var ResourceContentsSchema = import_v4.z.object({
142
153
  /**
143
154
  * The URI of this resource.
144
155
  */
145
156
  uri: import_v4.z.string(),
157
+ /**
158
+ * Optional display name of the resource content.
159
+ */
160
+ name: import_v4.z.optional(import_v4.z.string()),
161
+ /**
162
+ * Optional human readable title.
163
+ */
164
+ title: import_v4.z.optional(import_v4.z.string()),
146
165
  /**
147
166
  * The MIME type of this resource, if known.
148
167
  */
@@ -168,6 +187,21 @@ var CallToolResultSchema = ResultSchema.extend({
168
187
  toolResult: import_v4.z.unknown()
169
188
  })
170
189
  );
190
+ var ResourceTemplateSchema = import_v4.z.object({
191
+ uriTemplate: import_v4.z.string(),
192
+ name: import_v4.z.string(),
193
+ title: import_v4.z.optional(import_v4.z.string()),
194
+ description: import_v4.z.optional(import_v4.z.string()),
195
+ mimeType: import_v4.z.optional(import_v4.z.string())
196
+ }).loose();
197
+ var ListResourceTemplatesResultSchema = ResultSchema.extend({
198
+ resourceTemplates: import_v4.z.array(ResourceTemplateSchema)
199
+ });
200
+ var ReadResourceResultSchema = ResultSchema.extend({
201
+ contents: import_v4.z.array(
202
+ import_v4.z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
203
+ )
204
+ });
171
205
 
172
206
  // src/tool/json-rpc-message.ts
173
207
  var JSONRPC_VERSION = "2.0";
@@ -1569,6 +1603,15 @@ var DefaultMCPClient = class {
1569
1603
  });
1570
1604
  }
1571
1605
  break;
1606
+ case "resources/list":
1607
+ case "resources/read":
1608
+ case "resources/templates/list":
1609
+ if (!this.serverCapabilities.resources) {
1610
+ throw new MCPClientError({
1611
+ message: `Server does not support resources`
1612
+ });
1613
+ }
1614
+ break;
1572
1615
  default:
1573
1616
  throw new MCPClientError({
1574
1617
  message: `Unsupported method: ${method}`
@@ -1660,6 +1703,47 @@ var DefaultMCPClient = class {
1660
1703
  throw error;
1661
1704
  }
1662
1705
  }
1706
+ async listResourcesInternal({
1707
+ params,
1708
+ options
1709
+ } = {}) {
1710
+ try {
1711
+ return this.request({
1712
+ request: { method: "resources/list", params },
1713
+ resultSchema: ListResourcesResultSchema,
1714
+ options
1715
+ });
1716
+ } catch (error) {
1717
+ throw error;
1718
+ }
1719
+ }
1720
+ async readResourceInternal({
1721
+ uri,
1722
+ options
1723
+ }) {
1724
+ try {
1725
+ return this.request({
1726
+ request: { method: "resources/read", params: { uri } },
1727
+ resultSchema: ReadResourceResultSchema,
1728
+ options
1729
+ });
1730
+ } catch (error) {
1731
+ throw error;
1732
+ }
1733
+ }
1734
+ async listResourceTemplatesInternal({
1735
+ options
1736
+ } = {}) {
1737
+ try {
1738
+ return this.request({
1739
+ request: { method: "resources/templates/list" },
1740
+ resultSchema: ListResourceTemplatesResultSchema,
1741
+ options
1742
+ });
1743
+ } catch (error) {
1744
+ throw error;
1745
+ }
1746
+ }
1663
1747
  async notification(notification) {
1664
1748
  const jsonrpcNotification = {
1665
1749
  ...notification,
@@ -1708,6 +1792,23 @@ var DefaultMCPClient = class {
1708
1792
  throw error;
1709
1793
  }
1710
1794
  }
1795
+ listResources({
1796
+ params,
1797
+ options
1798
+ } = {}) {
1799
+ return this.listResourcesInternal({ params, options });
1800
+ }
1801
+ readResource({
1802
+ uri,
1803
+ options
1804
+ }) {
1805
+ return this.readResourceInternal({ uri, options });
1806
+ }
1807
+ listResourceTemplates({
1808
+ options
1809
+ } = {}) {
1810
+ return this.listResourceTemplatesInternal({ options });
1811
+ }
1711
1812
  onClose() {
1712
1813
  if (this.isClosed) return;
1713
1814
  this.isClosed = true;