Skip to main content
Glama

provision_postgres_project

Set up a new Postgres database with tiered pricing options. Returns credentials upon successful provisioning or payment details if required.

Instructions

Provision a new Postgres database. Returns project credentials on success, or payment details if x402 payment is needed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tierNoDatabase tier: prototype ($0.10/7d), hobby ($5/30d), team ($20/30d)prototype
nameNoOptional project name (auto-generated if omitted)

Implementation Reference

  • The handleProvision function executes the tool logic - makes an API request to provision a Postgres database, handles 402 payment responses, saves credentials to the keystore on success, and returns formatted results.
    export async function handleProvision(args: {
      tier?: string;
      name?: string;
    }): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> {
      const tier = args.tier || "prototype";
      const name = args.name;
    
      const res = await apiRequest("/v1/projects", {
        method: "POST",
        body: { tier, name },
      });
    
      if (res.is402) {
        const body = res.body as Record<string, unknown>;
        const lines = [
          `## Payment Required`,
          ``,
          `To provision a **${tier}** database, an x402 payment is needed.`,
          ``,
        ];
        if (body.x402) {
          lines.push(`**Payment details:**`);
          lines.push("```json");
          lines.push(JSON.stringify(body.x402, null, 2));
          lines.push("```");
        } else {
          lines.push(`**Server response:**`);
          lines.push("```json");
          lines.push(JSON.stringify(body, null, 2));
          lines.push("```");
        }
        lines.push(``);
        lines.push(
          `The user's wallet or payment agent must send the required amount. ` +
          `Once payment is confirmed, retry this tool call.`,
        );
        // Return as text (NOT isError) so the LLM can reason about payment
        return { content: [{ type: "text", text: lines.join("\n") }] };
      }
    
      if (!res.ok) return formatApiError(res, "provisioning project");
    
      const body = res.body as {
        project_id: string;
        anon_key: string;
        service_key: string;
        tier: string;
        lease_expires_at: string;
        schema_slot: string;
      };
    
      // Save credentials to local key store
      saveProject(body.project_id, {
        anon_key: body.anon_key,
        service_key: body.service_key,
        tier: body.tier,
        expires_at: body.lease_expires_at,
      });
    
      const lines = [
        `## Project Provisioned`,
        ``,
        `| Field | Value |`,
        `|-------|-------|`,
        `| project_id | \`${body.project_id}\` |`,
        `| tier | ${body.tier} |`,
        `| schema | ${body.schema_slot} |`,
        `| expires | ${body.lease_expires_at} |`,
        ``,
        `Keys saved to local key store. You can now use \`run_sql\`, \`rest_query\`, and \`upload_file\` with this project.`,
      ];
    
      return { content: [{ type: "text", text: lines.join("\n") }] };
    }
  • The provisionSchema defines input validation using Zod - accepts an optional 'tier' enum (prototype/hobby/team, defaulting to prototype) and an optional 'name' string for the project name.
    export const provisionSchema = {
      tier: z
        .enum(["prototype", "hobby", "team"])
        .default("prototype")
        .describe("Database tier: prototype ($0.10/7d), hobby ($5/30d), team ($20/30d)"),
      name: z
        .string()
        .optional()
        .describe("Optional project name (auto-generated if omitted)"),
    };
  • src/index.ts:65-70 (registration)
    Registers the 'provision_postgres_project' tool with the MCP server, providing a description and linking the schema and handler.
    server.tool(
      "provision_postgres_project",
      "Provision a new Postgres database. Returns project credentials on success, or payment details if x402 payment is needed.",
      provisionSchema,
      async (args) => handleProvision(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