@@ -33,7 +33,10 @@ export class BridgeHost implements BridgePort {
3333 start ( ) : Promise < void > {
3434 return new Promise ( ( resolve , reject ) => {
3535 const wss = new WebSocketServer ( { host : "127.0.0.1" , port : this . #requestedPort } ) ;
36- wss . on ( "listening" , ( ) => resolve ( ) ) ;
36+ wss . on ( "listening" , ( ) => {
37+ process . stderr . write ( `reins-mcp: bridge listening on 127.0.0.1:${ this . port } \n` ) ;
38+ resolve ( ) ;
39+ } ) ;
3740 wss . on ( "error" , ( err ) => {
3841 // Don't retain a server that never bound (e.g. EADDRINUSE) — avoids a leak on retry.
3942 this . #wss = undefined ;
@@ -55,7 +58,9 @@ export class BridgeHost implements BridgePort {
5558 }
5659
5760 #onConnection( ws : WebSocket , origin : string | undefined ) : void {
61+ process . stderr . write ( `reins-mcp: connection from origin=${ origin } \n` ) ;
5862 if ( ! origin ?. startsWith ( this . #originPrefix) ) {
63+ process . stderr . write ( `reins-mcp: rejected: origin not allowed (${ origin } )\n` ) ;
5964 ws . close ( 4003 , "origin not allowed" ) ;
6065 return ;
6166 }
@@ -68,11 +73,15 @@ export class BridgeHost implements BridgePort {
6873 if ( hello . success && hello . data . token === this . #token) {
6974 authed = true ;
7075 if ( this . #client && this . #client !== ws && this . #client. readyState === WebSocket . OPEN ) {
76+ process . stderr . write ( "reins-mcp: client replaced by new connection\n" ) ;
7177 this . #client. close ( 4002 , "replaced by a new connection" ) ;
7278 }
7379 this . #client = ws ;
80+ const browser = hello . data . browser ;
81+ process . stderr . write ( `reins-mcp: authed${ browser ? ` (browser=${ browser } )` : "" } \n` ) ;
7482 ws . send ( JSON . stringify ( WelcomeFrame . parse ( { type : "welcome" , server : "reins" } ) ) ) ;
7583 } else {
84+ process . stderr . write ( "reins-mcp: rejected: bad token\n" ) ;
7685 ws . close ( 4001 , "bad token" ) ;
7786 }
7887 return ;
@@ -82,7 +91,8 @@ export class BridgeHost implements BridgePort {
8291 this . #settle( response . data . id , response . data ) ;
8392 }
8493 } ) ;
85- ws . on ( "close" , ( ) => {
94+ ws . on ( "close" , ( code ) => {
95+ process . stderr . write ( `reins-mcp: connection closed (code=${ code } )\n` ) ;
8696 if ( this . #client === ws ) {
8797 this . #client = undefined ;
8898 // Spec §7: fail fast — don't leave in-flight requests hanging to timeout.
0 commit comments