Skip to main content
Glama
railwayapp

Railway MCP Server

Official
by railwayapp

Link Environment

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");
    	}
    };
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the fallback behavior (listing environments if none specified), which is useful. However, it doesn't disclose critical behavioral traits: whether linking is reversible, what permissions are required, if it affects existing configurations, or what the output looks like. For a mutation 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.

Conciseness5/5

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

The description is two concise sentences with zero waste. The first sentence states the primary purpose, and the second explains the fallback behavior. It's appropriately sized and front-loaded, with every sentence earning its place.

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

Completeness2/5

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

Given this is a mutation tool (linking implies change) with no annotations and no output schema, the description is incomplete. It doesn't explain what 'linking' entails operationally, what happens after linking, error conditions, or return values. The fallback behavior hint is helpful but insufficient for a tool that modifies state.

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%, so the schema already documents both parameters (workspacePath and environmentName). The description adds no additional parameter semantics beyond what the schema provides. It implies environmentName is optional in practice (contradicting the required schema), but doesn't clarify this parameter behavior. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Link to a specific Railway environment' specifies the verb (link) and resource (environment). It distinguishes from siblings like 'link-service' by focusing on environments rather than services. However, it doesn't explicitly differentiate from 'create-environment' which creates rather than links.

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 provides implied usage guidance: it mentions that without an environment specified, it will list available environments. This suggests it can be used for discovery. However, it doesn't explicitly state when to use this tool versus alternatives like 'create-environment' or 'list-projects', nor does it mention prerequisites or exclusions.

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