Skip to main content
Glama

variable_set

Set or update environment variables for services on railway-mcp, ideal for configuring values, managing secrets, and updating connection strings. Use for individual variable changes.

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
NameRequiredDescriptionDefault
environmentIdYesID of the environment for the variable (usually obtained from service_list)
nameYesName of the environment variable
projectIdYesID of the project containing the service
serviceIdNoOptional: ID of the service for the variable, if omitted creates/updates a shared variable
valueYesValue to set for the variable

Implementation Reference

  • The execution handler for the 'variable_set' tool, which delegates to the variable service's upsertVariable method.
    async ({ projectId, environmentId, name, value, serviceId }) => {
      return variableService.upsertVariable(projectId, environmentId, name, value, serviceId);
    }
  • Zod input schema defining 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")
    },
  • Creates and registers the 'variable_set' tool, including its metadata, schema, and handler. This is included in the exported variableTools array.
    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);
      }
    ),
  • Helper service method that performs the actual upsert (create or update) of the environment variable by calling the API client.
    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)}`);
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jason-tan-swe/railway-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server