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.

feat(mcp): get tasks by ticket ID (#1839)

Tin Sever8f56b4d2ddfd
diff --git a/apps/api/src/mcp/tools.ts b/apps/api/src/mcp/tools.ts
index 108a95d9b..0f11bae25 100644
--- a/apps/api/src/mcp/tools.ts
+++ b/apps/api/src/mcp/tools.ts
@@ -419,6 +419,31 @@ export function registerMcpTools(
),
);
+ 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",
{
diff --git a/apps/api/src/search/task-short-id.ts b/apps/api/src/search/task-short-id.ts
index 41c2b2c3f..f6296fb11 100644
--- a/apps/api/src/search/task-short-id.ts
+++ b/apps/api/src/search/task-short-id.ts
@@ -1,6 +1,7 @@
// A task's short id is its project key plus the task number, e.g. "DEP-23".
// Project keys come from `generateProjectSlug`, which follows the same Unicode
-// rules as `toSlug`, so a key can be "ПА" or "测试项" and not only A-Z. Matching
+// rules as `toSlug`, so a key can be "ПА", "测试项", or "123" and not only A-Z. Matching
// on ASCII alone left those projects without the "type the task key to jump to
// it" path.
-export const TASK_SHORT_ID_PATTERN = /^(\p{L}[\p{L}\p{N}\p{M}_-]*)-(\d+)$/u;
+export const TASK_SHORT_ID_PATTERN =
+ /^([\p{L}\p{N}][\p{L}\p{N}\p{M}_-]*)-(\d+)$/u;
diff --git a/apps/api/src/task/controllers/get-task-by-ticket-id.ts b/apps/api/src/task/controllers/get-task-by-ticket-id.ts
new file mode 100644
index 000000000..5812dbfaf
--- /dev/null
+++ b/apps/api/src/task/controllers/get-task-by-ticket-id.ts
@@ -0,0 +1,71 @@
+import { and, eq, ilike, inArray } from "drizzle-orm";
+import { HTTPException } from "hono/http-exception";
+import db from "../../database";
+import {
+ projectTable,
+ taskTable,
+ userTable,
+ workspaceUserTable,
+} from "../../database/schema";
+import { escapeLikePattern } from "../../search/like-pattern";
+import { TASK_SHORT_ID_PATTERN } from "../../search/task-short-id";
+import { hasInstanceAdminRole } from "../../utils/instance-admin-role";
+import getTask from "./get-task";
+
+export default async function getTaskByTicketId(
+ ticketId: string,
+ userId: string,
+ workspaceId?: string,
+ projectId?: string,
+) {
+ const match = ticketId.normalize("NFKC").match(TASK_SHORT_ID_PATTERN);
+ const number = Number(match?.[2]);
+ if (
+ !match?.[1] ||
+ !Number.isSafeInteger(number) ||
+ number < 1 ||
+ number > 2_147_483_647
+ ) {
+ throw new HTTPException(400, { message: "Invalid task ticket ID" });
+ }
+
+ const [user] = await db
+ .select({ role: userTable.role })
+ .from(userTable)
+ .where(eq(userTable.id, userId))
+ .limit(1);
+
+ const memberWorkspaces = db
+ .select({ workspaceId: workspaceUserTable.workspaceId })
+ .from(workspaceUserTable)
+ .where(eq(workspaceUserTable.userId, userId));
+
+ const matches = await db
+ .select({ id: taskTable.id })
+ .from(taskTable)
+ .innerJoin(projectTable, eq(taskTable.projectId, projectTable.id))
+ .where(
+ and(
+ ilike(projectTable.slug, escapeLikePattern(match[1])),
+ eq(taskTable.number, number),
+ workspaceId ? eq(projectTable.workspaceId, workspaceId) : undefined,
+ projectId ? eq(projectTable.id, projectId) : undefined,
+ hasInstanceAdminRole(user?.role)
+ ? undefined
+ : inArray(projectTable.workspaceId, memberWorkspaces),
+ ),
+ )
+ .limit(2);
+
+ const matchedTask = matches[0];
+ if (!matchedTask) {
+ throw new HTTPException(404, { message: "Task not found" });
+ }
+ if (matches.length > 1) {
+ throw new HTTPException(409, {
+ message: "Task ticket ID matches multiple accessible tasks",
+ });
+ }
+
+ return getTask(matchedTask.id);
+}
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index 878c4cf53..53c2e04e9 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -38,6 +38,7 @@ import createTask from "./controllers/create-task";
import deleteTask from "./controllers/delete-task";
import duplicateTask from "./controllers/duplicate-task";
import exportTasks from "./controllers/export-tasks";
+import getTaskByTicketId from "./controllers/get-task-by-ticket-id";
import getTask from "./controllers/get-task";
import getTasks from "./controllers/get-tasks";
import importTasks from "./controllers/import-tasks";
@@ -84,6 +85,8 @@ import {
moveTaskBody,
projectIdParam,
taskParam,
+ ticketIdParam,
+ ticketIdQuery,
updateAssigneeBody,
updateDescriptionBody,
updateDueDateBody,
@@ -224,6 +227,23 @@ const getTaskRoute = createRoute({
},
});
+const getTaskByTicketIdRoute = createRoute({
+ method: "get",
+ operationId: "getTaskByTicketId",
+ path: "/by-ticket-id/{ticketId}",
+ tags: ["Tasks"],
+ summary: "Get task by ticket ID",
+ description:
+ "Get a single task by its project key and number, such as KAN-12. If the ticket ID matches multiple accessible tasks, provide workspaceId or projectId to select one.",
+ request: { params: ticketIdParam, query: ticketIdQuery },
+ responses: {
+ 200: jsonResponse("Task details", taskWithAssigneeSchema),
+ 400: errorResponse("Invalid ticket ID"),
+ 404: errorResponse("No accessible task has this ticket ID"),
+ 409: errorResponse("Ticket ID matches multiple accessible tasks"),
+ },
+});
+
const moveTaskRoute = createRoute({
method: "put",
operationId: "moveTask",
@@ -730,6 +750,19 @@ const task = apiRouter<BaseVariables & { workspaceId: string }>()
200,
);
})
+ .openapi(getTaskByTicketIdRoute, async (c) => {
+ const { ticketId } = c.req.valid("param");
+ const { workspaceId, projectId } = c.req.valid("query");
+ return c.json(
+ await getTaskByTicketId(
+ ticketId,
+ c.get("userId"),
+ workspaceId,
+ projectId,
+ ),
+ 200,
+ );
+ })
.openapi(getTaskRoute, async (c) => {
const { id } = c.req.valid("param");
diff --git a/apps/api/src/task/schema.ts b/apps/api/src/task/schema.ts
index ae8fcdc50..ab85f70ee 100644
--- a/apps/api/src/task/schema.ts
+++ b/apps/api/src/task/schema.ts
@@ -1,9 +1,32 @@
import { pagingNumber, z } from "../openapi";
+import { TASK_SHORT_ID_PATTERN } from "../search/task-short-id";
import { MAX_TASK_POSITION } from "./controllers/next-task-position";
import { VALID_PRIORITIES } from "./validate-task-fields";
export const taskParam = z.object({ id: z.string() });
+export const ticketIdParam = z.object({
+ ticketId: z
+ .string()
+ .max(128)
+ .refine(
+ (value) => TASK_SHORT_ID_PATTERN.test(value),
+ "Invalid task ticket ID",
+ )
+ .openapi({
+ description: "Project key and task number, e.g. KAN-12.",
+ }),
+});
+
+export const ticketIdQuery = z.object({
+ workspaceId: z.string().min(1).optional().openapi({
+ description: "Select a workspace if the ticket ID exists in more than one.",
+ }),
+ projectId: z.string().min(1).optional().openapi({
+ description: "Select a project if the ticket ID exists more than once.",
+ }),
+});
+
export const projectIdParam = z.object({ projectId: z.string() });
const priority = z.enum(VALID_PRIORITIES);
diff --git a/apps/docs/core/integrations/mcp.mdx b/apps/docs/core/integrations/mcp.mdx
index f23f933d3..99a2eab7d 100644
--- a/apps/docs/core/integrations/mcp.mdx
+++ b/apps/docs/core/integrations/mcp.mdx
@@ -106,12 +106,14 @@ Both the HTTP endpoint and stdio package expose the same tools:
- Session: `whoami`, `list_workspaces`, `list_workspace_members`, `list_notifications`
- Search: `search`
- Projects: `list_projects`, `get_project`, `create_project`, `update_project`, `list_project_columns`
-- Tasks: `list_tasks`, `get_task`, `create_task`, `duplicate_task`, `update_task`, `delete_task`, `move_task`, `update_task_status`, `update_task_assignee`, `update_task_due_date`, `list_task_activity`
+- 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`
- 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`
- Task relations: `create_task_relation`, `get_task_relations`, `delete_task_relation`
+Use `get_task_by_ticket_id` with a key such as `KAN-12` to fetch one task directly. If the same key identifies multiple accessible tasks, pass `workspaceId` or `projectId` to select one.
+
`list_project_columns` is worth calling first when setting a status: the column
slugs it returns are exactly the values `create_task` and `update_task_status`
accept. Likewise `list_workspace_members` resolves the user IDs the assignee
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index 8d99a78b2..b263bb917 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -8778,6 +8778,96 @@
}
}
},
+ "/task/by-ticket-id/{ticketId}": {
+ "get": {
+ "operationId": "getTaskByTicketId",
+ "tags": [
+ "Tasks"
+ ],
+ "summary": "Get task by ticket ID",
+ "description": "Get a single task by its project key and number, such as KAN-12. If the ticket ID matches multiple accessible tasks, provide workspaceId or projectId to select one.",
+ "parameters": [
+ {
+ "schema": {
+ "type": "string",
+ "maxLength": 128,
+ "description": "Project key and task number, e.g. KAN-12."
+ },
+ "required": true,
+ "description": "Project key and task number, e.g. KAN-12.",
+ "name": "ticketId",
+ "in": "path"
+ },
+ {
+ "schema": {
+ "type": "string",
+ "minLength": 1,
+ "description": "Select a workspace if the ticket ID exists in more than one."
+ },
+ "required": false,
+ "description": "Select a workspace if the ticket ID exists in more than one.",
+ "name": "workspaceId",
+ "in": "query"
+ },
+ {
+ "schema": {
+ "type": "string",
+ "minLength": 1,
+ "description": "Select a project if the ticket ID exists more than once."
+ },
+ "required": false,
+ "description": "Select a project if the ticket ID exists more than once.",
+ "name": "projectId",
+ "in": "query"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Task details",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/TaskWithAssignee"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "Invalid ticket ID",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "401": {
+ "description": "Missing or invalid credentials"
+ },
+ "404": {
+ "description": "No accessible task has this ticket ID",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "409": {
+ "description": "Ticket ID matches multiple accessible tasks",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/task/{id}": {
"get": {
"operationId": "getTask",
diff --git a/apps/web/src/lib/generate-project-id.test.ts b/apps/web/src/lib/generate-project-id.test.ts
index 628dea907..129d4924e 100644
--- a/apps/web/src/lib/generate-project-id.test.ts
+++ b/apps/web/src/lib/generate-project-id.test.ts
@@ -25,6 +25,7 @@ describe("generateProjectSlug", () => {
it("keeps digits and punctuation handling as they were", () => {
expect(generateProjectSlug("Sprint 2")).toBe("S2");
+ expect(generateProjectSlug("123abc")).toBe("123");
expect(generateProjectSlug("[Alpha] Beta Gamma")).toBe("ABG");
});
diff --git a/apps/web/src/lib/generate-project-id.ts b/apps/web/src/lib/generate-project-id.ts
index 5ce6923de..d1c42c18a 100644
--- a/apps/web/src/lib/generate-project-id.ts
+++ b/apps/web/src/lib/generate-project-id.ts
@@ -21,7 +21,7 @@ function generateProjectSlug(projectName: string) {
// multilingual plane is two units, so `word[0]` would hand back half a
// surrogate pair and `slice(0, 3)` would cut one in half. Leading combining
// marks are skipped for the same reason `firstLetterOrNumber` skips them: a
- // key has to start with a letter to be typed back as a task short id.
+ // key has to start with a letter or number to be typed back as a task short id.
if (words.length === 1) {
const codePoints = Array.from(words[0]);
const firstLetter = codePoints.findIndex((char) =>
diff --git a/packages/mcp/README.md b/packages/mcp/README.md
index 37b2fbd93..471895d9b 100644
--- a/packages/mcp/README.md
+++ b/packages/mcp/README.md
@@ -118,7 +118,7 @@ For headless or sandboxed environments where opening a browser is impractical, s
- Session: `whoami`, `list_workspaces`, `list_workspace_members`, `list_notifications`
- Search: `search`
- Projects: `list_projects`, `get_project`, `create_project`, `update_project`, `list_project_columns`
-- Tasks: `list_tasks`, `get_task`, `create_task`, `update_task`, `delete_task`, `move_task`, `update_task_status`, `update_task_assignee`, `update_task_due_date`, `list_task_activity`
+- 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`
- 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`
@@ -126,6 +126,9 @@ For headless or sandboxed environments where opening a browser is impractical, s
Call `list_project_columns` before setting a status: the column slugs it
returns are the values `create_task` and `update_task_status` accept.
+Call `get_task_by_ticket_id` with a key such as `KAN-12` to retrieve one task
+without listing a project. If the same key identifies multiple accessible tasks,
+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.
diff --git a/packages/mcp/package.json b/packages/mcp/package.json
index 4efe589b5..06f7fd196 100644
--- a/packages/mcp/package.json
+++ b/packages/mcp/package.json
@@ -1,6 +1,6 @@
{
"name": "@kaneo/mcp",
- "version": "0.1.11",
+ "version": "0.1.12",
"mcpName": "io.github.usekaneo/kaneo",
"description": "Official MCP (Model Context Protocol) server for Kaneo, the open source project management platform: manage tasks, projects, and labels from Claude, Cursor, and other MCP clients",
"license": "MIT",
diff --git a/packages/mcp/server.json b/packages/mcp/server.json
index 0405722b6..84da918b2 100644
--- a/packages/mcp/server.json
+++ b/packages/mcp/server.json
@@ -6,12 +6,12 @@
"url": "https://github.com/usekaneo/kaneo",
"source": "github"
},
- "version": "0.1.11",
+ "version": "0.1.12",
"packages": [
{
"registryType": "npm",
"identifier": "@kaneo/mcp",
- "version": "0.1.11",
+ "version": "0.1.12",
"transport": {
"type": "stdio"
},
diff --git a/packages/mcp/src/tools/register.test.ts b/packages/mcp/src/tools/register.test.ts
index 91336ad96..19cfe606c 100644
--- a/packages/mcp/src/tools/register.test.ts
+++ b/packages/mcp/src/tools/register.test.ts
@@ -136,6 +136,36 @@ describe("registerTools", () => {
});
});
+ it("gets one task by ticket ID with an optional workspace", async () => {
+ const { server, tools } = createServerMock();
+ const client = {
+ json: vi.fn().mockResolvedValue({ id: "task-1", number: 12 }),
+ };
+ registerTools(server as never, { client: client as never });
+
+ const tool = tools.get("get_task_by_ticket_id");
+ expect(tool).toBeDefined();
+ await tool?.handler({ ticketId: "KAN-12" });
+ await tool?.handler({ ticketId: "KAN-12", workspaceId: "workspace 1" });
+ await tool?.handler({ ticketId: "KAN-12", projectId: "project 1" });
+
+ expect(client.json).toHaveBeenNthCalledWith(
+ 1,
+ "/api/task/by-ticket-id/KAN-12",
+ { method: "GET" },
+ );
+ expect(client.json).toHaveBeenNthCalledWith(
+ 2,
+ "/api/task/by-ticket-id/KAN-12?workspaceId=workspace+1",
+ { method: "GET" },
+ );
+ expect(client.json).toHaveBeenNthCalledWith(
+ 3,
+ "/api/task/by-ticket-id/KAN-12?projectId=project+1",
+ { method: "GET" },
+ );
+ });
+
it("fetches the current task and sends a full body for update_task", async () => {
const { server, tools } = createServerMock();
const client = {
diff --git a/packages/mcp/src/tools/register.ts b/packages/mcp/src/tools/register.ts
index 4665f0578..fc51f12d5 100644
--- a/packages/mcp/src/tools/register.ts
+++ b/packages/mcp/src/tools/register.ts
@@ -242,6 +242,31 @@ export function registerTools(
),
);
+ server.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" },
+ ),
+ );
+ },
+ );
+
server.registerTool(
"create_task",
{
diff --git a/tests/api-integration/task-ticket-id.test.ts b/tests/api-integration/task-ticket-id.test.ts
new file mode 100644
index 000000000..c93657553
--- /dev/null
+++ b/tests/api-integration/task-ticket-id.test.ts
@@ -0,0 +1,149 @@
+import { beforeEach, describe, expect, it } from "vite-plus/test";
+import db, { schema } from "../../apps/api/src/database";
+import { createApp } from "../../apps/api/src/index";
+import { mockAnonymousSession, mockAuthenticatedSession } from "./helpers/auth";
+import { resetTestDatabase } from "./helpers/database";
+import {
+ createProjectFixture,
+ createWorkspaceMember,
+} from "./helpers/fixtures";
+
+describe("API integration: task ticket ID lookup", () => {
+ beforeEach(async () => {
+ await resetTestDatabase();
+ });
+
+ it("returns the exact accessible task with full details", async () => {
+ const member = await createWorkspaceMember();
+ const outsider = await createWorkspaceMember();
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ slug: "DE_",
+ });
+ const { project: nearMatch } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ slug: "DEX",
+ });
+ const { project: privateProject } = await createProjectFixture({
+ workspaceId: outsider.workspace.id,
+ slug: "DE_",
+ });
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ title: "Direct match",
+ description: "Full description",
+ number: 23,
+ userId: member.user.id,
+ })
+ .returning();
+ await db.insert(schema.taskTable).values([
+ { projectId: nearMatch.id, title: "Wildcard match", number: 23 },
+ { projectId: privateProject.id, title: "Private match", number: 23 },
+ ]);
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+ const response = await app.request("/api/task/by-ticket-id/de_-23");
+
+ expect(response.status).toBe(200);
+ expect(await response.json()).toMatchObject({
+ id: task.id,
+ title: "Direct match",
+ description: "Full description",
+ assigneeName: member.user.name,
+ projectId: project.id,
+ number: 23,
+ });
+ const missing = await app.request("/api/task/by-ticket-id/DE_-24");
+ expect(missing.status).toBe(404);
+ const privateSelection = await app.request(
+ `/api/task/by-ticket-id/DE_-23?workspaceId=${outsider.workspace.id}`,
+ );
+ expect(privateSelection.status).toBe(404);
+ });
+
+ it("disambiguates accessible tasks by workspace or project", async () => {
+ const member = await createWorkspaceMember();
+ const other = await createWorkspaceMember();
+ await db.insert(schema.workspaceUserTable).values({
+ workspaceId: other.workspace.id,
+ userId: member.user.id,
+ role: "member",
+ joinedAt: new Date(),
+ });
+ const first = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ slug: "KAN",
+ });
+ const duplicate = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ slug: "kan",
+ });
+ const second = await createProjectFixture({
+ workspaceId: other.workspace.id,
+ slug: "KAN",
+ });
+ await db.insert(schema.taskTable).values([
+ { projectId: first.project.id, title: "First", number: 12 },
+ { projectId: duplicate.project.id, title: "Duplicate", number: 12 },
+ { projectId: second.project.id, title: "Second", number: 12 },
+ ]);
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+ const ambiguous = await app.request("/api/task/by-ticket-id/KAN-12");
+ expect(ambiguous.status).toBe(409);
+ const ambiguousInWorkspace = await app.request(
+ `/api/task/by-ticket-id/KAN-12?workspaceId=${member.workspace.id}`,
+ );
+ expect(ambiguousInWorkspace.status).toBe(409);
+
+ const chosenProject = await app.request(
+ `/api/task/by-ticket-id/KAN-12?projectId=${duplicate.project.id}`,
+ );
+ expect(chosenProject.status).toBe(200);
+ expect(await chosenProject.json()).toMatchObject({ title: "Duplicate" });
+
+ const selected = await app.request(
+ `/api/task/by-ticket-id/KAN-12?workspaceId=${other.workspace.id}`,
+ );
+ expect(selected.status).toBe(200);
+ expect(await selected.json()).toMatchObject({ title: "Second" });
+ });
+
+ it("accepts a ticket ID generated from a numeric-leading project name", async () => {
+ const member = await createWorkspaceMember();
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ slug: "123",
+ });
+ await db.insert(schema.taskTable).values({
+ projectId: project.id,
+ title: "Numeric key",
+ number: 1,
+ });
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+ const response = await app.request("/api/task/by-ticket-id/123-1");
+ expect(response.status).toBe(200);
+ expect(await response.json()).toMatchObject({ title: "Numeric key" });
+ });
+
+ it("rejects invalid and unauthenticated lookups", async () => {
+ const member = await createWorkspaceMember();
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+
+ for (const ticketId of ["KAN-0", "KAN-2147483648", "bad-id"]) {
+ const response = await app.request(`/api/task/by-ticket-id/${ticketId}`);
+ expect(response.status).toBe(400);
+ }
+
+ mockAnonymousSession();
+ const anonymous = await app.request("/api/task/by-ticket-id/KAN-12");
+ expect(anonymous.status).toBe(401);
+ });
+});
diff --git a/tests/api/mcp-stateless.test.ts b/tests/api/mcp-stateless.test.ts
index 4ec21ef67..9ce7f6765 100644
--- a/tests/api/mcp-stateless.test.ts
+++ b/tests/api/mcp-stateless.test.ts
@@ -120,6 +120,33 @@ describe("MCP 2026-07-28 stateless HTTP", () => {
).toBe(true);
});
+ it("gets one task by ticket ID through the HTTP MCP server", async () => {
+ const apiFetch = vi.fn(async (input: RequestInfo | URL) => {
+ expect(String(input)).toBe(
+ "http://api.test/api/task/by-ticket-id/KAN-12?workspaceId=workspace+1&projectId=project+1",
+ );
+ return Response.json({ id: "task-1", title: "Direct match" });
+ });
+ vi.stubGlobal("fetch", apiFetch);
+ const handler = createModernMcpHandler("test-token", "http://api.test");
+
+ const response = await handler.fetch(
+ modernRequest("tools/call", 1, {
+ name: "get_task_by_ticket_id",
+ arguments: {
+ ticketId: "KAN-12",
+ workspaceId: "workspace 1",
+ projectId: "project 1",
+ },
+ }),
+ );
+ const body = await rpcBody(response);
+
+ expect(response.status).toBe(200);
+ expect(body.result.content[0].text).toContain("Direct match");
+ expect(apiFetch).toHaveBeenCalledTimes(1);
+ });
+
it("validates bearer authentication on every modern POST", async () => {
const responses = await Promise.all(
[1, 2].map((id) =>
diff --git a/tests/api/search/task-short-id-pattern.test.ts b/tests/api/search/task-short-id-pattern.test.ts
index ee740fdeb..e7d828ba9 100644
--- a/tests/api/search/task-short-id-pattern.test.ts
+++ b/tests/api/search/task-short-id-pattern.test.ts
@@ -10,6 +10,7 @@ describe("TASK_SHORT_ID_PATTERN", () => {
it("matches an ASCII project key", () => {
expect(parse("DEP-23")).toEqual({ slug: "DEP", number: "23" });
expect(parse("S2-7")).toEqual({ slug: "S2", number: "7" });
+ expect(parse("123-1")).toEqual({ slug: "123", number: "1" });
});
it("matches keys generated from non-Latin project names", () => {
@@ -18,8 +19,7 @@ describe("TASK_SHORT_ID_PATTERN", () => {
expect(parse("ΑΒΓ-9")).toEqual({ slug: "ΑΒΓ", number: "9" });
});
- it("still requires a leading letter and a trailing number", () => {
- expect(parse("23-45")).toBeNull();
+ it("still requires a nonempty project key and a trailing number", () => {
expect(parse("DEP-")).toBeNull();
expect(parse("DEP")).toBeNull();
expect(parse("-23")).toBeNull();