@mcp-use/client 2.2.5 → 2.3.0

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.
@@ -0,0 +1,98 @@
1
+ import type { CallToolResult, Tool as MCPTool } from "@modelcontextprotocol/client";
2
+ import type { MCPConnection } from "../core/session.js";
3
+ /** The input shape passed to an MCP tool by the AI SDK. */
4
+ export type AiSdkToolInput = Record<string, unknown>;
5
+ /** The unmodified MCP result returned from a tool execution. */
6
+ export type AiSdkToolOutput = CallToolResult;
7
+ /** The JSON-schema view passed to the optional schema transformer. */
8
+ export type AiSdkInputSchema = Record<string, unknown>;
9
+ /** A successful pass-through result for an AI SDK dynamic-tool input. */
10
+ export interface AiSdkToolValidationResult {
11
+ /** Confirms that the adapter leaves validation to the MCP server. */
12
+ success: true;
13
+ /** The parsed value passed through to MCP without local schema coercion. */
14
+ value: unknown;
15
+ }
16
+ /**
17
+ * A JSON Schema wrapper understood by AI SDK dynamic tools.
18
+ *
19
+ * It uses AI SDK's runtime schema and validator markers without importing an
20
+ * AI SDK package. The pass-through validator keeps MCP servers authoritative
21
+ * for input validation while supporting AI SDK v5's validator path.
22
+ */
23
+ export interface AiSdkToolSchema {
24
+ /** AI SDK schema type placeholder for runtime-discovered tool inputs. */
25
+ _type: undefined;
26
+ /** The unmodified MCP JSON Schema sent to the AI SDK provider. */
27
+ jsonSchema: AiSdkInputSchema;
28
+ /** Accepts parsed JSON; the MCP server performs authoritative validation. */
29
+ validate(value: unknown): AiSdkToolValidationResult;
30
+ }
31
+ /** Execution context supplied by supported AI SDK dynamic-tool versions. */
32
+ export interface AiSdkToolExecutionOptions {
33
+ /** Cancels the corresponding MCP request when the AI SDK aborts it. */
34
+ abortSignal?: AbortSignal;
35
+ }
36
+ /**
37
+ * An AI SDK dynamic tool backed by an MCP tool.
38
+ *
39
+ * The `annotations`, `_meta`, and `metadata` fields are retained as MCP-side
40
+ * metadata. The structural type intentionally imports no AI SDK types so the
41
+ * client remains compatible with AI SDK v5, v6, and v7 without a dependency.
42
+ */
43
+ export interface AiSdkTool {
44
+ /** Identifies this as an AI SDK runtime-generated tool. */
45
+ type: "dynamic";
46
+ /** MCP tool description supplied to the model, when present. */
47
+ description?: string;
48
+ /** Human-readable MCP tool title, when present. */
49
+ title?: string;
50
+ /**
51
+ * Input schema passed to the AI SDK provider and dynamic-tool parser.
52
+ *
53
+ * `any` is intentional: AI SDK v5, v6, and v7 expose incompatible
54
+ * `FlexibleSchema` generations, while dynamic MCP tool inputs are runtime
55
+ * values in all of them.
56
+ */
57
+ inputSchema: any;
58
+ /** Executes the MCP tool with model-provided arguments. */
59
+ execute(args: unknown, executionOptions?: AiSdkToolExecutionOptions): Promise<AiSdkToolOutput>;
60
+ /** Original MCP tool annotations. */
61
+ annotations?: MCPTool["annotations"];
62
+ /** Original MCP tool metadata. */
63
+ _meta?: MCPTool["_meta"];
64
+ /** Adapter metadata retained for AI SDK/provider consumers. */
65
+ metadata?: any;
66
+ }
67
+ /** A source with the protocol-neutral MCP operations needed by the adapter. */
68
+ export type AiSdkToolConnection = Pick<MCPConnection, "listTools" | "callTool">;
69
+ /** Options controlling MCP tool discovery, schema normalization, and metadata. */
70
+ export interface CreateAiSdkToolsOptions {
71
+ /**
72
+ * Tool definitions to adapt. When omitted, the adapter fetches them with
73
+ * `connection.listTools()`. An explicitly supplied empty array is valid and
74
+ * does not trigger discovery.
75
+ */
76
+ tools?: MCPTool[];
77
+ /**
78
+ * Transforms the MCP input schema before it is passed to the AI SDK. The
79
+ * returned schema is preserved exactly; use this only for deliberate
80
+ * application-level compatibility transformations.
81
+ */
82
+ transformInputSchema?: (inputSchema: unknown) => unknown;
83
+ /**
84
+ * Client identity retained in the returned tool metadata. This does not
85
+ * change the already-connected MCP connection's client identity.
86
+ */
87
+ clientName?: string;
88
+ }
89
+ /** The AI SDK tools keyed by their original MCP tool names. */
90
+ export type AiSdkToolSet = Record<string, AiSdkTool>;
91
+ /**
92
+ * Creates AI SDK dynamic tools from one protocol-neutral MCP connection.
93
+ *
94
+ * This helper adapts tool definitions and invocation only. It does not own
95
+ * connection creation, authentication, transport lifetime, or cleanup.
96
+ */
97
+ export declare function createAiSdkTools(connection: AiSdkToolConnection, options?: CreateAiSdkToolsOptions): Promise<AiSdkToolSet>;
98
+ //# sourceMappingURL=ai-sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../../src/adapters/ai-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,IAAI,IAAI,OAAO,EAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKxD,2DAA2D;AAC3D,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErD,gEAAgE;AAChE,MAAM,MAAM,eAAe,GAAG,cAAc,CAAC;AAE7C,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEvD,yEAAyE;AACzE,MAAM,WAAW,yBAAyB;IACxC,qEAAqE;IACrE,OAAO,EAAE,IAAI,CAAC;IACd,4EAA4E;IAC5E,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,KAAK,EAAE,SAAS,CAAC;IACjB,kEAAkE;IAClE,UAAU,EAAE,gBAAgB,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,yBAAyB,CAAC;CACrD;AAED,4EAA4E;AAC5E,MAAM,WAAW,yBAAyB;IACxC,uEAAuE;IACvE,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,2DAA2D;IAC3D,IAAI,EAAE,SAAS,CAAC;IAChB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,WAAW,EAAE,GAAG,CAAC;IACjB,2DAA2D;IAC3D,OAAO,CACL,IAAI,EAAE,OAAO,EACb,gBAAgB,CAAC,EAAE,yBAAyB,GAC3C,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5B,qCAAqC;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACrC,kCAAkC;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED,+EAA+E;AAC/E,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC;AAEhF,kFAAkF;AAClF,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,OAAO,CAAC;IACzD;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,+DAA+D;AAC/D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAErD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,mBAAmB,EAC/B,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,YAAY,CAAC,CA+DvB"}
@@ -15,6 +15,7 @@ export { auth, UnauthorizedError } from "@modelcontextprotocol/client";
15
15
  export { BrowserMCPClient as MCPClient } from "./core/browser.js";
16
16
  export * from "./core/session.js";
17
17
  export * from "./core/config.js";
18
+ export * from "./adapters/ai-sdk.js";
18
19
  export * from "./transport/base.js";
19
20
  export * from "./transport/http.js";
20
21
  export * from "./utils/json-schema-validator.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index-browser.d.ts","sourceRoot":"","sources":["../src/index-browser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,kCAAkC,CAAC;AAE1C,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,0BAA0B,EAC1B,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACvE,sDAAsD;AACtD,OAAO,EAAE,gBAAgB,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAClE,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,GAAG,EACH,SAAS,EACT,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index-browser.d.ts","sourceRoot":"","sources":["../src/index-browser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,kCAAkC,CAAC;AAE1C,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,0BAA0B,EAC1B,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACvE,sDAAsD;AACtD,OAAO,EAAE,gBAAgB,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAClE,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AAErC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,GAAG,EACH,SAAS,EACT,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
@@ -128,7 +128,7 @@ var Logger = class {
128
128
  var logger = Logger.get();
129
129
 
130
130
  // src/utils/version.ts
131
- var VERSION = "2.2.5";
131
+ var VERSION = "2.3.0";
132
132
  function getPackageVersion() {
133
133
  return VERSION;
134
134
  }
@@ -4661,6 +4661,72 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
4661
4661
  }
4662
4662
  };
4663
4663
 
4664
+ // src/adapters/ai-sdk.ts
4665
+ var AI_SDK_SCHEMA_SYMBOL = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
4666
+ var AI_SDK_VALIDATOR_SYMBOL = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
4667
+ async function createAiSdkTools(connection, options = {}) {
4668
+ const tools = options.tools ?? await connection.listTools();
4669
+ const result = /* @__PURE__ */ Object.create(null);
4670
+ for (const mcpTool of tools) {
4671
+ const name = mcpTool.name;
4672
+ if (Object.prototype.hasOwnProperty.call(result, name)) {
4673
+ throw new Error(`Duplicate MCP tool name: ${name}`);
4674
+ }
4675
+ const rawInputSchema = mcpTool.inputSchema;
4676
+ const transformedInputSchema = options.transformInputSchema?.(rawInputSchema) ?? rawInputSchema;
4677
+ const inputSchema = toAiSdkInputSchema(
4678
+ asInputSchema(transformedInputSchema)
4679
+ );
4680
+ const title = mcpTool.title ?? mcpTool.annotations?.title;
4681
+ const metadata = {
4682
+ toolName: name,
4683
+ ...options.clientName !== void 0 ? { clientName: options.clientName } : {},
4684
+ ...title !== void 0 ? { title } : {},
4685
+ ...mcpTool.annotations !== void 0 ? { annotations: mcpTool.annotations } : {},
4686
+ ...mcpTool._meta !== void 0 ? { _meta: mcpTool._meta } : {}
4687
+ };
4688
+ const execute = async (args, executionOptions = {}) => {
4689
+ executionOptions?.abortSignal?.throwIfAborted();
4690
+ return connection.callTool(name, args, {
4691
+ signal: executionOptions?.abortSignal
4692
+ });
4693
+ };
4694
+ const dynamicDefinition = {
4695
+ type: "dynamic",
4696
+ ...mcpTool.description !== void 0 ? { description: mcpTool.description } : {},
4697
+ ...title !== void 0 ? { title } : {},
4698
+ inputSchema,
4699
+ execute,
4700
+ metadata,
4701
+ ...mcpTool.annotations !== void 0 ? { annotations: mcpTool.annotations } : {},
4702
+ ...mcpTool._meta !== void 0 ? { _meta: mcpTool._meta } : {}
4703
+ };
4704
+ Object.defineProperty(result, name, {
4705
+ configurable: true,
4706
+ enumerable: true,
4707
+ value: dynamicDefinition,
4708
+ writable: true
4709
+ });
4710
+ }
4711
+ return result;
4712
+ }
4713
+ function asInputSchema(schema) {
4714
+ if (schema && typeof schema === "object" && !Array.isArray(schema)) {
4715
+ return schema;
4716
+ }
4717
+ return {};
4718
+ }
4719
+ function toAiSdkInputSchema(jsonSchema) {
4720
+ const schema = {
4721
+ [AI_SDK_SCHEMA_SYMBOL]: true,
4722
+ [AI_SDK_VALIDATOR_SYMBOL]: true,
4723
+ _type: void 0,
4724
+ jsonSchema,
4725
+ validate: (value) => ({ success: true, value })
4726
+ };
4727
+ return schema;
4728
+ }
4729
+
4664
4730
  // src/utils/favicon.ts
4665
4731
  var FAVICON_API = "https://favicon.tools.mcp-use.com";
4666
4732
  var IPV4_RE = /^\d{1,3}(\.\d{1,3}){3}$/;
@@ -4748,6 +4814,7 @@ export {
4748
4814
  auth2 as auth,
4749
4815
  capturePostHog,
4750
4816
  completeOAuthFlow,
4817
+ createAiSdkTools,
4751
4818
  createConnectorFromConfig,
4752
4819
  createOAuthProvider,
4753
4820
  detectFavicon,