mcp tablas
This commit is contained in:
44
mcp-server/tools/tables/updateMetadata.js
Normal file
44
mcp-server/tools/tables/updateMetadata.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "../../auth/index.js";
|
||||
import { withAuthParams } from "../helpers/authSchema.js";
|
||||
import { handleToolError } from "../helpers/errorHandler.js";
|
||||
import { callSchemaEndpoint } from "./_schemaEndpoint.js";
|
||||
|
||||
// Tool: update_table_metadata
|
||||
// Edita el bloque [meta] de un schema (menuName, menuType, listPage*, etc.) y
|
||||
// opcionalmente renombra la tabla en MySQL. Delegamos en /api/schema/update-table-meta.
|
||||
|
||||
export function registerUpdateTableMetadataTool(server) {
|
||||
server.tool(
|
||||
"update_table_metadata",
|
||||
`Update the metadata block of a table (the [meta] section of its schema).
|
||||
|
||||
Accepted keys in 'meta' include:
|
||||
menuName, menuDesc, menuType, menuOrder, menuDisplay, menuHidden,
|
||||
controller, breadcrumbField, breadcrumbByLink, breadcrumbParentNum,
|
||||
listPageFields (csv), listPageOrder, listPageSearchFields.
|
||||
|
||||
If 'newTableName' is provided the underlying MySQL table is RENAMED. This is
|
||||
destructive because any hardcoded references (custom controllers, module SQL,
|
||||
embedded queries in content) WILL break — audit the codebase before renaming.
|
||||
|
||||
Table names are WITHOUT the 'cms_' prefix.`,
|
||||
withAuthParams({
|
||||
tableName: z.string().describe("Current table name, without 'cms_' prefix"),
|
||||
meta: z.object({}).passthrough().describe("Partial meta object with the keys you want to change"),
|
||||
newTableName: z.string().optional().describe("If set, rename the table. Breaks hardcoded references — confirm with user first."),
|
||||
}),
|
||||
{ readOnlyHint: false, destructiveHint: true },
|
||||
withAuth(async ({ tableName, meta, newTableName }, _extra) => {
|
||||
try {
|
||||
const body = { tableName, meta };
|
||||
if (newTableName) body.newTableName = newTableName;
|
||||
|
||||
const { mcp } = await callSchemaEndpoint("/api/schema/update-table-meta", body);
|
||||
return mcp;
|
||||
} catch (error) {
|
||||
return handleToolError(error, "update_table_metadata", { tableName, newTableName });
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user