variable_set
Create or update environment variables in Railway.app projects to configure services, manage secrets, and set connection strings for deployments.
Instructions
[API] Create or update an environment variable
⚡️ Best for: ✓ Setting configuration values ✓ Updating connection strings ✓ Managing service secrets
⚠️ Not for: × Bulk variable updates (use variable_bulk_set) × Temporary configuration changes
→ Prerequisites: service_list
→ Alternatives: variable_bulk_set
→ Next steps: deployment_trigger, service_restart
→ Related: variable_list, variable_delete
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | ID of the project containing the service | |
| environmentId | Yes | ID of the environment for the variable (usually obtained from service_list) | |
| name | Yes | Name of the environment variable | |
| value | Yes | Value to set for the variable | |
| serviceId | No | Optional: ID of the service for the variable, if omitted creates/updates a shared variable |
Implementation Reference
- src/tools/variable.tool.ts:32-63 (registration)Full registration of the 'variable_set' tool using createTool, including description, input schema, and handler function.createTool( "variable_set", formatToolDescription({ type: 'API', description: "Create or update an environment variable", bestFor: [ "Setting configuration values", "Updating connection strings", "Managing service secrets" ], notFor: [ "Bulk variable updates (use variable_bulk_set)", "Temporary configuration changes" ], relations: { prerequisites: ["service_list"], nextSteps: ["deployment_trigger", "service_restart"], alternatives: ["variable_bulk_set"], related: ["variable_list", "variable_delete"] } }), { projectId: z.string().describe("ID of the project containing the service"), environmentId: z.string().describe("ID of the environment for the variable (usually obtained from service_list)"), name: z.string().describe("Name of the environment variable"), value: z.string().describe("Value to set for the variable"), serviceId: z.string().optional().describe("Optional: ID of the service for the variable, if omitted creates/updates a shared variable") }, async ({ projectId, environmentId, name, value, serviceId }) => { return variableService.upsertVariable(projectId, environmentId, name, value, serviceId); } ),
- src/tools/variable.tool.ts:60-62 (handler)Handler function that executes the tool logic by delegating to variableService.upsertVariable.async ({ projectId, environmentId, name, value, serviceId }) => { return variableService.upsertVariable(projectId, environmentId, name, value, serviceId); }
- src/tools/variable.tool.ts:53-59 (schema)Zod schema defining the input parameters for the variable_set tool.{ projectId: z.string().describe("ID of the project containing the service"), environmentId: z.string().describe("ID of the environment for the variable (usually obtained from service_list)"), name: z.string().describe("Name of the environment variable"), value: z.string().describe("Value to set for the variable"), serviceId: z.string().optional().describe("Optional: ID of the service for the variable, if omitted creates/updates a shared variable") },
- src/tools/index.ts:32-36 (registration)MCP server registration loop that registers the variable_set tool (imported via variableTools).allTools.forEach((tool) => { server.tool( ...tool ); });
- Supporting service method upsertVariable called by the tool handler to perform the actual variable update via client API.async upsertVariable(projectId: string, environmentId: string, name: string, value: string, serviceId?: string) { try { await this.client.variables.upsertVariable({ projectId, environmentId, name, value, serviceId }); const variableType = serviceId ? "service variable" : "shared environment variable"; return createSuccessResponse({ text: `Successfully set ${variableType} "${name}"` }); } catch (error) { return createErrorResponse(`Error setting variable: ${formatError(error)}`); } }