@@ -21,6 +21,7 @@ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
2121import { spawn } from 'child_process' ;
2222import path from 'path' ;
2323import { fileURLToPath } from 'url' ;
24+ import psList from 'ps-list' ;
2425
2526import {
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+
391426async function startStandaloneServer ( ) {
392427 const transport = new StdioServerTransport ( ) ;
393428 await server . connect ( transport ) ;
394429 console . error ( 'Standalone Notebook MCP server running on stdio' ) ;
395430}
396431
397432async 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