Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/server/src/mcp/McpInvocationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,18 @@ export interface McpInvocationScope {
/**
* T3 Code renders `t3-thread://` links as thread chips. Other MCP clients cannot open them, so
* they get the hosted link Copy thread copies, which opens the thread in either app or a browser.
* A known `title` labels the chip for clients that cannot load this environment's threads.
*/
export const threadLinkFor = (
scope: Pick<McpInvocationScope, "environmentId" | "client">,
threadId: ThreadId,
title?: string,
): string => {
const hostedAppUrl = scope.client?.hostedAppUrl;
const ref = { environmentId: scope.environmentId, threadId };
return hostedAppUrl === undefined ? formatThreadLink(ref) : hostedThreadLink(ref, hostedAppUrl);
return hostedAppUrl === undefined
? formatThreadLink(ref, title)
: hostedThreadLink(ref, hostedAppUrl);
};

export class McpInvocationContext extends Context.Service<
Expand Down
24 changes: 15 additions & 9 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ function listItemFromShell(
threadId: shell.id,
projectId: shell.projectId,
title: shell.title,
link: threadLinkFor(scope, shell.id),
link: threadLinkFor(scope, shell.id, shell.title),
createdBy: shell.createdBy,
creationSource: shell.creationSource,
status: shell.activityRunStatus ?? shell.status,
Expand Down Expand Up @@ -839,7 +839,7 @@ function threadDetail(
threadId: projection.thread.id,
projectId: projection.thread.projectId,
title: projection.thread.title,
link: threadLinkFor(scope, projection.thread.id),
link: threadLinkFor(scope, projection.thread.id, projection.thread.title),
createdBy: projection.thread.createdBy,
creationSource: projection.thread.creationSource,
status: active?.status ?? latest?.status ?? "idle",
Expand Down Expand Up @@ -1630,10 +1630,10 @@ const make = Effect.gen(function* () {
const result = {
taskId: task.id,
childThreadId: task.childThreadId,
link: formatThreadLink({
environmentId: scope.environmentId,
threadId: task.childThreadId,
}),
link: formatThreadLink(
{ environmentId: scope.environmentId, threadId: task.childThreadId },
childControls.thread.title,
),
childRunId: childRun?.id ?? null,
childNodeId: task.id,
status,
Expand Down Expand Up @@ -1804,7 +1804,10 @@ const make = Effect.gen(function* () {
childThreadId: null,
...(task.remoteChild === undefined
? {}
: { remoteChild: task.remoteChild, link: formatThreadLink(task.remoteChild) }),
: {
remoteChild: task.remoteChild,
link: formatThreadLink(task.remoteChild, task.remoteChild.title),
}),
childRunId: null,
childNodeId: task.id,
status,
Expand Down Expand Up @@ -2992,7 +2995,10 @@ const make = Effect.gen(function* () {
);
return {
threadId,
link: formatThreadLink({ environmentId: scope.environmentId, threadId }),
link: formatThreadLink(
{ environmentId: scope.environmentId, threadId },
projection.thread.title,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
),
runId: run?.id ?? null,
status: run?.status ?? "idle",
title: projection.thread.title,
Expand Down Expand Up @@ -3209,7 +3215,7 @@ const make = Effect.gen(function* () {
);
return {
threadId: input.threadId,
link: threadLinkFor(scope, input.threadId),
link: threadLinkFor(scope, input.threadId, target.thread.title),
messageId,
runId: result.run.id,
...(result.run.delegatedTaskId === undefined ? {} : { taskId: result.run.delegatedTaskId }),
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/mcp/toolkits/project/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ it.effect(
expect(belowCeiling.result).toMatchObject({
projectId: belowCeiling.projectId,
modelSelection: belowCeiling.modelSelection,
link: `<t3-thread://v2/environment/${belowCeiling.launched[0]?.threadId}>`,
link: `[Fix](t3-thread://v2/environment/${belowCeiling.launched[0]?.threadId})`,
});
expect(belowCeiling.launched[0]?.runtimeMode).toBe("approval-required");
expect(belowCeiling.launched[0]?.initialMessage?.senderThreadId).toBeUndefined();
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/mcp/toolkits/project/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
const run = result.projection.runs.find((run) => run.userMessageId === messageId);
return {
threadId: thread.id,
link: McpInvocationContext.threadLinkFor(scope, thread.id),
link: McpInvocationContext.threadLinkFor(scope, thread.id, thread.title),
projectId: thread.projectId,
modelSelection: thread.modelSelection,
runId: run?.id ?? null,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/mcp/toolkits/thread/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
return {
matches: matches.map((match) => ({
...match,
link: McpInvocationContext.threadLinkFor(scope, match.threadId),
link: McpInvocationContext.threadLinkFor(scope, match.threadId, match.title),
})),
};
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/peer/RemoteDelegation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ it.effect("a task delegated to the box wakes the laptop's parent when it ends th
expect(yield* Ref.get(thread.launched)).toBe(delegated.remoteChild.threadId);
// Its link opens the thread there, so the parent can mention it like any other.
expect(delegated.link).toBe(
`<t3-thread://v2/${box.environmentId}/${delegated.remoteChild.threadId}>`,
`[Laptop parent](t3-thread://v2/${box.environmentId}/${delegated.remoteChild.threadId})`,
);
// ...naming the parent here, so the thread there links back to it.
expect(yield* Ref.get(thread.delegatedFrom)).toEqual({
Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/peer/RemoteDelegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,14 @@ const make = Effect.gen(function* () {
// the forwarder scopes the launch's, and the record's names it.
const key = input.clientRequestId ?? (yield* random.uuidV4());
const task = taskPrompt(input);
const title = input.title ?? parent.thread.title;
const launched = yield* forwarding.call(
scope,
ProjectToolkit.tools.t3_thread_launch,
target.environmentId,
{
projectId,
title: input.title ?? parent.thread.title,
title,
modelSelection: { instanceId, model, ...(options === undefined ? {} : { options }) },
...(runtimeMode === undefined ? {} : { runtimeMode }),
...(interactionMode === undefined ? {} : { interactionMode }),
Expand All @@ -291,6 +292,7 @@ const make = Effect.gen(function* () {
environmentId: target.environmentId,
threadId: launched.threadId,
label: link?.label ?? target.environmentId,
title,
...(launched.runId === null ? {} : { runId: launched.runId }),
};
const recorded = yield* threads
Expand Down
Loading
Loading