Skip to content

Commit 62a08b4

Browse files
committed
format the runs list
1 parent f60056e commit 62a08b4

File tree

2 files changed

+107
-3
lines changed

2 files changed

+107
-3
lines changed

packages/cli-v3/src/mcp/formatters.ts

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { RetrieveRunResponse, RetrieveRunTraceResponseBody } from "@trigger.dev/core/v3/schemas";
1+
import {
2+
ListRunResponseItem,
3+
RetrieveRunResponse,
4+
RetrieveRunTraceResponseBody,
5+
} from "@trigger.dev/core/v3/schemas";
6+
import { CursorPageResponse } from "@trigger.dev/core/v3/zodfetch";
27

38
export function formatRun(run: RetrieveRunResponse): string {
49
const lines: string[] = [];
@@ -276,3 +281,100 @@ function getStatusIndicator(
276281
if (spanData.isPartial) return "[PARTIAL]";
277282
return "[COMPLETED]";
278283
}
284+
285+
export function formatRunList(runsPage: CursorPageResponse<ListRunResponseItem>): string {
286+
const lines: string[] = [];
287+
288+
// Header with count info
289+
const totalRuns = runsPage.data.length;
290+
lines.push(`Found ${totalRuns} run${totalRuns === 1 ? "" : "s"}`);
291+
lines.push("");
292+
293+
if (totalRuns === 0) {
294+
lines.push("No runs found.");
295+
return lines.join("\n");
296+
}
297+
298+
// Format each run in a compact table-like format
299+
runsPage.data.forEach((run, index) => {
300+
lines.push(`${index + 1}. ${formatRunSummary(run)}`);
301+
});
302+
303+
// Pagination info
304+
lines.push("");
305+
const paginationInfo = [];
306+
if (runsPage.pagination.previous) {
307+
paginationInfo.push("← Previous page available");
308+
}
309+
if (runsPage.pagination.next) {
310+
paginationInfo.push("Next page available →");
311+
}
312+
313+
if (paginationInfo.length > 0) {
314+
lines.push(`Pagination: ${paginationInfo.join(" | ")}`);
315+
if (runsPage.pagination.next) {
316+
lines.push(`Next cursor: ${runsPage.pagination.next}`);
317+
}
318+
if (runsPage.pagination.previous) {
319+
lines.push(`Previous cursor: ${runsPage.pagination.previous}`);
320+
}
321+
}
322+
323+
return lines.join("\n");
324+
}
325+
326+
function formatRunSummary(run: ListRunResponseItem): string {
327+
const parts: string[] = [];
328+
329+
// Basic info: ID, task, status
330+
parts.push(`${run.id}`);
331+
parts.push(`${run.taskIdentifier}`);
332+
parts.push(`${formatStatus(run.status)}`);
333+
334+
// Environment
335+
parts.push(`env:${run.env.name}`);
336+
337+
// Timing - show the most relevant time
338+
let timeInfo = "";
339+
if (run.finishedAt) {
340+
timeInfo = `finished ${formatDateTime(run.finishedAt)}`;
341+
} else if (run.startedAt) {
342+
timeInfo = `started ${formatDateTime(run.startedAt)}`;
343+
} else if (run.delayedUntil) {
344+
timeInfo = `delayed until ${formatDateTime(run.delayedUntil)}`;
345+
} else {
346+
timeInfo = `created ${formatDateTime(run.createdAt)}`;
347+
}
348+
parts.push(timeInfo);
349+
350+
// Duration if available
351+
if (run.durationMs > 0) {
352+
parts.push(`took ${formatDuration(run.durationMs)}`);
353+
}
354+
355+
// Cost if significant
356+
if (run.costInCents > 0) {
357+
parts.push(`$${(run.costInCents / 100).toFixed(4)}`);
358+
}
359+
360+
// Tags if present
361+
if (run.tags && run.tags.length > 0) {
362+
const tagStr =
363+
run.tags.length > 2
364+
? `${run.tags.slice(0, 2).join(", ")}+${run.tags.length - 2}`
365+
: run.tags.join(", ");
366+
parts.push(`tags:[${tagStr}]`);
367+
}
368+
369+
// Test flag
370+
if (run.isTest) {
371+
parts.push("[TEST]");
372+
}
373+
374+
// Version if available
375+
if (run.version) {
376+
parts.push(`v${run.version}`);
377+
}
378+
379+
return parts.join(" | ");
380+
}

packages/cli-v3/src/mcp/tools/runs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { toolsMetadata } from "../config.js";
2-
import { formatRun, formatRunTrace } from "../formatters.js";
2+
import { formatRun, formatRunList, formatRunTrace } from "../formatters.js";
33
import { CommonRunsInput, GetRunDetailsInput, ListRunsInput } from "../schemas.js";
44
import { respondWithError, toolHandler } from "../utils.js";
55

@@ -142,8 +142,10 @@ export const listRunsTool = {
142142
machine: input.machine,
143143
});
144144

145+
const formattedRuns = formatRunList(result);
146+
145147
return {
146-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
148+
content: [{ type: "text", text: formattedRuns }],
147149
};
148150
}),
149151
};

0 commit comments

Comments
 (0)