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
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | The project ID | |
| key | Yes | Secret key (uppercase alphanumeric + underscores, e.g. 'STRIPE_SECRET_KEY') | |
| value | Yes | Secret value (will be injected as process.env in functions) |
Implementation Reference
- src/tools/set-secret.ts:16-45 (handler)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}\`.`, }, ], }; } - src/tools/set-secret.ts:6-14 (schema)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), );