UNPKG

@mseep/railway-mcp

Version:

Model Context Protocol server for Railway.app - Enables AI agents to manage Railway infrastructure through natural language

44 lines (43 loc) 1.63 kB
export class BaseApiClient { apiUrl = 'https://backboard.railway.app/graphql/v2'; wsUrl = 'wss://backboard.railway.app/graphql/v2'; token = null; constructor() { console.error('BaseApiClient initialized'); } getToken() { return this.token; } async request(query, variables) { if (!this.token) { console.error('No token available for request. Environment token:', process.env.RAILWAY_API_TOKEN); throw new Error('API token not set. Please either:\n1. Add RAILWAY_API_TOKEN to your environment variables, or\n2. Use the configure tool to set the token manually.'); } const debug = process.env.DEBUG; const isDebug = debug === 'railway:*' || debug?.includes('railway:api'); if (isDebug) { console.error('GraphQL Request:'); console.error('Query:', query); console.error('Variables:', JSON.stringify(variables, null, 2)); } const response = await fetch(this.apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.token}`, }, body: JSON.stringify({ query, variables, }), }); const result = await response.json(); if (isDebug) { console.error('GraphQL Response:', JSON.stringify(result, null, 2)); } if (result.errors && result.errors.length > 0) { throw new Error(result.errors[0].message); } return result.data; } }