Skip to main content
Glama

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
NameRequiredDescriptionDefault
workspacePathYesThe path to the workspace to link the environment to
environmentNameYesThe environment name to link to

Implementation Reference

  • 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", ); } },
  • 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";
  • 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"); } };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/railwayapp/railway-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server