Files

3 lines
1.2 KiB
JavaScript

const fs=require('fs');
(async()=>{const {Client}=await import('@modelcontextprotocol/sdk/client/index.js');const {StreamableHTTPClientTransport}=await import('@modelcontextprotocol/sdk/client/streamableHttp.js');const rows=JSON.parse(fs.readFileSync('/tmp/librechat-mcp-servers.json','utf8'));const results=await Promise.all(rows.filter(s=>s.auth==='bearer').map(async s=>{const client=new Client({name:'librechat-auth-check',version:'1.0.0'});try{const env='MCP_KEY_'+s.id.replace(/[^a-zA-Z0-9]/g,'_').toUpperCase();const key=process.env[env];if(!key||key.startsWith('FAKE_KEY_'))return {id:s.id,connected:false,error:'key-not-transferred'};await client.connect(new StreamableHTTPClientTransport(new URL(s.url),{requestInit:{headers:{Authorization:'Bearer '+key}}}),{timeout:10000});let count=0,cursor;do{const r=await client.listTools(cursor?{cursor}:undefined,{timeout:10000});count+=r.tools.length;cursor=r.nextCursor;}while(cursor);return {id:s.id,connected:true,tools:count};}catch(e){return {id:s.id,connected:false,error:e.name,code:typeof e.code==='number'?e.code:undefined}}finally{await client.close().catch(()=>{});}}));console.log(JSON.stringify(results));process.exit(0)})().catch(()=>{console.log('Verification failed; details suppressed');process.exit(1)});