link-service
Link a Railway service to your project workspace to integrate deployments. Specify a service name to connect it or list available services for selection.
Instructions
Link a service to the current Railway project. If no service is specified, it will list available services
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspacePath | Yes | The path to the workspace to link the service to | |
| serviceName | No | The service name to link |
Implementation Reference
- src/tools/link-service.ts:17-64 (handler)The async handler function for the 'link-service' tool. Handles linking a specific service or listing available services in the linked Railway project.handler: async ({ workspacePath, serviceName }: LinkServiceOptions) => { try { if (serviceName) { // Link the specified service const result = await linkRailwayService({ workspacePath, serviceName, }); return createToolResponse( `✅ Successfully linked service '${serviceName}':\n\n${result}`, ); } else { // List available services const servicesResult = await getRailwayServices({ workspacePath }); if (!servicesResult.success) { return createToolResponse( "❌ Failed to get Railway services\n\n" + `**Error:** ${servicesResult.error}\n\n` + "**Next Steps:**\n" + "• Ensure you have a Railway project linked\n" + "• Check that you have permissions to view services\n" + "• Run `railway link` to ensure proper project connection", ); } if (!servicesResult.services || servicesResult.services.length === 0) { return createToolResponse( "ℹ️ No services found in this project. Create a service first.", ); } const result = `Available services:\n${servicesResult.services.map((s) => `- ${s}`).join("\n")}\n\nRun with a service name to link it.`; return createToolResponse(result); } } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return createToolResponse( "❌ Failed to link Railway service\n\n" + `**Error:** ${errorMessage}\n\n` + "**Next Steps:**\n" + "• Ensure you have a Railway project linked\n" + "• Check that the service name is correct\n" + "• Verify you have permissions to link services\n" + "• Run `railway link` to ensure proper project connection", ); } },
- src/tools/link-service.ts:11-16 (schema)Zod-based input schema for the tool, requiring workspacePath and optionally serviceName.inputSchema: { workspacePath: z .string() .describe("The path to the workspace to link the service to"), serviceName: z.string().optional().describe("The service name to link"), },
- src/index.ts:21-31 (registration)Dynamic registration of all tools (including 'link-service') to the MCP server via server.registerTool in a loop over exported tools.Object.values(tools).forEach((tool) => { server.registerTool( tool.name, { title: tool.title, description: tool.description, inputSchema: tool.inputSchema, }, tool.handler, ); });
- src/tools/index.ts:9-9 (registration)Exports the linkServiceTool object from its implementation file for use in the central tools index.export { linkServiceTool } from "./link-service";
- src/cli/services.ts:49-69 (helper)Helper function called by the tool handler to perform the actual service linking via Railway CLI.export const linkRailwayService = async ({ workspacePath, serviceName, }: LinkServiceOptions): Promise<string> => { try { await checkRailwayCliStatus(); const result = await getLinkedProjectInfo({ workspacePath }); if (!result.success) { throw new Error(result.error); } const { output } = await runRailwayCommand( `railway service ${serviceName}`, workspacePath, ); return output; } catch (error: unknown) { return analyzeRailwayError(error, "railway service"); } };