UNPKG

@mseep/railway-mcp

Version:

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

139 lines (138 loc) 3.96 kB
export class ServiceRepository { client; constructor(client) { this.client = client; } async listServices(projectId) { const data = await this.client.request(` query project($projectId: String!) { project(id: $projectId) { services { edges { node { name id deployments(first: 5) { edges { node { id createdAt canRedeploy deploymentStopped environmentId } } } } } } } } `, { projectId }); return data.project.services.edges.map(edge => edge.node); } async getServiceInstance(serviceId, environmentId) { const data = await this.client.request(` query serviceInstance($serviceId: String!, $environmentId: String!) { serviceInstance(serviceId: $serviceId, environmentId: $environmentId) { id serviceId serviceName environmentId buildCommand startCommand rootDirectory region healthcheckPath sleepApplication numReplicas builder cronSchedule healthcheckTimeout isUpdatable railwayConfigFile restartPolicyType restartPolicyMaxRetries upstreamUrl watchPatterns } } `, { serviceId, environmentId }); return data.serviceInstance || null; } async createService(input) { const { projectId, name, source } = input; const variables = { projectId, name, source: source || undefined }; const data = await this.client.request(` mutation serviceCreate($projectId: String!, $name: String, $source: ServiceSourceInput) { serviceCreate( input: { projectId: $projectId, name: $name, source: $source } ) { id name projectId createdAt updatedAt deletedAt icon templateServiceId templateThreadSlug featureFlags } } `, variables); return data.serviceCreate; } async updateServiceInstance(serviceId, environmentId, updates) { const data = await this.client.request(` mutation serviceInstanceUpdate( $serviceId: String!, $environmentId: String!, $buildCommand: String, $startCommand: String, $rootDirectory: String, $healthcheckPath: String, $numReplicas: Int, $sleepApplication: Boolean, $region: String ) { serviceInstanceUpdate( serviceId: $serviceId, environmentId: $environmentId, input: { buildCommand: $buildCommand, startCommand: $startCommand, rootDirectory: $rootDirectory, healthcheckPath: $healthcheckPath, numReplicas: $numReplicas, sleepApplication: $sleepApplication, region: $region } ) } `, { serviceId, environmentId, ...updates }); return data.serviceInstanceUpdate; } async deleteService(serviceId) { await this.client.request(` mutation serviceDelete($serviceId: String!) { serviceDelete(id: $serviceId) } `, { serviceId }); } async restartService(serviceId, environmentId) { await this.client.request(` mutation serviceInstanceRedeploy($serviceId: String!, $environmentId: String!) { serviceInstanceRedeploy(serviceId: $serviceId, environmentId: $environmentId) } `, { serviceId, environmentId }); } }