Skip to main content
Glama

deploy_function

Deploy serverless Node.js functions with pre-bundled packages including Stripe, OpenAI, and Anthropic for handling HTTP requests in run402 projects.

Instructions

Deploy a serverless function (Node 22) to a project. Handler signature: export default async (req: Request) => Response. Pre-bundled packages: stripe, openai, @anthropic-ai/sdk, resend, zod, uuid, jsonwebtoken, bcryptjs, cheerio, csv-parse.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe project ID to deploy the function to
nameYesFunction name (URL-safe slug: lowercase, hyphens, alphanumeric, e.g. 'stripe-webhook')
codeYesTypeScript or JavaScript source code. Must export a default async function: export default async (req: Request) => Response
configNoOptional function configuration
depsNoOptional npm packages to install alongside pre-bundled packages

Implementation Reference

  • The main handler function that executes the deploy_function tool logic. Validates the project exists, makes a POST request to the admin API to deploy the function, handles payment-required errors, and returns a formatted response with function details including name, URL, status, runtime, timeout, and memory.
    export async function handleDeployFunction(args: {
      project_id: string;
      name: string;
      code: string;
      config?: { timeout?: number; memory?: number };
      deps?: 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}/functions`, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${project.service_key}`,
        },
        body: {
          name: args.name,
          code: args.code,
          config: args.config,
          deps: args.deps,
        },
      });
    
      if (res.is402) {
        const body = res.body as Record<string, unknown>;
        return {
          content: [
            {
              type: "text",
              text: `## Payment Required\n\nProject lease expired. Renew to continue deploying functions.\n\n\`\`\`json\n${JSON.stringify(body, null, 2)}\n\`\`\``,
            },
          ],
        };
      }
    
      if (!res.ok) return formatApiError(res, "deploying function");
    
      const body = res.body as {
        name: string;
        url: string;
        status: string;
        runtime: string;
        timeout: number;
        memory: number;
        created_at: string;
      };
    
      const lines = [
        `## Function Deployed`,
        ``,
        `| Field | Value |`,
        `|-------|-------|`,
        `| name | \`${body.name}\` |`,
        `| url | ${body.url} |`,
        `| status | ${body.status} |`,
        `| runtime | ${body.runtime} |`,
        `| timeout | ${body.timeout}s |`,
        `| memory | ${body.memory}MB |`,
        ``,
        `The function is live at **${body.url}**`,
        ``,
        `Invoke with: \`invoke_function(project_id: "${args.project_id}", name: "${body.name}")\``,
      ];
    
      return { content: [{ type: "text", text: lines.join("\n") }] };
    }
  • Input schema definition using Zod that validates and describes the tool parameters: project_id (required), name (function name slug), code (TypeScript/JavaScript source), config (optional timeout and memory settings), and deps (optional npm packages array).
    export const deployFunctionSchema = {
      project_id: z.string().describe("The project ID to deploy the function to"),
      name: z
        .string()
        .describe("Function name (URL-safe slug: lowercase, hyphens, alphanumeric, e.g. 'stripe-webhook')"),
      code: z
        .string()
        .describe("TypeScript or JavaScript source code. Must export a default async function: export default async (req: Request) => Response"),
      config: z
        .object({
          timeout: z.number().optional().describe("Timeout in seconds (default: tier max)"),
          memory: z.number().optional().describe("Memory in MB (default: tier max)"),
        })
        .optional()
        .describe("Optional function configuration"),
      deps: z
        .array(z.string())
        .optional()
        .describe("Optional npm packages to install alongside pre-bundled packages"),
    };
  • src/index.ts:139-144 (registration)
    Registers the deploy_function tool with the MCP server. Defines the tool name, description, schema, and handler function mapping. The description specifies Node 22 runtime and lists pre-bundled packages (stripe, openai, @anthropic-ai/sdk, etc.).
    server.tool(
      "deploy_function",
      "Deploy a serverless function (Node 22) to a project. Handler signature: export default async (req: Request) => Response. Pre-bundled packages: stripe, openai, @anthropic-ai/sdk, resend, zod, uuid, jsonwebtoken, bcryptjs, cheerio, csv-parse.",
      deployFunctionSchema,
      async (args) => handleDeployFunction(args),
    );
  • Import statement that brings in deployFunctionSchema and handleDeployFunction from the tools/deploy-function module, making them available for registration.
    import { deployFunctionSchema, handleDeployFunction } from "./tools/deploy-function.js";

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