Skip to content

Commit d6841e9

Browse files
ScottN-PVclaude
andauthored
fix(server): MCP thread list and read report every linked pull request (pingdotgg#17454)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent ff7b24a commit d6841e9

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
@@ -36,6 +36,7 @@ import {
3636
type OrchestratorMcpListScheduledTasksInput,
3737
type ProjectId,
3838
type OrchestratorMcpThreadDetail,
39+
type OrchestratorMcpThreadPullRequest,
3940
type OrchestratorMcpThreadInterruptInput,
4041
type OrchestratorMcpThreadInterruptResult,
4142
type OrchestratorMcpThreadListInput,
@@ -60,6 +61,10 @@ import {
6061
ThreadId,
6162
} from "@t3tools/contracts";
6263
import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
64+
import {
65+
normalizeThreadPullRequestKey,
66+
visibleThreadPullRequests,
67+
} from "@t3tools/shared/threadPullRequests";
6368
import * as Clock from "effect/Clock";
6469
import * as Context from "effect/Context";
6570
import * as Crypto from "effect/Crypto";
@@ -709,6 +714,20 @@ function threadSnooze(
709714
};
710715
}
711716

717+
/** The same links `list_thread_pull_requests` reports, without the snapshot details. */
718+
function threadPullRequests(
719+
links: OrchestrationV2ThreadShell["pullRequests"],
720+
): OrchestratorMcpThreadPullRequest[] {
721+
return visibleThreadPullRequests(links ?? []).map((link) => ({
722+
host: normalizeThreadPullRequestKey(link).host,
723+
repository: link.repository,
724+
number: link.number,
725+
url: link.url,
726+
source: link.source,
727+
state: link.snapshot?.state ?? null,
728+
}));
729+
}
730+
712731
function listItemFromShell(
713732
shell: OrchestrationV2ThreadShell,
714733
nowMs: number,
@@ -725,6 +744,7 @@ function listItemFromShell(
725744
runtimeMode: shell.runtimeMode,
726745
interactionMode: shell.interactionMode,
727746
linkedPullRequest: shell.linkedPullRequest ?? null,
747+
pullRequests: threadPullRequests(shell.pullRequests),
728748
...threadSettlement(shell),
729749
...threadSnooze(shell, nowMs),
730750
parentThreadId: shell.lineage.parentThreadId,
@@ -757,6 +777,7 @@ function threadDetail(
757777
runtimeMode: projection.thread.runtimeMode,
758778
interactionMode: projection.thread.interactionMode,
759779
linkedPullRequest: projection.thread.linkedPullRequest ?? null,
780+
pullRequests: threadPullRequests(projection.thread.pullRequests),
760781
titleRegeneration:
761782
projection.thread.titleRegeneration === undefined ||
762783
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
@@ -2388,6 +2388,58 @@ describe("orchestrator MCP toolkit", () => {
23882388
);
23892389
expect(unlinked.linkedPullRequest).toBeNull();
23902390

2391+
// Links added through thread.pull-request.link leave linkedPullRequest unchanged.
2392+
yield* orchestrator.dispatch({
2393+
type: "thread.pull-request.link",
2394+
commandId: CommandId.make("command:mcp-empty:link-other-repository"),
2395+
threadId: emptyThread.threadId,
2396+
host: "github.com",
2397+
repository: "octo/other-repo",
2398+
number: 42,
2399+
url: "https://github.com/octo/other-repo/pull/42",
2400+
source: "agent",
2401+
});
2402+
yield* orchestrator.dispatch({
2403+
type: "thread.pull-request.link",
2404+
commandId: CommandId.make("command:mcp-empty:link-dismissed"),
2405+
threadId: emptyThread.threadId,
2406+
host: "github.com",
2407+
repository: "octo/other-repo",
2408+
number: 43,
2409+
url: "https://github.com/octo/other-repo/pull/43",
2410+
source: "stack-dismissed",
2411+
});
2412+
const otherRepositoryLink = {
2413+
host: "github.com",
2414+
repository: "octo/other-repo",
2415+
number: 42,
2416+
url: "https://github.com/octo/other-repo/pull/42",
2417+
source: "agent",
2418+
state: null,
2419+
};
2420+
const otherRepositoryReadCall = yield* invoke("t3_thread_read", {
2421+
threadId: emptyThread.threadId,
2422+
});
2423+
const otherRepositoryRead = yield* decodeThreadReadResult(
2424+
otherRepositoryReadCall.structuredContent,
2425+
).pipe(Effect.orDie);
2426+
expect(otherRepositoryRead.thread).toMatchObject({
2427+
linkedPullRequest: null,
2428+
pullRequests: [otherRepositoryLink],
2429+
});
2430+
const otherRepositoryListCall = yield* invoke("t3_thread_list", { limit: 100 });
2431+
const otherRepositoryList = yield* decodeThreadListResult(
2432+
otherRepositoryListCall.structuredContent,
2433+
).pipe(Effect.orDie);
2434+
expect(
2435+
otherRepositoryList.threads.find(
2436+
(thread) => thread.threadId === emptyThread.threadId,
2437+
),
2438+
).toMatchObject({ linkedPullRequest: null, pullRequests: [otherRepositoryLink] });
2439+
expect(
2440+
otherRepositoryList.threads.find((thread) => thread.threadId === parentThreadId),
2441+
).toMatchObject({ pullRequests: [] });
2442+
23912443
const regenerateCall = yield* invoke("t3_thread_update", {
23922444
threadId: emptyThread.threadId,
23932445
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
@@ -192,7 +192,7 @@ export const CreateThreadsTool = Tool.make("create_threads", {
192192

193193
const ThreadListTool = Tool.make("t3_thread_list", {
194194
description:
195-
"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.",
195+
"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.",
196196
parameters: OrchestratorMcpThreadListInput,
197197
success: OrchestratorMcpThreadListResult,
198198
failure: OrchestratorMcpFailure,
@@ -206,7 +206,7 @@ const ThreadListTool = Tool.make("t3_thread_list", {
206206

207207
const ThreadReadTool = Tool.make("t3_thread_read", {
208208
description:
209-
"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.",
209+
"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.",
210210
parameters: OrchestratorMcpThreadReadInput,
211211
success: OrchestratorMcpThreadReadResult,
212212
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,
@@ -304,6 +309,15 @@ export const OrchestratorMcpThreadListInput = Schema.Struct({
304309
});
305310
export type OrchestratorMcpThreadListInput = typeof OrchestratorMcpThreadListInput.Type;
306311

312+
/** A pull request linked to a thread; `state` is null until the host has been read. */
313+
export const OrchestratorMcpThreadPullRequest = Schema.Struct({
314+
...ThreadPullRequestKey.fields,
315+
url: TrimmedNonEmptyString,
316+
source: ThreadPullRequestLinkSource,
317+
state: Schema.NullOr(PullRequestState),
318+
});
319+
export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullRequest.Type;
320+
307321
export const OrchestratorMcpThreadListItem = Schema.Struct({
308322
threadId: ThreadId,
309323
title: Schema.String,
@@ -316,6 +330,8 @@ export const OrchestratorMcpThreadListItem = Schema.Struct({
316330
runtimeMode: RuntimeMode,
317331
interactionMode: ProviderInteractionMode,
318332
linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
333+
/** Missing on older servers. */
334+
pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
319335
settled: Schema.Boolean,
320336
settledAt: Schema.NullOr(IsoDateTime),
321337
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)