{"version":3,"sources":["../../../../src/server/mcp/tools/get-server-action-by-id.ts"],"sourcesContent":["import type { McpServer } from 'next/dist/compiled/@modelcontextprotocol/sdk/server/mcp'\nimport { z } from 'next/dist/compiled/zod'\nimport { promises as fs } from 'fs'\nimport { join } from 'path'\nimport { mcpTelemetryTracker } from '../mcp-telemetry-tracker'\n\nconst INLINE_ACTION_PREFIX = '$$RSC_SERVER_ACTION_'\n\ninterface ActionEntry {\n workers?: Record\n layer?: Record\n filename: string\n exportedName: string\n}\n\ninterface ServerReferenceManifest {\n node: Record\n edge: Record\n encryptionKey: string\n}\n\nexport function registerGetActionByIdTool(server: McpServer, distDir: string) {\n server.registerTool(\n 'get_server_action_by_id',\n {\n description:\n 'Locates a Server Action by its ID in the server-reference-manifest.json. Returns the filename and export name for the action.',\n inputSchema: {\n actionId: z.string(),\n },\n },\n async (request) => {\n // Track telemetry\n mcpTelemetryTracker.recordToolCall('mcp/get_server_action_by_id')\n\n try {\n const { actionId } = request\n\n if (!actionId) {\n return {\n content: [\n {\n type: 'text',\n text: 'Error: actionId parameter is required',\n },\n ],\n }\n }\n\n const manifestPath = join(\n distDir,\n 'server',\n 'server-reference-manifest.json'\n )\n\n let manifestContent: string\n try {\n manifestContent = await fs.readFile(manifestPath, 'utf-8')\n } catch (error) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: Could not read server-reference-manifest.json at ${manifestPath}.`,\n },\n ],\n }\n }\n\n const manifest: ServerReferenceManifest = JSON.parse(manifestContent)\n\n // Search in node entries\n if (manifest.node && manifest.node[actionId]) {\n const entry = manifest.node[actionId]\n const isInlineAction =\n entry.exportedName.startsWith(INLINE_ACTION_PREFIX)\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(\n {\n actionId,\n runtime: 'node',\n filename: entry.filename,\n functionName: isInlineAction\n ? 'inline server action'\n : entry.exportedName,\n layer: entry.layer,\n workers: entry.workers,\n },\n null,\n 2\n ),\n },\n ],\n }\n }\n\n // Search in edge entries\n if (manifest.edge && manifest.edge[actionId]) {\n const entry = manifest.edge[actionId]\n const isInlineAction =\n entry.exportedName.startsWith(INLINE_ACTION_PREFIX)\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(\n {\n actionId,\n runtime: 'edge',\n filename: entry.filename,\n functionName: isInlineAction\n ? 'inline server action'\n : entry.exportedName,\n layer: entry.layer,\n workers: entry.workers,\n },\n null,\n 2\n ),\n },\n ],\n }\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Error: Action ID \"${actionId}\" not found in server-reference-manifest.json`,\n },\n ],\n }\n } catch (error) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: ${error instanceof Error ? error.message : String(error)}`,\n },\n ],\n }\n }\n }\n )\n}\n"],"names":["z","promises","fs","join","mcpTelemetryTracker","INLINE_ACTION_PREFIX","registerGetActionByIdTool","server","distDir","registerTool","description","inputSchema","actionId","string","request","recordToolCall","content","type","text","manifestPath","manifestContent","readFile","error","manifest","JSON","parse","node","entry","isInlineAction","exportedName","startsWith","stringify","runtime","filename","functionName","layer","workers","edge","Error","message","String"],"mappings":"AACA,SAASA,CAAC,QAAQ,yBAAwB;AAC1C,SAASC,YAAYC,EAAE,QAAQ,KAAI;AACnC,SAASC,IAAI,QAAQ,OAAM;AAC3B,SAASC,mBAAmB,QAAQ,2BAA0B;AAE9D,MAAMC,uBAAuB;AAe7B,OAAO,SAASC,0BAA0BC,MAAiB,EAAEC,OAAe;IAC1ED,OAAOE,YAAY,CACjB,2BACA;QACEC,aACE;QACFC,aAAa;YACXC,UAAUZ,EAAEa,MAAM;QACpB;IACF,GACA,OAAOC;QACL,kBAAkB;QAClBV,oBAAoBW,cAAc,CAAC;QAEnC,IAAI;YACF,MAAM,EAAEH,QAAQ,EAAE,GAAGE;YAErB,IAAI,CAACF,UAAU;gBACb,OAAO;oBACLI,SAAS;wBACP;4BACEC,MAAM;4BACNC,MAAM;wBACR;qBACD;gBACH;YACF;YAEA,MAAMC,eAAehB,KACnBK,SACA,UACA;YAGF,IAA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