Skip to content

Commit 0cf8beb

Browse files
authored
Merge branch 'main' into feature/codex-install-update
2 parents 78ca1ed + fb72bbf commit 0cf8beb

23 files changed

Lines changed: 1041 additions & 934 deletions

mcp/dist/index.js

Lines changed: 345 additions & 44 deletions
Large diffs are not rendered by default.

mcp/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mcp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@modelcontextprotocol/sdk": "^1.29.0",
15+
"ps-list": "^9.0.0",
1516
"tsx": "^4.7.0",
1617
"zod": "^3.22.0"
1718
},

mcp/server.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
2121
import { spawn } from 'child_process';
2222
import path from 'path';
2323
import { fileURLToPath } from 'url';
24+
import psList from 'ps-list';
2425

2526
import {
2627
CallToolRequestSchema,
@@ -388,14 +389,55 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
388389
}
389390
});
390391

392+
const IDE_MAPPING: Record<string, string> = {
393+
'code': 'visualstudiocode',
394+
'code-insiders': 'visualstudiocode',
395+
'cursor': 'cursor',
396+
'antigravity': 'antigravity'
397+
};
398+
399+
async function inferIdeName(): Promise<string | null> {
400+
try {
401+
const processes = await psList();
402+
let currentPid = process.pid;
403+
let depth = 0;
404+
const maxDepth = 20;
405+
406+
while (currentPid && currentPid > 1 && depth < maxDepth) {
407+
const proc = processes.find(p => p.pid === currentPid);
408+
if (!proc) break;
409+
410+
const name = proc.name.toLowerCase();
411+
for (const key in IDE_MAPPING) {
412+
if (name.includes(key)) {
413+
return IDE_MAPPING[key];
414+
}
415+
}
416+
417+
currentPid = proc.ppid;
418+
depth++;
419+
}
420+
} catch (error) {
421+
console.error('Error parsing process tree:', error);
422+
}
423+
return null;
424+
}
425+
391426
async function startStandaloneServer() {
392427
const transport = new StdioServerTransport();
393428
await server.connect(transport);
394429
console.error('Standalone Notebook MCP server running on stdio');
395430
}
396431

397432
async function run() {
398-
const ideName = process.env.DATA_CLOUD_CURR_IDE_NAME;
433+
let ideName = process.env.DATA_CLOUD_CURR_IDE_NAME;
434+
if (!ideName) {
435+
ideName = await inferIdeName();
436+
if (ideName) {
437+
console.error(`Inferred IDE name from process tree: ${ideName}`);
438+
}
439+
}
440+
399441
if (ideName) {
400442

401443
const proxyCmd = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../bin/mcp_proxy_bundle.cjs');

0 commit comments

Comments
 (0)