@ai-sdk/mcp 1.0.19 → 1.0.21

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/dist/index.mjs CHANGED
@@ -1765,15 +1765,11 @@ var DefaultMCPClient = class {
1765
1765
  params,
1766
1766
  options
1767
1767
  } = {}) {
1768
- try {
1769
- return this.request({
1770
- request: { method: "tools/list", params },
1771
- resultSchema: ListToolsResultSchema,
1772
- options
1773
- });
1774
- } catch (error) {
1775
- throw error;
1776
- }
1768
+ return this.request({
1769
+ request: { method: "tools/list", params },
1770
+ resultSchema: ListToolsResultSchema,
1771
+ options
1772
+ });
1777
1773
  }
1778
1774
  async callTool({
1779
1775
  name: name3,
@@ -1870,63 +1866,68 @@ var DefaultMCPClient = class {
1870
1866
  await this.transport.send(jsonrpcNotification);
1871
1867
  }
1872
1868
  /**
1873
- * Returns a set of AI SDK tools from the MCP server
1869
+ * Returns a set of AI SDK tools from the MCP server.
1870
+ * This fetches tool definitions and wraps them with execute functions.
1874
1871
  * @returns A record of tool names to their implementations
1875
1872
  */
1876
1873
  async tools({
1877
1874
  schemas = "automatic"
1878
1875
  } = {}) {
1876
+ const definitions = await this.listTools();
1877
+ return this.toolsFromDefinitions(definitions, {
1878
+ schemas
1879
+ });
1880
+ }
1881
+ /**
1882
+ * Creates AI SDK tools from tool definitions without fetching from the server.
1883
+ */
1884
+ toolsFromDefinitions(definitions, { schemas = "automatic" } = {}) {
1879
1885
  var _a3, _b3;
1880
1886
  const tools = {};
1881
- try {
1882
- const listToolsResult = await this.listTools();
1883
- for (const {
1884
- name: name3,
1885
- title,
1886
- description,
1887
- inputSchema,
1888
- annotations,
1889
- _meta
1890
- } of listToolsResult.tools) {
1891
- const resolvedTitle = title != null ? title : annotations == null ? void 0 : annotations.title;
1892
- if (schemas !== "automatic" && !(name3 in schemas)) {
1893
- continue;
1894
- }
1895
- const self = this;
1896
- const outputSchema = schemas !== "automatic" ? (_a3 = schemas[name3]) == null ? void 0 : _a3.outputSchema : void 0;
1897
- const execute = async (args, options) => {
1898
- var _a4;
1899
- (_a4 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a4.throwIfAborted();
1900
- const result = await self.callTool({ name: name3, args, options });
1901
- if (outputSchema != null) {
1902
- return self.extractStructuredContent(result, outputSchema, name3);
1903
- }
1904
- return result;
1905
- };
1906
- const toolWithExecute = schemas === "automatic" ? dynamicTool({
1907
- description,
1908
- title: resolvedTitle,
1909
- inputSchema: jsonSchema({
1910
- ...inputSchema,
1911
- properties: (_b3 = inputSchema.properties) != null ? _b3 : {},
1912
- additionalProperties: false
1913
- }),
1914
- execute,
1915
- toModelOutput: mcpToModelOutput
1916
- }) : tool({
1917
- description,
1918
- title: resolvedTitle,
1919
- inputSchema: schemas[name3].inputSchema,
1920
- ...outputSchema != null ? { outputSchema } : {},
1921
- execute,
1922
- toModelOutput: mcpToModelOutput
1923
- });
1924
- tools[name3] = { ...toolWithExecute, _meta };
1887
+ for (const {
1888
+ name: name3,
1889
+ title,
1890
+ description,
1891
+ inputSchema,
1892
+ annotations,
1893
+ _meta
1894
+ } of definitions.tools) {
1895
+ const resolvedTitle = title != null ? title : annotations == null ? void 0 : annotations.title;
1896
+ if (schemas !== "automatic" && !(name3 in schemas)) {
1897
+ continue;
1925
1898
  }
1926
- return tools;
1927
- } catch (error) {
1928
- throw error;
1899
+ const self = this;
1900
+ const outputSchema = schemas !== "automatic" ? (_a3 = schemas[name3]) == null ? void 0 : _a3.outputSchema : void 0;
1901
+ const execute = async (args, options) => {
1902
+ var _a4;
1903
+ (_a4 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a4.throwIfAborted();
1904
+ const result = await self.callTool({ name: name3, args, options });
1905
+ if (outputSchema != null) {
1906
+ return self.extractStructuredContent(result, outputSchema, name3);
1907
+ }
1908
+ return result;
1909
+ };
1910
+ const toolWithExecute = schemas === "automatic" ? dynamicTool({
1911
+ description,
1912
+ title: resolvedTitle,
1913
+ inputSchema: jsonSchema({
1914
+ ...inputSchema,
1915
+ properties: (_b3 = inputSchema.properties) != null ? _b3 : {},
1916
+ additionalProperties: false
1917
+ }),
1918
+ execute,
1919
+ toModelOutput: mcpToModelOutput
1920
+ }) : tool({
1921
+ description,
1922
+ title: resolvedTitle,
1923
+ inputSchema: schemas[name3].inputSchema,
1924
+ ...outputSchema != null ? { outputSchema } : {},
1925
+ execute,
1926
+ toModelOutput: mcpToModelOutput
1927
+ });
1928
+ tools[name3] = { ...toolWithExecute, _meta };
1929
1929
  }
1930
+ return tools;
1930
1931
  }
1931
1932
  /**
1932
1933
  * Extracts and validates structuredContent from a tool result.