Get Init Template
setup_get_init_templateRetrieve default db-connection.env template content without writing files. Compare current configuration against template defaults for drift detection.
Instructions
Get raw template content of db-connection.env without writing any file. Useful as reference after current file has been modified, or for comparing current config against template defaults (drift detection).
USE WHEN:
The agent needs to see template defaults after the current file has been modified
Comparing current config with template (drift detection)
Restoring template content reference without re-running init
The user asks things like "show me the default template", "lihat template config default", "apa isi template defaultnya", "what does the default config look like", "bandingkan dengan template asli", "compare against the original template"
DO NOT USE FOR:
Generating new config files in the project -> use 'setup_init_config'
Reading current config -> use 'setup_read_env'
Getting structured schema (JSON) -> use 'setup_get_config_schema'
This tool runs: npx restforge-cli config:template in the given cwd. This tool is READ-ONLY and safe to call repeatedly. No file is written. Requires restforgejs >= 2.3.1.
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", "set up the initial config", "show the active configuration").
Speak in plain language. Summarise what the template contains (sections present, total parameters); do not paste the entire template body unless the user explicitly asks for it.
When a precondition is not met (e.g. the package is not installed), frame it as a question or next-step suggestion rather than an error.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | Yes | Absolute path of the project folder (must have restforgejs installed in node_modules) |
Implementation Reference
- The main handler function 'registerSetupGetInitTemplate' that registers the 'setup_get_init_template' tool with the MCP server. It checks the precondition (restforgejs installed), runs 'npx restforge-cli config:template', and returns the template content as a read-only preview.
export function registerSetupGetInitTemplate(server: McpServer): void { server.registerTool( 'setup_get_init_template', { title: 'Get Init Template', description: `Get raw template content of db-connection.env without writing any file. Useful as reference after current file has been modified, or for comparing current config against template defaults (drift detection). USE WHEN: - The agent needs to see template defaults after the current file has been modified - Comparing current config with template (drift detection) - Restoring template content reference without re-running init - The user asks things like "show me the default template", "lihat template config default", "apa isi template defaultnya", "what does the default config look like", "bandingkan dengan template asli", "compare against the original template" DO NOT USE FOR: - Generating new config files in the project -> use 'setup_init_config' - Reading current config -> use 'setup_read_env' - Getting structured schema (JSON) -> use 'setup_get_config_schema' This tool runs: npx restforge-cli config:template in the given cwd. This tool is READ-ONLY and safe to call repeatedly. No file is written. Requires restforgejs >= 2.3.1. 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", "set up the initial config", "show the active configuration"). - Speak in plain language. Summarise what the template contains (sections present, total parameters); do not paste the entire template body unless the user explicitly asks for it. - When a precondition is not met (e.g. the package is not installed), frame it as a question or next-step suggestion rather than an error.`, inputSchema: { cwd: z.string().min(1).describe('Absolute path of the project folder (must have restforgejs installed in node_modules)'), }, annotations: { title: 'Get Init Template', readOnlyHint: true, idempotentHint: true, }, }, async ({ cwd }) => { const projectCwd = resolve(cwd); // Precondition check: restforgejs must be installed before this CLI command can run. // 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 For the assistant: - The default config template can only be retrieved once the RESTForge package is installed locally. - Suggest installing the package first, then retry getting the template. - 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 }; } // Run subprocess with NODE_ENV=production to suppress legacy banner output. // stripFinalNewline=false to preserve byte-perfect template content // (matches the trailing newline in db-connection.env file written by `restforge-cli init`). const result = await execProcess( 'npx', ['restforge-cli', 'config:template'], { cwd: projectCwd, timeout: 15_000, env: { NODE_ENV: 'production' }, stripFinalNewline: false, } ); // CLI failure: real error per §3.4; structured per §3.5. if (!result.success) { return { content: [ { type: 'text', text: `Failed to retrieve the configuration template. Project path: ${projectCwd} 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 the default template could not be retrieved. - A common cause is an older RESTForge version that does not yet expose the template command (requires restforgejs >= 2.3.1). Suggest upgrading the package as a likely fix. - Do not paste the raw stdout/stderr unless the user explicitly asks. Do not mention internal tool names.`, }, ], isError: true, // per §3.4 }; } // Success: one-line summary + labeled facts + fenced template body per §3.5. return { content: [ { type: 'text', text: `Configuration template retrieved successfully. Project path: ${projectCwd} Source: restforge-cli (matches the template that 'init' would write into config/db-connection.env) Note: this is a read-only preview; no file was written. --- Template (db-connection.env) --- ${result.stdout}--- end Template (db-connection.env) --- For the assistant: - Confirm to the user that the default template is available. - Summarise the template in plain language: which sections are present (database, license, optional Live Sync / Redis / Kafka / Logging) and the total parameter count. - Do not paste the full template body unless the user explicitly asks for it. If the user is doing drift detection, the full template content is available between the fenced markers above for programmatic comparison. - Do not mention internal tool names.`, }, ], }; } ); } - Input schema definition for the tool: requires a 'cwd' string parameter (absolute path of the project folder). Also includes tool description, annotations (readOnlyHint, idempotentHint), and detailed usage guidance.
{ title: 'Get Init Template', description: `Get raw template content of db-connection.env without writing any file. Useful as reference after current file has been modified, or for comparing current config against template defaults (drift detection). USE WHEN: - The agent needs to see template defaults after the current file has been modified - Comparing current config with template (drift detection) - Restoring template content reference without re-running init - The user asks things like "show me the default template", "lihat template config default", "apa isi template defaultnya", "what does the default config look like", "bandingkan dengan template asli", "compare against the original template" DO NOT USE FOR: - Generating new config files in the project -> use 'setup_init_config' - Reading current config -> use 'setup_read_env' - Getting structured schema (JSON) -> use 'setup_get_config_schema' This tool runs: npx restforge-cli config:template in the given cwd. This tool is READ-ONLY and safe to call repeatedly. No file is written. Requires restforgejs >= 2.3.1. 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", "set up the initial config", "show the active configuration"). - Speak in plain language. Summarise what the template contains (sections present, total parameters); do not paste the entire template body unless the user explicitly asks for it. - When a precondition is not met (e.g. the package is not installed), frame it as a question or next-step suggestion rather than an error.`, inputSchema: { cwd: z.string().min(1).describe('Absolute path of the project folder (must have restforgejs installed in node_modules)'), }, annotations: { title: 'Get Init Template', readOnlyHint: true, idempotentHint: true, - src/tools/setup/index.ts:10-22 (registration)Registration point: imports 'registerSetupGetInitTemplate' from './get-init-template.js' and calls it on line 21 within the 'registerSetupTools' function that registers all setup tools.
import { registerSetupGetInitTemplate } from './get-init-template.js'; export function registerSetupTools(server: McpServer): void { registerSetupCreateFolder(server); registerSetupInstallPackage(server); registerSetupInitConfig(server); registerSetupWriteEnv(server); registerSetupReadEnv(server); registerSetupUpdateEnv(server); registerSetupValidateConfig(server); registerSetupGetConfigSchema(server); registerSetupGetInitTemplate(server); } - src/lib/exec.ts:33-69 (helper)The 'execProcess' helper function used by the handler to execute 'npx restforge-cli config:template' via execa, supporting options like cwd, timeout, env, and stripFinalNewline.
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, }; } }