{"version":3,"file":"mcp-apps-servers.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/mcp-apps-servers.ts"],"sourcesContent":["import type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport type { McpAppsServerConfig } from \"../../core/runtime\";\n\nconst UNSUPPORTED_POLICY_KEYS = [\"includeTools\", \"excludeTools\"] as const;\nconst MCP_APPS_MIDDLEWARE_VERSION = \"@ag-ui/mcp-apps-middleware@0.0.3\";\nconst MCP_APPS_POLICY_ISSUE =\n  \"https://github.com/CopilotKit/CopilotKit/issues/5930\";\n\n/**\n * Select the servers for an agent and validate the policy boundary owned by\n * the installed MCP Apps middleware.\n */\nexport function resolveMcpAppsServers(\n  servers: readonly McpAppsServerConfig[],\n  agentId: string,\n): MCPClientConfig[] {\n  const violations: string[] = [];\n\n  for (const [index, server] of servers.entries()) {\n    const config = server as unknown as Record<string, unknown>;\n    for (const key of UNSUPPORTED_POLICY_KEYS) {\n      if (\n        Object.prototype.hasOwnProperty.call(config, key) &&\n        config[key] !== undefined\n      ) {\n        violations.push(\n          `${key} at server[${index}] (${server.serverId ?? server.url})`,\n        );\n      }\n    }\n  }\n\n  if (violations.length > 0) {\n    throw new Error(\n      `Unsupported MCP Apps tool policy: ${violations.join(\", \")}. ` +\n        `${MCP_APPS_MIDDLEWARE_VERSION} owns per-server tool policy and ` +\n        `does not support these keys; see ${MCP_APPS_POLICY_ISSUE}.`,\n    );\n  }\n\n  return servers\n    .filter((server) => !server.agentId || server.agentId === agentId)\n    .map(({ agentId: _agentId, ...server }) => server as MCPClientConfig);\n}\n"],"mappings":";;AAGA,MAAM,0BAA0B,CAAC,gBAAgB,eAAe;AAChE,MAAM,8BAA8B;AACpC,MAAM,wBACJ;;;;;AAMF,SAAgB,sBACd,SACA,SACmB;CACnB,MAAM,aAAuB,EAAE;AAE/B,MAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,SAAS,EAAE;EAC/C,MAAM,SAAS;AACf,OAAK,MAAM,OAAO,wBAChB,KACE,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI,IACjD,OAAO,SAAS,OAEhB,YAAW,KACT,GAAG,IAAI,aAAa,MAAM,KAAK,OAAO,YAAY,OAAO,IAAI,GAC9D;;AAKP,KAAI,WAAW,SAAS,EACtB,OAAM,IAAI,MACR,qCAAqC,WAAW,KAAK,KAAK,CAAC,IACtD,4BAA4B,oEACK,sBAAsB,GAC7D;AAGH,QAAO,QACJ,QAAQ,WAAW,CAAC,OAAO,WAAW,OAAO,YAAY,QAAQ,CACjE,KAAK,EAAE,SAAS,UAAU,GAAG,aAAa,OAA0B"}