Skip to main content
Glama

set_secret

Store or update environment variables for serverless functions by setting project secrets like API keys, which are injected as process.env variables during execution.

Instructions

Set a project secret (e.g. STRIPE_SECRET_KEY). Secrets are injected as process.env variables in functions. Setting an existing key overwrites it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe project ID
keyYesSecret key (uppercase alphanumeric + underscores, e.g. 'STRIPE_SECRET_KEY')
valueYesSecret value (will be injected as process.env in functions)

Implementation Reference

  • The handleSetSecret function executes the set_secret tool logic. It validates the project exists, makes a POST request to the API to set the secret, and returns a success message with instructions on how to access the secret in functions.
    export async function handleSetSecret(args: {
      project_id: string;
      key: string;
      value: string;
    }): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> {
      const project = getProject(args.project_id);
      if (!project) return projectNotFound(args.project_id);
    
      const res = await apiRequest(`/admin/v1/projects/${args.project_id}/secrets`, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${project.service_key}`,
        },
        body: {
          key: args.key,
          value: args.value,
        },
      });
    
      if (!res.ok) return formatApiError(res, "setting secret");
    
      return {
        content: [
          {
            type: "text",
            text: `## Secret Set\n\nSecret \`${args.key}\` has been set for project \`${args.project_id}\`.\n\nAccess it in your functions via \`process.env.${args.key}\`.`,
          },
        ],
      };
    }
  • Input schema definition using Zod for the set_secret tool. Defines three required parameters: project_id (string), key (string with uppercase alphanumeric + underscores format), and value (string that will be injected as process.env in functions).
    export const setSecretSchema = {
      project_id: z.string().describe("The project ID"),
      key: z
        .string()
        .describe("Secret key (uppercase alphanumeric + underscores, e.g. 'STRIPE_SECRET_KEY')"),
      value: z
        .string()
        .describe("Secret value (will be injected as process.env in functions)"),
    };
  • src/index.ts:176-181 (registration)
    Registration of the set_secret tool with the MCP server. Associates the tool name 'set_secret' with its schema (setSecretSchema) and handler function (handleSetSecret).
    server.tool(
      "set_secret",
      "Set a project secret (e.g. STRIPE_SECRET_KEY). Secrets are injected as process.env variables in functions. Setting an existing key overwrites it.",
      setSecretSchema,
      async (args) => handleSetSecret(args),
    );

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/kychee-com/run402'

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