robloxstudio-mcp 2.6.0-next.2 → 2.6.0-next.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "robloxstudio-mcp",
3
- "version": "2.6.0-next.2",
3
+ "version": "2.6.0-next.3",
4
4
  "description": "MCP Server for Roblox Studio Integration - Access Studio data, scripts, and objects through AI tools",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -194,7 +194,7 @@ function pollForRequests(connIndex: number) {
194
194
  el.troubleshootLabel.Visible = elapsed > 8;
195
195
  if (elapsed > 3 && elapsed % 5 < conn.pollInterval) {
196
196
  task.spawn(() => {
197
- const discovered = discoverPort();
197
+ const discovered = discoverPort(getUsedPorts(connIndex));
198
198
  if (discovered !== undefined && discovered !== conn.port) {
199
199
  conn.port = discovered;
200
200
  conn.serverUrl = `http://localhost:${discovered}`;
@@ -231,7 +231,7 @@ function pollForRequests(connIndex: number) {
231
231
 
232
232
  if (conn.consecutiveFailures === 5 || conn.consecutiveFailures % 20 === 0) {
233
233
  task.spawn(() => {
234
- const discovered = discoverPort();
234
+ const discovered = discoverPort(getUsedPorts(connIndex));
235
235
  if (discovered !== undefined && discovered !== conn.port) {
236
236
  conn.port = discovered;
237
237
  conn.serverUrl = `http://localhost:${discovered}`;
@@ -304,10 +304,33 @@ function pollForRequests(connIndex: number) {
304
304
  }
305
305
  }
306
306
 
307
- function discoverPort(): number | undefined {
307
+ function getUsedPorts(excludeIndex: number): Set<number> {
308
+ const ports = new Set<number>();
309
+ const conns = State.getConnections();
310
+ for (let i = 0; i < conns.size(); i++) {
311
+ if (i !== excludeIndex && conns[i].isActive) {
312
+ ports.add(conns[i].port);
313
+ }
314
+ }
315
+ return ports;
316
+ }
317
+
318
+ function checkPort(port: number): boolean {
319
+ const [ok, res] = pcall(() => {
320
+ return HttpService.RequestAsync({
321
+ Url: `http://localhost:${port}/status`,
322
+ Method: "GET",
323
+ Headers: { "Content-Type": "application/json" },
324
+ });
325
+ });
326
+ return ok && res.Success;
327
+ }
328
+
329
+ function discoverPort(excludePorts?: Set<number>): number | undefined {
308
330
  let firstActivePort: number | undefined;
309
331
  for (let offset = 0; offset < 5; offset++) {
310
332
  const port = State.BASE_PORT + offset;
333
+ if (excludePorts && excludePorts.has(port)) continue;
311
334
  const [success, result] = pcall(() => {
312
335
  return HttpService.RequestAsync({
313
336
  Url: `http://localhost:${port}/status`,
@@ -351,13 +374,16 @@ function activatePlugin(connIndex?: number) {
351
374
  UI.updateTabDot(idx);
352
375
 
353
376
  task.spawn(() => {
354
- const discoveredPort = discoverPort();
355
- if (discoveredPort !== undefined) {
356
- conn.port = discoveredPort;
357
- conn.serverUrl = `http://localhost:${discoveredPort}`;
358
- UI.updateTabLabel(idx);
359
- if (idx === State.getActiveTabIndex()) {
360
- ui.urlInput.Text = conn.serverUrl;
377
+ if (!checkPort(conn.port)) {
378
+ const usedPorts = getUsedPorts(idx);
379
+ const discoveredPort = discoverPort(usedPorts);
380
+ if (discoveredPort !== undefined) {
381
+ conn.port = discoveredPort;
382
+ conn.serverUrl = `http://localhost:${discoveredPort}`;
383
+ UI.updateTabLabel(idx);
384
+ if (idx === State.getActiveTabIndex()) {
385
+ ui.urlInput.Text = conn.serverUrl;
386
+ }
361
387
  }
362
388
  }
363
389
 
@@ -32,8 +32,14 @@ function addConnection(port?: number): number | undefined {
32
32
  if (connections.size() >= MAX_CONNECTIONS) {
33
33
  return undefined;
34
34
  }
35
- const lastPort = connections[connections.size() - 1].port;
36
- const conn = createConnection(port ?? lastPort + 1);
35
+ if (port === undefined) {
36
+ let maxPort = BASE_PORT - 1;
37
+ for (const conn of connections) {
38
+ if (conn.port > maxPort) maxPort = conn.port;
39
+ }
40
+ port = maxPort + 1;
41
+ }
42
+ const conn = createConnection(port);
37
43
  connections.push(conn);
38
44
  return connections.size() - 1;
39
45
  }