import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import type { ToolContext } from "../utils/api.js";
const json = (d: unknown) => ({ type: "text" as const, text: JSON.stringify(d, null, 2) });
export function registerAdmin(server: McpServer, ctx: ToolContext): void {
const { api, requireConfig, buildQuery } = ctx;
server.registerTool(
"fetch_users",
{ description: "List users in the space." },
async () => {
requireConfig();
const d = await api("/space_users");
return { content: [json(d)] };
}
);
server.registerTool(
"fetch_roles",
{ description: "List roles in the space." },
async () => {
requireConfig();
const d = await api("/space_roles");
return { content: [json(d)] };
}
);
server.registerTool(
"fetch_activity_log",
{
description: "List activity log. Optional per_page, page, user_id.",
inputSchema: { per_page: z.number().optional(), page: z.number().optional(), user_id: z.string().optional() },
},
async (a) => {
requireConfig();
const q = buildQuery({ per_page: a?.per_page, page: a?.page, user_id: a?.user_id });
const d = await api(`/activities${q}`);
return { content: [json(d)] };
}
);
server.registerTool(
"fetch_tasks",
{
description: "List tasks. Optional per_page, page, story_id.",
inputSchema: { per_page: z.number().optional(), page: z.number().optional(), story_id: z.string().optional() },
},
async (a) => {
requireConfig();
const q = buildQuery({ per_page: a?.per_page, page: a?.page, story_id: a?.story_id });
const d = await api(`/tasks${q}`);
return { content: [json(d)] };
}
);
server.registerTool(
"create_task",
{
description: "Create a task. Pass name, description, assigned_to_user_id, story_id, etc.",
inputSchema: { name: z.string(), description: z.string().optional(), assigned_to_user_id: z.number().optional(), story_id: z.number().optional() },
},
async (body) => {
requireConfig();
const d = await api("/tasks", { method: "POST", body: JSON.stringify({ task: body }) });
return { content: [json(d)] };
}
);
server.registerTool(
"update_task",
{
description: "Update a task by ID.",
inputSchema: { task_id: z.string(), name: z.string().optional(), description: z.string().optional(), resolved: z.boolean().optional() },
},
async ({ task_id, ...rest }) => {
requireConfig();
const d = await api(`/tasks/${task_id}`, { method: "PUT", body: JSON.stringify({ task: rest }) });
return { content: [json(d)] };
}
);
server.registerTool(
"delete_task",
{ description: "Delete a task by ID.", inputSchema: { task_id: z.string() } },
async ({ task_id }) => {
requireConfig();
await api(`/tasks/${task_id}`, { method: "DELETE" });
return { content: [json({ success: true })] };
}
);
}