⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(mcp): read and set task custom fields
Tin20be7fb1b0c1
diff --git a/apps/docs/core/integrations/mcp.mdx b/apps/docs/core/integrations/mcp.mdxindex 432fa942f..1c377ea6a 100644--- a/apps/docs/core/integrations/mcp.mdx+++ b/apps/docs/core/integrations/mcp.mdx@@ -8,7 +8,7 @@ Kaneo supports the Model Context Protocol (MCP) in two ways:1. **Built-in HTTP endpoint**: every Kaneo instance exposes `/api/mcp` out of the box. No extra setup, no extra process.2. **Stdio package** ([`@kaneo/mcp`](https://www.npmjs.com/package/@kaneo/mcp)): the official Kaneo MCP package on npm, a local stdio server for clients that prefer stdio transport.-Both offer the same tools for managing workspaces, projects, tasks, comments, and labels.+Both offer the same tools for managing workspaces, projects, tasks, custom fields, comments, and labels.To work with Kaneo from a terminal or a shell script instead, use the [Kaneo CLI](/cli).@@ -109,6 +109,7 @@ Both the HTTP endpoint and stdio package expose the same tools:- Search: `search`- Projects: `list_projects`, `get_project`, `create_project`, `update_project`, `list_project_columns`- Tasks: `list_tasks`, `get_task`, `get_task_by_ticket_id`, `create_task`, `duplicate_task`, `update_task`, `delete_task`, `move_task`, `update_task_status`, `update_task_assignee`, `update_task_due_date`, `list_task_activity`+- Custom fields: `list_project_custom_fields`, `get_task_custom_field_values`, `set_task_custom_field_value`- Time entries: `list_task_time_entries`, `get_time_entry`, `create_time_entry`, `update_time_entry`- Comments: `list_task_comments`, `create_task_comment`, `update_task_comment`, `delete_task_comment`- Labels: `list_workspace_labels`, `create_label`, `attach_label_to_task`, `detach_label_from_task`, `delete_label`@@ -122,6 +123,12 @@ accept. Likewise `list_workspace_members` resolves the user IDs the assigneetools expect. Time entries have no delete endpoint on the API, so there is no`delete_time_entry` tool.+`get_task` and `list_tasks` don't include custom field values. Call+`list_project_custom_fields` for a project's field IDs, types, and options, and+`get_task_custom_field_values` for one task's values. `set_task_custom_field_value`+takes a string, number, or boolean, an array of options for a multiselect field,+or `null` to clear the value. Dates use `YYYY-MM-DD`.+## DebuggingTo run the stdio server directly:diff --git a/packages/mcp/README.md b/packages/mcp/README.mdindex 471895d9b..362ff242f 100644--- a/packages/mcp/README.md+++ b/packages/mcp/README.md@@ -119,6 +119,7 @@ For headless or sandboxed environments where opening a browser is impractical, s- Search: `search`- Projects: `list_projects`, `get_project`, `create_project`, `update_project`, `list_project_columns`- Tasks: `list_tasks`, `get_task`, `get_task_by_ticket_id`, `create_task`, `update_task`, `delete_task`, `move_task`, `update_task_status`, `update_task_assignee`, `update_task_due_date`, `list_task_activity`+- Custom fields: `list_project_custom_fields`, `get_task_custom_field_values`, `set_task_custom_field_value`- Time entries: `list_task_time_entries`, `get_time_entry`, `create_time_entry`, `update_time_entry`- Comments: `list_task_comments`, `create_task_comment`, `update_task_comment`, `delete_task_comment`- Labels: `list_workspace_labels`, `create_label`, `attach_label_to_task`, `detach_label_from_task`, `delete_label`@@ -132,6 +133,9 @@ pass `workspaceId` or `projectId` to select one.`list_workspace_members` resolves the user IDs the assignee tools expect.Time entries have no delete endpoint on the API, so there is no`delete_time_entry` tool.+Call `list_project_custom_fields` for the field IDs and options+`set_task_custom_field_value` expects. Pass multiselect values as an array of+options, dates as `YYYY-MM-DD`, and `null` to clear a value.## Releasingdiff --git a/packages/mcp/src/kaneo/custom-field-value.test.ts b/packages/mcp/src/kaneo/custom-field-value.test.tsnew file mode 100644index 000000000..92c3b9838--- /dev/null+++ b/packages/mcp/src/kaneo/custom-field-value.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from "vite-plus/test";+import { encodeCustomFieldValue } from "./custom-field-value.js";++describe("encodeCustomFieldValue", () => {+ it("encodes multiselect options as a JSON array string", () => {+ expect(encodeCustomFieldValue(["Frontend", "API"])).toBe(+ '["Frontend","API"]',+ );+ });++ it("clears the value for null or an empty selection", () => {+ expect(encodeCustomFieldValue(null)).toBe("");+ expect(encodeCustomFieldValue([])).toBe("");+ });++ it("stringifies numbers and booleans", () => {+ expect(encodeCustomFieldValue(3.5)).toBe("3.5");+ expect(encodeCustomFieldValue(false)).toBe("false");+ expect(encodeCustomFieldValue("2026-10-17")).toBe("2026-10-17");+ });+});diff --git a/packages/mcp/src/kaneo/custom-field-value.ts b/packages/mcp/src/kaneo/custom-field-value.tsnew file mode 100644index 000000000..6d5ba27df--- /dev/null+++ b/packages/mcp/src/kaneo/custom-field-value.ts@@ -0,0 +1,9 @@+export type CustomFieldValueInput = string | number | boolean | string[] | null;++// The API stores every custom field value as a string: multiselect values are+// a JSON array, and an empty string clears the field.+export function encodeCustomFieldValue(value: CustomFieldValueInput): string {+ if (value === null) return "";+ if (Array.isArray(value)) return value.length ? JSON.stringify(value) : "";+ return String(value);+}diff --git a/packages/mcp/src/tools/register.test.ts b/packages/mcp/src/tools/register.test.tsindex 6822a3551..a0b05f280 100644--- a/packages/mcp/src/tools/register.test.ts+++ b/packages/mcp/src/tools/register.test.ts@@ -351,6 +351,80 @@ describe("registerTools", () => {).toThrow();});+ it("lists a project's custom field definitions", async () => {+ const { server, tools } = createServerMock();+ const client = { json: vi.fn().mockResolvedValue([]) };++ registerTools(server as never, { client: client as never });++ await tools+ .get("list_project_custom_fields")+ ?.handler({ projectId: "project 1" });++ expect(client.json).toHaveBeenCalledWith(+ "/api/custom-field/project/project%201",+ );+ });++ it("reads a task's custom field values", async () => {+ const { server, tools } = createServerMock();+ const client = { json: vi.fn().mockResolvedValue([]) };++ registerTools(server as never, { client: client as never });++ await tools+ .get("get_task_custom_field_values")+ ?.handler({ taskId: "task 1" });++ expect(client.json).toHaveBeenCalledWith("/api/custom-field/task/task%201");+ });++ it.each([+ [["Frontend", "API"], '["Frontend","API"]'],+ [5, "5"],+ [true, "true"],+ ["2026-10-17", "2026-10-17"],+ [null, ""],+ ])("sets custom field value %j as %j", async (value, encoded) => {+ const { server, tools } = createServerMock();+ const client = { json: vi.fn().mockResolvedValue({ id: "value-1" }) };++ registerTools(server as never, { client: client as never });++ const result = await tools+ .get("set_task_custom_field_value")+ ?.handler({ taskId: "task-1", fieldId: "field-1", value });++ expect(client.json).toHaveBeenCalledWith("/api/custom-field/value", {+ method: "PUT",+ body: JSON.stringify({+ taskId: "task-1",+ fieldId: "field-1",+ value: encoded,+ }),+ });+ expect(result?.isError).toBe(false);+ });++ it("rejects a custom field value that is missing or an object", async () => {+ const { server, tools } = createServerMock();+ const client = { json: vi.fn() };++ registerTools(server as never, { client: client as never });++ const tool = tools.get("set_task_custom_field_value");+ const missing = await tool?.handler({ taskId: "task-1", fieldId: "f" });+ const object = await tool?.handler({+ taskId: "task-1",+ fieldId: "f",+ value: { option: "a" },+ });++ expect(missing?.isError).toBe(true);+ expect(object?.isError).toBe(true);+ expect(client.json).not.toHaveBeenCalled();+ });+it("creates a task relation with the expected body", async () => {const { server, tools } = createServerMock();const client = {diff --git a/packages/mcp/src/tools/register.ts b/packages/mcp/src/tools/register.tsindex ffa83ef85..c607fa505 100644--- a/packages/mcp/src/tools/register.ts+++ b/packages/mcp/src/tools/register.ts@@ -1,5 +1,6 @@import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";import { z } from "zod";+import { encodeCustomFieldValue } from "../kaneo/custom-field-value.js";import { buildFullTaskUpdateBody } from "../kaneo/task-helpers.js";import { errorResult, textResult } from "../utils/mcp-result.js";import { getCurrentUser } from "./get-current-user.js";@@ -225,7 +226,7 @@ export function registerTools("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.",+ "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. Custom field values are not included; use get_task_custom_field_values.",inputSchema: listTasksSchema,},async (args) => {@@ -246,7 +247,8 @@ export function registerTools(registerTool("get_task",{- description: "Get a task by ID.",+ description:+ "Get a task by ID. Custom field values are not included; use get_task_custom_field_values.",inputSchema: z.object({ taskId: nonEmptyString }),},async (args) =>@@ -717,6 +719,63 @@ export function registerTools(),);+ registerTool(+ "list_project_custom_fields",+ {+ description:+ "List a project's custom field definitions: id, name, type (text, number, date, dropdown, boolean, multiselect), required, options, and defaultValue.",+ inputSchema: z.object({ projectId: nonEmptyString }),+ },+ async (args) =>+ run(() =>+ client.json(+ `/api/custom-field/project/${encodeURIComponent(args.projectId)}`,+ ),+ ),+ );++ registerTool(+ "get_task_custom_field_values",+ {+ description:+ "List a task's custom field values with each field's name, type, and options. Fields without a value are omitted. Multiselect values are JSON array strings.",+ inputSchema: z.object({ taskId: nonEmptyString }),+ },+ async (args) =>+ run(() =>+ client.json(+ `/api/custom-field/task/${encodeURIComponent(args.taskId)}`,+ ),+ ),+ );++ registerTool(+ "set_task_custom_field_value",+ {+ description:+ "Set or clear one custom field value on a task. Get fieldId from list_project_custom_fields. Pass dates as YYYY-MM-DD, a dropdown value as one of its options, multiselect values as an array of options, and null to clear the value (required fields can't be cleared).",+ inputSchema: z.object({+ taskId: nonEmptyString,+ fieldId: nonEmptyString,+ value: z+ .union([z.string(), z.number(), z.boolean(), z.array(z.string())])+ .nullable()+ .describe("New value, or null to clear it"),+ }),+ },+ async (args) =>+ run(() =>+ client.json("/api/custom-field/value", {+ method: "PUT",+ body: JSON.stringify({+ taskId: args.taskId,+ fieldId: args.fieldId,+ value: encodeCustomFieldValue(args.value),+ }),+ }),+ ),+ );+registerTool("delete_task",{diff --git a/tests/api/mcp-tools.test.ts b/tests/api/mcp-tools.test.tsindex e8ff9620c..7dad41152 100644--- a/tests/api/mcp-tools.test.ts+++ b/tests/api/mcp-tools.test.ts@@ -98,6 +98,40 @@ describe("MCP tool catalog", () => {expect(lastRequest().url).toBe("http://api.test/api/column/p1");});+ it("reads custom field definitions and task values", async () => {+ await call("list_project_custom_fields", { projectId: "p1" });+ expect(lastRequest().url).toBe(+ "http://api.test/api/custom-field/project/p1",+ );++ await call("get_task_custom_field_values", { taskId: "t1" });+ expect(lastRequest().url).toBe("http://api.test/api/custom-field/task/t1");+ });++ it("sets a multiselect custom field value and clears it", async () => {+ await call("set_task_custom_field_value", {+ taskId: "t1",+ fieldId: "f1",+ value: ["Frontend", "API"],+ });+ expect(lastRequest()).toMatchObject({+ url: "http://api.test/api/custom-field/value",+ method: "PUT",+ body: { taskId: "t1", fieldId: "f1", value: '["Frontend","API"]' },+ });++ await call("set_task_custom_field_value", {+ taskId: "t1",+ fieldId: "f1",+ value: null,+ });+ expect(lastRequest().body).toEqual({+ taskId: "t1",+ fieldId: "f1",+ value: "",+ });+ });+it("deletes a task", async () => {await call("delete_task", { taskId: "t1" });