Skip to content

Commit 6ad6d6e

Browse files
fix(server): restore the list_thread_pull_requests state filter
Review requires `states: ["open"]` to return the open PRs on page one when older merged links fill the first page. Restore the optional `states` input, filtered before paging. A PR with no known state counts as open, as in openPullRequestCount. The MCP tool list grows 74 bytes over main. The eval runner needs an Anthropic API key to check a guidance cut that would offset it, so this growth needs the agent-context-increase label. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 60ece6d commit 6ad6d6e

5 files changed

Lines changed: 31 additions & 9 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,25 @@ describe("listThreadPullRequests", () => {
641641
),
642642
).toEqual(Array.from({ length: 50 }, (_, index) => index + 51));
643643
});
644+
645+
it("filters by state before paging, counting a PR with no known state as open", () => {
646+
const merged = (number: number) => {
647+
const link = makeLink(number, { headBranch: `feat-${number}` });
648+
return { ...link, snapshot: { ...link.snapshot!, state: "merged" as const } };
649+
};
650+
const thread = {
651+
pullRequests: [
652+
...Array.from({ length: 50 }, (_, index) => merged(index + 1)),
653+
...Array.from({ length: 10 }, (_, index) => makeLink(index + 51)),
654+
],
655+
};
656+
const open = listThreadPullRequests(thread, undefined, ["open"]);
657+
expect(open.pullRequests.map((entry) => entry.number)).toEqual(
658+
Array.from({ length: 10 }, (_, index) => index + 51),
659+
);
660+
expect(open.nextCursor).toBeNull();
661+
expect(listThreadPullRequests(thread, undefined, ["merged"]).nextCursor).toBeNull();
662+
});
644663
});
645664

646665
describe("pull request guide tools", () => {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CommandId,
33
type OrchestrationProjectShell,
4+
type PullRequestState,
45
type OrchestrationV2ThreadShell,
56
type ThreadId,
67
type ThreadPullRequestLink,
@@ -85,9 +86,11 @@ function pullRequestListPosition(link: ThreadPullRequestLink): string {
8586
export function listThreadPullRequests(
8687
thread: Pick<OrchestrationV2ThreadShell, "pullRequests">,
8788
cursor?: string,
89+
states?: ReadonlyArray<PullRequestState>,
8890
): ListThreadPullRequestsResult {
8991
const chains = resolveThreadPullRequestChains(thread.pullRequests ?? []);
9092
const after = visibleThreadPullRequests(thread.pullRequests ?? [])
93+
.filter((link) => states === undefined || states.includes(link.snapshot?.state ?? "open"))
9194
.map((link) => ({ link, position: pullRequestListPosition(link) }))
9295
.filter(({ position }) => cursor === undefined || position > cursor)
9396
.toSorted((left, right) => (left.position < right.position ? -1 : 1));
@@ -426,7 +429,7 @@ const make = Effect.gen(function* () {
426429
),
427430
list_thread_pull_requests: McpToolAccess.reads((input) =>
428431
requireThread(PullRequestListFailedError, input.threadId).pipe(
429-
Effect.map((thread) => listThreadPullRequests(thread, input.cursor)),
432+
Effect.map((thread) => listThreadPullRequests(thread, input.cursor, input.states)),
430433
),
431434
),
432435
watch_pull_request: writesThread((input) => setWatching(input, true)),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ const ListThreadPullRequestsTool = Tool.make("list_thread_pull_requests", {
311311
parameters: Schema.Struct({
312312
environmentId: OrchestratorMcpEnvironmentTarget,
313313
threadId: Schema.optional(ThreadId.annotate({ description: "Thread. Default: this thread." })),
314+
states: Schema.optional(Schema.Array(PullRequestState)),
314315
cursor: Schema.optional(Schema.String),
315316
}),
316317
success: ListThreadPullRequestsResult,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"claudeSystemAppendBytes": 5597,
33
"codexAdditionalContextBytes": 7327,
4-
"mcpToolListJsonBytes": 48087
4+
"mcpToolListJsonBytes": 48173
55
}

‎evals/mcp-tool-use/run.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,17 +1303,16 @@ export const t3Default = (
13031303
case "unwatch_pull_request":
13041304
return { ...pr(), watching: false, wasWatching: true };
13051305
case "list_thread_pull_requests": {
1306-
const linked = [...sample.linked].map((url) => ({
1307-
...linkedEntry(sample, url),
1308-
source: "agent",
1309-
watching: false,
1310-
}));
1306+
const states = Array.isArray(input.states) ? input.states : undefined;
1307+
const matching = [...sample.linked]
1308+
.map((url) => ({ ...linkedEntry(sample, url), source: "agent", watching: false }))
1309+
.filter((entry) => states === undefined || states.includes(entry.state));
13111310
const start = Number(valueText(input.cursor)) || 0;
13121311
const end = start + 50;
13131312
return {
1314-
pullRequests: linked.slice(start, end),
1313+
pullRequests: matching.slice(start, end),
13151314
chains: [],
1316-
nextCursor: end < linked.length ? String(end) : null,
1315+
nextCursor: end < matching.length ? String(end) : null,
13171316
};
13181317
}
13191318
case "t3_thread_read": {

0 commit comments

Comments
 (0)