libraries
This commit is contained in:
61
mcp-server/tools/libraries/set_global_libraries.js
Normal file
61
mcp-server/tools/libraries/set_global_libraries.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "../../auth/index.js";
|
||||
import { withAuthParams } from "../helpers/authSchema.js";
|
||||
import { handleToolError } from "../helpers/errorHandler.js";
|
||||
import { pythonPost } from "../helpers/pythonServerClient.js";
|
||||
import { getCurrentProjectInfo } from "../files/helpers.js";
|
||||
|
||||
// Tool: set_global_libraries
|
||||
// Replaces the entire list of libraries for a section. Destructive — overwrites
|
||||
// everything. Prefer add/remove for incremental edits; use this for bulk reorder
|
||||
// or full replacement.
|
||||
|
||||
export function registerSetGlobalLibrariesTool(server) {
|
||||
server.tool(
|
||||
"set_global_libraries",
|
||||
`Replace the entire list of libraries for a section. Destructive — overwrites all existing entries. Prefer add/remove for incremental edits. Use for bulk reorder/replace.`,
|
||||
withAuthParams({
|
||||
section: z.enum(["top", "bottom"]).describe("Target section: 'top' = <head>, 'bottom' = before </body>"),
|
||||
libraries: z.array(z.object({
|
||||
url: z.string().min(1),
|
||||
})).describe("Full replacement list. Order is preserved."),
|
||||
}),
|
||||
{ readOnlyHint: false, destructiveHint: true },
|
||||
withAuth(async ({ section, libraries }, _extra) => {
|
||||
try {
|
||||
const { projectSlug } = getCurrentProjectInfo();
|
||||
|
||||
const saveResult = await pythonPost("/api/project/libraries/save", {
|
||||
project: projectSlug,
|
||||
section,
|
||||
libraries,
|
||||
});
|
||||
if (!saveResult?.success) {
|
||||
return {
|
||||
content: [{
|
||||
type: "text",
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error: saveResult?.error || "Could not save libraries",
|
||||
}),
|
||||
}],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
content: [{
|
||||
type: "text",
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
section: saveResult.section || section,
|
||||
entries: saveResult.libraries || [],
|
||||
}, null, 2),
|
||||
}],
|
||||
};
|
||||
} catch (error) {
|
||||
return handleToolError(error, "set_global_libraries", { section, count: Array.isArray(libraries) ? libraries.length : 0 });
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user