{"version":3,"sources":["../../src/util/transport.ts"],"sourcesContent":["/**\n * Copyright 2025 Google LLC\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 { McpServerConfig } from '../client/client.mjs';\nimport type { StdioServerParameters, Transport } from '../client/index.mjs';\n\n/**\n * Creates an MCP transport instance based on the provided server configuration.\n * It supports creating SSE, Stdio, or using a pre-configured custom transport.\n *\n * @param config The configuration for the MCP server, determining the type of transport to create.\n * @returns A Promise resolving to an object containing the created `Transport` instance\n *          (or `null` if configuration is invalid) and a string indicating the `type` of transport.\n * @throws May throw an error if essential MCP SDK components cannot be imported.\n */\nexport async function transportFrom(\n  config: McpServerConfig,\n  sessionId?: string\n): Promise<{\n  transport: Transport | null;\n  type: string;\n}> {\n  // Handle pre-configured transport first\n  if ('transport' in config && config.transport) {\n    return { transport: config.transport, type: 'custom' };\n  }\n  // Handle SSE config\n  if ('url' in config && config.url) {\n    const { url, ...httpConfig } = config;\n    const { StreamableHTTPClientTransport } = await import(\n      '@modelcontextprotocol/sdk/client/streamableHttp.js'\n    );\n    return {\n      transport: new StreamableHTTPClientTransport(new URL(url), {\n        ...httpConfig,\n        sessionId,\n      }),\n      type: 'http',\n    };\n  }\n  // Handle Stdio config\n  if ('command' in config && config.command) {\n    // Create a copy and remove McpServerControls properties\n    const stdioConfig = { ...config };\n    const { StdioClientTransport } = await import(\n      '@modelcontextprotocol/sdk/client/stdio.js'\n    );\n    return {\n      transport: new StdioClientTransport(stdioConfig as StdioServerParameters),\n      type: 'stdio',\n    };\n  }\n  return { transport: null, type: 'unknown' };\n}\n"],"mappings":"AA4BA,eAAsB,cACpB,QACA,WAIC;AAED,MAAI,eAAe,UAAU,OAAO,WAAW;AAC7C,WAAO,EAAE,WAAW,OAAO,WAAW,MAAM,SAAS;AAAA,EACvD;AAEA,MAAI,SAAS,UAAU,OAAO,KAAK;AACjC,UAAM,EAAE,KAAK,GAAG,WAAW,IAAI;AAC/B,UAAM,EAAE,8BAA8B,IAAI,MAAM,OAC9C,oDACF;AACA,WAAO;AAAA,MACL,WAAW,IAAI,8BAA8B,IAAI,IAAI,GAAG,GAAG;AAAA,QACzD,GAAG;AAAA,QACH;AAAA,MACF,CAAC;AAAA,MACD,MAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI,aAAa,UAAU,OAAO,SAAS;AAEzC,UAAM,cAAc,EAAE,GAAG,OAAO;AAChC,UAAM,EAAE,qBAAqB,IAAI,MAAM,OACrC,2CACF;AACA,WAAO;AAAA,MACL,WAAW,IAAI,qBAAqB,WAAoC;AAAA,MACxE,MAAM;AAAA,IACR;AAAA,EACF;AACA,SAAO,EAAE,WAAW,MAAM,MAAM,UAAU;AAC5C;","names":[]}