Skip to content

Commit 85cf325

Browse files
feat(server): agents read failing CI logs and re-run checks through MCP tools
Agents read red CI with gh run view --log-failed or the job logs API (about 500 times in 45 days) and re-ran it with gh run rerun, on the user's own quota and outside T3's forge sign-in. ci_logs returns the end of the PR's failing check logs, or of one named check; ci_rerun re-runs them. Both work from the PR's checks, which every forge reports by name, so agents never look up run ids. - PullRequestProvider gains optional getCheckLogs and rerunChecks. - GitHub: an Actions check run is a job, so its link gives the job's log, and a run's failed jobs re-run together (GitHub refuses a second job re-run while the run re-runs). - GitCafe: logs of checks the GitHub mirror ran come through GitCafe's check-log endpoint; GitCafe Actions runs re-run, and mirrored checks say to re-run them on GitHub. - PullRequestService picks the failing checks (failure or cancelled), or the named one, and lists the checks when the name matches none. The tool list grows by another 756 bytes. New mcp-tool-use cases pass on Sonnet 5.5 (ci_logs 3/4, ci_rerun 4/4, control 4/4; 0/4, 0/4, 4/4 on main). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d43ec75 commit 85cf325

15 files changed

Lines changed: 613 additions & 4 deletions

File tree

‎apps/server/src/mcp/toolkits/pullRequests/handlers.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,28 @@ const make = Effect.gen(function* () {
849849
return { ...identityOf(target), state: after.state };
850850
}),
851851
),
852+
ci_logs: McpToolAccess.reads((input) =>
853+
Effect.gen(function* () {
854+
const { target, ref } = yield* locate(input);
855+
const checks = yield* pullRequests
856+
.checkLogs({
857+
...ref,
858+
tailLines: input.tailLines ?? 200,
859+
...(input.check === undefined ? {} : { check: input.check }),
860+
})
861+
.pipe(Effect.mapError(forgeFailure));
862+
return { ...identityOf(target), checks };
863+
}),
864+
),
865+
ci_rerun: McpToolAccess.writesWithCapability((input) =>
866+
Effect.gen(function* () {
867+
const { target, ref } = yield* locate(input);
868+
const checks = yield* pullRequests
869+
.rerunChecks({ ...ref, ...(input.check === undefined ? {} : { check: input.check }) })
870+
.pipe(Effect.mapError(forgeFailure));
871+
return { ...identityOf(target), checks };
872+
}),
873+
),
852874
} satisfies McpToolAccess.Handlers<typeof PullRequestsToolkit.tools>;
853875
});
854876

‎apps/server/src/mcp/toolkits/pullRequests/tools.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,70 @@ const MergePullRequestTool = Tool.make("pull_request_merge", {
694694
.annotate(Tool.Idempotent, false)
695695
.annotate(Tool.OpenWorld, true);
696696

697+
export const CheckLogsResult = Schema.Struct({
698+
...PullRequestIdentity,
699+
checks: Schema.Array(
700+
Schema.Struct({
701+
name: Schema.String,
702+
url: Schema.NullOr(Schema.String),
703+
log: Schema.NullOr(Schema.String),
704+
truncated: Schema.Boolean,
705+
detail: Schema.NullOr(Schema.String),
706+
}),
707+
),
708+
});
709+
export type CheckLogsResult = typeof CheckLogsResult.Type;
710+
711+
export const RerunChecksResult = Schema.Struct({
712+
...PullRequestIdentity,
713+
checks: Schema.Array(
714+
Schema.Struct({
715+
name: Schema.String,
716+
rerun: Schema.Boolean,
717+
detail: Schema.NullOr(Schema.String),
718+
}),
719+
),
720+
});
721+
export type RerunChecksResult = typeof RerunChecksResult.Type;
722+
723+
const CheckLogsTool = Tool.make("ci_logs", {
724+
description:
725+
"Read the end of a PR's failing check logs, or of one named check. Use instead of gh run view --log-failed.",
726+
parameters: Schema.Struct({
727+
...ThreadPullRequestInput.fields,
728+
check: Schema.optional(TrimmedNonEmptyString),
729+
tailLines: Schema.optional(
730+
Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 2000 })).annotate({
731+
description: "Default: 200.",
732+
}),
733+
),
734+
}),
735+
success: CheckLogsResult,
736+
failure: PullRequestToolError,
737+
dependencies: forgeDependencies,
738+
})
739+
.annotate(Tool.Title, "Read CI logs")
740+
.annotate(Tool.Readonly, true)
741+
.annotate(Tool.Destructive, false)
742+
.annotate(Tool.Idempotent, true)
743+
.annotate(Tool.OpenWorld, true);
744+
745+
const RerunChecksTool = Tool.make("ci_rerun", {
746+
description: "Re-run a PR's failing checks, or one named check.",
747+
parameters: Schema.Struct({
748+
...ThreadPullRequestInput.fields,
749+
check: Schema.optional(TrimmedNonEmptyString),
750+
}),
751+
success: RerunChecksResult,
752+
failure: PullRequestToolError,
753+
dependencies: forgeDependencies,
754+
})
755+
.annotate(Tool.Title, "Re-run CI")
756+
.annotate(Tool.Readonly, false)
757+
.annotate(Tool.Destructive, false)
758+
.annotate(Tool.Idempotent, false)
759+
.annotate(Tool.OpenWorld, true);
760+
697761
export const PullRequestsToolkit = Toolkit.make(
698762
LinkPullRequestTool,
699763
UnlinkPullRequestTool,
@@ -708,4 +772,6 @@ export const PullRequestsToolkit = Toolkit.make(
708772
UpdatePullRequestTool,
709773
RespondToPullRequestTool,
710774
MergePullRequestTool,
775+
CheckLogsTool,
776+
RerunChecksTool,
711777
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"claudeSystemAppendBytes": 5135,
33
"codexAdditionalContextBytes": 6865,
4-
"mcpToolListJsonBytes": 48722
4+
"mcpToolListJsonBytes": 49478
55
}

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,51 @@ it.effect(
10951095
}),
10961096
);
10971097

1098+
it.effect(
1099+
"reads logs of the failing checks, or of the one named, and names the checks it lacks",
1100+
() =>
1101+
Effect.gen(function* () {
1102+
const asked: Array<ReadonlyArray<string>> = [];
1103+
const check = (name: string, status: "success" | "failure" | "cancelled") => ({
1104+
name,
1105+
status,
1106+
description: null,
1107+
url: `https://github.com/acme/web/runs/${name.length}`,
1108+
});
1109+
const service = yield* makeService({
1110+
projects: [
1111+
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
1112+
],
1113+
providers: [
1114+
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
1115+
getChangeRequestChecks: () =>
1116+
Effect.succeed({
1117+
state: "open",
1118+
checks: [
1119+
check("Lint", "success"),
1120+
check("Test", "failure"),
1121+
check("E2E", "cancelled"),
1122+
],
1123+
}),
1124+
getCheckLogs: (input) =>
1125+
Effect.sync(() => {
1126+
asked.push(input.checks.map((entry) => entry.name));
1127+
return [];
1128+
}),
1129+
}),
1130+
],
1131+
});
1132+
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
1133+
yield* service.checkLogs({ ...reference, tailLines: 50 });
1134+
yield* service.checkLogs({ ...reference, check: "lint", tailLines: 50 });
1135+
const missing = yield* Effect.flip(
1136+
service.checkLogs({ ...reference, check: "Deploy", tailLines: 50 }),
1137+
);
1138+
assert.deepStrictEqual(asked, [["Test", "E2E"], ["Lint"]]);
1139+
assert.include(missing.message, "Lint, Test, E2E");
1140+
}),
1141+
);
1142+
10981143
it.effect("refuses a merge whose head moved past expectedHeadSha and pins the host merge", () =>
10991144
Effect.gen(function* () {
11001145
const pinned: Array<string | undefined> = [];

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ import type { SourceControlProviderContext } from "@t3tools/source-control-core/
8686
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
8787
import {
8888
type ProviderChangeRequest,
89+
type ProviderCheckLog,
90+
type ProviderCheckRerun,
8991
type ProviderDiffFilePaths,
9092
type ProviderFilterOptionPage,
9193
type ProviderListCursor,
@@ -247,6 +249,14 @@ export class PullRequestService extends Context.Service<
247249
input: PullRequestRef,
248250
) => Effect.Effect<PullRequestChangeBreakdown, PullRequestError>;
249251
readonly runAction: (input: PullRequestActionInput) => Effect.Effect<void, PullRequestError>;
252+
/** Tails of the failing checks' logs, or only the named check's. */
253+
readonly checkLogs: (
254+
input: PullRequestRef & { readonly check?: string; readonly tailLines: number },
255+
) => Effect.Effect<ReadonlyArray<ProviderCheckLog>, PullRequestError>;
256+
/** Re-runs the failing checks, or only the named check. */
257+
readonly rerunChecks: (
258+
input: PullRequestRef & { readonly check?: string },
259+
) => Effect.Effect<ReadonlyArray<ProviderCheckRerun>, PullRequestError>;
250260
readonly update: (input: PullRequestUpdateInput) => Effect.Effect<void, PullRequestError>;
251261
readonly comment: (input: PullRequestCommentInput) => Effect.Effect<void, PullRequestError>;
252262
readonly updateComment: (
@@ -577,6 +587,12 @@ function withRateLimitBackoff(
577587
? {}
578588
: { getFileRevisions: wrap("getFileRevisions", api.getFileRevisions) }),
579589
runAction: interactive("runAction", api.runAction),
590+
...(api.getCheckLogs === undefined
591+
? {}
592+
: { getCheckLogs: interactive("getCheckLogs", api.getCheckLogs) }),
593+
...(api.rerunChecks === undefined
594+
? {}
595+
: { rerunChecks: interactive("rerunChecks", api.rerunChecks) }),
580596
...(api.updateChangeRequest === undefined
581597
? {}
582598
: {
@@ -3519,6 +3535,83 @@ export const make = Effect.gen(function* () {
35193535
);
35203536
yield* SubscriptionRef.set(pullRequestRefreshes, listingsEpoch);
35213537
});
3538+
const selectChecks = Effect.fn("PullRequestService.selectChecks")(function* (
3539+
project: SupportedProject,
3540+
input: PullRequestRef & { readonly check?: string },
3541+
operation: string,
3542+
) {
3543+
const ref = {
3544+
cwd: project.project.workspaceRoot,
3545+
repository: project.repository,
3546+
host: project.host,
3547+
number: input.number,
3548+
};
3549+
const { checks } = yield* (
3550+
project.api.getChangeRequestChecks === undefined
3551+
? project.api.getChangeRequest(ref)
3552+
: project.api.getChangeRequestChecks(ref)
3553+
).pipe(Effect.mapError(toPullRequestError(operation)));
3554+
const named = input.check?.trim().toLowerCase();
3555+
if (named === undefined) {
3556+
return checks
3557+
.filter((check) => check.status === "failure" || check.status === "cancelled")
3558+
.map(({ name, url }) => ({ name, url }));
3559+
}
3560+
const matches = checks.filter((check) => check.name.toLowerCase() === named);
3561+
if (matches.length === 0) {
3562+
return yield* new PullRequestOperationError({
3563+
operation,
3564+
detail: `No check is named ${input.check}. Checks: ${checks.map((check) => check.name).join(", ") || "none"}.`,
3565+
});
3566+
}
3567+
return matches.map(({ name, url }) => ({ name, url }));
3568+
});
3569+
3570+
const checkLogs: PullRequestService["Service"]["checkLogs"] = Effect.fn(
3571+
"PullRequestService.checkLogs",
3572+
)(function* (input) {
3573+
const project = yield* requireProject(input);
3574+
const read = project.api.getCheckLogs;
3575+
if (read === undefined) {
3576+
return yield* new PullRequestOperationError({
3577+
operation: "checkLogs",
3578+
detail: "This host cannot read check logs.",
3579+
});
3580+
}
3581+
const checks = yield* selectChecks(project, input, "checkLogs");
3582+
if (checks.length === 0) return [];
3583+
return yield* read({
3584+
cwd: project.project.workspaceRoot,
3585+
repository: project.repository,
3586+
host: project.host,
3587+
checks,
3588+
tailLines: input.tailLines,
3589+
}).pipe(Effect.mapError(toPullRequestError("checkLogs")));
3590+
});
3591+
3592+
const rerunChecks: PullRequestService["Service"]["rerunChecks"] = Effect.fn(
3593+
"PullRequestService.rerunChecks",
3594+
)(function* (input) {
3595+
const project = yield* requireProject(input);
3596+
const rerun = project.api.rerunChecks;
3597+
if (rerun === undefined) {
3598+
return yield* new PullRequestOperationError({
3599+
operation: "rerunChecks",
3600+
detail: "This host cannot re-run checks.",
3601+
});
3602+
}
3603+
const checks = yield* selectChecks(project, input, "rerunChecks");
3604+
if (checks.length === 0) return [];
3605+
const outcomes = yield* rerun({
3606+
cwd: project.project.workspaceRoot,
3607+
repository: project.repository,
3608+
host: project.host,
3609+
checks,
3610+
}).pipe(Effect.mapError(toPullRequestError("rerunChecks")));
3611+
yield* readCache.invalidate(refScope(yield* canonicalRef(input)));
3612+
return outcomes;
3613+
});
3614+
35223615
const runActionAndInvalidate: PullRequestService["Service"]["runAction"] = Effect.fn(
35233616
"PullRequestService.runActionAndInvalidate",
35243617
)(function* (input) {
@@ -3707,6 +3800,8 @@ export const make = Effect.gen(function* () {
37073800
Cache.get(changeBreakdownCache, refCacheKey(input)),
37083801
),
37093802
runAction: runActionAndInvalidate,
3803+
checkLogs,
3804+
rerunChecks,
37103805
update: invalidatedByMutation(update),
37113806
comment: invalidatedByMutation(comment),
37123807
updateComment: invalidatedByMutation(updateComment),

0 commit comments

Comments
 (0)