list-variables
Display environment variables for active Railway projects to manage configuration settings across services and deployments.
Instructions
Show variables for the active environment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspacePath | Yes | The path to the workspace to list variables from | |
| service | No | The service to show variables for (optional) | |
| environment | No | The environment to show variables for (optional) | |
| kv | No | Show variables in KV format (optional) | |
| json | No | Output in JSON format (optional) |
Implementation Reference
- src/tools/list-variables.ts:28-58 (handler)The MCP tool handler for 'list-variables' that invokes the CLI wrapper function and formats the response with error handling.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-based input schema defining parameters for the list-variables tool.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)Registration of all tools (imported as * from './tools') into the MCP server, including the list-variables tool.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)Helper function that constructs and executes the 'railway variables' CLI command with provided options.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"); } };