@iqai/adk 0.2.2 → 0.2.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,11 @@
1
1
  # @iqai/adk
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 298edf1: `convertMcpToolToBaseTool` now takes in a optional toolHandler for more modularity
8
+
3
9
  ## 0.2.2
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -4,7 +4,7 @@ import { LanguageModel } from 'ai';
4
4
  import * as zod from 'zod';
5
5
  import { z } from 'zod';
6
6
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
7
- import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
7
+ import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
8
8
  import { Kysely, Generated } from 'kysely';
9
9
  import { StorageOptions } from '@google-cloud/storage';
10
10
  import { Tracer } from '@opentelemetry/api';
@@ -2079,7 +2079,12 @@ declare class McpClientService {
2079
2079
  removeSamplingHandler(): void;
2080
2080
  }
2081
2081
 
2082
- declare function convertMcpToolToBaseTool(mcpTool: Tool, client?: Client): Promise<BaseTool>;
2082
+ type ConvertMcpToolTooBaseToolParams = {
2083
+ mcpTool: Tool;
2084
+ client?: Client;
2085
+ toolHandler?: (name: string, args: unknown) => Promise<CallToolResult>;
2086
+ };
2087
+ declare function convertMcpToolToBaseTool(params: ConvertMcpToolTooBaseToolParams): Promise<BaseTool>;
2083
2088
 
2084
2089
  /**
2085
2090
  * Converts an ADK-style BaseTool to an MCP tool format
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { LanguageModel } from 'ai';
4
4
  import * as zod from 'zod';
5
5
  import { z } from 'zod';
6
6
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
7
- import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
7
+ import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
8
8
  import { Kysely, Generated } from 'kysely';
9
9
  import { StorageOptions } from '@google-cloud/storage';
10
10
  import { Tracer } from '@opentelemetry/api';
@@ -2079,7 +2079,12 @@ declare class McpClientService {
2079
2079
  removeSamplingHandler(): void;
2080
2080
  }
2081
2081
 
2082
- declare function convertMcpToolToBaseTool(mcpTool: Tool, client?: Client): Promise<BaseTool>;
2082
+ type ConvertMcpToolTooBaseToolParams = {
2083
+ mcpTool: Tool;
2084
+ client?: Client;
2085
+ toolHandler?: (name: string, args: unknown) => Promise<CallToolResult>;
2086
+ };
2087
+ declare function convertMcpToolToBaseTool(params: ConvertMcpToolTooBaseToolParams): Promise<BaseTool>;
2083
2088
 
2084
2089
  /**
2085
2090
  * Converts an ADK-style BaseTool to an MCP tool format
package/dist/index.js CHANGED
@@ -5816,9 +5816,13 @@ function mcpSchemaToParameters(mcpTool) {
5816
5816
  }
5817
5817
 
5818
5818
  // src/tools/mcp/create-tool.ts
5819
- async function convertMcpToolToBaseTool(mcpTool, client) {
5819
+ async function convertMcpToolToBaseTool(params) {
5820
5820
  try {
5821
- return new McpToolAdapter(mcpTool, client);
5821
+ return new McpToolAdapter(
5822
+ params.mcpTool,
5823
+ params.client,
5824
+ params.toolHandler
5825
+ );
5822
5826
  } catch (error) {
5823
5827
  if (!(error instanceof McpError)) {
5824
5828
  throw new McpError(
@@ -5834,8 +5838,9 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
5834
5838
 
5835
5839
 
5836
5840
  __init37() {this.clientService = null}
5841
+
5837
5842
  __init38() {this.logger = new Logger({ name: "McpToolAdapter" })}
5838
- constructor(mcpTool, client) {
5843
+ constructor(mcpTool, client, handler) {
5839
5844
  const metadata = mcpTool.metadata || {};
5840
5845
  super({
5841
5846
  name: mcpTool.name || `mcp_${Date.now()}`,
@@ -5846,6 +5851,7 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
5846
5851
  });_class23.prototype.__init37.call(this);_class23.prototype.__init38.call(this);;
5847
5852
  this.mcpTool = mcpTool;
5848
5853
  this.client = client;
5854
+ this.toolHandler = handler;
5849
5855
  if (client && client.reinitialize && typeof client.reinitialize === "function") {
5850
5856
  this.clientService = client;
5851
5857
  }
@@ -5900,6 +5906,9 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
5900
5906
  });
5901
5907
  return result;
5902
5908
  }
5909
+ if (this.toolHandler) {
5910
+ return await this.toolHandler(this.name, args);
5911
+ }
5903
5912
  throw new McpError(
5904
5913
  `Cannot execute MCP tool ${this.name}: No execution method found`,
5905
5914
  "tool_execution_error" /* TOOL_EXECUTION_ERROR */
@@ -6158,10 +6167,10 @@ var McpToolset = (_class24 = class {
6158
6167
  for (const mcpTool of toolsResponse.tools) {
6159
6168
  if (this.isSelected(mcpTool, context4)) {
6160
6169
  try {
6161
- const tool = await convertMcpToolToBaseTool(
6170
+ const tool = await convertMcpToolToBaseTool({
6162
6171
  mcpTool,
6163
6172
  client
6164
- );
6173
+ });
6165
6174
  tools.push(tool);
6166
6175
  } catch (toolError) {
6167
6176
  console.error(
package/dist/index.mjs CHANGED
@@ -5816,9 +5816,13 @@ function mcpSchemaToParameters(mcpTool) {
5816
5816
  }
5817
5817
 
5818
5818
  // src/tools/mcp/create-tool.ts
5819
- async function convertMcpToolToBaseTool(mcpTool, client) {
5819
+ async function convertMcpToolToBaseTool(params) {
5820
5820
  try {
5821
- return new McpToolAdapter(mcpTool, client);
5821
+ return new McpToolAdapter(
5822
+ params.mcpTool,
5823
+ params.client,
5824
+ params.toolHandler
5825
+ );
5822
5826
  } catch (error) {
5823
5827
  if (!(error instanceof McpError)) {
5824
5828
  throw new McpError(
@@ -5834,8 +5838,9 @@ var McpToolAdapter = class extends BaseTool {
5834
5838
  mcpTool;
5835
5839
  client;
5836
5840
  clientService = null;
5841
+ toolHandler;
5837
5842
  logger = new Logger({ name: "McpToolAdapter" });
5838
- constructor(mcpTool, client) {
5843
+ constructor(mcpTool, client, handler) {
5839
5844
  const metadata = mcpTool.metadata || {};
5840
5845
  super({
5841
5846
  name: mcpTool.name || `mcp_${Date.now()}`,
@@ -5846,6 +5851,7 @@ var McpToolAdapter = class extends BaseTool {
5846
5851
  });
5847
5852
  this.mcpTool = mcpTool;
5848
5853
  this.client = client;
5854
+ this.toolHandler = handler;
5849
5855
  if (client && client.reinitialize && typeof client.reinitialize === "function") {
5850
5856
  this.clientService = client;
5851
5857
  }
@@ -5900,6 +5906,9 @@ var McpToolAdapter = class extends BaseTool {
5900
5906
  });
5901
5907
  return result;
5902
5908
  }
5909
+ if (this.toolHandler) {
5910
+ return await this.toolHandler(this.name, args);
5911
+ }
5903
5912
  throw new McpError(
5904
5913
  `Cannot execute MCP tool ${this.name}: No execution method found`,
5905
5914
  "tool_execution_error" /* TOOL_EXECUTION_ERROR */
@@ -6158,10 +6167,10 @@ var McpToolset = class {
6158
6167
  for (const mcpTool of toolsResponse.tools) {
6159
6168
  if (this.isSelected(mcpTool, context4)) {
6160
6169
  try {
6161
- const tool = await convertMcpToolToBaseTool(
6170
+ const tool = await convertMcpToolToBaseTool({
6162
6171
  mcpTool,
6163
6172
  client
6164
- );
6173
+ });
6165
6174
  tools.push(tool);
6166
6175
  } catch (toolError) {
6167
6176
  console.error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iqai/adk",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Agent Development Kit for TypeScript with multi-provider LLM support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",