variable_delete
Removes specific environment variables in Railway services to manage configurations, enhance security, or clean up unused settings. Requires project, environment, and variable details for precise deletion.
Instructions
[API] Delete a variable for a service in a specific environment
⚡️ Best for: ✓ Removing unused configuration ✓ Security cleanup ✓ Configuration management
⚠️ Not for: × Temporary variable disabling × Bulk variable removal
→ Prerequisites: service_list
→ Next steps: deployment_trigger, service_restart
→ Related: variable_list, variable_set
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| environmentId | Yes | ID of the environment to delete the variable from (usually obtained from service_list) | |
| name | Yes | Name of the variable to delete | |
| projectId | Yes | ID of the project | |
| serviceId | No | ID of the service (optional, if omitted deletes a shared variable) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"environmentId": {
"description": "ID of the environment to delete the variable from (usually obtained from service_list)",
"type": "string"
},
"name": {
"description": "Name of the variable to delete",
"type": "string"
},
"projectId": {
"description": "ID of the project",
"type": "string"
},
"serviceId": {
"description": "ID of the service (optional, if omitted deletes a shared variable)",
"type": "string"
}
},
"required": [
"projectId",
"environmentId",
"name"
],
"type": "object"
}
Implementation Reference
- src/tools/variable.tool.ts:65-94 (registration)Registration of the 'variable_delete' tool using createTool, including formatted description, Zod input schema, and handler function that delegates to variableService.deleteVariablecreateTool( "variable_delete", formatToolDescription({ type: 'API', description: "Delete a variable for a service in a specific environment", bestFor: [ "Removing unused configuration", "Security cleanup", "Configuration management" ], notFor: [ "Temporary variable disabling", "Bulk variable removal" ], relations: { prerequisites: ["service_list"], nextSteps: ["deployment_trigger", "service_restart"], related: ["variable_list", "variable_set"] } }), { projectId: z.string().describe("ID of the project"), environmentId: z.string().describe("ID of the environment to delete the variable from (usually obtained from service_list)"), name: z.string().describe("Name of the variable to delete"), serviceId: z.string().optional().describe("ID of the service (optional, if omitted deletes a shared variable)") }, async ({ projectId, environmentId, name, serviceId }) => { return variableService.deleteVariable(projectId, environmentId, name, serviceId); } ),
- src/tools/variable.tool.ts:91-93 (handler)The core handler function for the variable_delete tool, which invokes the variable service to perform the deletionasync ({ projectId, environmentId, name, serviceId }) => { return variableService.deleteVariable(projectId, environmentId, name, serviceId); }
- src/tools/variable.tool.ts:85-89 (schema)Zod schema defining the input parameters for the variable_delete tool{ projectId: z.string().describe("ID of the project"), environmentId: z.string().describe("ID of the environment to delete the variable from (usually obtained from service_list)"), name: z.string().describe("Name of the variable to delete"), serviceId: z.string().optional().describe("ID of the service (optional, if omitted deletes a shared variable)")
- VariableService.deleteVariable method: wraps the repository call, handles errors, and formats success/error responsesasync deleteVariable(projectId: string, environmentId: string, name: string, serviceId?: string) { try { await this.client.variables.deleteVariable({ projectId, environmentId, name, serviceId }); const variableType = serviceId ? "service variable" : "shared environment variable"; return createSuccessResponse({ text: `Successfully deleted ${variableType} "${name}"` }); } catch (error) { return createErrorResponse(`Error deleting variable: ${formatError(error)}`); } }
- Repository layer executes the GraphQL mutation to delete the variable via Railway APIasync deleteVariable(input: VariableDeleteInput): Promise<void> { const { projectId, environmentId, serviceId, name } = input; await this.client.request<{ variableDelete: boolean }>(` mutation variableDelete( $projectId: String!, $environmentId: String!, $serviceId: String, $name: String! ) { variableDelete( input: { projectId: $projectId, environmentId: $environmentId, serviceId: $serviceId, name: $name } ) } `, { projectId, environmentId, serviceId, name }); }