variable_set
Create or update an environment variable to set configuration values, update connection strings, or manage service secrets.
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
| 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:60-62 (handler)The handler function for the 'variable_set' tool. It calls variableService.upsertVariable() with projectId, environmentId, name, value, and optional serviceId.
async ({ projectId, environmentId, name, value, serviceId }) => { return variableService.upsertVariable(projectId, environmentId, name, value, serviceId); } - src/tools/variable.tool.ts:53-59 (schema)The Zod schema defining input parameters for variable_set: projectId, environmentId, name, value (all required strings), and serviceId (optional string).
{ 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)Registration of all tools (including variable_set) with the MCP server via server.tool().
allTools.forEach((tool) => { server.tool( ...tool ); }); - The upsertVariable() method in VariableService that executes the actual API call to set/update a variable.
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)}`); } } - src/tools/variable.tool.ts:6-19 (helper)The createTool() function from utils/tools.ts that wraps the name, description, schema, and handler into a tuple.
createTool( "list_service_variables", formatToolDescription({ type: 'API', description: "List all environment variables for a service", bestFor: [ "Viewing service configuration", "Auditing environment variables", "Checking connection strings" ], relations: { prerequisites: ["service_list"], nextSteps: ["variable_set", "variable_delete"], related: ["service_info", "variable_bulk_set"]