Skip to main content
Glama
restforge

@restforge-dev/mcp-server

Official
by restforge

Generate Payload

codegen_generate_payload

Generate a payload specification file from a database table by introspecting its schema. Use this after setting up the project config to create the input needed for code generation.

Instructions

Generate a payload spec file (metadata, fields, action specs) from a database table by introspecting its schema via restforge-cli.

USE WHEN:

  • The user asks to generate a payload, payload spec, or payload metadata file from a database table

  • The user asks things like "buatkan payload dari table X", "generate payload guest_book", "scan schema table to JSON", "create payload for endpoint generation"

  • The user wants to "introspect" or "scan" a database table into a JSON spec

  • Starting CLI codegen workflow after the project config has been validated

  • Re-generating payload after a schema change in the database

DO NOT USE FOR:

  • Filling in credentials in db-connection.env -> use 'setup_write_env'

  • Validating config before generating payload -> use 'setup_validate_config'

  • Creating the project / endpoint code from a payload -> that is the next CLI step (will be wrapped in a future tool, not yet available)

This tool runs: npx restforge-cli payload --table= --config= in the given cwd. The CLI connects to the database described in the config file, reads the table schema, and writes a payload JSON file (e.g. table 'guest_book' -> 'guest-book.json' with underscore mapped to hyphen). The payload file is the input for the next codegen step (project + endpoint creation).

Preconditions:

  • The project must have restforgejs installed in node_modules.

  • The config file (default 'db-connection.env') must exist in the project and contain valid database credentials. This tool does not pre-check that — if the CLI fails, the failure response will surface the underlying cause.

PRESENTATION GUIDANCE:

  • Match the user's language. If the user writes in Indonesian, respond in Indonesian.

  • Never mention internal tool names in the reply to the user. Describe actions by what they do (e.g. "install the package", "fill in the credentials", "generate the payload").

  • Speak in plain language. Summarise the result; do not paste raw CLI output unless the user explicitly asks.

  • When a precondition is not met, frame it as a question or next-step suggestion rather than an error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdYesAbsolute path of the project folder (must contain node_modules/restforgejs and the config file)
tableYesName of the database table to introspect (e.g. guest_book)
configNoConfig file name (relative to project) used by the CLI to connect to the databasedb-connection.env

Implementation Reference

  • The async handler function that executes the 'codegen_generate_payload' tool logic. It checks for the restforgejs package in node_modules, then runs 'npx restforge-cli payload --table=<table> --config=<config>' to introspect the database table and generate a payload spec file.
        async ({ cwd, table, config }) => {
          const projectCwd = resolve(cwd);
    
          // Precondition check: restforgejs must be present in node_modules.
          // Treated as a non-error precondition per the authoring guide §3.4.
          try {
            await access(join(projectCwd, 'node_modules', 'restforgejs'));
          } catch {
            return {
              content: [
                {
                  type: 'text',
                  text: `Precondition not met: the RESTForge package is not installed in this project.
    
    Project path: ${projectCwd}
    Expected location: node_modules/restforgejs
    Requested table: ${table}
    Requested config: ${config}
    
    For the assistant:
    - The user needs to install the RESTForge package before a payload can be generated from a table schema.
    - Use the appropriate package-installation tool to do this, then retry generating the payload.
    - When explaining to the user, say something like "the RESTForge package isn't installed yet — should I install it first?". Do not mention internal tool names.`,
                },
              ],
              isError: false, // per §3.4
            };
          }
    
          const result = await execProcess(
            'npx',
            ['restforge-cli', 'payload', `--table=${table}`, `--config=${config}`],
            { cwd: projectCwd, timeout: 30_000 }
          );
    
          // CLI failure: real error per §3.4; structured per §3.5.
          if (!result.success) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Failed to generate payload.
    
    Project path: ${projectCwd}
    Table: ${table}
    Config: ${config}
    Command: ${result.command}
    Exit code: ${result.exitCode}
    
    --- CLI output ---
    stdout:
    ${result.stdout}
    
    stderr:
    ${result.stderr}
    --- end CLI output ---
    
    For the assistant:
    - Tell the user that generating the payload did not complete successfully.
    - Summarise the likely cause from the CLI output in plain language (common causes: the config file is missing or has incomplete credentials, the database is unreachable, or the requested table does not exist in the database). Do not paste the raw stdout/stderr unless the user explicitly asks.
    - Offer to retry once the underlying issue is resolved. Do not mention internal tool names.`,
                },
              ],
              isError: true, // per §3.4
            };
          }
    
          // Success: one-line summary + labeled facts + fenced raw output per §3.5.
          // The CLI itself prints the output filename in stdout; we do not try to re-derive it here.
          return {
            content: [
              {
                type: 'text',
                text: `Payload generated successfully.
    
    Project path: ${projectCwd}
    Table: ${table}
    Config: ${config}
    Output: payload file generated by restforge-cli (see CLI output below for the exact filename; underscores in the table name are mapped to hyphens, e.g. 'guest_book' -> 'guest-book.json').
    
    --- CLI output ---
    ${result.stdout}
    --- end CLI output ---
    
    For the assistant:
    - Confirm to the user that the payload spec for the requested table is ready.
    - Mention in plain language that the payload is the input for the next codegen step (generating the project and endpoint code from this payload). That follow-up step is part of the CLI workflow but is not wrapped as a tool yet.
    - Suggest that the user can review or edit the generated payload file before the next step.
    - Keep the reply concise. Do not paste the raw CLI output unless the user explicitly asks. Do not mention internal tool names.`,
              },
            ],
          };
        }
      );
    }
  • Input schema for the tool using Zod: cwd (string, required), table (string, required), config (string, default 'db-connection.env').
    inputSchema: {
      cwd: z
        .string()
        .min(1)
        .describe('Absolute path of the project folder (must contain node_modules/restforgejs and the config file)'),
      table: z
        .string()
        .min(1)
        .describe('Name of the database table to introspect (e.g. guest_book)'),
      config: z
        .string()
        .min(1)
        .default('db-connection.env')
        .describe('Config file name (relative to project) used by the CLI to connect to the database'),
    },
  • Registration of the tool via registerCodegenGeneratePayload(server) in the codegen tools aggregator.
    export function registerCodegenTools(server: McpServer): void {
      registerCodegenGeneratePayload(server);
  • The registerCodegenGeneratePayload function that calls server.registerTool('codegen_generate_payload', ...).
    export function registerCodegenGeneratePayload(server: McpServer): void {
      server.registerTool(
        'codegen_generate_payload',
  • The execProcess helper utility used by the handler to run the npx CLI command.
    export async function execProcess(
      command: string,
      args: string[],
      options: ExecOptions = {}
    ): Promise<ExecResult> {
      const { cwd = process.cwd(), timeout = 60_000, env, stripFinalNewline = true } = options;
      const fullCommand = `${command} ${args.join(' ')}`;
    
      // Merge env: parent env first, custom env overrides
      const mergedEnv = env ? { ...process.env, ...env } : undefined;
    
      try {
        const result = await execa(command, args, {
          cwd,
          timeout,
          reject: false,
          stripFinalNewline,
          ...(mergedEnv ? { env: mergedEnv } : {}),
        });
        return {
          success: result.exitCode === 0,
          stdout: result.stdout,
          stderr: result.stderr,
          exitCode: result.exitCode ?? -1,
          command: fullCommand,
        };
      } catch (error) {
        const e = error as ExecaError;
        return {
          success: false,
          stdout: e.stdout?.toString() ?? '',
          stderr: e.stderr?.toString() ?? e.message,
          exitCode: e.exitCode ?? -1,
          command: fullCommand,
        };
      }
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate readOnlyHint=false and idempotentHint=false. The description adds behavioral context: it runs a CLI command, writes a payload file, and has preconditions. It also mentions failure behavior. This adds value beyond annotations, but could further detail side effects like overwriting existing files.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (use when, do not use, preconditions, presentation guidance). Every sentence serves a purpose; no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (3 parameters, no output schema), the description thoroughly covers preconditions, CLI invocation, output file naming, and presentation guidance. It is complete for an agent to use correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description adds meaning beyond the schema by explaining the cwd precondition, that table is the database table name, and config default. This enhances understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it generates a payload spec file by introspecting a database table via CLI. It uses specific verbs and resources, and distinguishes from sibling tools like setup_write_env and setup_validate_config.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly enumerates when to use (e.g., user asks to generate payload, after project config validated) and when not to use (e.g., for credentials or validation), naming alternative tools. This provides comprehensive guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/restforge/restforge-mcp'

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