{"version":3,"sources":["../../src/tools/mcp.ts"],"names":["MCPToolOutput","JSONToolOutput","MCPTool","Tool","name","description","emitter","client","tool","options","Emitter","root","child","namespace","creator","inputSchema","_run","input","_options","run","result","callTool","arguments","undefined","signal","fromClient","tools","paginate","size","Infinity","handler","cursor","nextCursor","listTools","data","map"],"mappings":";;;;;;;;AA6BO,MAAMA,sBAAsBC,uBAAAA,CAAAA;EA7BnC;;;AA6BwD;AAEjD,MAAMC,gBAAgBC,aAAAA,CAAAA;EA/B7B;;;AAgCkBC,EAAAA,IAAAA;AACAC,EAAAA,WAAAA;AACAC,EAAAA,OAAAA;AAEAC,EAAAA,MAAAA;AACCC,EAAAA,IAAAA;AAEjB,EAAA,WAAA,CAAmB,EAAED,MAAAA,EAAQC,IAAM,EAAA,GAAGC,SAAyB,EAAA;AAC7D,IAAA,KAAA,CAAMA,OAAAA,CAAAA;AACN,IAAA,IAAA,CAAKF,MAASA,GAAAA,MAAAA;AACd,IAAA,IAAA,CAAKC,IAAOA,GAAAA,IAAAA;AACZ,IAAA,IAAA,CAAKJ,OAAOI,IAAKJ,CAAAA,IAAAA;AACjB,IAAKC,IAAAA,CAAAA,WAAAA,GACHG,KAAKH,WAAe,IAAA,sEAAA;AACtB,IAAKC,IAAAA,CAAAA,OAAAA,GAAUI,mBAAQC,CAAAA,IAAAA,CAAKC,KAAM,CAAA;MAChCC,SAAW,EAAA;AAAC,QAAA,MAAA;AAAQ,QAAA,KAAA;QAAO,IAAKT,CAAAA;;MAChCU,OAAS,EAAA;KACX,CAAA;AACF;EAEOC,WAAc,GAAA;AACnB,IAAA,OAAO,KAAKP,IAAKO,CAAAA,WAAAA;AACnB;EAEA,MAAgBC,IAAAA,CACdC,KACAC,EAAAA,QAAAA,EACAC,GACA,EAAA;AACA,IAAA,MAAMC,MAAS,GAAA,MAAM,IAAKb,CAAAA,MAAAA,CAAOc,QAAS,CAAA;AAAEjB,MAAAA,IAAAA,EAAM,IAAKA,CAAAA,IAAAA;MAAMkB,SAAWL,EAAAA;AAAM,KAAA,EAAGM,MAAW,EAAA;AAC1FC,MAAAA,MAAAA,EAAQL,GAAIK,CAAAA;KACd,CAAA;AACA,IAAO,OAAA,IAAIxB,cAAcoB,MAAAA,CAAAA;AAC3B;AAEA,EAAA,aAAoBK,WAAWlB,MAAuC,EAAA;AACpE,IAAMmB,MAAAA,KAAAA,GAAQ,MAAMC,qBAAS,CAAA;MAC3BC,IAAMC,EAAAA,QAAAA;MACNC,OAAS,kBAAA,MAAA,CAAA,OAAO,EAAEC,MAAAA,EAA6B,KAAA;AAC7C,QAAA,MAAM,EAAEL,KAAAA,EAAAA,MAAAA,EAAOM,YAAe,GAAA,MAAMzB,OAAO0B,SAAU,CAAA;AAAEF,UAAAA;SAAO,CAAA;AAC9D,QAAO,OAAA;UAAEG,IAAMR,EAAAA,MAAAA;AAAOM,UAAAA;AAAW,SAAA;OAF1B,EAAA,SAAA;KAIX,CAAA;AACA,IAAA,OAAON,KAAMS,CAAAA,GAAAA,CAAI,CAAC3B,IAAAA,KAAS,IAAIN,OAAQ,CAAA;AAAEK,MAAAA,MAAAA;AAAQC,MAAAA;AAAK,KAAA,CAAA,CAAA;AACxD;AACF","file":"mcp.cjs","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BaseToolRunOptions, ToolEmitter, ToolInput, JSONToolOutput, Tool } from \"@/tools/base.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { GetRunContext } from \"@/context.js\";\nimport { Client as MCPClient } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { ListToolsResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { SchemaObject } from \"ajv\";\nimport { paginate } from \"@/internals/helpers/paginate.js\";\n\nexport interface MCPToolInput {\n  client: MCPClient;\n  tool: ListToolsResult[\"tools\"][number];\n}\n\nexport class MCPToolOutput extends JSONToolOutput<any> {}\n\nexport class MCPTool extends Tool<MCPToolOutput> {\n  public readonly name: string;\n  public readonly description: string;\n  public readonly emitter: ToolEmitter<ToolInput<this>, MCPToolOutput>;\n\n  public readonly client: MCPClient;\n  private readonly tool: ListToolsResult[\"tools\"][number];\n\n  public constructor({ client, tool, ...options }: MCPToolInput) {\n    super(options);\n    this.client = client;\n    this.tool = tool;\n    this.name = tool.name;\n    this.description =\n      tool.description ?? \"No available description, use the tool based on its name and schema.\";\n    this.emitter = Emitter.root.child({\n      namespace: [\"tool\", \"mcp\", this.name],\n      creator: this,\n    });\n  }\n\n  public inputSchema() {\n    return this.tool.inputSchema as SchemaObject;\n  }\n\n  protected async _run(\n    input: ToolInput<this>,\n    _options: BaseToolRunOptions,\n    run: GetRunContext<typeof this>,\n  ) {\n    const result = await this.client.callTool({ name: this.name, arguments: input }, undefined, {\n      signal: run.signal,\n    });\n    return new MCPToolOutput(result);\n  }\n\n  public static async fromClient(client: MCPClient): Promise<MCPTool[]> {\n    const tools = await paginate({\n      size: Infinity,\n      handler: async ({ cursor }: { cursor?: string }) => {\n        const { tools, nextCursor } = await client.listTools({ cursor });\n        return { data: tools, nextCursor } as const;\n      },\n    });\n    return tools.map((tool) => new MCPTool({ client, tool }));\n  }\n}\n"]}