Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions vscode-plugins/stella-ide-mcp/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,29 @@ async function handleCallTool(params) {
}
}

// Check if server is already running on port
function checkServerRunning(port) {
return new Promise((resolve) => {
const req = http.get(`http://127.0.0.1:${port}/health`, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const json = JSON.parse(data);
resolve(json.status === 'ok' && json.tools === TOOLS.length);
} catch {
resolve(false);
}
});
});
req.on('error', () => resolve(false));
req.setTimeout(1000, () => {
req.destroy();
resolve(false);
});
});
}

// HTTP Server
function startServer(port) {
server = http.createServer(async (req, res) => {
Expand Down Expand Up @@ -357,9 +380,21 @@ function startServer(port) {
vscode.window.showInformationMessage(`Stella IDE MCP server running on port ${port}`);
});

server.on('error', (e) => {
log(`Server error: ${e.message}`);
vscode.window.showErrorMessage(`Stella IDE MCP server error: ${e.message}`);
server.on('error', async (e) => {
if (e.code === 'EADDRINUSE') {
log(`Port ${port} in use, checking if it's another instance...`);
const isOurServer = await checkServerRunning(port);
if (isOurServer) {
log(`Server already running in another extension host on port ${port} - skipping`);
server = null; // Clear server reference since we're not running it
} else {
log(`Port ${port} occupied by another process`);
vscode.window.showErrorMessage(`Stella IDE MCP: Port ${port} is in use by another process`);
}
} else {
log(`Server error: ${e.message}`);
vscode.window.showErrorMessage(`Stella IDE MCP server error: ${e.message}`);
}
});
}

Expand All @@ -382,13 +417,21 @@ function activate(context) {
startServer(port);

// Status command
const statusCmd = vscode.commands.registerCommand('stella-ide-mcp.status', () => {
const statusCmd = vscode.commands.registerCommand('stella-ide-mcp.status', async () => {
if (server && server.listening) {
vscode.window.showInformationMessage(
`Stella IDE MCP server running on port ${port}. Tools: ${TOOLS.map(t => t.name).join(', ')}`
`Stella IDE MCP server running on port ${port} (this extension host). Tools: ${TOOLS.map(t => t.name).join(', ')}`
);
} else {
vscode.window.showWarningMessage('Stella IDE MCP server is not running');
// Check if server is running in another extension host
const isRunning = await checkServerRunning(port);
if (isRunning) {
vscode.window.showInformationMessage(
`Stella IDE MCP server running on port ${port} (another extension host). Tools: ${TOOLS.map(t => t.name).join(', ')}`
);
} else {
vscode.window.showWarningMessage('Stella IDE MCP server is not running');
}
}
});

Expand Down