Skip to main content
Glama

create-environment

Generate a new Railway environment for the linked project, with options to duplicate an existing environment and configure service variables for streamlined setup.

Instructions

Create a new Railway environment for the currently linked project. Optionally duplicate an existing environment and set service variables.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
duplicateEnvironmentNoThe name of an existing environment to duplicate
environmentNameYesThe name for the new environment
serviceVariablesNoService variables to assign in the new environment (only works when duplicating)
workspacePathYesThe path to the workspace where the environment should be created

Implementation Reference

  • Handler function that implements the core logic of the 'create-environment' tool by invoking the Railway CLI via createRailwayEnvironment and handling responses/errors.
    handler: async ({ workspacePath, environmentName, duplicateEnvironment, serviceVariables, }: CreateEnvironmentOptions) => { try { const result = await createRailwayEnvironment({ workspacePath, environmentName, duplicateEnvironment, serviceVariables, }); return createToolResponse(result); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return createToolResponse( "❌ Failed to create environment\n\n" + `**Error:** ${errorMessage}\n\n` + "**Next Steps:**\n" + "• Ensure you have a Railway project linked\n" + "• Check that the environment name is valid and unique\n" + "• Verify you have permissions to create environments in this project\n" + "• If duplicating, ensure the source environment exists\n" + "• If using service variables, ensure the service exists in the source environment", ); } },
  • Zod-based input schema defining the parameters for the 'create-environment' tool: workspacePath, environmentName, optional duplicateEnvironment, and optional serviceVariables.
    inputSchema: { workspacePath: z .string() .describe( "The path to the workspace where the environment should be created", ), environmentName: z.string().describe("The name for the new environment"), duplicateEnvironment: z .string() .optional() .describe("The name of an existing environment to duplicate"), serviceVariables: z .array( z.object({ service: z.string().describe("The service name or UUID"), variable: z .string() .describe("The variable assignment (e.g., 'BACKEND_PORT=3000')"), }), ) .optional() .describe( "Service variables to assign in the new environment (only works when duplicating)", ), },
  • src/index.ts:21-31 (registration)
    Dynamic registration of all exported tools from src/tools (including 'create-environment') to the MCP server via registerTool, using each tool's 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, ); });
  • Core helper function that constructs and runs the Railway CLI command for creating a new environment, with support for duplicating and setting service variables; invoked by the tool handler.
    export const createRailwayEnvironment = async ({ workspacePath, environmentName, duplicateEnvironment, serviceVariables, }: CreateEnvironmentOptions): Promise<string> => { try { await checkRailwayCliStatus(); const result = await getLinkedProjectInfo({ workspacePath }); if (!result.success) { throw new Error(result.error); } let command = `railway environment new ${environmentName}`; if (duplicateEnvironment) { command += ` --duplicate ${duplicateEnvironment}`; } if (serviceVariables && serviceVariables.length > 0) { for (const sv of serviceVariables) { command += ` --service-variable ${sv.service} ${sv.variable}`; } } const { output } = await runRailwayCommand(command, workspacePath); return output; } catch (error: unknown) { return analyzeRailwayError( error, `railway environment new ${environmentName}`, ); } };

Other Tools

Related Tools

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