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): share tools and support workspace label deletion

Tin42a6c94c25f0
diff --git a/apps/api/package.json b/apps/api/package.json
index bdb848006..3f7f6fcb6 100644
--- a/apps/api/package.json
+++ b/apps/api/package.json
@@ -54,7 +54,8 @@
"octokit": "^5.0.5",
"pg": "^8.23.0",
"valibot": "^1.5.0",
- "zod": "^4.6.5"
+ "zod": "^4.6.5",
+ "@kaneo/mcp": "workspace:*"
},
"devDependencies": {
"@types/node": "^26.6.2",
diff --git a/apps/api/src/mcp/tools.ts b/apps/api/src/mcp/tools.ts
index 0f11bae25..b28cfd747 100644
--- a/apps/api/src/mcp/tools.ts
+++ b/apps/api/src/mcp/tools.ts
@@ -1,27 +1,14 @@
-import { z } from "zod";
+import { registerTools, type ToolRegistrar } from "@kaneo/mcp/tools";
+import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
+import type { z } from "zod";
-type McpToolResult = {
- content: Array<{ type: "text"; text: string }>;
- isError?: boolean;
-};
-
-/** Minimal tool-registration contract shared by legacy and modern MCP servers. */
-export type McpToolRegistrar = {
- registerTool(
- name: string,
- config: {
- description: string;
- inputSchema: z.ZodObject;
- },
- callback: (args: unknown) => Promise<McpToolResult>,
- ): unknown;
-};
+export type McpToolRegistrar = ToolRegistrar;
type ShapeToolServer = {
registerTool(
name: string,
config: { description: string; inputSchema: z.ZodRawShape },
- callback: (args: unknown) => Promise<McpToolResult>,
+ callback: (args: unknown) => Promise<CallToolResult>,
): unknown;
};
@@ -40,6 +27,7 @@ export function toMcpToolRegistrar(server: ShapeToolServer): McpToolRegistrar {
}
class ApiClient {
+ readonly usingApiKey = false;
constructor(
private baseUrl: string,
private token: string,
@@ -81,926 +69,10 @@ class ApiClient {
}
}
-function textResult(data: unknown, isError = false): McpToolResult {
- const text =
- typeof data === "string" ? data : (JSON.stringify(data, null, 2) ?? "");
- return { content: [{ type: "text", text }], isError };
-}
-
-function errorResult(message: string): McpToolResult {
- return textResult({ error: message }, true);
-}
-
-function run(fn: () => Promise<unknown>): Promise<McpToolResult> {
- return fn()
- .then((data) => textResult(data))
- .catch((e: unknown) =>
- errorResult(e instanceof Error ? e.message : String(e)),
- );
-}
-
-const PRIORITIES = ["no-priority", "low", "medium", "high", "urgent"] as const;
-
-function isTaskPriority(v: string): v is (typeof PRIORITIES)[number] {
- return (PRIORITIES as readonly string[]).includes(v);
-}
-
-function formatOptionalIso(value: unknown): string | undefined {
- if (value === null || value === undefined) return undefined;
- if (value instanceof Date) return value.toISOString();
- if (typeof value === "string") return value;
- return undefined;
-}
-
-function buildFullTaskUpdateBody(
- existing: Record<string, unknown>,
- patch: Record<string, unknown>,
-): Record<string, string | number | undefined> {
- const positionRaw = patch.position ?? existing.position;
- const position =
- typeof positionRaw === "number"
- ? positionRaw
- : typeof positionRaw === "string"
- ? Number(positionRaw)
- : Number.NaN;
- if (!Number.isFinite(position))
- throw new Error(
- "Cannot update task: missing numeric `position` on existing task.",
- );
-
- const title =
- (patch.title as string) ??
- (typeof existing.title === "string" ? existing.title : undefined);
- if (!title) throw new Error("Cannot update task: missing title.");
-
- const description =
- patch.description !== undefined
- ? patch.description === null
- ? ""
- : String(patch.description)
- : existing.description == null
- ? ""
- : String(existing.description);
-
- const status =
- (patch.status as string) ??
- (typeof existing.status === "string" ? existing.status : undefined);
- if (!status) throw new Error("Cannot update task: missing status.");
-
- const priorityRaw =
- (patch.priority as string) ??
- (typeof existing.priority === "string" ? existing.priority : undefined);
- if (!priorityRaw || !isTaskPriority(priorityRaw))
- throw new Error("Cannot update task: invalid or missing priority.");
-
- const projectId =
- (patch.projectId as string) ??
- (typeof existing.projectId === "string" ? existing.projectId : undefined);
- if (!projectId) throw new Error("Cannot update task: missing projectId.");
-
- const userId =
- patch.userId !== undefined
- ? patch.userId === null
- ? ""
- : (patch.userId as string)
- : typeof existing.userId === "string"
- ? existing.userId
- : undefined;
-
- const startDate = formatOptionalIso(
- patch.startDate !== undefined ? patch.startDate : existing.startDate,
- );
- const dueDate = formatOptionalIso(
- patch.dueDate !== undefined ? patch.dueDate : existing.dueDate,
- );
-
- const body: Record<string, string | number | undefined> = {
- title,
- description,
- status,
- priority: priorityRaw,
- projectId,
- position,
- };
- if (startDate !== undefined) body.startDate = startDate;
- if (dueDate !== undefined) body.dueDate = dueDate;
- if (userId !== undefined) body.userId = userId;
- return body;
-}
-
-const prioritySchema = z.enum([
- "no-priority",
- "low",
- "medium",
- "high",
- "urgent",
-]);
-const nonEmptyString = z.string().trim().min(1);
-const optionalNonEmptyString = nonEmptyString.optional();
-const nullableOptionalNonEmptyString = nonEmptyString.nullable().optional();
-const isoDateTimeSchema = z.string().datetime({ offset: true });
-const optionalIsoDateTimeSchema = isoDateTimeSchema.optional();
-const nullableOptionalIsoDateTimeSchema = isoDateTimeSchema
- .nullable()
- .optional();
-const hexColorSchema = z
- .string()
- .regex(
- /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,
- "Expected a hex color like #FF6600",
- );
-
-/** Register Kaneo's authenticated tool catalog on an MCP server adapter. */
export function registerMcpTools(
server: McpToolRegistrar,
baseUrl: string,
token: string,
): void {
- const client = new ApiClient(baseUrl, token);
- const registerTool = <InputSchema extends z.ZodObject>(
- name: string,
- config: { description: string; inputSchema: InputSchema },
- callback: (args: z.output<InputSchema>) => Promise<McpToolResult>,
- ) =>
- server.registerTool(name, config, async (args) => {
- const parsed = config.inputSchema.safeParse(args);
- if (!parsed.success) {
- return errorResult(z.prettifyError(parsed.error));
- }
- return callback(parsed.data);
- });
-
- registerTool(
- "whoami",
- {
- description: "Return the current Kaneo session and user.",
- inputSchema: z.object({}),
- },
- async () =>
- run(() => client.json("/api/auth/get-session", { method: "GET" })),
- );
-
- registerTool(
- "list_workspaces",
- {
- description: "List workspaces the signed-in user can access.",
- inputSchema: z.object({}),
- },
- async () =>
- run(() => client.json("/api/auth/organization/list", { method: "GET" })),
- );
-
- registerTool(
- "list_projects",
- {
- description: "List projects in a workspace.",
- inputSchema: z.object({
- workspaceId: nonEmptyString.describe("Workspace ID"),
- includeArchived: z
- .boolean()
- .optional()
- .describe("Include archived projects"),
- }),
- },
- async (args) => {
- const qs = new URLSearchParams({ workspaceId: args.workspaceId });
- if (args.includeArchived === true) qs.set("includeArchived", "true");
- return run(() =>
- client.json(`/api/project?${qs.toString()}`, { method: "GET" }),
- );
- },
- );
-
- registerTool(
- "get_project",
- {
- description: "Get a single project by ID.",
- inputSchema: z.object({ id: nonEmptyString }),
- },
- async (args) =>
- run(() => client.json(`/api/project/${encodeURIComponent(args.id)}`)),
- );
-
- registerTool(
- "create_project",
- {
- description: "Create a project in a workspace.",
- inputSchema: z.object({
- name: nonEmptyString,
- workspaceId: nonEmptyString,
- icon: nonEmptyString,
- slug: nonEmptyString,
- }),
- },
- async (args) =>
- run(() =>
- client.json("/api/project", {
- method: "POST",
- body: JSON.stringify({
- name: args.name,
- workspaceId: args.workspaceId,
- icon: args.icon,
- slug: args.slug,
- }),
- }),
- ),
- );
-
- registerTool(
- "update_project",
- {
- description:
- "Update project metadata (PATCH-style: only provided fields are changed).",
- inputSchema: z.object({
- id: nonEmptyString,
- name: optionalNonEmptyString,
- icon: z.string().optional(),
- slug: optionalNonEmptyString,
- description: z.string().optional(),
- isPublic: z.boolean().optional(),
- }),
- },
- async (args) => {
- const { id, ...patch } = args;
- return run(async () => {
- const existing = (await client.json(
- `/api/project/${encodeURIComponent(id)}`,
- { method: "GET" },
- )) as Record<string, unknown>;
- const name =
- patch.name ??
- (typeof existing.name === "string" ? existing.name : "");
- if (!name) throw new Error("Cannot update project: missing name.");
- const icon =
- patch.icon !== undefined
- ? patch.icon
- : typeof existing.icon === "string"
- ? existing.icon
- : "Layout";
- const slug =
- patch.slug ??
- (typeof existing.slug === "string" ? existing.slug : "");
- if (!slug) throw new Error("Cannot update project: missing slug.");
- const description =
- patch.description !== undefined
- ? patch.description
- : typeof existing.description === "string"
- ? existing.description
- : "";
- const isPublic =
- patch.isPublic !== undefined
- ? patch.isPublic
- : typeof existing.isPublic === "boolean"
- ? existing.isPublic
- : false;
- return client.json(`/api/project/${encodeURIComponent(id)}`, {
- method: "PUT",
- body: JSON.stringify({ name, icon, slug, description, isPublic }),
- });
- });
- },
- );
-
- registerTool(
- "list_tasks",
- {
- description:
- "List a bounded page of tasks for a project (50 by default, maximum 100). Use pagination.totalPages and page to retrieve the rest; filters and sorting apply before pagination. For every task page, also follow relatedPage through pagination.relatedTotalPages for complete labels, links and column metadata.",
- inputSchema: z.object({
- projectId: nonEmptyString,
- status: optionalNonEmptyString,
- priority: prioritySchema.optional(),
- assigneeId: optionalNonEmptyString,
- page: z.number().int().min(1).max(1_000_000).optional(),
- relatedPage: z.number().int().min(1).max(1_000_000).optional(),
- limit: z.number().int().min(1).max(100).optional(),
- sortBy: z
- .enum([
- "createdAt",
- "priority",
- "dueDate",
- "position",
- "title",
- "number",
- ])
- .optional(),
- sortOrder: z.enum(["asc", "desc"]).optional(),
- dueBefore: optionalIsoDateTimeSchema,
- dueAfter: optionalIsoDateTimeSchema,
- }),
- },
- async (args) => {
- const { projectId, ...rest } = args;
- const qs = new URLSearchParams();
- for (const [k, v] of Object.entries(rest)) {
- if (v !== undefined && v !== null) qs.set(k, String(v));
- }
- const q = qs.toString();
- return run(() =>
- client.json(
- `/api/task/tasks/${encodeURIComponent(projectId)}${q ? `?${q}` : ""}`,
- { method: "GET" },
- ),
- );
- },
- );
-
- registerTool(
- "get_task",
- {
- description: "Get a task by ID.",
- inputSchema: z.object({ taskId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/task/${encodeURIComponent(args.taskId)}`, {
- method: "GET",
- }),
- ),
- );
-
- registerTool(
- "get_task_by_ticket_id",
- {
- description:
- "Get one task by its ticket ID (project key and number, e.g. KAN-12). If multiple accessible tasks share the ID, provide workspaceId or projectId.",
- inputSchema: z.object({
- ticketId: nonEmptyString,
- workspaceId: optionalNonEmptyString,
- projectId: optionalNonEmptyString,
- }),
- },
- async ({ ticketId, workspaceId, projectId }) => {
- const query = new URLSearchParams();
- if (workspaceId) query.set("workspaceId", workspaceId);
- if (projectId) query.set("projectId", projectId);
- const suffix = query.toString();
- return run(() =>
- client.json(
- `/api/task/by-ticket-id/${encodeURIComponent(ticketId)}${suffix ? `?${suffix}` : ""}`,
- { method: "GET" },
- ),
- );
- },
- );
-
- registerTool(
- "create_task",
- {
- description: "Create a task in a project.",
- inputSchema: z.object({
- projectId: nonEmptyString,
- title: nonEmptyString,
- description: z.string(),
- priority: prioritySchema,
- status: nonEmptyString,
- startDate: optionalIsoDateTimeSchema,
- dueDate: optionalIsoDateTimeSchema,
- userId: optionalNonEmptyString,
- }),
- },
- async (args) => {
- const body: Record<string, string | undefined> = {
- title: args.title,
- description: args.description,
- priority: args.priority,
- status: args.status,
- };
- if (args.startDate !== undefined) body.startDate = args.startDate;
- if (args.dueDate !== undefined) body.dueDate = args.dueDate;
- if (args.userId !== undefined) body.userId = args.userId;
- return run(() =>
- client.json(`/api/task/${encodeURIComponent(args.projectId)}`, {
- method: "POST",
- body: JSON.stringify(body),
- }),
- );
- },
- );
-
- registerTool(
- "duplicate_task",
- {
- description:
- "Duplicate a task in the same project, copying its fields and labels. Pass title to rename the copy.",
- inputSchema: z.object({
- taskId: nonEmptyString,
- title: optionalNonEmptyString,
- }),
- },
- async (args) => {
- const body: Record<string, string> = {};
- if (args.title !== undefined) body.title = args.title;
- return run(() =>
- client.json(`/api/task/duplicate/${encodeURIComponent(args.taskId)}`, {
- method: "POST",
- body: JSON.stringify(body),
- }),
- );
- },
- );
-
- registerTool(
- "update_task",
- {
- description:
- "Update a task (fetches current task, merges fields, then full update).",
- inputSchema: z.object({
- taskId: nonEmptyString,
- title: optionalNonEmptyString,
- description: z.string().nullable().optional(),
- status: optionalNonEmptyString,
- priority: prioritySchema.optional(),
- projectId: optionalNonEmptyString,
- position: z.number().optional(),
- startDate: nullableOptionalIsoDateTimeSchema,
- dueDate: nullableOptionalIsoDateTimeSchema,
- userId: nullableOptionalNonEmptyString,
- }),
- },
- async (args) => {
- const { taskId, ...patch } = args;
- return run(async () => {
- const existing = (await client.json(
- `/api/task/${encodeURIComponent(taskId)}`,
- { method: "GET" },
- )) as Record<string, unknown>;
- const body = buildFullTaskUpdateBody(existing, patch);
- return client.json(`/api/task/${encodeURIComponent(taskId)}`, {
- method: "PUT",
- body: JSON.stringify(body),
- });
- });
- },
- );
-
- registerTool(
- "move_task",
- {
- description:
- "Move a task to another project (and optional column status).",
- inputSchema: z.object({
- taskId: nonEmptyString,
- destinationProjectId: nonEmptyString,
- destinationStatus: optionalNonEmptyString,
- }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/task/move/${encodeURIComponent(args.taskId)}`, {
- method: "PUT",
- body: JSON.stringify({
- destinationProjectId: args.destinationProjectId,
- ...(args.destinationStatus !== undefined
- ? { destinationStatus: args.destinationStatus }
- : {}),
- }),
- }),
- ),
- );
-
- registerTool(
- "update_task_status",
- {
- description: "Update only the status (column) of a task.",
- inputSchema: z.object({ taskId: nonEmptyString, status: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/task/status/${encodeURIComponent(args.taskId)}`, {
- method: "PUT",
- body: JSON.stringify({ status: args.status }),
- }),
- ),
- );
-
- registerTool(
- "list_task_comments",
- {
- description: "List comments on a task.",
- inputSchema: z.object({ taskId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/comment/${encodeURIComponent(args.taskId)}`, {
- method: "GET",
- }),
- ),
- );
-
- registerTool(
- "create_task_comment",
- {
- description: "Add a comment to a task.",
- inputSchema: z.object({
- taskId: nonEmptyString,
- content: nonEmptyString,
- }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/comment/${encodeURIComponent(args.taskId)}`, {
- method: "POST",
- body: JSON.stringify({ content: args.content }),
- }),
- ),
- );
-
- registerTool(
- "update_task_comment",
- {
- description: "Update one of your comments on a task.",
- inputSchema: z.object({
- commentId: nonEmptyString,
- content: nonEmptyString,
- }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/comment/${encodeURIComponent(args.commentId)}`, {
- method: "PUT",
- body: JSON.stringify({ content: args.content }),
- }),
- ),
- );
-
- registerTool(
- "delete_task_comment",
- {
- description: "Delete one of your comments from a task.",
- inputSchema: z.object({ commentId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/comment/${encodeURIComponent(args.commentId)}`, {
- method: "DELETE",
- }),
- ),
- );
-
- registerTool(
- "list_workspace_labels",
- {
- description: "List labels defined in a workspace.",
- inputSchema: z.object({ workspaceId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(
- `/api/label/workspace/${encodeURIComponent(args.workspaceId)}`,
- { method: "GET" },
- ),
- ),
- );
-
- registerTool(
- "create_label",
- {
- description:
- "Create a label in a workspace (optionally attach to a task).",
- inputSchema: z.object({
- name: nonEmptyString,
- color: hexColorSchema,
- workspaceId: nonEmptyString,
- taskId: optionalNonEmptyString,
- }),
- },
- async (args) =>
- run(() =>
- client.json("/api/label", {
- method: "POST",
- body: JSON.stringify({
- name: args.name,
- color: args.color,
- workspaceId: args.workspaceId,
- ...(args.taskId !== undefined ? { taskId: args.taskId } : {}),
- }),
- }),
- ),
- );
-
- registerTool(
- "attach_label_to_task",
- {
- description: "Attach an existing label to a task.",
- inputSchema: z.object({
- labelId: nonEmptyString,
- taskId: nonEmptyString,
- }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/label/${encodeURIComponent(args.labelId)}/task`, {
- method: "PUT",
- body: JSON.stringify({ taskId: args.taskId }),
- }),
- ),
- );
-
- registerTool(
- "detach_label_from_task",
- {
- description: "Detach a label from its current task.",
- inputSchema: z.object({ labelId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/label/${encodeURIComponent(args.labelId)}/task`, {
- method: "DELETE",
- }),
- ),
- );
-
- registerTool(
- "create_task_relation",
- {
- description:
- "Create a relation between two tasks. relationType: 'subtask' (sourceTaskId is the parent, targetTaskId the child), 'blocks' (sourceTaskId blocks targetTaskId), or 'related' (bidirectional).",
- inputSchema: z.object({
- sourceTaskId: nonEmptyString,
- targetTaskId: nonEmptyString,
- relationType: z.enum(["subtask", "blocks", "related"]),
- }),
- },
- async (args) =>
- run(() =>
- client.json("/api/task-relation", {
- method: "POST",
- body: JSON.stringify({
- sourceTaskId: args.sourceTaskId,
- targetTaskId: args.targetTaskId,
- relationType: args.relationType,
- }),
- }),
- ),
- );
-
- registerTool(
- "get_task_relations",
- {
- description:
- "List all relations (subtask/blocks/related) involving a task.",
- inputSchema: z.object({ taskId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/task-relation/${encodeURIComponent(args.taskId)}`, {
- method: "GET",
- }),
- ),
- );
-
- registerTool(
- "delete_task_relation",
- {
- description: "Delete a task relation by its relation ID.",
- inputSchema: z.object({ id: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/task-relation/${encodeURIComponent(args.id)}`, {
- method: "DELETE",
- }),
- ),
- );
-
- registerTool(
- "delete_label",
- {
- description:
- "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(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",
- });
- }),
- );
-
- registerTool(
- "list_workspace_members",
- {
- description:
- "List the members of a workspace. Use this to resolve the user ID an assignee tool expects.",
- inputSchema: z.object({ workspaceId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(
- `/api/workspace/${encodeURIComponent(args.workspaceId)}/members`,
- ),
- ),
- );
-
- registerTool(
- "search",
- {
- description:
- "Search across tasks, projects, workspaces, comments, and activities.",
- inputSchema: z.object({
- q: nonEmptyString.describe("Search query"),
- type: z
- .enum([
- "all",
- "tasks",
- "projects",
- "workspaces",
- "comments",
- "activities",
- ])
- .optional()
- .describe("Restrict results to one kind. Defaults to all."),
- workspaceId: optionalNonEmptyString.describe("Limit to one workspace"),
- projectId: optionalNonEmptyString.describe("Limit to one project"),
- limit: z
- .number()
- .int()
- .min(1)
- .max(50)
- .optional()
- .describe("Maximum results, 1 to 50. Defaults to 20."),
- }),
- },
- async (args) => {
- const qs = new URLSearchParams({ q: args.q });
- if (args.type) qs.set("type", args.type);
- if (args.workspaceId) qs.set("workspaceId", args.workspaceId);
- if (args.projectId) qs.set("projectId", args.projectId);
- if (args.limit !== undefined) qs.set("limit", String(args.limit));
- return run(() => client.json(`/api/search?${qs.toString()}`));
- },
- );
-
- registerTool(
- "list_project_columns",
- {
- description:
- "List a project's columns. Their slugs are the values update_task_status and create_task accept as a status.",
- inputSchema: z.object({ projectId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/column/${encodeURIComponent(args.projectId)}`),
- ),
- );
-
- registerTool(
- "delete_task",
- {
- description: "Delete a task by ID.",
- inputSchema: z.object({ taskId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/task/${encodeURIComponent(args.taskId)}`, {
- method: "DELETE",
- }),
- ),
- );
-
- registerTool(
- "update_task_assignee",
- {
- description:
- "Assign a task to a workspace member, or pass a null userId to unassign it.",
- inputSchema: z.object({
- taskId: nonEmptyString,
- userId: nonEmptyString
- .nullable()
- .describe("Member user ID, or null to unassign"),
- }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/task/assignee/${encodeURIComponent(args.taskId)}`, {
- method: "PUT",
- body: JSON.stringify({ userId: args.userId }),
- }),
- ),
- );
-
- registerTool(
- "update_task_due_date",
- {
- description: "Set a task's due date. Omit dueDate to clear it.",
- inputSchema: z.object({
- taskId: nonEmptyString,
- dueDate: optionalIsoDateTimeSchema,
- }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/task/due-date/${encodeURIComponent(args.taskId)}`, {
- method: "PUT",
- body: JSON.stringify(
- args.dueDate === undefined ? {} : { dueDate: args.dueDate },
- ),
- }),
- ),
- );
-
- registerTool(
- "list_task_time_entries",
- {
- description: "List the time entries logged against a task.",
- inputSchema: z.object({ taskId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/time-entry/task/${encodeURIComponent(args.taskId)}`),
- ),
- );
-
- registerTool(
- "get_time_entry",
- {
- description: "Get a single time entry by ID.",
- inputSchema: z.object({ id: nonEmptyString }),
- },
- async (args) =>
- run(() => client.json(`/api/time-entry/${encodeURIComponent(args.id)}`)),
- );
-
- registerTool(
- "create_time_entry",
- {
- description:
- "Log time against a task. Omit endTime to leave the entry running.",
- inputSchema: z.object({
- taskId: nonEmptyString,
- startTime: isoDateTimeSchema,
- endTime: optionalIsoDateTimeSchema,
- description: optionalNonEmptyString,
- }),
- },
- async (args) =>
- run(() =>
- client.json("/api/time-entry", {
- method: "POST",
- body: JSON.stringify({
- taskId: args.taskId,
- startTime: args.startTime,
- ...(args.endTime ? { endTime: args.endTime } : {}),
- ...(args.description ? { description: args.description } : {}),
- }),
- }),
- ),
- );
-
- registerTool(
- "update_time_entry",
- {
- description:
- "Update a time entry. startTime is required; omitting endTime keeps the stored one. startTime cannot be later than the end time.",
- inputSchema: z.object({
- id: nonEmptyString,
- startTime: isoDateTimeSchema,
- endTime: optionalIsoDateTimeSchema,
- description: optionalNonEmptyString,
- }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/time-entry/${encodeURIComponent(args.id)}`, {
- method: "PUT",
- body: JSON.stringify({
- startTime: args.startTime,
- ...(args.endTime ? { endTime: args.endTime } : {}),
- ...(args.description ? { description: args.description } : {}),
- }),
- }),
- ),
- );
-
- registerTool(
- "list_task_activity",
- {
- description: "List a task's activity history.",
- inputSchema: z.object({ taskId: nonEmptyString }),
- },
- async (args) =>
- run(() =>
- client.json(`/api/activity/${encodeURIComponent(args.taskId)}`),
- ),
- );
-
- registerTool(
- "list_notifications",
- {
- description: "List the signed-in user's notifications.",
- inputSchema: z.object({}),
- },
- async () => run(() => client.json("/api/notification")),
- );
+ registerTools(server, { client: new ApiClient(baseUrl, token) });
}
diff --git a/packages/mcp/package.json b/packages/mcp/package.json
index 06f7fd196..59e9aef3d 100644
--- a/packages/mcp/package.json
+++ b/packages/mcp/package.json
@@ -19,6 +19,10 @@
".": {
"import": "./dist/server.js",
"types": "./dist/server.d.ts"
+ },
+ "./tools": {
+ "types": "./dist/tools/register.d.ts",
+ "import": "./dist/tools/register.js"
}
},
"publishConfig": {
diff --git a/packages/mcp/src/tools/register.test.ts b/packages/mcp/src/tools/register.test.ts
index 19cfe606c..99332565b 100644
--- a/packages/mcp/src/tools/register.test.ts
+++ b/packages/mcp/src/tools/register.test.ts
@@ -369,42 +369,51 @@ describe("registerTools", () => {
});
});
- it("deletes a task-associated label after a preflight check", async () => {
+ it("deletes a task-associated label without an obsolete preflight", async () => {
+ const { server, tools } = createServerMock();
+ const client = { json: vi.fn().mockResolvedValue({ id: "label-1" }) };
+ registerTools(server as never, { client: client as never });
+ const result = await tools.get("delete_label")?.handler({ id: "label-1" });
+ expect(client.json).toHaveBeenCalledExactlyOnceWith("/api/label/label-1", {
+ method: "DELETE",
+ });
+ expect(result?.isError).toBe(false);
+ });
+
+ it("resumes workspace label deletion until the API completes it", async () => {
const { server, tools } = createServerMock();
const client = {
json: vi
.fn()
- .mockResolvedValueOnce({ id: "label-1", taskId: "task-1" })
- .mockResolvedValueOnce({ id: "label-1" }),
+ .mockResolvedValueOnce({
+ id: "label-1",
+ taskId: null,
+ pendingDeletion: true,
+ })
+ .mockResolvedValueOnce({ 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(client.json).toHaveBeenNthCalledWith(1, "/api/label/label-1", {
- method: "GET",
- });
+ expect(result?.isError).toBe(false);
+ expect(client.json).toHaveBeenCalledTimes(2);
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 () => {
+ it("returns resumable progress when a cascade exceeds one tool call", async () => {
const { server, tools } = createServerMock();
const client = {
- json: vi.fn().mockResolvedValue({ id: "label-1", taskId: null }),
+ json: vi.fn().mockResolvedValue({ pendingDeletion: true }),
};
-
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",
- });
+ const result = await tools.get("delete_label")?.handler({ id: "large" });
+ expect(result?.isError).toBe(false);
+ expect(client.json).toHaveBeenCalledTimes(100);
+ expect(result?.content).toEqual([
+ expect.objectContaining({
+ text: expect.stringContaining('"pendingDeletion": true'),
+ }),
+ ]);
});
});
diff --git a/packages/mcp/src/tools/register.ts b/packages/mcp/src/tools/register.ts
index fc51f12d5..ab30bcfe2 100644
--- a/packages/mcp/src/tools/register.ts
+++ b/packages/mcp/src/tools/register.ts
@@ -1,10 +1,20 @@
-import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { z } from "zod";
-import type { KaneoClient } from "../kaneo/client.js";
import { buildFullTaskUpdateBody } from "../kaneo/task-helpers.js";
import { errorResult, textResult } from "../utils/mcp-result.js";
+export type ToolClient = {
+ readonly usingApiKey?: boolean;
+ json<T = unknown>(path: string, init?: RequestInit): Promise<T>;
+};
+export type ToolRegistrar = {
+ registerTool(
+ name: string,
+ config: { description: string; inputSchema: z.ZodObject },
+ callback: (args: unknown) => Promise<CallToolResult>,
+ ): unknown;
+};
+
const prioritySchema = z.enum([
"no-priority",
"low",
@@ -37,12 +47,22 @@ function run(fn: () => Promise<unknown>): Promise<CallToolResult> {
}
export function registerTools(
- server: McpServer,
- ctx: { client: KaneoClient },
+ server: ToolRegistrar,
+ ctx: { client: ToolClient },
): void {
const { client } = ctx;
-
- server.registerTool(
+ const registerTool = <S extends z.ZodObject>(
+ name: string,
+ config: { description: string; inputSchema: S },
+ callback: (args: z.output<S>) => Promise<CallToolResult>,
+ ) =>
+ server.registerTool(name, config, async (args) => {
+ const parsed = config.inputSchema.safeParse(args);
+ if (!parsed.success) return errorResult(z.prettifyError(parsed.error));
+ return callback(parsed.data);
+ });
+
+ registerTool(
"whoami",
{
description:
@@ -58,7 +78,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"list_workspaces",
{
description:
@@ -69,7 +89,7 @@ export function registerTools(
run(() => client.json("/api/auth/organization/list", { method: "GET" })),
);
- server.registerTool(
+ registerTool(
"list_projects",
{
description: "List projects in a workspace.",
@@ -93,7 +113,7 @@ export function registerTools(
},
);
- server.registerTool(
+ registerTool(
"get_project",
{
description: "Get a single project by ID.",
@@ -103,7 +123,7 @@ export function registerTools(
run(() => client.json(`/api/project/${encodeURIComponent(args.id)}`)),
);
- server.registerTool(
+ registerTool(
"create_project",
{
description: "Create a project in a workspace.",
@@ -128,7 +148,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"update_project",
{
description:
@@ -206,7 +226,7 @@ export function registerTools(
dueAfter: optionalIsoDateTimeSchema,
});
- server.registerTool(
+ registerTool(
"list_tasks",
{
description:
@@ -228,7 +248,7 @@ export function registerTools(
},
);
- server.registerTool(
+ registerTool(
"get_task",
{
description: "Get a task by ID.",
@@ -242,7 +262,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"get_task_by_ticket_id",
{
description:
@@ -267,7 +287,7 @@ export function registerTools(
},
);
- server.registerTool(
+ registerTool(
"create_task",
{
description: "Create a task in a project.",
@@ -307,7 +327,7 @@ export function registerTools(
},
);
- server.registerTool(
+ registerTool(
"duplicate_task",
{
description:
@@ -344,7 +364,7 @@ export function registerTools(
userId: nullableOptionalNonEmptyString,
});
- server.registerTool(
+ registerTool(
"update_task",
{
description:
@@ -367,7 +387,7 @@ export function registerTools(
},
);
- server.registerTool(
+ registerTool(
"move_task",
{
description:
@@ -392,7 +412,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"update_task_status",
{
description: "Update only the status (column) of a task.",
@@ -410,7 +430,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"list_task_comments",
{
description: "List comments on a task.",
@@ -424,7 +444,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"create_task_comment",
{
description: "Add a comment to a task.",
@@ -442,7 +462,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"update_task_comment",
{
description: "Update one of your comments on a task.",
@@ -460,7 +480,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"delete_task_comment",
{
description: "Delete one of your comments from a task.",
@@ -474,7 +494,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"list_workspace_labels",
{
description: "List labels defined in a workspace.",
@@ -489,7 +509,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"create_label",
{
description:
@@ -515,7 +535,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"attach_label_to_task",
{
description: "Attach an existing label to a task.",
@@ -533,7 +553,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"detach_label_from_task",
{
description: "Detach a label from its current task.",
@@ -547,7 +567,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"create_task_relation",
{
description:
@@ -571,7 +591,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"get_task_relations",
{
description:
@@ -586,7 +606,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"delete_task_relation",
{
description: "Delete a task relation by its relation ID.",
@@ -600,31 +620,35 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"delete_label",
{
description:
- "Delete a label by ID. Only task-associated labels can be deleted; workspace-level labels (taskId null) are rejected by the API.",
+ "Delete a task or workspace label by ID. Workspace-label cascades resume automatically; repeat the tool if pendingDeletion remains true.",
inputSchema: z.object({ id: nonEmptyString }),
},
async (args) =>
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).",
+ let result: unknown;
+ // Bound work per tool call. The API persists the continuation boundary.
+ for (let page = 0; page < 100; page++) {
+ result = await client.json(
+ `/api/label/${encodeURIComponent(args.id)}`,
+ { method: "DELETE" },
);
+ if (
+ !result ||
+ typeof result !== "object" ||
+ !("pendingDeletion" in result) ||
+ !result.pendingDeletion
+ )
+ break;
}
- return client.json(`/api/label/${encodeURIComponent(args.id)}`, {
- method: "DELETE",
- });
+ return result;
}),
);
- server.registerTool(
+ registerTool(
"list_workspace_members",
{
description:
@@ -639,7 +663,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"search",
{
description:
@@ -678,7 +702,7 @@ export function registerTools(
},
);
- server.registerTool(
+ registerTool(
"list_project_columns",
{
description:
@@ -691,7 +715,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"delete_task",
{
description: "Delete a task by ID.",
@@ -705,7 +729,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"update_task_assignee",
{
description:
@@ -726,7 +750,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"update_task_due_date",
{
description: "Set a task's due date. Omit dueDate to clear it.",
@@ -746,7 +770,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"list_task_time_entries",
{
description: "List the time entries logged against a task.",
@@ -758,7 +782,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"get_time_entry",
{
description: "Get a single time entry by ID.",
@@ -768,7 +792,7 @@ export function registerTools(
run(() => client.json(`/api/time-entry/${encodeURIComponent(args.id)}`)),
);
- server.registerTool(
+ registerTool(
"create_time_entry",
{
description:
@@ -794,7 +818,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"update_time_entry",
{
description:
@@ -819,7 +843,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"list_task_activity",
{
description: "List a task's activity history.",
@@ -831,7 +855,7 @@ export function registerTools(
),
);
- server.registerTool(
+ registerTool(
"list_notifications",
{
description: "List the signed-in user's notifications.",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3d9060881..68f511cb5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -133,6 +133,9 @@ importers:
'@kaneo/email':
specifier: workspace:*
version: link:../../packages/email
+ '@kaneo/mcp':
+ specifier: workspace:*
+ version: link:../../packages/mcp
'@kaneo/permissions':
specifier: workspace:*
version: link:../../packages/permissions