Files
Athena-Deck/integrations/librechat-unraid/mcp/configure.js
T

6 lines
1.4 KiB
JavaScript

const fs=require('fs'),yaml=require('js-yaml'),{configSchema}=require('librechat-data-provider');
const rows=JSON.parse(fs.readFileSync('/tmp/librechat-mcp-servers.json','utf8'));const v=yaml.load(fs.readFileSync('/app/librechat.yaml','utf8'));
v.mcpServers=v.mcpServers||{};v.mcpSettings=v.mcpSettings||{};const allowed=new Set(v.mcpSettings.allowedAddresses||[]);let authCount=0;
for(const s of rows){const url=new URL(s.url);allowed.add(url.host);const entry={type:'streamable-http',url:s.url,title:({HomeAssistant:"Home Assistant","db-timetable":"Bahnverbindungen - TravioREL",HomeServer:"Unraid - MUA"}[s.id]||s.name.replace(/[^a-zA-Z0-9 '-]/g," ")),requiresOAuth:false,chatMenu:true,serverInstructions:true,startup:s.auth==='none'};if(s.auth==='bearer'){authCount++;const key='MCP_KEY_'+s.id.replace(/[^a-zA-Z0-9]/g,'_').toUpperCase();entry.headers={Authorization:'Bearer ${'+key+'}'};entry.description='API-Key-Platzhalter: '+key+' im LibreChat-Container ersetzen.';}else if(s.auth!=='none')throw Error('Unsupported auth type');v.mcpServers[s.id]=entry;}
v.mcpSettings.allowedAddresses=[...allowed];const result=configSchema.safeParse(v);if(!result.success){console.log(JSON.stringify(result.error.issues));process.exit(1)}fs.writeFileSync('/tmp/librechat-mcp.yaml',yaml.dump(v,{lineWidth:140,noRefs:true}));console.log(JSON.stringify({configured:rows.length,noAuth:rows.length-authCount,keyPlaceholders:authCount,schemaValidated:true}));