@ai-sdk/mcp 1.0.18 → 1.0.20

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.20
4
+
5
+ ### Patch Changes
6
+
7
+ - 60ee2df: feat(mcp): expose serializable data from the server tools
8
+
9
+ ## 1.0.19
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [7168375]
14
+ - @ai-sdk/provider@3.0.8
15
+ - @ai-sdk/provider-utils@4.0.14
16
+
3
17
  ## 1.0.18
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -291,6 +291,25 @@ type PaginatedRequest = Request & {
291
291
  cursor?: string;
292
292
  };
293
293
  };
294
+ declare const ListToolsResultSchema: z.ZodObject<{
295
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
296
+ nextCursor: z.ZodOptional<z.ZodString>;
297
+ tools: z.ZodArray<z.ZodObject<{
298
+ name: z.ZodString;
299
+ title: z.ZodOptional<z.ZodString>;
300
+ description: z.ZodOptional<z.ZodString>;
301
+ inputSchema: z.ZodObject<{
302
+ type: z.ZodLiteral<"object">;
303
+ properties: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
304
+ }, z.core.$loose>;
305
+ outputSchema: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
306
+ annotations: z.ZodOptional<z.ZodObject<{
307
+ title: z.ZodOptional<z.ZodString>;
308
+ }, z.core.$loose>>;
309
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
310
+ }, z.core.$loose>>;
311
+ }, z.core.$loose>;
312
+ type ListToolsResult = z.infer<typeof ListToolsResultSchema>;
294
313
  declare const ListResourcesResultSchema: z.ZodObject<{
295
314
  _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
296
315
  nextCursor: z.ZodOptional<z.ZodString>;
@@ -447,6 +466,19 @@ interface MCPClient {
447
466
  tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
448
467
  schemas?: TOOL_SCHEMAS;
449
468
  }): Promise<McpToolSet<TOOL_SCHEMAS>>;
469
+ /**
470
+ * Lists available tools from the MCP server.
471
+ */
472
+ listTools(options?: {
473
+ params?: PaginatedRequest['params'];
474
+ options?: RequestOptions;
475
+ }): Promise<ListToolsResult>;
476
+ /**
477
+ * Creates AI SDK tools from tool definitions.
478
+ */
479
+ toolsFromDefinitions<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(definitions: ListToolsResult, options?: {
480
+ schemas?: TOOL_SCHEMAS;
481
+ }): McpToolSet<TOOL_SCHEMAS>;
450
482
  listResources(options?: {
451
483
  params?: PaginatedRequest['params'];
452
484
  options?: RequestOptions;
@@ -471,4 +503,4 @@ interface MCPClient {
471
503
  close: () => Promise<void>;
472
504
  }
473
505
 
474
- export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, 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 };
506
+ 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 };
package/dist/index.d.ts CHANGED
@@ -291,6 +291,25 @@ type PaginatedRequest = Request & {
291
291
  cursor?: string;
292
292
  };
293
293
  };
294
+ declare const ListToolsResultSchema: z.ZodObject<{
295
+ _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
296
+ nextCursor: z.ZodOptional<z.ZodString>;
297
+ tools: z.ZodArray<z.ZodObject<{
298
+ name: z.ZodString;
299
+ title: z.ZodOptional<z.ZodString>;
300
+ description: z.ZodOptional<z.ZodString>;
301
+ inputSchema: z.ZodObject<{
302
+ type: z.ZodLiteral<"object">;
303
+ properties: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
304
+ }, z.core.$loose>;
305
+ outputSchema: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
306
+ annotations: z.ZodOptional<z.ZodObject<{
307
+ title: z.ZodOptional<z.ZodString>;
308
+ }, z.core.$loose>>;
309
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
310
+ }, z.core.$loose>>;
311
+ }, z.core.$loose>;
312
+ type ListToolsResult = z.infer<typeof ListToolsResultSchema>;
294
313
  declare const ListResourcesResultSchema: z.ZodObject<{
295
314
  _meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
296
315
  nextCursor: z.ZodOptional<z.ZodString>;
@@ -447,6 +466,19 @@ interface MCPClient {
447
466
  tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
448
467
  schemas?: TOOL_SCHEMAS;
449
468
  }): Promise<McpToolSet<TOOL_SCHEMAS>>;
469
+ /**
470
+ * Lists available tools from the MCP server.
471
+ */
472
+ listTools(options?: {
473
+ params?: PaginatedRequest['params'];
474
+ options?: RequestOptions;
475
+ }): Promise<ListToolsResult>;
476
+ /**
477
+ * Creates AI SDK tools from tool definitions.
478
+ */
479
+ toolsFromDefinitions<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(definitions: ListToolsResult, options?: {
480
+ schemas?: TOOL_SCHEMAS;
481
+ }): McpToolSet<TOOL_SCHEMAS>;
450
482
  listResources(options?: {
451
483
  params?: PaginatedRequest['params'];
452
484
  options?: RequestOptions;
@@ -471,4 +503,4 @@ interface MCPClient {
471
503
  close: () => Promise<void>;
472
504
  }
473
505
 
474
- export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, 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 };
506
+ 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 };
package/dist/index.js CHANGED
@@ -1791,15 +1791,11 @@ var DefaultMCPClient = class {
1791
1791
  params,
1792
1792
  options
1793
1793
  } = {}) {
1794
- try {
1795
- return this.request({
1796
- request: { method: "tools/list", params },
1797
- resultSchema: ListToolsResultSchema,
1798
- options
1799
- });
1800
- } catch (error) {
1801
- throw error;
1802
- }
1794
+ return this.request({
1795
+ request: { method: "tools/list", params },
1796
+ resultSchema: ListToolsResultSchema,
1797
+ options
1798
+ });
1803
1799
  }
1804
1800
  async callTool({
1805
1801
  name: name3,
@@ -1896,63 +1892,68 @@ var DefaultMCPClient = class {
1896
1892
  await this.transport.send(jsonrpcNotification);
1897
1893
  }
1898
1894
  /**
1899
- * Returns a set of AI SDK tools from the MCP server
1895
+ * Returns a set of AI SDK tools from the MCP server.
1896
+ * This fetches tool definitions and wraps them with execute functions.
1900
1897
  * @returns A record of tool names to their implementations
1901
1898
  */
1902
1899
  async tools({
1903
1900
  schemas = "automatic"
1904
1901
  } = {}) {
1902
+ const definitions = await this.listTools();
1903
+ return this.toolsFromDefinitions(definitions, {
1904
+ schemas
1905
+ });
1906
+ }
1907
+ /**
1908
+ * Creates AI SDK tools from tool definitions without fetching from the server.
1909
+ */
1910
+ toolsFromDefinitions(definitions, { schemas = "automatic" } = {}) {
1905
1911
  var _a3, _b3;
1906
1912
  const tools = {};
1907
- try {
1908
- const listToolsResult = await this.listTools();
1909
- for (const {
1910
- name: name3,
1911
- title,
1912
- description,
1913
- inputSchema,
1914
- annotations,
1915
- _meta
1916
- } of listToolsResult.tools) {
1917
- const resolvedTitle = title != null ? title : annotations == null ? void 0 : annotations.title;
1918
- if (schemas !== "automatic" && !(name3 in schemas)) {
1919
- continue;
1920
- }
1921
- const self = this;
1922
- const outputSchema = schemas !== "automatic" ? (_a3 = schemas[name3]) == null ? void 0 : _a3.outputSchema : void 0;
1923
- const execute = async (args, options) => {
1924
- var _a4;
1925
- (_a4 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a4.throwIfAborted();
1926
- const result = await self.callTool({ name: name3, args, options });
1927
- if (outputSchema != null) {
1928
- return self.extractStructuredContent(result, outputSchema, name3);
1929
- }
1930
- return result;
1931
- };
1932
- const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils3.dynamicTool)({
1933
- description,
1934
- title: resolvedTitle,
1935
- inputSchema: (0, import_provider_utils3.jsonSchema)({
1936
- ...inputSchema,
1937
- properties: (_b3 = inputSchema.properties) != null ? _b3 : {},
1938
- additionalProperties: false
1939
- }),
1940
- execute,
1941
- toModelOutput: mcpToModelOutput
1942
- }) : (0, import_provider_utils3.tool)({
1943
- description,
1944
- title: resolvedTitle,
1945
- inputSchema: schemas[name3].inputSchema,
1946
- ...outputSchema != null ? { outputSchema } : {},
1947
- execute,
1948
- toModelOutput: mcpToModelOutput
1949
- });
1950
- tools[name3] = { ...toolWithExecute, _meta };
1913
+ for (const {
1914
+ name: name3,
1915
+ title,
1916
+ description,
1917
+ inputSchema,
1918
+ annotations,
1919
+ _meta
1920
+ } of definitions.tools) {
1921
+ const resolvedTitle = title != null ? title : annotations == null ? void 0 : annotations.title;
1922
+ if (schemas !== "automatic" && !(name3 in schemas)) {
1923
+ continue;
1951
1924
  }
1952
- return tools;
1953
- } catch (error) {
1954
- throw error;
1925
+ const self = this;
1926
+ const outputSchema = schemas !== "automatic" ? (_a3 = schemas[name3]) == null ? void 0 : _a3.outputSchema : void 0;
1927
+ const execute = async (args, options) => {
1928
+ var _a4;
1929
+ (_a4 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a4.throwIfAborted();
1930
+ const result = await self.callTool({ name: name3, args, options });
1931
+ if (outputSchema != null) {
1932
+ return self.extractStructuredContent(result, outputSchema, name3);
1933
+ }
1934
+ return result;
1935
+ };
1936
+ const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils3.dynamicTool)({
1937
+ description,
1938
+ title: resolvedTitle,
1939
+ inputSchema: (0, import_provider_utils3.jsonSchema)({
1940
+ ...inputSchema,
1941
+ properties: (_b3 = inputSchema.properties) != null ? _b3 : {},
1942
+ additionalProperties: false
1943
+ }),
1944
+ execute,
1945
+ toModelOutput: mcpToModelOutput
1946
+ }) : (0, import_provider_utils3.tool)({
1947
+ description,
1948
+ title: resolvedTitle,
1949
+ inputSchema: schemas[name3].inputSchema,
1950
+ ...outputSchema != null ? { outputSchema } : {},
1951
+ execute,
1952
+ toModelOutput: mcpToModelOutput
1953
+ });
1954
+ tools[name3] = { ...toolWithExecute, _meta };
1955
1955
  }
1956
+ return tools;
1956
1957
  }
1957
1958
  /**
1958
1959
  * Extracts and validates structuredContent from a tool result.