@@ -7,6 +7,7 @@ const outputFile = process.env.GITHUB_AW_SAFE_OUTPUTS;
77if ( ! outputFile )
88 throw new Error ( "GITHUB_AW_SAFE_OUTPUTS not set, no output file" ) ;
99const SERVER_INFO = { name : "safe-outputs-mcp-server" , version : "1.0.0" } ;
10+ const debug = ( msg ) => process . stderr . write ( `[${ SERVER_INFO . name } ] ${ msg } \n` ) ;
1011function writeMessage ( obj ) {
1112 const json = JSON . stringify ( obj ) ;
1213 const bytes = encoder . encode ( json ) ;
@@ -20,6 +21,7 @@ let buffer = Buffer.alloc(0);
2021function onData ( chunk ) {
2122 buffer = Buffer . concat ( [ buffer , chunk ] ) ;
2223 while ( true ) {
24+ debug ( `on data buffer length: ${ buffer . length } - ${ buffer . toString ( "utf8" ) } ` ) ;
2325 const sep = buffer . indexOf ( "\r\n\r\n" ) ;
2426 if ( sep === - 1 ) break ;
2527
@@ -50,10 +52,6 @@ function onData(chunk) {
5052 }
5153}
5254
53- process . stdin . on ( "data" , onData ) ;
54- process . stdin . on ( "error" , ( ) => { } ) ;
55- process . stdin . resume ( ) ;
56-
5755function replyResult ( id , result ) {
5856 if ( id === undefined || id === null ) return ; // notification
5957 const res = { jsonrpc : "2.0" , id, result } ;
@@ -316,15 +314,15 @@ const TOOLS = Object.fromEntries(
316314 . map ( tool => [ tool . name , tool ] )
317315) ;
318316
319- process . stderr . write (
320- `[ ${ SERVER_INFO . name } ] v${ SERVER_INFO . version } ready on stdio\n `
317+ debug (
318+ `v${ SERVER_INFO . version } ready on stdio`
321319) ;
322- process . stderr . write ( `[ ${ SERVER_INFO . name } ] output file: ${ outputFile } \n `) ;
323- process . stderr . write (
324- `[ ${ SERVER_INFO . name } ] config: ${ JSON . stringify ( safeOutputsConfig ) } \n `
320+ debug ( ` output file: ${ outputFile } `) ;
321+ debug (
322+ ` config: ${ JSON . stringify ( safeOutputsConfig ) } `
325323) ;
326- process . stderr . write (
327- `[ ${ SERVER_INFO . name } ] tools: ${ Object . keys ( TOOLS ) . join ( ", " ) } \n `
324+ debug (
325+ ` tools: ${ Object . keys ( TOOLS ) . join ( ", " ) } `
328326) ;
329327if ( ! Object . keys ( TOOLS ) . length )
330328 throw new Error ( "No tools enabled in configuration" ) ;
@@ -408,4 +406,7 @@ function handleMessage(req) {
408406 }
409407}
410408
411- process . stderr . write ( `[${ SERVER_INFO . name } ] listening...\n` ) ;
409+ process . stdin . on ( "data" , onData ) ;
410+ process . stdin . on ( "error" , ( err ) => debug ( `stdin error: ${ err } ` ) ) ;
411+ process . stdin . resume ( ) ;
412+ debug ( `listening...` ) ;
0 commit comments