Skip to main content
Glama
railwayapp

Railway MCP Server

Official
by railwayapp

Create Environment

create-environment

Create a new Railway environment for your project, optionally duplicating an existing environment and setting service variables to manage configurations.

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
workspacePathYesThe path to the workspace where the environment should be created
environmentNameYesThe name for the new environment
duplicateEnvironmentNoThe name of an existing environment to duplicate
serviceVariablesNoService variables to assign in the new environment (only works when duplicating)

Implementation Reference

  • The handler function that implements the core logic for the 'create-environment' tool. It invokes the Railway CLI via createRailwayEnvironment and formats responses or 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",
    		);
    	}
    },
  • The Zod input schema defining parameters for the 'create-environment' tool: workspacePath, environmentName, optional duplicateEnvironment and 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 tools from './tools' (including 'create-environment') into the MCP server using server.registerTool.
    Object.values(tools).forEach((tool) => {
    	server.registerTool(
    		tool.name,
    		{
    			title: tool.title,
    			description: tool.description,
    			inputSchema: tool.inputSchema,
    		},
    		tool.handler,
    	);
    });
  • Helper function that executes the actual Railway CLI command to create the environment, used 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}`,
    		);
    	}
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions the creation action and optional duplication, it lacks critical details like required permissions, whether this is a destructive operation, rate limits, or what happens on failure. For a creation tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with two sentences that efficiently convey the core functionality and optional features. It's front-loaded with the primary purpose, though it could be slightly more structured by explicitly separating required from optional behaviors.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a creation tool with 4 parameters, 100% schema coverage, but no annotations and no output schema, the description is moderately complete. It covers the basic purpose but lacks behavioral context, error handling information, and output expectations, which are important for a tool that creates resources.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing good documentation for all parameters. The description adds minimal value beyond the schema by mentioning the optional duplication and service variables, but doesn't explain parameter interactions (e.g., that serviceVariables only works with duplicateEnvironment) or provide additional context beyond what's already in the schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Create a new Railway environment') and resource ('for the currently linked project'), distinguishing it from siblings like 'create-project-and-link' or 'link-environment'. It also mentions optional capabilities ('duplicate an existing environment and set service variables'), providing comprehensive purpose clarity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context ('for the currently linked project') but doesn't explicitly state when to use this tool versus alternatives like 'link-environment' or 'create-project-and-link'. No exclusions or prerequisites are mentioned, leaving some ambiguity about appropriate scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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