Open History to see the last commit
1export type T3McpToolLogo = "t3-code";
2
3export interface T3McpToolPresentation {
4 readonly displayName: string;
5 readonly logo: T3McpToolLogo;
6}
7
8export type T3McpToolSummaryAction =
9 | "capabilities"
10 | "delegate"
11 | "task-status"
12 | "task-cancel"
13 | "schedule-create"
14 | "schedule-list"
15 | "schedule-update"
16 | "schedule-delete"
17 | "thread-create"
18 | "thread-list"
19 | "thread-read"
20 | "thread-send"
21 | "thread-wait"
22 | "thread-interrupt";
23
24const T3_MCP_SERVER_ALIASES = new Set(["t3-code", "t3_code", "t3code"]);
25
26const T3_MCP_TOOLS: Record<
27 string,
28 { readonly displayName: string; readonly summaryAction?: T3McpToolSummaryAction }
29> = {
30 orchestrator_capabilities: {
31 displayName: "Get orchestration capabilities",
32 summaryAction: "capabilities",
33 },
34 delegate_task: { displayName: "Delegate a child task", summaryAction: "delegate" },
35 task_status: { displayName: "Get delegated task status", summaryAction: "task-status" },
36 task_cancel: { displayName: "Cancel delegated task", summaryAction: "task-cancel" },
37 run_scheduled_task_now: { displayName: "Run scheduled task now" },
38 schedule_task: { displayName: "Schedule a recurring task", summaryAction: "schedule-create" },
39 list_scheduled_tasks: { displayName: "List scheduled tasks", summaryAction: "schedule-list" },
40 update_scheduled_task: {
41 displayName: "Update a scheduled task",
42 summaryAction: "schedule-update",
43 },
44 delete_scheduled_task: {
45 displayName: "Delete a scheduled task",
46 summaryAction: "schedule-delete",
47 },
48 create_threads: { displayName: "Create T3 threads", summaryAction: "thread-create" },
49 t3_thread_start: { displayName: "Start a T3 thread", summaryAction: "thread-create" },
50 t3_thread_list: { displayName: "List T3 threads", summaryAction: "thread-list" },
51 t3_thread_read: { displayName: "Read a T3 thread", summaryAction: "thread-read" },
52 t3_queue_list: { displayName: "List queued messages" },
53 t3_queue_read: { displayName: "Read a queued message" },
54 t3_queue_edit: { displayName: "Edit a queued message" },
55 t3_queue_cancel: { displayName: "Cancel a queued run" },
56 t3_queue_reorder: { displayName: "Reorder a queued run" },
57 t3_queue_promote_to_steer: { displayName: "Steer with a queued message" },
58 t3_pending_request_list: { displayName: "List pending questions" },
59 t3_pending_request_read: { displayName: "Read pending questions" },
60 t3_pending_request_respond: { displayName: "Answer pending questions" },
61 t3_thread_configuration: { displayName: "Read thread configuration" },
62 t3_thread_configure: { displayName: "Set thread model" },
63 t3_thread_fork: { displayName: "Fork this thread" },
64 t3_thread_merge_back: { displayName: "Merge thread context" },
65 t3_thread_search: { displayName: "Search thread content" },
66 t3_thread_transfers: { displayName: "Read thread transfers" },
67 t3_thread_organize: { displayName: "Organize a thread" },
68 t3_thread_update: { displayName: "Update T3 thread metadata" },
69 t3_thread_send: { displayName: "Send to a T3 thread", summaryAction: "thread-send" },
70 t3_thread_wait: { displayName: "Wait for a T3 thread", summaryAction: "thread-wait" },
71 t3_thread_interrupt: { displayName: "Interrupt a T3 thread", summaryAction: "thread-interrupt" },
72 t3_worktree_handoff: { displayName: "Hand off thread to a git worktree" },
73 t3_worktree_list: { displayName: "List workspace branches" },
74 t3_worktree_status: { displayName: "Get thread worktree status" },
75 t3_preview_list: { displayName: "List preview tabs" },
76 t3_preview_close: { displayName: "Close a preview tab" },
77 t3_environment_read: { displayName: "Read environment preferences" },
78 t3_environment_preferences_update: { displayName: "Update environment preferences" },
79 t3_thread_launch: { displayName: "Launch a project thread" },
80 t3_project_list: { displayName: "List projects" },
81 t3_project_read: { displayName: "Read a project" },
82 t3_project_create: { displayName: "Create a project" },
83 t3_project_update: { displayName: "Update a project" },
84 t3_project_delete: { displayName: "Delete a project" },
85 t3_project_clone: { displayName: "Clone a repository" },
86 t3_attachment_prepare_upload: { displayName: "Prepare attachment upload" },
87 t3_attachment_discard: { displayName: "Discard pending attachment" },
88 t3_thread_send_attachments: { displayName: "Send attachments" },
89 preview_status: { displayName: "Get preview browser status" },
90 preview_open: { displayName: "Open a page in the preview browser" },
91 preview_navigate: { displayName: "Navigate the preview browser" },
92 preview_snapshot: { displayName: "Snapshot the preview page" },
93 preview_click: { displayName: "Click in the preview browser" },
94 preview_press: { displayName: "Press a key in the preview browser" },
95 preview_type: { displayName: "Type in the preview browser" },
96 preview_scroll: { displayName: "Scroll the preview browser" },
97 preview_resize: { displayName: "Resize the preview browser" },
98 preview_evaluate: { displayName: "Evaluate script in the preview browser" },
99 preview_wait_for: { displayName: "Wait for the preview page" },
100 preview_set_appearance: { displayName: "Set preview browser appearance" },
101 preview_recording_start: { displayName: "Start recording the preview browser" },
102 preview_recording_stop: { displayName: "Stop recording the preview browser" },
103};
104
105/**
106 * The T3 orchestration tool inventory, used to gate loose name matching on
107 * both the server (ACP MCP identity recovery) and the client (logo branding).
108 */
109export const T3_MCP_TOOL_NAMES: ReadonlySet<string> = new Set(Object.keys(T3_MCP_TOOLS));
110
111function normalizeT3McpToolLabel(value: string): string {
112 return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim();
113}
114
115/**
116 * ACP agents disagree on how the injected T3 server prefixes its tools:
117 * `mcp__t3-code__x` (Claude/Cursor), `t3-code.x` (Codex), plus single
118 * underscore, colon, slash, dash, and space separators seen from registry
119 * agents. The prefix match is deliberately loose because the display-name
120 * table below is the real gate; unknown tools stay on the generic renderer.
121 */
122function resolveT3McpToolName(value: string): string | null {
123 const label = normalizeT3McpToolLabel(value);
124 const mcpMatch = /^mcp__(?<server>.+?)__(?<tool>.+)$/.exec(label);
125 if (mcpMatch?.groups) {
126 const { server, tool } = mcpMatch.groups;
127 return server !== undefined &&
128 tool !== undefined &&
129 T3_MCP_SERVER_ALIASES.has(server.toLowerCase())
130 ? tool
131 : null;
132 }
133
134 const namespaceMatch = /^(?<server>t3-code|t3_code|t3code)[.:/](?<tool>.+)$/i.exec(label);
135 if (namespaceMatch?.groups) {
136 return namespaceMatch.groups.tool ?? null;
137 }
138
139 const prefixed = /^(?:mcp[-_]{1,2})?t3[-_ ]?code(?:__|[-_.:/ ])(?<tool>.+)$/i.exec(label);
140 const candidate = prefixed?.groups?.tool ?? label;
141 return Object.hasOwn(T3_MCP_TOOLS, candidate) ? candidate : null;
142}
143
144export function resolveT3McpToolPresentation(
145 toolName: string | null | undefined,
146): T3McpToolPresentation | null {
147 const resolvedToolName =
148 toolName === undefined || toolName === null ? null : resolveT3McpToolName(toolName);
149 if (resolvedToolName === null) {
150 return null;
151 }
152 const displayName = T3_MCP_TOOLS[resolvedToolName]?.displayName;
153 if (displayName === undefined) {
154 return null;
155 }
156 return {
157 displayName,
158 logo: "t3-code",
159 };
160}
161
162export function resolveT3McpToolSummaryAction(
163 toolName: string | null | undefined,
164): T3McpToolSummaryAction | null {
165 const name = toolName == null ? null : resolveT3McpToolName(toolName);
166 return name === null ? null : (T3_MCP_TOOLS[name]?.summaryAction ?? null);
167}