@mcp-use/client 2.4.1 → 2.4.2-canary.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.
@@ -1,4 +1,4 @@
1
- import type { CallToolResult, Tool } from "@modelcontextprotocol/client";
1
+ import type { CallToolResult, ProtocolEra, RequestOptions, Tool } from "@modelcontextprotocol/client";
2
2
  import type { MCPClient } from "../core/node.js";
3
3
  import { BaseConnector } from "../transport/base.js";
4
4
  export declare const CODE_MODE_AGENT_PROMPT = "\n## MCP Code Mode Tool Usage Guide\n\nYou have access to an MCP Code Mode Client that allows you to execute JavaScript/TypeScript code with access to registered tools. Follow this workflow:\n\n### 1. Tool Discovery Phase\n**Always start by discovering available tools:**\n- Tools are organized by server namespace (e.g., `server_name.tool_name`)\n- Use the `search_tools(query, detail_level)` function to find available tools\n- You can access `__tool_namespaces` to see all available server namespaces\n\n```javascript\n// Find all GitHub-related tools\nconst tools = await search_tools(\"github\");\nfor (const tool of tools) {\n console.log(`${tool.server}.${tool.name}: ${tool.description}`);\n}\n\n// Get only tool names for quick overview\nconst tools = await search_tools(\"\", \"names\");\n```\n\n### 2. Interface Introspection\n**Understand tool contracts before using them:**\n- Use `search_tools` to get tool descriptions and input schemas\n- Look for \"Access as: server.tool(args)\" patterns in descriptions\n\n### 3. Code Execution Guidelines\n**When writing code:**\n- Use `await server.tool({ param: value })` syntax for all tool calls\n- Tools are async functions that return promises\n- You have access to standard JavaScript globals: `console`, `JSON`, `Math`, `Date`, etc.\n- All console output (`console.log`, `console.error`, etc.) is automatically captured and returned\n- Build properly structured input objects based on interface definitions\n- Handle errors appropriately with try/catch blocks\n- Chain tool calls by using results from previous calls\n\n### 4. Best Practices\n- **Discover first, code second**: Always explore available tools before writing execution code\n- **Respect namespaces**: Use full `server.tool` names to avoid conflicts\n- **Minimize Context**: Process large data in code, return only essential results\n- **Error handling**: Wrap tool calls in try/catch for robustness\n- **Data flow**: Chain tools by passing outputs as inputs to subsequent tools\n\n### 5. Available Runtime Context\n- `search_tools(query, detail_level)`: Function to discover tools\n- `__tool_namespaces`: Array of available server namespaces\n- All registered tools as `server.tool` functions\n- Standard JavaScript built-ins for data processing\n\n### Example Workflow\n\n```javascript\n// 1. Discover available tools\nconst github_tools = await search_tools(\"github pull request\");\nconsole.log(`Available GitHub PR tools: ${github_tools.map(t => t.name)}`);\n\n// 2. Call tools with proper parameters\nconst pr = await github.get_pull_request({\n owner: \"facebook\",\n repo: \"react\",\n number: 12345\n});\n\n// 3. Process results\nlet result;\nif (pr.state === 'open' && pr.labels.some(l => l.name === 'bug')) {\n // 4. Chain with other tools\n await slack.post_message({\n channel: \"#bugs\",\n text: `\uD83D\uDC1B Bug PR needs review: ${pr.title}`\n });\n result = \"Notification sent\";\n} else {\n result = \"No action needed\";\n}\n\n// 5. Return structured results\nreturn {\n pr_number: pr.number,\n pr_title: pr.title,\n action_taken: result\n};\n```\n\nRemember: Always discover and understand available tools before attempting to use them in code execution.\n";
@@ -20,7 +20,57 @@ export declare class CodeModeConnector extends BaseConnector {
20
20
  get publicIdentifier(): Record<string, string>;
21
21
  private _createToolsList;
22
22
  get tools(): Tool[];
23
+ /**
24
+ * Returns fresh tools available in code mode.
25
+ *
26
+ * @param options - Optional per-request options (e.g. abort signal).
27
+ * @returns List of Tool objects for execute_code and search_tools.
28
+ */
29
+ listTools(options?: RequestOptions): Promise<Tool[]>;
30
+ get protocolEra(): ProtocolEra | undefined;
31
+ get negotiatedProtocolVersion(): string | undefined;
23
32
  initialize(): Promise<any>;
24
- callTool(name: string, args: Record<string, any>): Promise<CallToolResult>;
33
+ /**
34
+ * Code mode internal server does not expose resources. Returns an empty list.
35
+ *
36
+ * @param _cursor - Optional pagination cursor (unused).
37
+ * @param options - Optional request options.
38
+ * @returns Empty resource list.
39
+ */
40
+ listResources(_cursor?: string, options?: RequestOptions): Promise<{
41
+ /** Empty resource list in code mode. */
42
+ resources: any[];
43
+ }>;
44
+ /**
45
+ * Code mode internal server does not expose resources. Returns an empty list.
46
+ *
47
+ * @param options - Optional request options.
48
+ * @returns Empty resource list.
49
+ */
50
+ listAllResources(options?: RequestOptions): Promise<{
51
+ /** Empty resource list in code mode. */
52
+ resources: any[];
53
+ }>;
54
+ /**
55
+ * Code mode internal server does not expose resource templates. Returns an empty list.
56
+ *
57
+ * @param options - Optional request options.
58
+ * @returns Empty resource template list.
59
+ */
60
+ listResourceTemplates(options?: RequestOptions): Promise<{
61
+ /** Empty resource template list in code mode. */
62
+ resourceTemplates: any[];
63
+ }>;
64
+ /**
65
+ * Code mode internal server does not expose prompts. Returns an empty list.
66
+ *
67
+ * @param options - Optional request options.
68
+ * @returns Empty prompt list.
69
+ */
70
+ listPrompts(options?: RequestOptions): Promise<{
71
+ /** Empty prompt list in code mode. */
72
+ prompts: any[];
73
+ }>;
74
+ callTool(name: string, args: Record<string, any>, options?: RequestOptions): Promise<CallToolResult>;
25
75
  }
26
76
  //# sourceMappingURL=connector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/code-mode/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,eAAO,MAAM,sBAAsB,0rGAsFlC,CAAC;AAKF;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,SAAS;cAOJ,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5D,IAAI,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE7C;IAED,OAAO,CAAC,gBAAgB;IA4DxB,IAAI,KAAK,IAAI,IAAI,EAAE,CAElB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;OAKG;IACY,gBAAgB,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC;QACjE,wCAAwC;QACxC,SAAS,EAAE,GAAG,EAAE,CAAC;KAClB,CAAC;IAQF;;;;;OAKG;IACY,qBAAqB,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC;QACtE,iDAAiD;QACjD,iBAAiB,EAAE,GAAG,EAAE,CAAC;KAC1B,CAAC;IAQF;;;;;OAKG;IACY,WAAW,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC;QAC5D,sCAAsC;QACtC,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;IAQa,QAAQ,CACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,cAAc,CAAC;CAoD3B"}
@@ -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.4.1";
131
+ var VERSION = "2.4.2-canary.0";
132
132
  function getPackageVersion() {
133
133
  return VERSION;
134
134
  }
package/dist/index.js CHANGED
@@ -1559,7 +1559,7 @@ init_connector_telemetry();
1559
1559
  init_logging();
1560
1560
 
1561
1561
  // src/utils/version.ts
1562
- var VERSION = "2.4.1";
1562
+ var VERSION = "2.4.2-canary.0";
1563
1563
  function getPackageVersion() {
1564
1564
  return VERSION;
1565
1565
  }
@@ -5385,6 +5385,40 @@ return {
5385
5385
  Remember: Always discover and understand available tools before attempting to use them in code execution.
5386
5386
  `;
5387
5387
  var DETAIL_LEVELS = /* @__PURE__ */ new Set(["names", "descriptions", "full"]);
5388
+ function throwIfAborted(signal) {
5389
+ if (!signal?.aborted) return;
5390
+ if (typeof signal.throwIfAborted === "function") {
5391
+ signal.throwIfAborted();
5392
+ }
5393
+ throw signal.reason ?? new Error("This operation was aborted");
5394
+ }
5395
+ function raceAbort(promise, signal) {
5396
+ if (!signal) {
5397
+ return promise;
5398
+ }
5399
+ throwIfAborted(signal);
5400
+ return new Promise((resolve, reject) => {
5401
+ const onAbort = () => {
5402
+ signal.removeEventListener("abort", onAbort);
5403
+ try {
5404
+ throwIfAborted(signal);
5405
+ } catch (err) {
5406
+ reject(err);
5407
+ }
5408
+ };
5409
+ signal.addEventListener("abort", onAbort, { once: true });
5410
+ promise.then(
5411
+ (value) => {
5412
+ signal.removeEventListener("abort", onAbort);
5413
+ resolve(value);
5414
+ },
5415
+ (error) => {
5416
+ signal.removeEventListener("abort", onAbort);
5417
+ reject(error);
5418
+ }
5419
+ );
5420
+ });
5421
+ }
5388
5422
  var CodeModeConnector = class extends BaseConnector {
5389
5423
  mcpClient;
5390
5424
  _tools;
@@ -5393,6 +5427,13 @@ var CodeModeConnector = class extends BaseConnector {
5393
5427
  this.mcpClient = client;
5394
5428
  this.connected = true;
5395
5429
  this._tools = this._createToolsList();
5430
+ this.toolsCache = this._tools;
5431
+ this.capabilitiesCache = { tools: {} };
5432
+ this.serverInfoCache = {
5433
+ name: "code_mode",
5434
+ version: "1.0.0",
5435
+ description: "MCP Code Mode Internal Server"
5436
+ };
5396
5437
  }
5397
5438
  async establishTransport() {
5398
5439
  }
@@ -5446,15 +5487,104 @@ var CodeModeConnector = class extends BaseConnector {
5446
5487
  get tools() {
5447
5488
  return this._tools;
5448
5489
  }
5490
+ /**
5491
+ * Returns fresh tools available in code mode.
5492
+ *
5493
+ * @param options - Optional per-request options (e.g. abort signal).
5494
+ * @returns List of Tool objects for execute_code and search_tools.
5495
+ */
5496
+ async listTools(options) {
5497
+ if (!this.connected) {
5498
+ throw new Error("MCP client is not connected");
5499
+ }
5500
+ throwIfAborted(options?.signal);
5501
+ return [...this._tools];
5502
+ }
5503
+ get protocolEra() {
5504
+ return this.connected ? "modern" : void 0;
5505
+ }
5506
+ get negotiatedProtocolVersion() {
5507
+ return this.connected ? "2026-07-28" : void 0;
5508
+ }
5449
5509
  async initialize() {
5450
5510
  this.toolsCache = this._tools;
5451
- return { capabilities: {}, version: "1.0.0" };
5511
+ this.capabilitiesCache = { tools: {} };
5512
+ this.serverInfoCache = {
5513
+ name: "code_mode",
5514
+ version: "1.0.0",
5515
+ description: "MCP Code Mode Internal Server"
5516
+ };
5517
+ return {
5518
+ capabilities: this.capabilitiesCache,
5519
+ serverInfo: this.serverInfoCache,
5520
+ protocolVersion: "2026-07-28"
5521
+ };
5452
5522
  }
5453
- async callTool(name, args) {
5523
+ /**
5524
+ * Code mode internal server does not expose resources. Returns an empty list.
5525
+ *
5526
+ * @param _cursor - Optional pagination cursor (unused).
5527
+ * @param options - Optional request options.
5528
+ * @returns Empty resource list.
5529
+ */
5530
+ async listResources(_cursor, options) {
5531
+ if (!this.connected) {
5532
+ throw new Error("MCP client is not connected");
5533
+ }
5534
+ throwIfAborted(options?.signal);
5535
+ return { resources: [] };
5536
+ }
5537
+ /**
5538
+ * Code mode internal server does not expose resources. Returns an empty list.
5539
+ *
5540
+ * @param options - Optional request options.
5541
+ * @returns Empty resource list.
5542
+ */
5543
+ async listAllResources(options) {
5544
+ if (!this.connected) {
5545
+ throw new Error("MCP client is not connected");
5546
+ }
5547
+ throwIfAborted(options?.signal);
5548
+ return { resources: [] };
5549
+ }
5550
+ /**
5551
+ * Code mode internal server does not expose resource templates. Returns an empty list.
5552
+ *
5553
+ * @param options - Optional request options.
5554
+ * @returns Empty resource template list.
5555
+ */
5556
+ async listResourceTemplates(options) {
5557
+ if (!this.connected) {
5558
+ throw new Error("MCP client is not connected");
5559
+ }
5560
+ throwIfAborted(options?.signal);
5561
+ return { resourceTemplates: [] };
5562
+ }
5563
+ /**
5564
+ * Code mode internal server does not expose prompts. Returns an empty list.
5565
+ *
5566
+ * @param options - Optional request options.
5567
+ * @returns Empty prompt list.
5568
+ */
5569
+ async listPrompts(options) {
5570
+ if (!this.connected) {
5571
+ throw new Error("MCP client is not connected");
5572
+ }
5573
+ throwIfAborted(options?.signal);
5574
+ return { prompts: [] };
5575
+ }
5576
+ async callTool(name, args, options) {
5577
+ if (!this.connected) {
5578
+ throw new Error("MCP client is not connected");
5579
+ }
5580
+ throwIfAborted(options?.signal);
5454
5581
  if (name === "execute_code") {
5455
5582
  const code = args.code;
5456
5583
  const timeout = args.timeout || 3e4;
5457
- const result = await this.mcpClient.executeCode(code, timeout);
5584
+ const result = await raceAbort(
5585
+ this.mcpClient.executeCode(code, timeout),
5586
+ options?.signal
5587
+ );
5458
5588
  return {
5459
5589
  content: [
5460
5590
  {
@@ -5466,9 +5596,12 @@ var CodeModeConnector = class extends BaseConnector {
5466
5596
  } else if (name === "search_tools") {
5467
5597
  const query = args.query || "";
5468
5598
  const detailLevel = args.detail_level;
5469
- const result = await this.mcpClient.searchTools(
5470
- query,
5471
- DETAIL_LEVELS.has(detailLevel) ? detailLevel : "full"
5599
+ const result = await raceAbort(
5600
+ this.mcpClient.searchTools(
5601
+ query,
5602
+ DETAIL_LEVELS.has(detailLevel) ? detailLevel : "full"
5603
+ ),
5604
+ options?.signal
5472
5605
  );
5473
5606
  return {
5474
5607
  content: [