// Run on the other laptop alongside the existing bimwright/rvt-mcp connection. // Credentials come from environment only; they are never written into project files. import readline from 'node:readline'; const endpoint=process.env.TOCHKA_MCP_URL||'https://urban-os.online/tochka/mcp.php'; const token=process.env.TOCHKA_RAG_TOKEN; if(!token){process.stderr.write('TOCHKA_RAG_TOKEN is required. Create a temporary key in the director cabinet.\n');process.exit(1);} if(!endpoint.startsWith('https://')){process.stderr.write('HTTPS is required.\n');process.exit(1);} const lines=readline.createInterface({input:process.stdin,crlfDelay:Infinity});let queue=Promise.resolve(); async function handle(line){let m;try{m=JSON.parse(line);}catch{return;}try{let r=await fetch(endpoint,{method:'POST',headers:{'Content-Type':'application/json','Authorization':'Bearer '+token},body:JSON.stringify(m),signal:AbortSignal.timeout(60000)});if(m.id===undefined)return;let body=await r.json();if(!body.jsonrpc)body={jsonrpc:'2.0',id:m.id,error:{code:-32001,message:body.error||'RAG service unavailable'}};process.stdout.write(JSON.stringify(body)+'\n');}catch(e){if(m.id!==undefined)process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,error:{code:-32000,message:'RAG connection failed'}})+'\n');}} lines.on('line',line=>{queue=queue.then(()=>handle(line));});