insert_adjacent_schema
Insert a new UI schema node at a specified position relative to a target node: before, after, as first child, or as last child.
Instructions
Insert a schema node at a position relative to a target node. Position values: beforeBegin (prev sibling), afterBegin (first child), beforeEnd (last child), afterEnd (next sibling)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | Target UI schema UID to insert relative to | |
| schema | Yes | New schema node to insert (JSON) | |
| position | Yes | Insert position relative to the target node |
Implementation Reference
- src/index.ts:108-124 (registration)Registration of the insert_adjacent_schema tool on the McpServer. This is where the tool is registered with its name, input schema, and handler.
// 9. insert_adjacent_schema server.registerTool( "insert_adjacent_schema", { description: "Insert a schema node at a position relative to a target node. Position values: beforeBegin (prev sibling), afterBegin (first child), beforeEnd (last child), afterEnd (next sibling)", inputSchema: { uid: z.string().describe("Target UI schema UID to insert relative to"), schema: JsonObject.describe("New schema node to insert (JSON)"), position: z.enum(["beforeBegin", "afterBegin", "beforeEnd", "afterEnd"]).describe("Insert position relative to the target node"), }, }, async ({ uid, schema, position }) => ok(await nocoFetch(`/api/uiSchemas:insertAdjacent/${uid}`, { method: "POST", body: JSON.stringify({ schema, position }), })) ); - src/index.ts:119-124 (handler)The handler function for inserd_adjacent_schema. It takes uid, schema, and position parameters and makes an HTTP POST request to /api/uiSchemas:insertAdjacent/{uid} with the schema and position in the body.
async ({ uid, schema, position }) => ok(await nocoFetch(`/api/uiSchemas:insertAdjacent/${uid}`, { method: "POST", body: JSON.stringify({ schema, position }), })) ); - src/index.ts:113-117 (schema)Input schema definition for the insert_adjacent_schema tool. Defines three parameters: uid (string), schema (arbitrary JSON object), and position (enum of beforeBegin/afterBegin/beforeEnd/afterEnd).
inputSchema: { uid: z.string().describe("Target UI schema UID to insert relative to"), schema: JsonObject.describe("New schema node to insert (JSON)"), position: z.enum(["beforeBegin", "afterBegin", "beforeEnd", "afterEnd"]).describe("Insert position relative to the target node"), }, - src/index.ts:29-31 (helper)Helper function that wraps data into an MCP content result with JSON-formatted text.
const ok = (data: unknown) => ({ content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }); - src/index.ts:18-27 (helper)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; } }