Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(mcp): guard delete_label against workspace labels

dmtrTm27b83048bd1c
diff --git a/apps/api/src/mcp/tools.ts b/apps/api/src/mcp/tools.ts
index 400252a9e..ffde29765 100644
--- a/apps/api/src/mcp/tools.ts
+++ b/apps/api/src/mcp/tools.ts
@@ -637,14 +637,23 @@ export function registerMcpTools(
"delete_label",
{
description:
- "Delete a workspace label by ID (removes it from all tasks).",
+ "Delete a label by ID. Only task-associated labels can be deleted; workspace-level labels (taskId null) are rejected by the API.",
inputSchema: z.object({ id: nonEmptyString }),
},
async (args) =>
- run(() =>
- client.json(`/api/label/${encodeURIComponent(args.id)}`, {
+ run(async () => {
+ const label = (await client.json(
+ `/api/label/${encodeURIComponent(args.id)}`,
+ { method: "GET" },
+ )) as { taskId?: string | null };
+ if (!label?.taskId) {
+ throw new Error(
+ "Label is not associated with a task and cannot be deleted (workspace-level labels are not deletable via this endpoint).",
+ );
+ }
+ return client.json(`/api/label/${encodeURIComponent(args.id)}`, {
method: "DELETE",
- }),
- ),
+ });
+ }),
);
}
diff --git a/packages/mcp/src/tools/register.test.ts b/packages/mcp/src/tools/register.test.ts
index d46ebb211..c63f1c051 100644
--- a/packages/mcp/src/tools/register.test.ts
+++ b/packages/mcp/src/tools/register.test.ts
@@ -282,16 +282,42 @@ describe("registerTools", () => {
});
});
- it("deletes a label by id", async () => {
+ it("deletes a task-associated label after a preflight check", async () => {
const { server, tools } = createServerMock();
- const client = { json: vi.fn().mockResolvedValue({}) };
+ const client = {
+ json: vi
+ .fn()
+ .mockResolvedValueOnce({ id: "label-1", taskId: "task-1" })
+ .mockResolvedValueOnce({ id: "label-1" }),
+ };
registerTools(server as never, { client: client as never });
- await tools.get("delete_label")?.handler({ id: "label-1" });
+ const result = await tools.get("delete_label")?.handler({ id: "label-1" });
- expect(client.json).toHaveBeenCalledWith("/api/label/label-1", {
+ expect(client.json).toHaveBeenNthCalledWith(1, "/api/label/label-1", {
+ method: "GET",
+ });
+ expect(client.json).toHaveBeenNthCalledWith(2, "/api/label/label-1", {
method: "DELETE",
});
+ expect(result?.isError).toBe(false);
+ });
+
+ it("refuses to delete a workspace label (taskId null)", async () => {
+ const { server, tools } = createServerMock();
+ const client = {
+ json: vi.fn().mockResolvedValue({ id: "label-1", taskId: null }),
+ };
+
+ registerTools(server as never, { client: client as never });
+
+ const result = await tools.get("delete_label")?.handler({ id: "label-1" });
+
+ expect(result?.isError).toBe(true);
+ expect(client.json).toHaveBeenCalledTimes(1);
+ expect(client.json).toHaveBeenCalledWith("/api/label/label-1", {
+ method: "GET",
+ });
});
});
diff --git a/packages/mcp/src/tools/register.ts b/packages/mcp/src/tools/register.ts
index 6e43ba99b..e74d43132 100644
--- a/packages/mcp/src/tools/register.ts
+++ b/packages/mcp/src/tools/register.ts
@@ -516,14 +516,23 @@ export function registerTools(
"delete_label",
{
description:
- "Delete a workspace label by ID (removes it from all tasks).",
+ "Delete a label by ID. Only task-associated labels can be deleted; workspace-level labels (taskId null) are rejected by the API.",
inputSchema: z.object({ id: nonEmptyString }),
},
async (args) =>
- run(() =>
- client.json(`/api/label/${encodeURIComponent(args.id)}`, {
+ run(async () => {
+ const label = (await client.json(
+ `/api/label/${encodeURIComponent(args.id)}`,
+ { method: "GET" },
+ )) as { taskId?: string | null };
+ if (!label?.taskId) {
+ throw new Error(
+ "Label is not associated with a task and cannot be deleted (workspace-level labels are not deletable via this endpoint).",
+ );
+ }
+ return client.json(`/api/label/${encodeURIComponent(args.id)}`, {
method: "DELETE",
- }),
- ),
+ });
+ }),
);
}