@crazyrabbitltc/railway-mcp
Version:
Railway MCP Server - 146+ tools with 100% Railway API coverage, comprehensive MCP testing framework, and real infrastructure management through AI assistants. Enhanced version with enterprise features, based on original work by Jason Tan.
343 lines (342 loc) • 10.1 kB
JavaScript
export class NetworkingRepository {
client;
constructor(client) {
this.client = client;
}
async listPrivateNetworks(projectId) {
const query = `
query listPrivateNetworks($projectId: String!) {
project(id: $projectId) {
privateNetworks {
edges {
node {
id
projectId
name
cidr
region
isActive
endpoints {
serviceId
serviceName
ipAddress
port
}
createdAt
updatedAt
}
}
}
}
}
`;
const response = await this.client.request(query, { projectId });
return response.project.privateNetworks.edges.map(edge => edge.node);
}
async createPrivateNetwork(projectId, name, cidr, region) {
const query = `
mutation createPrivateNetwork($projectId: String!, $name: String!, $cidr: String!, $region: String!) {
privateNetworkCreate(projectId: $projectId, name: $name, cidr: $cidr, region: $region) {
id
projectId
name
cidr
region
isActive
endpoints {
serviceId
serviceName
ipAddress
port
}
createdAt
}
}
`;
const response = await this.client.request(query, {
projectId, name, cidr, region
});
return response.privateNetworkCreate;
}
async addNetworkEndpoint(networkId, serviceId, port, protocol) {
const query = `
mutation addNetworkEndpoint($networkId: String!, $serviceId: String!, $port: Int!, $protocol: NetworkProtocol!) {
networkEndpointAdd(networkId: $networkId, serviceId: $serviceId, port: $port, protocol: $protocol) {
id
networkId
serviceId
serviceName
ipAddress
port
protocol
isActive
createdAt
}
}
`;
const response = await this.client.request(query, {
networkId, serviceId, port, protocol
});
return response.networkEndpointAdd;
}
async removeNetworkEndpoint(endpointId) {
const query = `
mutation removeNetworkEndpoint($endpointId: String!) {
networkEndpointRemove(id: $endpointId)
}
`;
const response = await this.client.request(query, { endpointId });
return response.networkEndpointRemove;
}
async listLoadBalancers(projectId) {
const query = `
query listLoadBalancers($projectId: String!) {
project(id: $projectId) {
loadBalancers {
edges {
node {
id
projectId
name
type
algorithm
healthCheck {
path
port
protocol
interval
timeout
healthyThreshold
unhealthyThreshold
}
targets {
serviceId
serviceName
weight
isHealthy
}
listeners {
port
protocol
certificateId
}
status
createdAt
updatedAt
}
}
}
}
}
`;
const response = await this.client.request(query, { projectId });
return response.project.loadBalancers.edges.map(edge => edge.node);
}
async createLoadBalancer(projectId, name, type, algorithm, healthCheck, listeners) {
const query = `
mutation createLoadBalancer($projectId: String!, $name: String!, $type: LoadBalancerType!, $algorithm: LoadBalancerAlgorithm!, $healthCheck: HealthCheckInput!, $listeners: [ListenerInput!]!) {
loadBalancerCreate(projectId: $projectId, name: $name, type: $type, algorithm: $algorithm, healthCheck: $healthCheck, listeners: $listeners) {
id
projectId
name
type
algorithm
healthCheck {
path
port
protocol
interval
timeout
healthyThreshold
unhealthyThreshold
}
listeners {
port
protocol
certificateId
}
status
createdAt
}
}
`;
const response = await this.client.request(query, {
projectId, name, type, algorithm, healthCheck, listeners
});
return response.loadBalancerCreate;
}
async addLoadBalancerTarget(loadBalancerId, serviceId, weight) {
const query = `
mutation addLoadBalancerTarget($loadBalancerId: String!, $serviceId: String!, $weight: Int!) {
loadBalancerTargetAdd(loadBalancerId: $loadBalancerId, serviceId: $serviceId, weight: $weight) {
id
targets {
serviceId
serviceName
weight
isHealthy
}
updatedAt
}
}
`;
const response = await this.client.request(query, {
loadBalancerId, serviceId, weight
});
return response.loadBalancerTargetAdd;
}
async removeLoadBalancerTarget(loadBalancerId, serviceId) {
const query = `
mutation removeLoadBalancerTarget($loadBalancerId: String!, $serviceId: String!) {
loadBalancerTargetRemove(loadBalancerId: $loadBalancerId, serviceId: $serviceId) {
id
targets {
serviceId
serviceName
weight
isHealthy
}
updatedAt
}
}
`;
const response = await this.client.request(query, {
loadBalancerId, serviceId
});
return response.loadBalancerTargetRemove;
}
async updateLoadBalancerHealthCheck(loadBalancerId, healthCheck) {
const query = `
mutation updateLoadBalancerHealthCheck($loadBalancerId: String!, $healthCheck: HealthCheckInput!) {
loadBalancerHealthCheckUpdate(id: $loadBalancerId, healthCheck: $healthCheck) {
id
healthCheck {
path
port
protocol
interval
timeout
healthyThreshold
unhealthyThreshold
}
updatedAt
}
}
`;
const response = await this.client.request(query, {
loadBalancerId, healthCheck
});
return response.loadBalancerHealthCheckUpdate;
}
async deleteLoadBalancer(loadBalancerId) {
const query = `
mutation deleteLoadBalancer($loadBalancerId: String!) {
loadBalancerDelete(id: $loadBalancerId)
}
`;
const response = await this.client.request(query, { loadBalancerId });
return response.loadBalancerDelete;
}
async listNetworkRoutes(networkId) {
const query = `
query listNetworkRoutes($networkId: String!) {
privateNetwork(id: $networkId) {
routes {
id
networkId
destination
gateway
metric
isActive
createdAt
}
}
}
`;
const response = await this.client.request(query, { networkId });
return response.privateNetwork.routes;
}
async createNetworkRoute(networkId, destination, gateway, metric) {
const query = `
mutation createNetworkRoute($networkId: String!, $destination: String!, $gateway: String!, $metric: Int!) {
networkRouteCreate(networkId: $networkId, destination: $destination, gateway: $gateway, metric: $metric) {
id
networkId
destination
gateway
metric
isActive
createdAt
}
}
`;
const response = await this.client.request(query, {
networkId, destination, gateway, metric
});
return response.networkRouteCreate;
}
async deleteNetworkRoute(routeId) {
const query = `
mutation deleteNetworkRoute($routeId: String!) {
networkRouteDelete(id: $routeId)
}
`;
const response = await this.client.request(query, { routeId });
return response.networkRouteDelete;
}
async listSecurityGroups(networkId) {
const query = `
query listSecurityGroups($networkId: String!) {
privateNetwork(id: $networkId) {
securityGroups {
id
networkId
name
description
rules {
id
direction
protocol
portRange
source
action
priority
}
isActive
createdAt
updatedAt
}
}
}
`;
const response = await this.client.request(query, { networkId });
return response.privateNetwork.securityGroups;
}
async createSecurityGroup(networkId, name, description, rules) {
const query = `
mutation createSecurityGroup($networkId: String!, $name: String!, $description: String!, $rules: [SecurityRuleInput!]!) {
securityGroupCreate(networkId: $networkId, name: $name, description: $description, rules: $rules) {
id
networkId
name
description
rules {
id
direction
protocol
portRange
source
action
priority
}
isActive
createdAt
}
}
`;
const response = await this.client.request(query, {
networkId, name, description, rules
});
return response.securityGroupCreate;
}
}