update_js_block
Update the code content of a JavaScript block on a classic page by specifying its UI schema UID and providing new JavaScript code.
Instructions
Update the code content of a JS block UI schema by UID (for classic 'page' type pages, not flowPage)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | UI schema UID of the JS block | |
| code | Yes | New JavaScript code content |
Implementation Reference
- src/index.ts:348-364 (registration)Registration of the 'update_js_block' tool with inputSchema (uid, code) and handler calling PATCH /api/uiSchemas/${uid} to update the JS block code content.
server.registerTool( "update_js_block", { description: "Update the code content of a JS block UI schema by UID (for classic 'page' type pages, not flowPage)", inputSchema: { uid: z.string().describe("UI schema UID of the JS block"), code: z.string().describe("New JavaScript code content"), }, }, async ({ uid, code }) => ok( await nocoFetch(`/api/uiSchemas/${uid}`, { method: "PATCH", body: JSON.stringify({ "x-component-props": { code } }), }) ) ); - src/index.ts:357-363 (handler)Handler function for update_js_block: receives uid and code, then calls nocoFetch to PATCH the UI schema with new code in 'x-component-props'.
async ({ uid, code }) => ok( await nocoFetch(`/api/uiSchemas/${uid}`, { method: "PATCH", body: JSON.stringify({ "x-component-props": { code } }), }) ) - src/index.ts:351-356 (schema)Input schema for update_js_block: requires uid (string) and code (string) parameters.
description: "Update the code content of a JS block UI schema by UID (for classic 'page' type pages, not flowPage)", inputSchema: { uid: z.string().describe("UI schema UID of the JS block"), code: z.string().describe("New JavaScript code content"), }, }, - src/index.ts:18-27 (helper)The nocoFetch helper function used by the handler to make authenticated HTTP requests to the NocoBase API.
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; } } - src/index.ts:29-31 (helper)The ok helper function that wraps the response data into the MCP content format.
const ok = (data: unknown) => ({ content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], });