libraries
This commit is contained in:
62
mcp-server/tools/libraries/list_global_libraries.js
Normal file
62
mcp-server/tools/libraries/list_global_libraries.js
Normal file
@@ -0,0 +1,62 @@
|
||||
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: list_global_libraries
|
||||
// Lists the global libraries (CSS/JS/fonts) injected in <head> and before </body>
|
||||
// for the current Acai project. Use this before add/remove to inspect the current
|
||||
// state. Read-only — delegates to the Python endpoint which parses layout.json.
|
||||
|
||||
export function registerListGlobalLibrariesTool(server) {
|
||||
server.tool(
|
||||
"list_global_libraries",
|
||||
`List the project's global libraries (CSS/JS/fonts injected site-wide).
|
||||
|
||||
Returns two sections:
|
||||
- top: entries injected inside <head> (CSS, preloaded fonts, critical JS).
|
||||
- bottom: entries injected right before </body> (most JS).
|
||||
|
||||
Each entry is { num, url } where num is the internal index used by the CMS.
|
||||
Also returns layoutExists to signal whether layout.json exists for the project.
|
||||
|
||||
Use this before add_global_library / remove_global_library to verify current state
|
||||
or to check whether a library is already registered.`,
|
||||
withAuthParams({}),
|
||||
{ readOnlyHint: true, destructiveHint: false },
|
||||
withAuth(async (_args, _extra) => {
|
||||
try {
|
||||
const { projectSlug } = getCurrentProjectInfo();
|
||||
const result = await pythonGet("/api/project/libraries", {
|
||||
project: projectSlug,
|
||||
});
|
||||
if (!result?.success) {
|
||||
return {
|
||||
content: [{
|
||||
type: "text",
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error: result?.error || "Could not read libraries",
|
||||
}),
|
||||
}],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
content: [{
|
||||
type: "text",
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
top: result.top || [],
|
||||
bottom: result.bottom || [],
|
||||
layoutExists: !!result.layoutExists,
|
||||
}, null, 2),
|
||||
}],
|
||||
};
|
||||
} catch (error) {
|
||||
return handleToolError(error, "list_global_libraries", {});
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user