Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b63049d79 | ||
|
|
d4fea6b290 |
@@ -0,0 +1,153 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import type { AgentSessionRecord } from "../repositories/agents.js";
|
||||
import { TaskerClient } from "../tasker/client.js";
|
||||
import { executeMcpTool, getToolsForSession } from "./tool-runtime.js";
|
||||
|
||||
const session: AgentSessionRecord = {
|
||||
agent: {
|
||||
id: "agent-1",
|
||||
ownerUserId: "owner-1",
|
||||
ownerEmail: "owner@example.test",
|
||||
displayName: "Codex Agent",
|
||||
avatarUrl: null,
|
||||
status: "active",
|
||||
createdAt: "2026-08-21T00:00:00.000Z",
|
||||
updatedAt: "2026-08-21T00:00:00.000Z",
|
||||
},
|
||||
token: {
|
||||
id: "token-1",
|
||||
agentId: "agent-1",
|
||||
name: "test",
|
||||
status: "active",
|
||||
grantScope: "agent",
|
||||
tokenSuffix: "test",
|
||||
expiresAt: null,
|
||||
lastUsedAt: null,
|
||||
createdAt: "2026-08-21T00:00:00.000Z",
|
||||
},
|
||||
grants: [
|
||||
{
|
||||
id: "grant-1",
|
||||
agentId: "agent-1",
|
||||
workspaceSlug: "nodedc",
|
||||
projectId: "project-1",
|
||||
scopes: ["issue:read"],
|
||||
mode: "voluntary",
|
||||
createdByUserId: "owner-1",
|
||||
createdAt: "2026-08-21T00:00:00.000Z",
|
||||
updatedAt: "2026-08-21T00:00:00.000Z",
|
||||
},
|
||||
],
|
||||
grantSource: "agent",
|
||||
};
|
||||
|
||||
test("tasker_audit_comments is read-only and forwards bounded inventory arguments", async () => {
|
||||
const tool = getToolsForSession(session).find((candidate) => candidate.name === "tasker_audit_comments");
|
||||
assert.ok(tool);
|
||||
assert.equal(tool.annotations?.readOnlyHint, true);
|
||||
|
||||
const forwarded: unknown[] = [];
|
||||
const taskerClient = new TaskerClient({ baseUrl: "http://tasker.test", internalAccessToken: "test" });
|
||||
taskerClient.auditComments = async (...args) => {
|
||||
forwarded.push(args);
|
||||
return { ok: true, inventory: { active_count: 3, deleted_count: 2 } };
|
||||
};
|
||||
|
||||
const result = await executeMcpTool(
|
||||
session,
|
||||
"tasker_audit_comments",
|
||||
{
|
||||
project_id: "project-1",
|
||||
workspace_slug: "nodedc",
|
||||
issue_id: "issue-1",
|
||||
include_bodies: true,
|
||||
offset: 10,
|
||||
limit: 50,
|
||||
},
|
||||
{ taskerClient }
|
||||
);
|
||||
|
||||
assert.deepEqual(forwarded, [
|
||||
[
|
||||
session,
|
||||
{
|
||||
project_id: "project-1",
|
||||
workspace_slug: "nodedc",
|
||||
issue_id: "issue-1",
|
||||
include_bodies: true,
|
||||
offset: 10,
|
||||
limit: 50,
|
||||
},
|
||||
],
|
||||
]);
|
||||
assert.deepEqual(result.structuredContent, {
|
||||
ok: true,
|
||||
inventory: { active_count: 3, deleted_count: 2 },
|
||||
});
|
||||
});
|
||||
|
||||
test("tasker_audit_comments rejects pages above the incident-response bound", async () => {
|
||||
const taskerClient = new TaskerClient({ baseUrl: "http://tasker.test", internalAccessToken: "test" });
|
||||
|
||||
await assert.rejects(
|
||||
executeMcpTool(
|
||||
session,
|
||||
"tasker_audit_comments",
|
||||
{
|
||||
project_id: "project-1",
|
||||
limit: 501,
|
||||
},
|
||||
{ taskerClient }
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
test("tasker_list_comments is read-only and forwards stable paging arguments", async () => {
|
||||
const tool = getToolsForSession(session).find((candidate) => candidate.name === "tasker_list_comments");
|
||||
assert.ok(tool);
|
||||
assert.equal(tool.annotations?.readOnlyHint, true);
|
||||
assert.deepEqual(tool.inputSchema.required, ["issue_id", "project_id"]);
|
||||
|
||||
const forwarded: unknown[] = [];
|
||||
const taskerClient = new TaskerClient({ baseUrl: "http://tasker.test", internalAccessToken: "test" });
|
||||
taskerClient.listComments = async (...args) => {
|
||||
forwarded.push(args);
|
||||
return { ok: true, comments: [{ id: "comment-1", body: "anchor" }], total_count: 1 };
|
||||
};
|
||||
|
||||
const result = await executeMcpTool(
|
||||
session,
|
||||
"tasker_list_comments",
|
||||
{
|
||||
issue_id: "issue-1",
|
||||
project_id: "project-1",
|
||||
workspace_slug: "nodedc",
|
||||
order: "desc",
|
||||
offset: 25,
|
||||
limit: 50,
|
||||
},
|
||||
{ taskerClient }
|
||||
);
|
||||
|
||||
assert.deepEqual(forwarded, [
|
||||
[
|
||||
session,
|
||||
"issue-1",
|
||||
{
|
||||
issue_id: "issue-1",
|
||||
project_id: "project-1",
|
||||
workspace_slug: "nodedc",
|
||||
order: "desc",
|
||||
offset: 25,
|
||||
limit: 50,
|
||||
},
|
||||
],
|
||||
]);
|
||||
assert.deepEqual(result.structuredContent, {
|
||||
ok: true,
|
||||
comments: [{ id: "comment-1", body: "anchor" }],
|
||||
total_count: 1,
|
||||
});
|
||||
});
|
||||
@@ -158,6 +158,41 @@ export const mcpRuntimeTools: McpToolRuntimeDefinition[] = [
|
||||
},
|
||||
annotations: { readOnlyHint: true },
|
||||
},
|
||||
{
|
||||
name: "tasker_audit_comments",
|
||||
title: "NODE.DC Ops: Audit Comments",
|
||||
description:
|
||||
"Direct NODE.DC Ops MCP read-only incident tool. Count active and soft-deleted comments in a granted project, return per-card counts, and page through deleted comment metadata and deletion activities.",
|
||||
requiredScopes: ["issue:read"],
|
||||
inputSchema: {
|
||||
...projectInputSchema,
|
||||
properties: {
|
||||
...projectInputSchema.properties,
|
||||
issue_id: { type: "string" },
|
||||
include_bodies: { type: "boolean", default: false },
|
||||
offset: { type: "integer", minimum: 0, maximum: 1000000, default: 0 },
|
||||
limit: { type: "integer", minimum: 1, maximum: 500, default: 100 },
|
||||
},
|
||||
},
|
||||
annotations: { readOnlyHint: true },
|
||||
},
|
||||
{
|
||||
name: "tasker_list_comments",
|
||||
title: "NODE.DC Ops: List Card Comments",
|
||||
description:
|
||||
"Direct NODE.DC Ops MCP read-only tool. Page through active comments on one granted Tasker/Ops card in stable chronological or reverse-chronological order.",
|
||||
requiredScopes: ["issue:read"],
|
||||
inputSchema: {
|
||||
...projectAndIssueInputSchema,
|
||||
properties: {
|
||||
...projectAndIssueInputSchema.properties,
|
||||
order: { type: "string", enum: ["asc", "desc"], default: "asc" },
|
||||
offset: { type: "integer", minimum: 0, maximum: 1000000, default: 0 },
|
||||
limit: { type: "integer", minimum: 1, maximum: 500, default: 100 },
|
||||
},
|
||||
},
|
||||
annotations: { readOnlyHint: true },
|
||||
},
|
||||
{
|
||||
name: "tasker_create_issue",
|
||||
title: "NODE.DC Ops: Create Card",
|
||||
@@ -345,6 +380,12 @@ const projectArgsSchema = z.object({
|
||||
const searchIssuesArgsSchema = projectArgsSchema.extend({
|
||||
query: z.string().min(1).optional(),
|
||||
});
|
||||
const auditCommentsArgsSchema = projectArgsSchema.extend({
|
||||
issue_id: z.string().min(1).optional(),
|
||||
include_bodies: z.boolean().default(false),
|
||||
offset: z.number().int().min(0).max(1_000_000).default(0),
|
||||
limit: z.number().int().min(1).max(500).default(100),
|
||||
});
|
||||
const prioritySchema = z.enum(["none", "low", "medium", "high", "urgent"]);
|
||||
const createIssueArgsSchema = z.object({
|
||||
project_id: z.string().min(1),
|
||||
@@ -360,6 +401,11 @@ const issueArgsSchema = z.object({
|
||||
project_id: z.string().min(1),
|
||||
workspace_slug: z.string().min(1).nullish(),
|
||||
});
|
||||
const listCommentsArgsSchema = issueArgsSchema.extend({
|
||||
order: z.enum(["asc", "desc"]).default("asc"),
|
||||
offset: z.number().int().min(0).max(1_000_000).default(0),
|
||||
limit: z.number().int().min(1).max(500).default(100),
|
||||
});
|
||||
const updateIssueArgsSchema = issueArgsSchema.extend({
|
||||
title: z.string().min(1).max(500).optional(),
|
||||
description: z.string().max(20000).optional(),
|
||||
@@ -503,6 +549,16 @@ async function executeMcpToolOnce(
|
||||
requireToolAccess(session, "issue:read", input.project_id, input.workspace_slug);
|
||||
return asToolResult(await deps.taskerClient.listIssues(session, input.project_id, input.workspace_slug, input.query));
|
||||
}
|
||||
case "tasker_audit_comments": {
|
||||
const input = auditCommentsArgsSchema.parse(args);
|
||||
requireToolAccess(session, "issue:read", input.project_id, input.workspace_slug);
|
||||
return asToolResult(await deps.taskerClient.auditComments(session, input));
|
||||
}
|
||||
case "tasker_list_comments": {
|
||||
const input = listCommentsArgsSchema.parse(args);
|
||||
requireToolAccess(session, "issue:read", input.project_id, input.workspace_slug);
|
||||
return asToolResult(await deps.taskerClient.listComments(session, input.issue_id, input));
|
||||
}
|
||||
case "tasker_create_issue": {
|
||||
const input = createIssueArgsSchema.parse(args);
|
||||
requireToolAccess(session, "issue:create", input.project_id, input.workspace_slug);
|
||||
|
||||
@@ -34,6 +34,29 @@ export async function registerToolRoutes(app: FastifyInstance, deps: ToolRouteDe
|
||||
return result.structuredContent;
|
||||
});
|
||||
|
||||
app.get("/api/v1/tools/projects/:projectId/comments/audit", async (request) => {
|
||||
const session = await authenticateAgent(request, deps);
|
||||
const params = request.params as { projectId: string };
|
||||
const query = request.query as {
|
||||
workspace_slug?: string;
|
||||
issue_id?: string;
|
||||
include_bodies?: boolean;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
};
|
||||
const result = await executeMcpTool(
|
||||
session,
|
||||
"tasker_audit_comments",
|
||||
{
|
||||
...query,
|
||||
project_id: params.projectId,
|
||||
},
|
||||
deps,
|
||||
toolOptions(request)
|
||||
);
|
||||
return result.structuredContent;
|
||||
});
|
||||
|
||||
app.post("/api/v1/tools/projects/:projectId/labels/ensure", async (request) => {
|
||||
const session = await authenticateAgent(request, deps);
|
||||
const params = request.params as { projectId: string };
|
||||
@@ -111,6 +134,29 @@ export async function registerToolRoutes(app: FastifyInstance, deps: ToolRouteDe
|
||||
return result.structuredContent;
|
||||
});
|
||||
|
||||
app.get("/api/v1/tools/issues/:issueId/comments", async (request) => {
|
||||
const session = await authenticateAgent(request, deps);
|
||||
const params = request.params as { issueId: string };
|
||||
const query = request.query as {
|
||||
project_id?: string;
|
||||
workspace_slug?: string;
|
||||
order?: "asc" | "desc";
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
};
|
||||
const result = await executeMcpTool(
|
||||
session,
|
||||
"tasker_list_comments",
|
||||
{
|
||||
...query,
|
||||
issue_id: params.issueId,
|
||||
},
|
||||
deps,
|
||||
toolOptions(request)
|
||||
);
|
||||
return result.structuredContent;
|
||||
});
|
||||
|
||||
app.patch("/api/v1/tools/issues/:issueId/comments/:commentId", async (request) => {
|
||||
const session = await authenticateAgent(request, deps);
|
||||
const params = request.params as { issueId: string; commentId: string };
|
||||
|
||||
@@ -77,6 +77,23 @@ export type CommentInput = {
|
||||
body: string;
|
||||
};
|
||||
|
||||
export type AuditCommentsInput = {
|
||||
project_id: string;
|
||||
workspace_slug?: string | null;
|
||||
issue_id?: string;
|
||||
include_bodies?: boolean;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
};
|
||||
|
||||
export type ListCommentsInput = {
|
||||
project_id: string;
|
||||
workspace_slug?: string | null;
|
||||
order?: "asc" | "desc";
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
};
|
||||
|
||||
export type SetLabelsInput = {
|
||||
project_id: string;
|
||||
workspace_slug?: string | null;
|
||||
@@ -194,6 +211,47 @@ export class TaskerClient {
|
||||
);
|
||||
}
|
||||
|
||||
async auditComments(session: AgentSessionRecord, input: AuditCommentsInput): Promise<unknown> {
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
if (input.workspace_slug) {
|
||||
searchParams.set("workspace_slug", input.workspace_slug);
|
||||
}
|
||||
if (input.issue_id) {
|
||||
searchParams.set("issue_id", input.issue_id);
|
||||
}
|
||||
searchParams.set("include_bodies", input.include_bodies ? "true" : "false");
|
||||
searchParams.set("offset", String(input.offset ?? 0));
|
||||
searchParams.set("limit", String(input.limit ?? 100));
|
||||
|
||||
return this.request(
|
||||
`/api/internal/nodedc/agent/projects/${encodeURIComponent(input.project_id)}/comments/audit?${searchParams.toString()}`,
|
||||
{
|
||||
method: "GET",
|
||||
session,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async listComments(session: AgentSessionRecord, issueId: string, input: ListCommentsInput): Promise<unknown> {
|
||||
const searchParams = new URLSearchParams({ project_id: input.project_id });
|
||||
|
||||
if (input.workspace_slug) {
|
||||
searchParams.set("workspace_slug", input.workspace_slug);
|
||||
}
|
||||
searchParams.set("order", input.order ?? "asc");
|
||||
searchParams.set("offset", String(input.offset ?? 0));
|
||||
searchParams.set("limit", String(input.limit ?? 100));
|
||||
|
||||
return this.request(
|
||||
`/api/internal/nodedc/agent/issues/${encodeURIComponent(issueId)}/comments?${searchParams.toString()}`,
|
||||
{
|
||||
method: "GET",
|
||||
session,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async setLabels(session: AgentSessionRecord, issueId: string, input: SetLabelsInput): Promise<unknown> {
|
||||
return this.request(`/api/internal/nodedc/agent/issues/${encodeURIComponent(issueId)}/labels`, {
|
||||
method: "PUT",
|
||||
|
||||
Reference in New Issue
Block a user