list-variables
Display environment variables for a specified workspace, service, or environment in plain text, KV, or JSON format using the Railway MCP Server.
Instructions
Show variables for the active environment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| environment | No | The environment to show variables for (optional) | |
| json | No | Output in JSON format (optional) | |
| kv | No | Show variables in KV format (optional) | |
| service | No | The service to show variables for (optional) | |
| workspacePath | Yes | The path to the workspace to list variables from |
Implementation Reference
- src/tools/list-variables.ts:28-58 (handler)The handler function for the 'list-variables' tool. It calls listRailwayVariables with provided options, returns the result wrapped in createToolResponse, or formats an error message on failure.handler: async ({ workspacePath, service, environment, kv, json, }: ListVariablesOptions) => { try { const variables = await listRailwayVariables({ workspacePath, service, environment, kv, json, }); return createToolResponse(variables); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return createToolResponse( "❌ Failed to list Railway variables\n\n" + `**Error:** ${errorMessage}\n\n` + "**Next Steps:**\n" + "• Ensure you have a Railway project linked\n" + "• Check that the service and environment exist\n" + "• Verify you have permissions to view variables\n" + "• Run `railway link` to ensure proper project connection", ); } },
- src/tools/list-variables.ts:10-27 (schema)Zod input schema defining parameters for the list-variables tool: workspacePath (required), service, environment, kv, json (optional).inputSchema: { workspacePath: z .string() .describe("The path to the workspace to list variables from"), service: z .string() .optional() .describe("The service to show variables for (optional)"), environment: z .string() .optional() .describe("The environment to show variables for (optional)"), kv: z .boolean() .optional() .describe("Show variables in KV format (optional)"), json: z.boolean().optional().describe("Output in JSON format (optional)"), },
- src/index.ts:21-31 (registration)Registers all tools (including list-variables) from the tools module 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, ); });
- src/cli/variables.ts:13-47 (helper)Core helper function that constructs and executes the 'railway variables' CLI command with options, handling errors via analyzeRailwayError.export const listRailwayVariables = async ({ workspacePath, service, environment, kv, json, }: ListVariablesOptions): Promise<string> => { try { await checkRailwayCliStatus(); const result = await getLinkedProjectInfo({ workspacePath }); if (!result.success) { throw new Error(result.error); } let command = "railway variables"; if (service) { command += ` --service ${service}`; } if (environment) { command += ` --environment ${environment}`; } if (kv) { command += " --kv"; } if (json) { command += " --json"; } const { output } = await runRailwayCommand(command, workspacePath); return output; } catch (error: unknown) { return analyzeRailwayError(error, "railway variables"); } };