save_as_template
Save an existing UI schema node as a reusable block template by providing a UID and metadata such as name and collection.
Instructions
Save an existing UI schema node as a reusable block template
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | UI schema UID to save as template | |
| values | Yes | Template metadata (e.g. name, componentName, collectionName) |
Implementation Reference
- src/index.ts:174-179 (handler)The handler function that executes the save_as_template tool logic. It makes a POST request to /api/uiSchemas:saveAsTemplate/{uid} with template metadata values.
async ({ uid, values }) => ok(await nocoFetch(`/api/uiSchemas:saveAsTemplate/${uid}`, { method: "POST", body: JSON.stringify({ values }), })) ); - src/index.ts:167-172 (schema)Input schema for save_as_template: requires uid (string) and values (record of unknown, i.e. JSON object) for template metadata.
{ description: "Save an existing UI schema node as a reusable block template", inputSchema: { uid: z.string().describe("UI schema UID to save as template"), values: JsonObject.describe("Template metadata (e.g. name, componentName, collectionName)"), }, - src/index.ts:165-179 (registration)Registration of the 'save_as_template' tool on the MCP server via server.registerTool().
server.registerTool( "save_as_template", { description: "Save an existing UI schema node as a reusable block template", inputSchema: { uid: z.string().describe("UI schema UID to save as template"), values: JsonObject.describe("Template metadata (e.g. name, componentName, collectionName)"), }, }, async ({ uid, values }) => ok(await nocoFetch(`/api/uiSchemas:saveAsTemplate/${uid}`, { method: "POST", body: JSON.stringify({ values }), })) ); - src/index.ts:18-27 (helper)The nocoFetch helper function used by the handler to make HTTP requests to the NocoBase API backend.
async function nocoFetch(path: string, options: RequestInit = {}): Promise<unknown> { const url = `${NOCOBASE_URL}${path}`; const res = await fetch(url, { ...options, headers: { ...reqHeaders, ...(options.headers as Record<string, string> | undefined) }, }); const text = await res.text(); if (!res.ok) throw new Error(`HTTP ${res.status} ${res.statusText}: ${text}`); try { return JSON.parse(text); } catch { return text; } }