Skip to content

Commit 7bdcb1e

Browse files
authored
fix(server): pull request tools point a bare thread uuid at its mcp: thread (pingdotgg#30375)
1 parent 56d893e commit 7bdcb1e

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const makeHarness = Effect.fn("makePullRequestsToolkitHarness")(function* (
191191
}),
192192
Layer.mock(Orchestrator.OrchestratorV2)({
193193
getThreadShell: (id) =>
194-
Effect.succeed(id === THREAD_ID && thread ? v2PullRequestThread(thread) : null),
194+
Effect.succeed(id === thread?.id ? v2PullRequestThread(thread) : null),
195195
dispatch,
196196
}),
197197
Layer.succeed(SecureRandom.SecureRandom, testCrypto),
@@ -237,6 +237,21 @@ describe("pull request toolkit handlers", () => {
237237
}),
238238
);
239239

240+
it.effect("points a bare thread uuid at the mcp: thread it belongs to", () =>
241+
Effect.gen(function* () {
242+
const bareId = ThreadId.make("5d0b4a3e-8c1f-4a52-9d37-2f6c7e1b9a04");
243+
const harness = yield* makeHarness({
244+
thread: { ...makeThread([]), id: ThreadId.make(`mcp:${bareId}`) },
245+
});
246+
const error = yield* harness
247+
.call("link_pull_request", { threadId: bareId, number: 123 })
248+
.pipe(Effect.flip);
249+
expect(error.message).toBe(`Thread ${bareId} was not found. Did you mean \`mcp:${bareId}\`?`);
250+
expect(error).toMatchObject({ _tag: "OrchestratorMcpFailure", code: "thread_not_found" });
251+
expect(yield* Ref.get(harness.commands)).toEqual([]);
252+
}),
253+
);
254+
240255
it.effect("links by URL with source agent on the token's thread", () =>
241256
Effect.gen(function* () {
242257
const harness = yield* makeHarness();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from "../../../sourceControl/threadPullRequests.ts";
2828
import * as McpInvocationContext from "../../McpInvocationContext.ts";
2929
import * as McpToolAccess from "../../McpToolAccess.ts";
30+
import { threadNotFound } from "../../threadAccess.ts";
3031
import {
3132
type ListThreadPullRequestsResult,
3233
PullRequestLinkFailedError,
@@ -40,7 +41,6 @@ import {
4041
type PullRequestTargetInput,
4142
PullRequestWatchFailedError,
4243
PullRequestWatchFromSubagentError,
43-
PullRequestThreadNotFoundError,
4444
PullRequestThreadRequiredError,
4545
PullRequestGuideFailedError,
4646
PullRequestProjectNotFoundError,
@@ -226,7 +226,7 @@ const make = Effect.gen(function* () {
226226
Effect.mapError((cause) => new Failure({ cause })),
227227
);
228228
if (Option.isNone(thread) || thread.value.deletedAt !== null) {
229-
return yield* new PullRequestThreadNotFoundError({ threadId });
229+
return yield* threadNotFound(engine, threadId, `Thread ${threadId} was not found.`);
230230
}
231231
return thread.value;
232232
});

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,6 @@ export class PullRequestThreadRequiredError extends Schema.TaggedError<PullReque
104104
}
105105
}
106106

107-
export class PullRequestThreadNotFoundError extends Schema.TaggedError<PullRequestThreadNotFoundError>()(
108-
"PullRequestThreadNotFoundError",
109-
{ threadId: Schema.String },
110-
) {
111-
override get message(): string {
112-
return `Thread ${this.threadId} was not found.`;
113-
}
114-
}
115-
116107
export class PullRequestLinkFailedError extends Schema.TaggedError<PullRequestLinkFailedError>()(
117108
"PullRequestLinkFailedError",
118109
{ cause: Schema.Defect() },
@@ -193,7 +184,6 @@ export const PullRequestToolError = Schema.Union([
193184
PullRequestHostRequiredError,
194185
PullRequestUrlUnavailableError,
195186
PullRequestThreadRequiredError,
196-
PullRequestThreadNotFoundError,
197187
PullRequestLinkFailedError,
198188
PullRequestUnlinkFailedError,
199189
PullRequestListFailedError,

0 commit comments

Comments
 (0)