File size: 4,684 Bytes
c592d77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "registerGetActionByIdTool", {
    enumerable: true,
    get: function() {
        return registerGetActionByIdTool;
    }
});
const _zod = require("next/dist/compiled/zod");
const _fs = require("fs");
const _path = require("path");
const _mcptelemetrytracker = require("../mcp-telemetry-tracker");
const INLINE_ACTION_PREFIX = '$$RSC_SERVER_ACTION_';
function registerGetActionByIdTool(server, distDir) {
    server.registerTool('get_server_action_by_id', {
        description: 'Locates a Server Action by its ID in the server-reference-manifest.json. Returns the filename and export name for the action.',
        inputSchema: {
            actionId: _zod.z.string()
        }
    }, async (request)=>{
        // Track telemetry
        _mcptelemetrytracker.mcpTelemetryTracker.recordToolCall('mcp/get_server_action_by_id');
        try {
            const { actionId } = request;
            if (!actionId) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({
                                error: 'actionId parameter is required'
                            })
                        }
                    ]
                };
            }
            const manifestPath = (0, _path.join)(distDir, 'server', 'server-reference-manifest.json');
            let manifestContent;
            try {
                manifestContent = await _fs.promises.readFile(manifestPath, 'utf-8');
            } catch (error) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({
                                error: `Could not read server-reference-manifest.json at ${manifestPath}.`
                            })
                        }
                    ]
                };
            }
            const manifest = JSON.parse(manifestContent);
            // Search in node entries
            if (manifest.node && manifest.node[actionId]) {
                const entry = manifest.node[actionId];
                const isInlineAction = entry.exportedName.startsWith(INLINE_ACTION_PREFIX);
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({
                                actionId,
                                runtime: 'node',
                                filename: entry.filename,
                                functionName: isInlineAction ? 'inline server action' : entry.exportedName,
                                layer: entry.layer,
                                workers: entry.workers
                            }, null, 2)
                        }
                    ]
                };
            }
            // Search in edge entries
            if (manifest.edge && manifest.edge[actionId]) {
                const entry = manifest.edge[actionId];
                const isInlineAction = entry.exportedName.startsWith(INLINE_ACTION_PREFIX);
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({
                                actionId,
                                runtime: 'edge',
                                filename: entry.filename,
                                functionName: isInlineAction ? 'inline server action' : entry.exportedName,
                                layer: entry.layer,
                                workers: entry.workers
                            }, null, 2)
                        }
                    ]
                };
            }
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            error: `Action ID "${actionId}" not found in server-reference-manifest.json`
                        })
                    }
                ]
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            error: error instanceof Error ? error.message : String(error)
                        })
                    }
                ]
            };
        }
    });
}

//# sourceMappingURL=get-server-action-by-id.js.map