Files
agenticSystem/mcp-server/tools/layout/get_layout_field.js
2026-04-21 16:55:37 +00:00

57 lines
2.6 KiB
JavaScript

import { z } from "zod";
import { withAuth } from "../../auth/index.js";
import { withAuthParams } from "../helpers/authSchema.js";
import { handleToolError } from "../helpers/errorHandler.js";
import { pythonGet } from "../helpers/pythonServerClient.js";
import { getCurrentProjectInfo } from "../files/helpers.js";
// Tool: get_layout_field
// Reads a global layout field (style or javascript) from the project's layout.json
// via the Python endpoint. Read-only — delegates to the backend which parses
// layout.json and returns the raw content string plus layoutExists flag.
export function registerGetLayoutFieldTool(server) {
server.tool(
"get_layout_field",
`Get the content of a global layout field: 'style', 'javascript', 'header' or 'footer'. For header/footer this is the source of truth — the .tpl files in template/estandar/modulos/custom-{header,footer}-twig/ are generated artifacts. Always prefer this over acai-view on those .tpl files when you need to read the global header/footer source.`,
withAuthParams({
field: z.enum(["style", "javascript", "header", "footer"]).describe("Which layout field: 'style', 'javascript', 'header' or 'footer'"),
}),
{ readOnlyHint: true, destructiveHint: false },
withAuth(async ({ field }, _extra) => {
try {
const { projectSlug } = getCurrentProjectInfo();
const result = await pythonGet("/api/project/layout-field", {
project: projectSlug,
field,
});
if (!result?.success) {
return {
content: [{
type: "text",
text: JSON.stringify({
success: false,
error: result?.error || "Could not read layout field",
}),
}],
isError: true,
};
}
return {
content: [{
type: "text",
text: JSON.stringify({
success: true,
field: result.field || field,
content: result.content || "",
layoutExists: !!result.layoutExists,
}, null, 2),
}],
};
} catch (error) {
return handleToolError(error, "get_layout_field", { field });
}
})
);
}