ninja-terminals 2.2.3 → 2.2.4
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/mcp-server.js +44 -17
- package/package.json +1 -1
package/mcp-server.js
CHANGED
|
@@ -694,24 +694,51 @@ mcpServer.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
694
694
|
|
|
695
695
|
// ── Start Servers ───────────────────────────────────────────
|
|
696
696
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
for (let i = 0; i < terminalCount; i++) {
|
|
709
|
-
const label = labels[i] || `T${i + 1}`;
|
|
710
|
-
spawnTerminal(label, [], process.cwd(), 'pro');
|
|
711
|
-
console.error(` Spawned ${label}`);
|
|
712
|
-
}
|
|
713
|
-
console.error(`All ${terminalCount} terminals ready`);
|
|
697
|
+
// Check if port is in use
|
|
698
|
+
function isPortInUse(port) {
|
|
699
|
+
return new Promise((resolve) => {
|
|
700
|
+
const net = require('net');
|
|
701
|
+
const server = net.createServer();
|
|
702
|
+
server.once('error', () => resolve(true));
|
|
703
|
+
server.once('listening', () => {
|
|
704
|
+
server.close();
|
|
705
|
+
resolve(false);
|
|
706
|
+
});
|
|
707
|
+
server.listen(port, '127.0.0.1');
|
|
714
708
|
});
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// Proxy mode flag - when true, MCP tools should call existing server via HTTP
|
|
712
|
+
let proxyMode = false;
|
|
713
|
+
|
|
714
|
+
async function main() {
|
|
715
|
+
// Check if server.js is already running on port 3300
|
|
716
|
+
const portInUse = await isPortInUse(HTTP_PORT);
|
|
717
|
+
|
|
718
|
+
if (portInUse) {
|
|
719
|
+
// Proxy mode: server.js is already running, just run MCP on stdio
|
|
720
|
+
proxyMode = true;
|
|
721
|
+
console.error(`Ninja Terminals server already running on port ${HTTP_PORT}`);
|
|
722
|
+
console.error('MCP server starting in proxy mode (will use existing server)');
|
|
723
|
+
} else {
|
|
724
|
+
// Standalone mode: start our own HTTP server
|
|
725
|
+
httpServer.listen(HTTP_PORT, () => {
|
|
726
|
+
console.error(`Ninja Terminals HTTP server running on http://localhost:${HTTP_PORT}`);
|
|
727
|
+
|
|
728
|
+
// Auto-spawn terminals based on tier (NINJA_TERMINAL_COUNT env var)
|
|
729
|
+
// Free = 2, Paid = 4
|
|
730
|
+
const terminalCount = parseInt(process.env.NINJA_TERMINAL_COUNT || '2', 10);
|
|
731
|
+
const labels = ['T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8'];
|
|
732
|
+
|
|
733
|
+
console.error(`Auto-spawning ${terminalCount} terminals...`);
|
|
734
|
+
for (let i = 0; i < terminalCount; i++) {
|
|
735
|
+
const label = labels[i] || `T${i + 1}`;
|
|
736
|
+
spawnTerminal(label, [], process.cwd(), 'pro');
|
|
737
|
+
console.error(` Spawned ${label}`);
|
|
738
|
+
}
|
|
739
|
+
console.error(`All ${terminalCount} terminals ready`);
|
|
740
|
+
});
|
|
741
|
+
}
|
|
715
742
|
|
|
716
743
|
// Start MCP server on stdio
|
|
717
744
|
const transport = new StdioServerTransport();
|
package/package.json
CHANGED