Skip to content

Commit c4a3bdf

Browse files
ScottN-PVclaude
andcommitted
fix(server): MCP thread list and read report every linked pull request
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 43f8a8d commit c4a3bdf

4 files changed

Lines changed: 94 additions & 3 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
type OrchestratorMcpListScheduledTasksInput,
3636
type ProjectId,
3737
type OrchestratorMcpThreadDetail,
38+
type OrchestratorMcpThreadPullRequest,
3839
type OrchestratorMcpThreadInterruptInput,
3940
type OrchestratorMcpThreadInterruptResult,
4041
type OrchestratorMcpThreadListInput,
@@ -58,6 +59,10 @@ import {
5859
ThreadId,
5960
} from "@t3tools/contracts";
6061
import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
62+
import {
63+
normalizeThreadPullRequestKey,
64+
visibleThreadPullRequests,
65+
} from "@t3tools/shared/threadPullRequests";
6166
import * as Clock from "effect/Clock";
6267
import * as Context from "effect/Context";
6368
import * as Crypto from "effect/Crypto";
@@ -633,6 +638,20 @@ function threadSnooze(
633638
};
634639
}
635640

641+
/** The same links `list_thread_pull_requests` reports, without the snapshot details. */
642+
function threadPullRequests(
643+
links: OrchestrationV2ThreadShell["pullRequests"],
644+
): OrchestratorMcpThreadPullRequest[] {
645+
return visibleThreadPullRequests(links ?? []).map((link) => ({
646+
host: normalizeThreadPullRequestKey(link).host,
647+
repository: link.repository,
648+
number: link.number,
649+
url: link.url,
650+
source: link.source,
651+
state: link.snapshot?.state ?? null,
652+
}));
653+
}
654+
636655
function listItemFromShell(
637656
shell: OrchestrationV2ThreadShell,
638657
nowMs: number,
@@ -649,6 +668,7 @@ function listItemFromShell(
649668
runtimeMode: shell.runtimeMode,
650669
interactionMode: shell.interactionMode,
651670
linkedPullRequest: shell.linkedPullRequest ?? null,
671+
pullRequests: threadPullRequests(shell.pullRequests),
652672
...threadSettlement(shell),
653673
...threadSnooze(shell, nowMs),
654674
parentThreadId: shell.lineage.parentThreadId,
@@ -681,6 +701,7 @@ function threadDetail(
681701
runtimeMode: projection.thread.runtimeMode,
682702
interactionMode: projection.thread.interactionMode,
683703
linkedPullRequest: projection.thread.linkedPullRequest ?? null,
704+
pullRequests: threadPullRequests(projection.thread.pullRequests),
684705
titleRegeneration:
685706
projection.thread.titleRegeneration === undefined ||
686707
projection.thread.titleRegeneration === null

‎apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,58 @@ describe("orchestrator MCP toolkit", () => {
22872287
);
22882288
expect(unlinked.linkedPullRequest).toBeNull();
22892289

2290+
// Links added through thread.pull-request.link leave linkedPullRequest unchanged.
2291+
yield* orchestrator.dispatch({
2292+
type: "thread.pull-request.link",
2293+
commandId: CommandId.make("command:mcp-empty:link-other-repository"),
2294+
threadId: emptyThread.threadId,
2295+
host: "github.com",
2296+
repository: "octo/other-repo",
2297+
number: 42,
2298+
url: "https://github.com/octo/other-repo/pull/42",
2299+
source: "agent",
2300+
});
2301+
yield* orchestrator.dispatch({
2302+
type: "thread.pull-request.link",
2303+
commandId: CommandId.make("command:mcp-empty:link-dismissed"),
2304+
threadId: emptyThread.threadId,
2305+
host: "github.com",
2306+
repository: "octo/other-repo",
2307+
number: 43,
2308+
url: "https://github.com/octo/other-repo/pull/43",
2309+
source: "stack-dismissed",
2310+
});
2311+
const otherRepositoryLink = {
2312+
host: "github.com",
2313+
repository: "octo/other-repo",
2314+
number: 42,
2315+
url: "https://github.com/octo/other-repo/pull/42",
2316+
source: "agent",
2317+
state: null,
2318+
};
2319+
const otherRepositoryReadCall = yield* invoke("t3_thread_read", {
2320+
threadId: emptyThread.threadId,
2321+
});
2322+
const otherRepositoryRead = yield* decodeThreadReadResult(
2323+
otherRepositoryReadCall.structuredContent,
2324+
).pipe(Effect.orDie);
2325+
expect(otherRepositoryRead.thread).toMatchObject({
2326+
linkedPullRequest: null,
2327+
pullRequests: [otherRepositoryLink],
2328+
});
2329+
const otherRepositoryListCall = yield* invoke("t3_thread_list", { limit: 100 });
2330+
const otherRepositoryList = yield* decodeThreadListResult(
2331+
otherRepositoryListCall.structuredContent,
2332+
).pipe(Effect.orDie);
2333+
expect(
2334+
otherRepositoryList.threads.find(
2335+
(thread) => thread.threadId === emptyThread.threadId,
2336+
),
2337+
).toMatchObject({ linkedPullRequest: null, pullRequests: [otherRepositoryLink] });
2338+
expect(
2339+
otherRepositoryList.threads.find((thread) => thread.threadId === parentThreadId),
2340+
).toMatchObject({ pullRequests: [] });
2341+
22902342
const regenerateCall = yield* invoke("t3_thread_update", {
22912343
threadId: emptyThread.threadId,
22922344
action: "regenerate_title",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export const CreateThreadsTool = Tool.make("create_threads", {
178178

179179
const ThreadListTool = Tool.make("t3_thread_list", {
180180
description:
181-
"List T3 threads in a project, newest first. Omit projectId for the calling thread's project. Filter by durable run status, title, or settled state (settled=true lists threads the user or auto-settlement moved out of the active list), or snoozed state, and paginate with the returned cursor. A snoozed thread wakes early when it asks for something, fails, or completes. To link a thread for the user, write `[title](t3-thread://v1/<threadId>)` with the threadId exactly as returned, not URL-encoded; T3 Code shows the thread's current title.",
181+
"List T3 threads in a project, newest first. Omit projectId for the calling thread's project. Filter by durable run status, title, or settled state (settled=true lists threads the user or auto-settlement moved out of the active list), or snoozed state, and paginate with the returned cursor. A snoozed thread wakes early when it asks for something, fails, or completes. pullRequests lists every pull request linked to each thread; linkedPullRequest is a legacy single link and can be null while pullRequests still has entries. To link a thread for the user, write `[title](t3-thread://v1/<threadId>)` with the threadId exactly as returned, not URL-encoded; T3 Code shows the thread's current title.",
182182
parameters: OrchestratorMcpThreadListInput,
183183
success: OrchestratorMcpThreadListResult,
184184
failure: OrchestratorMcpFailure,
@@ -192,7 +192,7 @@ const ThreadListTool = Tool.make("t3_thread_list", {
192192

193193
const ThreadReadTool = Tool.make("t3_thread_read", {
194194
description:
195-
"Read durable state and a paginated timeline from any T3 thread in this environment. The default messages view returns user messages, assistant messages, and proposed plans; activity returns all summarized timeline items. Reading an untruncated terminal assistant result from this parent thread's direct app-owned child acknowledges that child's automatic completion delivery. Continue with afterPosition=nextPosition. Recover long item text with itemId and textOffset=nextTextOffset until nextTextOffset is null; offsets count UTF-16 code units. The thread also reports its snooze state. To link a thread for the user, write `[title](t3-thread://v1/<threadId>)` with the threadId exactly as returned, not URL-encoded; T3 Code shows the thread's current title.",
195+
"Read durable state and a paginated timeline from any T3 thread in this environment. The default messages view returns user messages, assistant messages, and proposed plans; activity returns all summarized timeline items. Reading an untruncated terminal assistant result from this parent thread's direct app-owned child acknowledges that child's automatic completion delivery. Continue with afterPosition=nextPosition. Recover long item text with itemId and textOffset=nextTextOffset until nextTextOffset is null; offsets count UTF-16 code units. The thread also reports its snooze state and, in pullRequests, every linked pull request; linkedPullRequest is a legacy single link and can be null while pullRequests still has entries. To link a thread for the user, write `[title](t3-thread://v1/<threadId>)` with the threadId exactly as returned, not URL-encoded; T3 Code shows the thread's current title.",
196196
parameters: OrchestratorMcpThreadReadInput,
197197
success: OrchestratorMcpThreadReadResult,
198198
failure: OrchestratorMcpFailure,

‎packages/contracts/src/orchestratorMcp.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import {
2323
ScheduledTaskUpsertSchedule,
2424
} from "./scheduledTask.ts";
2525
import { ProviderInteractionMode, RuntimeMode } from "./providerPolicy.ts";
26-
import { ThreadLinkedPullRequest } from "./threadPullRequest.ts";
26+
import { PullRequestState } from "./pullRequest.ts";
27+
import {
28+
ThreadLinkedPullRequest,
29+
ThreadPullRequestKey,
30+
ThreadPullRequestLinkSource,
31+
} from "./threadPullRequest.ts";
2732
import { ThreadTitleRegeneration } from "./threadTitle.ts";
2833
import {
2934
OrchestrationV2Actor,
@@ -302,6 +307,15 @@ export const OrchestratorMcpThreadListInput = Schema.Struct({
302307
});
303308
export type OrchestratorMcpThreadListInput = typeof OrchestratorMcpThreadListInput.Type;
304309

310+
/** A pull request linked to a thread; `state` is null until the host has been read. */
311+
export const OrchestratorMcpThreadPullRequest = Schema.Struct({
312+
...ThreadPullRequestKey.fields,
313+
url: TrimmedNonEmptyString,
314+
source: ThreadPullRequestLinkSource,
315+
state: Schema.NullOr(PullRequestState),
316+
});
317+
export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullRequest.Type;
318+
305319
export const OrchestratorMcpThreadListItem = Schema.Struct({
306320
threadId: ThreadId,
307321
title: Schema.String,
@@ -314,6 +328,8 @@ export const OrchestratorMcpThreadListItem = Schema.Struct({
314328
runtimeMode: RuntimeMode,
315329
interactionMode: ProviderInteractionMode,
316330
linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
331+
/** Missing on older servers. */
332+
pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
317333
settled: Schema.Boolean,
318334
settledAt: Schema.NullOr(IsoDateTime),
319335
snoozed: Schema.Boolean,
@@ -363,6 +379,8 @@ export const OrchestratorMcpThreadDetail = Schema.Struct({
363379
runtimeMode: RuntimeMode,
364380
interactionMode: ProviderInteractionMode,
365381
linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
382+
/** Missing on older servers. */
383+
pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
366384
titleRegeneration: Schema.NullOr(ThreadTitleRegeneration),
367385
branch: Schema.NullOr(Schema.String),
368386
worktreePath: Schema.NullOr(Schema.String),

0 commit comments

Comments
 (0)