@adiholick/nvstudio-mcp 2.2.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -35,166 +35,797 @@ const server = new index_js_1.Server({
35
35
  tools: {},
36
36
  },
37
37
  });
38
- // 3 & 4. Daftarkan tool call_mcp_tool dan definisikan schema parameternya
39
- server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
40
- return {
41
- tools: [
42
- {
43
- name: "call_mcp_tool",
44
- description: "ALAT MUTLAK UNTUK ROBLOX. Command: patch_script_source, get_children, get_full_tree, get_script_source, update_script_source, rollback_script, get_logs, create_instance, search_instance, generate_terrain, insert_asset, delete_instance, get_properties, set_properties, script_grep, execute_luau, search_asset.",
45
- inputSchema: {
38
+ // 3. Definisi Semantic Tools MCP untuk Roblox Studio
39
+ const TOOLS = [
40
+ {
41
+ name: "execute_luau",
42
+ description: "Eksekusi kode Luau sembarang secara langsung di Roblox Studio dan kembalikan output/hasilnya (mendukung return table, primitif, dan console log).",
43
+ inputSchema: {
44
+ type: "object",
45
+ properties: {
46
+ code: {
47
+ type: "string",
48
+ description: "Kode Luau yang akan dieksekusi di Roblox Studio.",
49
+ },
50
+ target: {
51
+ type: "string",
52
+ description: "Path opsional objek target (contoh: 'Workspace.Map').",
53
+ },
54
+ placeId: {
55
+ type: "number",
56
+ description: "Place ID Roblox tujuan jika membuka beberapa Studio (multi-Studio routing).",
57
+ },
58
+ studioId: {
59
+ type: "string",
60
+ description: "Session ID Studio spesifik jika diketahui.",
61
+ },
62
+ },
63
+ required: ["code"],
64
+ },
65
+ },
66
+ {
67
+ name: "get_children",
68
+ description: "Ambil daftar child langsung (nama dan ClassName) dari suatu Instance di Roblox Studio.",
69
+ inputSchema: {
70
+ type: "object",
71
+ properties: {
72
+ target: {
73
+ type: "string",
74
+ description: "Path absolut dari objek target di Roblox (contoh: 'Workspace', 'ReplicatedStorage.Modules').",
75
+ },
76
+ placeId: {
77
+ type: "number",
78
+ description: "Target Place ID untuk multi-Studio routing.",
79
+ },
80
+ studioId: {
81
+ type: "string",
82
+ description: "Target Studio session ID.",
83
+ },
84
+ },
85
+ required: ["target"],
86
+ },
87
+ },
88
+ {
89
+ name: "get_full_tree",
90
+ description: "Ambil struktur hierarki pohon instance secara rekursif hingga kedalaman (depth) tertentu.",
91
+ inputSchema: {
92
+ type: "object",
93
+ properties: {
94
+ target: {
95
+ type: "string",
96
+ description: "Path root objek untuk hierarki (contoh: 'Workspace', 'StarterGui').",
97
+ },
98
+ max_depth: {
99
+ type: "number",
100
+ description: "Kedalaman maksimal penelusuran hierarki (default: 2).",
101
+ },
102
+ placeId: {
103
+ type: "number",
104
+ description: "Target Place ID untuk multi-Studio routing.",
105
+ },
106
+ studioId: {
107
+ type: "string",
108
+ description: "Target Studio session ID.",
109
+ },
110
+ },
111
+ required: ["target"],
112
+ },
113
+ },
114
+ {
115
+ name: "get_script_source",
116
+ description: "Baca seluruh isi source code Luau dari sebuah Script, LocalScript, atau ModuleScript.",
117
+ inputSchema: {
118
+ type: "object",
119
+ properties: {
120
+ target: {
121
+ type: "string",
122
+ description: "Path absolut ke Script target (contoh: 'ServerScriptService.GameManager').",
123
+ },
124
+ placeId: {
125
+ type: "number",
126
+ description: "Target Place ID untuk multi-Studio routing.",
127
+ },
128
+ studioId: {
129
+ type: "string",
130
+ description: "Target Studio session ID.",
131
+ },
132
+ },
133
+ required: ["target"],
134
+ },
135
+ },
136
+ {
137
+ name: "update_script_source",
138
+ description: "Ganti seluruh isi source code script dengan kode baru. Dilengkapi validasi sintaks otomatis (AST check) dan riwayat rollback.",
139
+ inputSchema: {
140
+ type: "object",
141
+ properties: {
142
+ target: {
143
+ type: "string",
144
+ description: "Path absolut ke Script target (contoh: 'ServerScriptService.MainHandler').",
145
+ },
146
+ code: {
147
+ type: "string",
148
+ description: "Source code Luau baru yang akan ditulis.",
149
+ },
150
+ placeId: {
151
+ type: "number",
152
+ description: "Target Place ID untuk multi-Studio routing.",
153
+ },
154
+ studioId: {
155
+ type: "string",
156
+ description: "Target Studio session ID.",
157
+ },
158
+ },
159
+ required: ["target", "code"],
160
+ },
161
+ },
162
+ {
163
+ name: "patch_script_source",
164
+ description: "Ganti bagian tertentu dari source code script (search and replace chunk) tanpa menimpa seluruh file.",
165
+ inputSchema: {
166
+ type: "object",
167
+ properties: {
168
+ target: {
169
+ type: "string",
170
+ description: "Path absolut ke Script target.",
171
+ },
172
+ target_content: {
173
+ type: "string",
174
+ description: "Potongan kode lama yang ingin diganti (persis karakter per karakter).",
175
+ },
176
+ replacement_content: {
177
+ type: "string",
178
+ description: "Potongan kode baru sebagai pengganti.",
179
+ },
180
+ allow_multiple: {
181
+ type: "boolean",
182
+ description: "Jika true, ganti semua kemunculan alih-alih hanya kemunculan pertama (default: false).",
183
+ },
184
+ placeId: {
185
+ type: "number",
186
+ description: "Target Place ID untuk multi-Studio routing.",
187
+ },
188
+ studioId: {
189
+ type: "string",
190
+ description: "Target Studio session ID.",
191
+ },
192
+ },
193
+ required: ["target", "target_content", "replacement_content"],
194
+ },
195
+ },
196
+ {
197
+ name: "rollback_script",
198
+ description: "Kembalikan source code script ke versi sebelumnya dari riwayat backup sesi saat ini.",
199
+ inputSchema: {
200
+ type: "object",
201
+ properties: {
202
+ target: {
203
+ type: "string",
204
+ description: "Path absolut ke Script yang ingin di-rollback.",
205
+ },
206
+ placeId: {
207
+ type: "number",
208
+ description: "Target Place ID untuk multi-Studio routing.",
209
+ },
210
+ studioId: {
211
+ type: "string",
212
+ description: "Target Studio session ID.",
213
+ },
214
+ },
215
+ required: ["target"],
216
+ },
217
+ },
218
+ {
219
+ name: "get_properties",
220
+ description: "Ambil properti umum, attributes, dan tags dari suatu Instance di Roblox Studio.",
221
+ inputSchema: {
222
+ type: "object",
223
+ properties: {
224
+ target: {
225
+ type: "string",
226
+ description: "Path absolut ke Instance (contoh: 'Workspace.Baseplate', 'Lighting').",
227
+ },
228
+ placeId: {
229
+ type: "number",
230
+ description: "Target Place ID untuk multi-Studio routing.",
231
+ },
232
+ studioId: {
233
+ type: "string",
234
+ description: "Target Studio session ID.",
235
+ },
236
+ },
237
+ required: ["target"],
238
+ },
239
+ },
240
+ {
241
+ name: "set_properties",
242
+ description: "Ubah properti dari suatu Instance di Roblox Studio menggunakan key-value JSON.",
243
+ inputSchema: {
244
+ type: "object",
245
+ properties: {
246
+ target: {
247
+ type: "string",
248
+ description: "Path absolut ke Instance target (contoh: 'Workspace.Part').",
249
+ },
250
+ properties: {
46
251
  type: "object",
47
- properties: {
48
- command: {
49
- type: "string",
50
- description: "Perintah yang dieksekusi (contoh: 'set_properties', 'get_full_tree', 'patch_script_source').",
51
- },
52
- target: {
53
- type: "string",
54
- description: "Path absolut dari objek target di Roblox Studio (contoh: 'Workspace.Map.Script').",
55
- },
56
- data: {
57
- type: "string",
58
- description: "Data tambahan. Untuk set_properties: JSON string dari properti. Untuk delete_instance: kirim 'force' jika descendants > 10. Untuk patch/update: source code.",
59
- },
60
- },
61
- required: ["command"],
62
- },
63
- },
64
- ],
65
- };
66
- });
67
- // 5. Handler untuk menangani pemanggilan call_mcp_tool
68
- server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
69
- await roblox_bridge_1.bridgeReadyPromise;
70
- if (request.params.name !== "call_mcp_tool") {
71
- throw new Error(`Tool tidak dikenali: ${request.params.name}`);
72
- }
73
- const args = request.params.arguments;
74
- const { command, target, data } = args;
75
- if (!command) {
76
- return {
77
- content: [
78
- {
79
- type: "text",
80
- text: JSON.stringify({
81
- status: "error",
82
- error: "Parameter 'command' wajib diisi.",
83
- }),
252
+ description: "Objek key-value properti (contoh: { \"Anchored\": true, \"Size\": [10, 2, 10], \"Color\": [255, 0, 0] }).",
84
253
  },
85
- ],
86
- isError: true,
87
- };
88
- }
89
- // Pre-commit validation for full source replacement
90
- if (command === "update_script_source" && data) {
91
- const validation = (0, luau_validator_1.validateLuauSyntax)(String(data));
92
- if (!validation.valid) {
93
- return {
94
- content: [{
95
- type: "text",
96
- text: JSON.stringify({
97
- status: "error",
98
- error: `Syntax error terdeteksi (Pre-commit check Node.js): ${validation.error} pada baris ${validation.line || 'unknown'}`
99
- })
100
- }],
101
- isError: true
102
- };
254
+ placeId: {
255
+ type: "number",
256
+ description: "Target Place ID untuk multi-Studio routing.",
257
+ },
258
+ studioId: {
259
+ type: "string",
260
+ description: "Target Studio session ID.",
261
+ },
262
+ },
263
+ required: ["target", "properties"],
264
+ },
265
+ },
266
+ {
267
+ name: "create_instance",
268
+ description: "Buat Instance baru di Roblox Studio di bawah parent target dengan ClassName dan properti awal opsional.",
269
+ inputSchema: {
270
+ type: "object",
271
+ properties: {
272
+ class_name: {
273
+ type: "string",
274
+ description: "ClassName Roblox (contoh: 'Part', 'Folder', 'RemoteEvent', 'Script').",
275
+ },
276
+ target: {
277
+ type: "string",
278
+ description: "Path parent tempat Instance akan dibuat (contoh: 'Workspace', 'ReplicatedStorage').",
279
+ },
280
+ properties: {
281
+ type: "object",
282
+ description: "Properti awal opsional yang disetel saat instance dibuat.",
283
+ },
284
+ placeId: {
285
+ type: "number",
286
+ description: "Target Place ID untuk multi-Studio routing.",
287
+ },
288
+ studioId: {
289
+ type: "string",
290
+ description: "Target Studio session ID.",
291
+ },
292
+ },
293
+ required: ["class_name", "target"],
294
+ },
295
+ },
296
+ {
297
+ name: "delete_instance",
298
+ description: "Hapus (Destroy) Instance dari game. Service utama dilindungi guardrail dan objek dengan >10 descendant memerlukan force: true.",
299
+ inputSchema: {
300
+ type: "object",
301
+ properties: {
302
+ target: {
303
+ type: "string",
304
+ description: "Path absolut ke Instance yang ingin dihapus.",
305
+ },
306
+ force: {
307
+ type: "boolean",
308
+ description: "Wajib disetel ke true jika instance memiliki lebih dari 10 descendants.",
309
+ },
310
+ placeId: {
311
+ type: "number",
312
+ description: "Target Place ID untuk multi-Studio routing.",
313
+ },
314
+ studioId: {
315
+ type: "string",
316
+ description: "Target Studio session ID.",
317
+ },
318
+ },
319
+ required: ["target"],
320
+ },
321
+ },
322
+ {
323
+ name: "search_instance",
324
+ description: "Cari Instance berdasarkan nama atau substring di dalam hierarki Roblox Studio.",
325
+ inputSchema: {
326
+ type: "object",
327
+ properties: {
328
+ query: {
329
+ type: "string",
330
+ description: "Nama atau substring instance yang dicari.",
331
+ },
332
+ target: {
333
+ type: "string",
334
+ description: "Scope root opsional tempat mencari (default: seluruh service utama).",
335
+ },
336
+ placeId: {
337
+ type: "number",
338
+ description: "Target Place ID untuk multi-Studio routing.",
339
+ },
340
+ studioId: {
341
+ type: "string",
342
+ description: "Target Studio session ID.",
343
+ },
344
+ },
345
+ required: ["query"],
346
+ },
347
+ },
348
+ {
349
+ name: "generate_terrain",
350
+ description: "Generate blok voxel terrain di Workspace.Terrain dengan material, posisi, dan ukuran tertentu.",
351
+ inputSchema: {
352
+ type: "object",
353
+ properties: {
354
+ material: {
355
+ type: "string",
356
+ description: "Nama material terrain (contoh: 'Grass', 'Water', 'Sand', 'Rock', 'Snow').",
357
+ },
358
+ position: {
359
+ type: "array",
360
+ items: { type: "number" },
361
+ description: "Posisi voxel region [X, Y, Z].",
362
+ },
363
+ size: {
364
+ type: "array",
365
+ items: { type: "number" },
366
+ description: "Ukuran dimensi voxel region [X, Y, Z].",
367
+ },
368
+ placeId: {
369
+ type: "number",
370
+ description: "Target Place ID untuk multi-Studio routing.",
371
+ },
372
+ studioId: {
373
+ type: "string",
374
+ description: "Target Studio session ID.",
375
+ },
376
+ },
377
+ required: ["material", "position", "size"],
378
+ },
379
+ },
380
+ {
381
+ name: "insert_asset",
382
+ description: "Muat dan masukkan aset Roblox (Model/Package) berdasarkan Asset ID ke dalam Workspace atau target tertentu.",
383
+ inputSchema: {
384
+ type: "object",
385
+ properties: {
386
+ asset_id: {
387
+ type: "string",
388
+ description: "Roblox Asset ID angka (atau rbxassetid://).",
389
+ },
390
+ target: {
391
+ type: "string",
392
+ description: "Parent tujuan tempat menempatkan model (default: 'Workspace').",
393
+ },
394
+ placeId: {
395
+ type: "number",
396
+ description: "Target Place ID untuk multi-Studio routing.",
397
+ },
398
+ studioId: {
399
+ type: "string",
400
+ description: "Target Studio session ID.",
401
+ },
402
+ },
403
+ required: ["asset_id"],
404
+ },
405
+ },
406
+ {
407
+ name: "search_asset",
408
+ description: "Cari aset publik di Roblox Creator Store / Marketplace (Model, Audio, Decal, Image).",
409
+ inputSchema: {
410
+ type: "object",
411
+ properties: {
412
+ keyword: {
413
+ type: "string",
414
+ description: "Kata kunci pencarian aset.",
415
+ },
416
+ category: {
417
+ type: "string",
418
+ enum: ["Model", "Audio", "Decal", "Image"],
419
+ description: "Kategori aset yang dicari (default: 'Model').",
420
+ },
421
+ },
422
+ required: ["keyword"],
423
+ },
424
+ },
425
+ {
426
+ name: "script_grep",
427
+ description: "Cari teks atau pola (pattern) di dalam seluruh script di dalam game (Workspace, ServerScriptService, dll.).",
428
+ inputSchema: {
429
+ type: "object",
430
+ properties: {
431
+ query: {
432
+ type: "string",
433
+ description: "String atau pola teks yang ingin dicari di baris kode.",
434
+ },
435
+ target: {
436
+ type: "string",
437
+ description: "Scope root opsional tempat mencari script.",
438
+ },
439
+ placeId: {
440
+ type: "number",
441
+ description: "Target Place ID untuk multi-Studio routing.",
442
+ },
443
+ studioId: {
444
+ type: "string",
445
+ description: "Target Studio session ID.",
446
+ },
447
+ },
448
+ required: ["query"],
449
+ },
450
+ },
451
+ {
452
+ name: "get_logs",
453
+ description: "Ambil log konsol / output terbaru Roblox Studio yang ditangkap oleh plugin.",
454
+ inputSchema: {
455
+ type: "object",
456
+ properties: {
457
+ placeId: {
458
+ type: "number",
459
+ description: "Target Place ID untuk multi-Studio routing.",
460
+ },
461
+ studioId: {
462
+ type: "string",
463
+ description: "Target Studio session ID.",
464
+ },
465
+ },
466
+ },
467
+ },
468
+ {
469
+ name: "list_connected_studios",
470
+ description: "Lihat daftar seluruh sesi Roblox Studio yang sedang terhubung ke Bridge Server, Place ID masing-masing, status koneksi, dan transport (WebSocket/Long-Polling).",
471
+ inputSchema: {
472
+ type: "object",
473
+ properties: {},
474
+ },
475
+ },
476
+ {
477
+ name: "call_mcp_tool",
478
+ description: "Legacy tool dispatcher untuk kompatibilitas mundur. Mendukung semua command: execute_luau, get_children, get_full_tree, get_script_source, update_script_source, patch_script_source, rollback_script, get_properties, set_properties, create_instance, delete_instance, search_instance, generate_terrain, insert_asset, search_asset, script_grep, get_logs.",
479
+ inputSchema: {
480
+ type: "object",
481
+ properties: {
482
+ command: {
483
+ type: "string",
484
+ description: "Nama perintah yang dieksekusi.",
485
+ },
486
+ target: {
487
+ type: "string",
488
+ description: "Path objek target di Roblox Studio.",
489
+ },
490
+ data: {
491
+ type: "string",
492
+ description: "Data tambahan sesuai command.",
493
+ },
494
+ placeId: {
495
+ type: "number",
496
+ description: "Target Place ID untuk multi-Studio routing.",
497
+ },
498
+ studioId: {
499
+ type: "string",
500
+ description: "Target Studio session ID.",
501
+ },
502
+ },
503
+ required: ["command"],
504
+ },
505
+ },
506
+ ];
507
+ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
508
+ return { tools: TOOLS };
509
+ });
510
+ /**
511
+ * Dispatcher pusat untuk meneruskan task ke Roblox Studio (Bridge Hosting lokal atau eksternal).
512
+ */
513
+ async function dispatchTaskToStudio(command, target, data, options) {
514
+ const placeId = options?.placeId;
515
+ const studioId = options?.studioId;
516
+ if (roblox_bridge_1.isBridgeHosting) {
517
+ if (!(0, roblox_bridge_1.isStudioConnected)({ placeId, studioId })) {
518
+ for (let i = 0; i < 10; i++) {
519
+ await new Promise(r => setTimeout(r, 50));
520
+ if ((0, roblox_bridge_1.isStudioConnected)({ placeId, studioId }))
521
+ break;
522
+ }
523
+ if (!(0, roblox_bridge_1.isStudioConnected)({ placeId, studioId })) {
524
+ const errorMsg = placeId !== undefined
525
+ ? `Roblox Studio dengan Place ID ${placeId} tidak terdeteksi aktif. Studio yang saat ini terhubung: ${JSON.stringify((0, roblox_bridge_1.getConnectedStudios)())}`
526
+ : "Roblox Studio tidak terdeteksi aktif. Pastikan Roblox Studio dibuka, place telah dimuat, dan plugin nvstudio-mcp dalam status terhubung.";
527
+ throw new Error(errorMsg);
528
+ }
103
529
  }
530
+ return await (0, task_queue_1.addTaskToQueue)(command, target, data, { placeId, studioId });
104
531
  }
105
- // Intercept command yang dieksekusi di server lokal (Node.js) alih-alih di Studio
106
- if (command === "search_asset" && data) {
532
+ else {
533
+ let forwardedToBridge = false;
107
534
  try {
108
- const queryParams = typeof data === "string" ? JSON.parse(data) : data;
109
- const keyword = encodeURIComponent(queryParams.keyword || "");
110
- let assetType = "10"; // Default: Model
111
- if (queryParams.category === "Audio") {
112
- assetType = "9"; // Audio
113
- }
114
- else if (queryParams.category === "Decal" || queryParams.category === "Image") {
115
- assetType = "13"; // Decal
116
- }
117
- const url = `https://catalog.roblox.com/v1/search/items?category=All&keyword=${keyword}&limit=10&itemTypes=Asset&assetTypes=${assetType}`;
118
- const res = await fetch(url);
119
- const jsonRes = await res.json();
120
- return {
121
- content: [
122
- {
123
- type: "text",
124
- text: JSON.stringify({
125
- status: "success",
126
- result: jsonRes.data || jsonRes
127
- }, null, 2)
128
- }
129
- ]
130
- };
535
+ const controller = new AbortController();
536
+ const timeoutId = setTimeout(() => controller.abort(), 35000);
537
+ const bridgeRes = await fetch("http://localhost:3055/api/tasks/enqueue", {
538
+ method: "POST",
539
+ headers: { "Content-Type": "application/json" },
540
+ body: JSON.stringify({ command, target, data, placeId, studioId }),
541
+ signal: controller.signal,
542
+ });
543
+ clearTimeout(timeoutId);
544
+ if (bridgeRes.ok) {
545
+ forwardedToBridge = true;
546
+ const bridgeJson = (await bridgeRes.json());
547
+ if (bridgeJson.status === "error") {
548
+ throw new Error(bridgeJson.error);
549
+ }
550
+ return bridgeJson.result;
551
+ }
552
+ else {
553
+ throw new Error(`Bridge server returned HTTP ${bridgeRes.status}`);
554
+ }
131
555
  }
132
556
  catch (err) {
133
- return {
134
- content: [{ type: "text", text: JSON.stringify({ status: "error", error: "Gagal mencari aset: " + err.message }) }],
135
- isError: true
136
- };
557
+ if (forwardedToBridge)
558
+ throw err;
559
+ throw new Error("Gagal menghubungi server Bridge. Pastikan server daemon berjalan di port 3055.");
137
560
  }
138
561
  }
139
- // 8. Teruskan ke antrean tugas
562
+ }
563
+ /**
564
+ * Helper untuk mengeksekusi pencarian aset di katalog web Roblox.
565
+ */
566
+ async function handleSearchAsset(keyword, category = "Model") {
567
+ const encodedKeyword = encodeURIComponent(keyword || "");
568
+ let assetType = "10"; // Default: Model
569
+ if (category === "Audio") {
570
+ assetType = "9";
571
+ }
572
+ else if (category === "Decal" || category === "Image") {
573
+ assetType = "13";
574
+ }
575
+ const url = `https://catalog.roblox.com/v1/search/items?category=All&keyword=${encodedKeyword}&limit=10&itemTypes=Asset&assetTypes=${assetType}`;
576
+ const res = await fetch(url);
577
+ const jsonRes = await res.json();
578
+ return jsonRes.data || jsonRes;
579
+ }
580
+ // 4. Handler untuk memproses panggilan tools
581
+ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
582
+ await roblox_bridge_1.bridgeReadyPromise;
583
+ const toolName = request.params.name;
584
+ const args = (request.params.arguments || {});
140
585
  try {
141
586
  let result;
142
- if (roblox_bridge_1.isBridgeHosting) {
143
- // Instance ini sendiri yang meng-host bridge server
144
- if (!(0, roblox_bridge_1.isStudioConnected)()) {
145
- for (let i = 0; i < 6; i++) {
146
- await new Promise(r => setTimeout(r, 50));
147
- if ((0, roblox_bridge_1.isStudioConnected)())
148
- break;
149
- }
150
- if (!(0, roblox_bridge_1.isStudioConnected)()) {
151
- return {
152
- content: [
153
- {
154
- type: "text",
155
- text: JSON.stringify({
156
- status: "error",
157
- error: "Roblox Studio tidak terdeteksi aktif. Pastikan Roblox Studio dibuka, place telah dimuat, dan plugin nvstudio-mcp dalam status terhubung.",
158
- }),
159
- },
160
- ],
161
- isError: true,
162
- };
587
+ switch (toolName) {
588
+ case "execute_luau": {
589
+ const code = String(args.code ?? "");
590
+ if (!code)
591
+ throw new Error("Parameter 'code' wajib diisi.");
592
+ result = await dispatchTaskToStudio("execute_luau", args.target || "", code, {
593
+ placeId: args.placeId,
594
+ studioId: args.studioId,
595
+ });
596
+ break;
597
+ }
598
+ case "get_children": {
599
+ const target = String(args.target ?? "");
600
+ if (!target)
601
+ throw new Error("Parameter 'target' wajib diisi.");
602
+ result = await dispatchTaskToStudio("get_children", target, "", {
603
+ placeId: args.placeId,
604
+ studioId: args.studioId,
605
+ });
606
+ break;
607
+ }
608
+ case "get_full_tree": {
609
+ const target = String(args.target ?? "");
610
+ if (!target)
611
+ throw new Error("Parameter 'target' wajib diisi.");
612
+ const depth = String(args.max_depth ?? 2);
613
+ result = await dispatchTaskToStudio("get_full_tree", target, depth, {
614
+ placeId: args.placeId,
615
+ studioId: args.studioId,
616
+ });
617
+ break;
618
+ }
619
+ case "get_script_source": {
620
+ const target = String(args.target ?? "");
621
+ if (!target)
622
+ throw new Error("Parameter 'target' wajib diisi.");
623
+ result = await dispatchTaskToStudio("get_script_source", target, "", {
624
+ placeId: args.placeId,
625
+ studioId: args.studioId,
626
+ });
627
+ break;
628
+ }
629
+ case "update_script_source": {
630
+ const target = String(args.target ?? "");
631
+ const code = String(args.code ?? "");
632
+ if (!target)
633
+ throw new Error("Parameter 'target' wajib diisi.");
634
+ // Pre-commit AST syntax check di Node.js
635
+ const validation = (0, luau_validator_1.validateLuauSyntax)(code);
636
+ if (!validation.valid) {
637
+ throw new Error(`Syntax error terdeteksi (Pre-commit check Node.js): ${validation.error} pada baris ${validation.line || 'unknown'}`);
163
638
  }
639
+ backupScript(target, code);
640
+ result = await dispatchTaskToStudio("update_script_source", target, code, {
641
+ placeId: args.placeId,
642
+ studioId: args.studioId,
643
+ });
644
+ break;
164
645
  }
165
- result = await (0, task_queue_1.addTaskToQueue)(command, target, data);
166
- }
167
- else {
168
- // Bridge server aktif di proses background lain (port 3055)
169
- let forwardedToBridge = false;
170
- try {
171
- const controller = new AbortController();
172
- const timeoutId = setTimeout(() => controller.abort(), 35000);
173
- const bridgeRes = await fetch("http://localhost:3055/api/tasks/enqueue", {
174
- method: "POST",
175
- headers: { "Content-Type": "application/json" },
176
- body: JSON.stringify({ command, target, data }),
177
- signal: controller.signal
178
- });
179
- clearTimeout(timeoutId);
180
- if (bridgeRes.ok) {
181
- forwardedToBridge = true;
182
- const bridgeJson = await bridgeRes.json();
183
- if (bridgeJson.status === "error") {
184
- throw new Error(bridgeJson.error);
185
- }
186
- result = bridgeJson.result;
646
+ case "patch_script_source": {
647
+ const target = String(args.target ?? "");
648
+ if (!target)
649
+ throw new Error("Parameter 'target' wajib diisi.");
650
+ if (!args.target_content)
651
+ throw new Error("Parameter 'target_content' wajib diisi.");
652
+ if (args.replacement_content === undefined)
653
+ throw new Error("Parameter 'replacement_content' wajib diisi.");
654
+ const payload = JSON.stringify({
655
+ target_content: args.target_content,
656
+ replacement_content: args.replacement_content,
657
+ allow_multiple: !!args.allow_multiple,
658
+ });
659
+ result = await dispatchTaskToStudio("patch_script_source", target, payload, {
660
+ placeId: args.placeId,
661
+ studioId: args.studioId,
662
+ });
663
+ break;
664
+ }
665
+ case "rollback_script": {
666
+ const target = String(args.target ?? "");
667
+ if (!target)
668
+ throw new Error("Parameter 'target' wajib diisi.");
669
+ result = await dispatchTaskToStudio("rollback_script", target, "", {
670
+ placeId: args.placeId,
671
+ studioId: args.studioId,
672
+ });
673
+ break;
674
+ }
675
+ case "get_properties": {
676
+ const target = String(args.target ?? "");
677
+ if (!target)
678
+ throw new Error("Parameter 'target' wajib diisi.");
679
+ result = await dispatchTaskToStudio("get_properties", target, "", {
680
+ placeId: args.placeId,
681
+ studioId: args.studioId,
682
+ });
683
+ break;
684
+ }
685
+ case "set_properties": {
686
+ const target = String(args.target ?? "");
687
+ if (!target)
688
+ throw new Error("Parameter 'target' wajib diisi.");
689
+ if (!args.properties)
690
+ throw new Error("Parameter 'properties' wajib diisi.");
691
+ const propsData = typeof args.properties === "string" ? args.properties : JSON.stringify(args.properties);
692
+ result = await dispatchTaskToStudio("set_properties", target, propsData, {
693
+ placeId: args.placeId,
694
+ studioId: args.studioId,
695
+ });
696
+ break;
697
+ }
698
+ case "create_instance": {
699
+ const className = String(args.class_name ?? "");
700
+ const target = String(args.target ?? "");
701
+ if (!className)
702
+ throw new Error("Parameter 'class_name' wajib diisi.");
703
+ if (!target)
704
+ throw new Error("Parameter 'target' wajib diisi.");
705
+ const payload = JSON.stringify({
706
+ ClassName: className,
707
+ Properties: args.properties || {},
708
+ });
709
+ result = await dispatchTaskToStudio("create_instance", target, payload, {
710
+ placeId: args.placeId,
711
+ studioId: args.studioId,
712
+ });
713
+ break;
714
+ }
715
+ case "delete_instance": {
716
+ const target = String(args.target ?? "");
717
+ if (!target)
718
+ throw new Error("Parameter 'target' wajib diisi.");
719
+ const data = args.force ? "force" : "";
720
+ result = await dispatchTaskToStudio("delete_instance", target, data, {
721
+ placeId: args.placeId,
722
+ studioId: args.studioId,
723
+ });
724
+ break;
725
+ }
726
+ case "search_instance": {
727
+ const query = String(args.query ?? "");
728
+ if (!query)
729
+ throw new Error("Parameter 'query' wajib diisi.");
730
+ result = await dispatchTaskToStudio("search_instance", args.target || "", query, {
731
+ placeId: args.placeId,
732
+ studioId: args.studioId,
733
+ });
734
+ break;
735
+ }
736
+ case "generate_terrain": {
737
+ const material = String(args.material ?? "");
738
+ if (!material)
739
+ throw new Error("Parameter 'material' wajib diisi.");
740
+ if (!args.position || !Array.isArray(args.position))
741
+ throw new Error("Parameter 'position' [X, Y, Z] wajib diisi.");
742
+ if (!args.size || !Array.isArray(args.size))
743
+ throw new Error("Parameter 'size' [X, Y, Z] wajib diisi.");
744
+ const payload = JSON.stringify({
745
+ Material: material,
746
+ Position: args.position,
747
+ Size: args.size,
748
+ });
749
+ result = await dispatchTaskToStudio("generate_terrain", "", payload, {
750
+ placeId: args.placeId,
751
+ studioId: args.studioId,
752
+ });
753
+ break;
754
+ }
755
+ case "insert_asset": {
756
+ const assetId = String(args.asset_id ?? "");
757
+ if (!assetId)
758
+ throw new Error("Parameter 'asset_id' wajib diisi.");
759
+ result = await dispatchTaskToStudio("insert_asset", args.target || "Workspace", assetId, {
760
+ placeId: args.placeId,
761
+ studioId: args.studioId,
762
+ });
763
+ break;
764
+ }
765
+ case "search_asset": {
766
+ const keyword = String(args.keyword ?? "");
767
+ if (!keyword)
768
+ throw new Error("Parameter 'keyword' wajib diisi.");
769
+ result = await handleSearchAsset(keyword, args.category);
770
+ break;
771
+ }
772
+ case "script_grep": {
773
+ const query = String(args.query ?? "");
774
+ if (!query)
775
+ throw new Error("Parameter 'query' wajib diisi.");
776
+ result = await dispatchTaskToStudio("script_grep", args.target || "", query, {
777
+ placeId: args.placeId,
778
+ studioId: args.studioId,
779
+ });
780
+ break;
781
+ }
782
+ case "get_logs": {
783
+ result = await dispatchTaskToStudio("get_logs", "", "", {
784
+ placeId: args.placeId,
785
+ studioId: args.studioId,
786
+ });
787
+ break;
788
+ }
789
+ case "list_connected_studios": {
790
+ if (roblox_bridge_1.isBridgeHosting) {
791
+ result = (0, roblox_bridge_1.getConnectedStudios)();
187
792
  }
188
793
  else {
189
- throw new Error(`Bridge server returned HTTP ${bridgeRes.status}`);
794
+ try {
795
+ const statsRes = await fetch("http://localhost:3055/api/stats");
796
+ const statsJson = (await statsRes.json());
797
+ result = statsJson.connectedStudios || [];
798
+ }
799
+ catch {
800
+ result = [];
801
+ }
190
802
  }
803
+ break;
191
804
  }
192
- catch (err) {
193
- if (forwardedToBridge) {
194
- throw err;
805
+ case "call_mcp_tool": {
806
+ const { command, target, data, placeId, studioId } = args;
807
+ if (!command)
808
+ throw new Error("Parameter 'command' wajib diisi.");
809
+ // Pre-commit validation for full source replacement
810
+ if (command === "update_script_source" && data) {
811
+ const validation = (0, luau_validator_1.validateLuauSyntax)(String(data));
812
+ if (!validation.valid) {
813
+ throw new Error(`Syntax error terdeteksi (Pre-commit check Node.js): ${validation.error} pada baris ${validation.line || 'unknown'}`);
814
+ }
815
+ if (target)
816
+ backupScript(target, String(data));
817
+ }
818
+ // Intercept search_asset di Node.js
819
+ if (command === "search_asset" && data) {
820
+ const queryParams = typeof data === "string" ? JSON.parse(data) : data;
821
+ result = await handleSearchAsset(queryParams.keyword || "", queryParams.category);
822
+ break;
195
823
  }
196
- throw new Error("Gagal menghubungi server Bridge. Pastikan server daemon berjalan di port 3055.");
824
+ result = await dispatchTaskToStudio(command, target || "", data, { placeId, studioId });
825
+ break;
197
826
  }
827
+ default:
828
+ throw new Error(`Tool tidak dikenali: ${toolName}`);
198
829
  }
199
830
  return {
200
831
  content: [
@@ -220,27 +851,25 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
220
851
  };
221
852
  }
222
853
  });
223
- // 8. Jalankan koneksi MCP menggunakan StdioServerTransport (hanya jika bukan mode Daemon)
854
+ // 5. Jalankan koneksi MCP menggunakan StdioServerTransport (hanya jika bukan mode Daemon)
224
855
  async function main() {
225
856
  const transport = new stdio_js_1.StdioServerTransport();
226
857
  await server.connect(transport);
227
858
  console.error("[nvstudio-mcp] MCP Server aktif melalui StdioServerTransport.");
228
- // Beritahu SSE plugin bahwa MCP agent sekarang aktif
859
+ // Beritahu SSE/WS plugin bahwa MCP agent sekarang aktif
229
860
  (0, roblox_bridge_1.setMcpConnected)(true);
230
861
  let isShuttingDown = false;
231
862
  const shutdown = () => {
232
863
  if (isShuttingDown)
233
864
  return;
234
865
  isShuttingDown = true;
235
- (0, roblox_bridge_1.setMcpConnected)(false); // Beritahu SSE plugin bahwa MCP agent sudah menutup koneksi
866
+ (0, roblox_bridge_1.setMcpConnected)(false);
236
867
  console.error("[nvstudio-mcp] Koneksi ditutup oleh IDE. Mematikan server...");
237
868
  process.exit(0);
238
869
  };
239
- // Tangani penutupan koneksi stdin (ketika IDE menutup pipe)
240
870
  process.stdin.on('close', shutdown);
241
871
  process.stdin.on('end', shutdown);
242
872
  process.stdin.on('error', shutdown);
243
- // Fallback dihapus karena menyebabkan disconnect palsu di beberapa environment AGY
244
873
  }
245
874
  if (isDaemon) {
246
875
  console.error("[nvstudio-mcp] Berjalan dalam mode DAEMON (Background Bridge Server di port 3055).");