import { createRequire } from "node:module";
var __defProp = Object.defineProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: (newValue) => all[name] = () => newValue
    });
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __require = /* @__PURE__ */ createRequire(import.meta.url);

// src/tools/mcp-client.ts
import { experimental_createMCPClient } from "@ai-sdk/mcp";
import { Experimental_StdioMCPTransport as StdioClientTransport } from "@ai-sdk/mcp/mcp-stdio";
async function mcpServerToTools(config) {
  const transport = new StdioClientTransport({
    command: config.command,
    args: config.args,
    env: config.env
  });
  const client = await experimental_createMCPClient({ transport });
  const tools = await client.tools();
  return {
    tools,
    cleanup: () => client.close()
  };
}
async function createMcpToolsets(configs) {
  const results = await Promise.all(configs.map(mcpServerToTools));
  const combinedTools = {};
  for (const result of results) {
    Object.assign(combinedTools, result.tools);
  }
  return {
    tools: combinedTools,
    cleanup: async () => {
      await Promise.all(results.map((r) => r.cleanup()));
    }
  };
}
export {
  mcpServerToTools,
  createMcpToolsets
};
