link-environment
Link a workspace to a specific Railway environment or list available environments for selection to manage deployments and configurations.
Instructions
Link to a specific Railway environment. If no environment is specified, it will list available environments for selection.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspacePath | Yes | The path to the workspace to link the environment to | |
| environmentName | Yes | The environment name to link to |
Implementation Reference
- src/tools/link-environment.ts:17-39 (handler)The MCP tool handler function that invokes the linkRailwayEnvironment helper with user inputs and formats success or error responses using createToolResponse.handler: async ({ workspacePath, environmentName, }: LinkEnvironmentOptions) => { try { const result = await linkRailwayEnvironment({ workspacePath, environmentName, }); return createToolResponse(result); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return createToolResponse( "❌ Failed to link environment\n\n" + `**Error:** ${errorMessage}\n\n` + "**Next Steps:**\n" + "• Ensure you have a Railway project linked\n" + "• Check that the environment name is correct\n" + "• Run `railway environment` to see available environments", ); } },
- src/tools/link-environment.ts:11-16 (schema)Zod schema for tool inputs: workspacePath (string) and environmentName (string).inputSchema: { workspacePath: z .string() .describe("The path to the workspace to link the environment to"), environmentName: z.string().describe("The environment name to link to"), },
- src/index.ts:21-31 (registration)Generic registration loop in the MCP server startup that registers the 'link-environment' tool (and others) using its name, metadata, schema, and handler.Object.values(tools).forEach((tool) => { server.registerTool( tool.name, { title: tool.title, description: tool.description, inputSchema: tool.inputSchema, }, tool.handler, ); });
- src/tools/index.ts:8-8 (registration)Re-export of the linkEnvironmentTool object from its implementation module for easy import in the tools index.export { linkEnvironmentTool } from "./link-environment";
- src/cli/environments.ts:68-88 (helper)Core helper function that executes the 'railway environment [name]' CLI command to link an environment, with prerequisite checks and error analysis.export const linkRailwayEnvironment = async ({ workspacePath, environmentName, }: LinkEnvironmentOptions): Promise<string> => { try { await checkRailwayCliStatus(); const result = await getLinkedProjectInfo({ workspacePath }); if (!result.success) { throw new Error(result.error); } const command = environmentName ? `railway environment ${environmentName}` : "railway environment"; const { output } = await runRailwayCommand(command, workspacePath); return output; } catch (error: unknown) { return analyzeRailwayError(error, "railway environment"); } };