Skip to content

Commit 895e24a

Browse files
authored
fix(cli): various mcp server fixes (#2430)
* fix: span events are optional, as logs don't have them * remove CI: true env var to prevent massive tool responses * fix github resolver relative path * prevent the dev command from asking for user input when not interactive * Remove lodash.get because it's deprecated * span output can be object other than an object, like a string * prevent large traces from causing get_run_details failures * Decreased max log lines, made it a tool input property * Some install mcp tweaks
1 parent 58ff034 commit 895e24a

File tree

13 files changed

+89
-67
lines changed

13 files changed

+89
-67
lines changed

apps/webapp/app/env.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ const EnvironmentSchema = z.object({
436436
EVENT_LOOP_MONITOR_ENABLED: z.string().default("1"),
437437
MAXIMUM_LIVE_RELOADING_EVENTS: z.coerce.number().int().default(1000),
438438
MAXIMUM_TRACE_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(25_000),
439+
MAXIMUM_TRACE_DETAILED_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(10_000),
439440
TASK_PAYLOAD_OFFLOAD_THRESHOLD: z.coerce.number().int().default(524_288), // 512KB
440441
TASK_PAYLOAD_MAXIMUM_SIZE: z.coerce.number().int().default(3_145_728), // 3MB
441442
BATCH_TASK_PAYLOAD_MAXIMUM_SIZE: z.coerce.number().int().default(1_000_000), // 1MB

apps/webapp/app/v3/taskEventStore.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class TaskEventStore {
285285
: Prisma.empty
286286
}
287287
ORDER BY "startTime" ASC
288-
LIMIT ${env.MAXIMUM_TRACE_SUMMARY_VIEW_COUNT}
288+
LIMIT ${env.MAXIMUM_TRACE_DETAILED_SUMMARY_VIEW_COUNT}
289289
`;
290290
} else {
291291
return await this.readReplica.$queryRaw<DetailedTraceEvent[]>`
@@ -320,7 +320,7 @@ export class TaskEventStore {
320320
: Prisma.empty
321321
}
322322
ORDER BY "startTime" ASC
323-
LIMIT ${env.MAXIMUM_TRACE_SUMMARY_VIEW_COUNT}
323+
LIMIT ${env.MAXIMUM_TRACE_DETAILED_SUMMARY_VIEW_COUNT}
324324
`;
325325
}
326326
}

packages/cli-v3/src/commands/dev.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,47 +107,50 @@ export function configureDevCommand(program: Command) {
107107
export async function devCommand(options: DevCommandOptions) {
108108
runtimeChecks();
109109

110-
const skipMCPInstall = typeof options.skipMCPInstall === "boolean" && options.skipMCPInstall;
110+
// Only show these install prompts if the user is in a terminal (not in a Coding Agent)
111+
if (process.stdout.isTTY) {
112+
const skipMCPInstall = typeof options.skipMCPInstall === "boolean" && options.skipMCPInstall;
111113

112-
if (!skipMCPInstall) {
113-
const hasSeenMCPInstallPrompt = readConfigHasSeenMCPInstallPrompt();
114+
if (!skipMCPInstall) {
115+
const hasSeenMCPInstallPrompt = readConfigHasSeenMCPInstallPrompt();
114116

115-
if (!hasSeenMCPInstallPrompt) {
116-
const installChoice = await confirm({
117-
message: "Would you like to install the Trigger.dev MCP server?",
118-
initialValue: true,
119-
});
117+
if (!hasSeenMCPInstallPrompt) {
118+
const installChoice = await confirm({
119+
message: "Would you like to install the Trigger.dev MCP server?",
120+
initialValue: true,
121+
});
120122

121-
writeConfigHasSeenMCPInstallPrompt(true);
123+
writeConfigHasSeenMCPInstallPrompt(true);
122124

123-
const skipInstall = isCancel(installChoice) || !installChoice;
125+
const skipInstall = isCancel(installChoice) || !installChoice;
124126

125-
if (!skipInstall) {
126-
log.step("Welcome to the Trigger.dev MCP server install wizard 🧙");
127+
if (!skipInstall) {
128+
log.step("Welcome to the Trigger.dev MCP server install wizard 🧙");
127129

128-
const [installError] = await tryCatch(
129-
installMcpServer({
130-
yolo: false,
131-
tag: VERSION as string,
132-
logLevel: options.logLevel,
133-
})
134-
);
130+
const [installError] = await tryCatch(
131+
installMcpServer({
132+
yolo: false,
133+
tag: VERSION as string,
134+
logLevel: options.logLevel,
135+
})
136+
);
135137

136-
if (installError) {
137-
log.error(`Failed to install MCP server: ${installError.message}`);
138+
if (installError) {
139+
log.error(`Failed to install MCP server: ${installError.message}`);
140+
}
138141
}
139142
}
140143
}
141-
}
142144

143-
const skipRulesInstall =
144-
typeof options.skipRulesInstall === "boolean" && options.skipRulesInstall;
145+
const skipRulesInstall =
146+
typeof options.skipRulesInstall === "boolean" && options.skipRulesInstall;
145147

146-
if (!skipRulesInstall) {
147-
await initiateRulesInstallWizard({
148-
manifestPath: options.rulesInstallManifestPath,
149-
branch: options.rulesInstallBranch,
150-
});
148+
if (!skipRulesInstall) {
149+
await initiateRulesInstallWizard({
150+
manifestPath: options.rulesInstallManifestPath,
151+
branch: options.rulesInstallBranch,
152+
});
153+
}
151154
}
152155

153156
const authorization = await login({

packages/cli-v3/src/commands/install-mcp.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ export async function installMcpServer(
233233
);
234234

235235
log.info("More examples:");
236-
log.message(` • ${chalk.green('"List my Trigger.dev projects"')}`);
237-
log.message(` • ${chalk.green('"Create a new Trigger.dev project called MyApp"')}`);
238-
log.message(` • ${chalk.green('"Show me all tasks in my project"')}`);
239-
log.message(` • ${chalk.green('"Trigger the email-notification task"')}`);
236+
log.message(` • ${chalk.green('"Trigger the hello-world task"')}`);
237+
log.message(` • ${chalk.green('"Can you help me debug the prod run run_1234"')}`);
238+
log.message(` • ${chalk.green('"Deploy my trigger project to staging"')}`);
239+
log.message(` • ${chalk.green('"What trigger task handles uploading files to S3?"')}`);
240240
log.message(` • ${chalk.green('"How do I create a scheduled task in Trigger.dev?"')}`);
241-
log.message(` • ${chalk.green('"Search Trigger.dev docs for webhook examples"')}`);
241+
log.message(` • ${chalk.green('"Search Trigger.dev docs for ffmpeg examples"')}`);
242242

243243
log.info("Helpful links:");
244244
log.message(` • ${cliLink("Trigger.dev docs", "https://trigger.dev/docs")}`);
@@ -318,17 +318,13 @@ async function installMcpServerForClient(
318318
return;
319319
}
320320

321-
const clientSpinner = spinner();
322-
323-
clientSpinner.start(`Installing in ${clientName}`);
324-
325321
const scope = await resolveScopeForClient(clientName, options);
326322

327-
clientSpinner.message(`Installing in ${scope.scope} scope at ${scope.location}`);
323+
// clientSpinner.message(`Installing in ${scope.scope} scope at ${scope.location}`);
328324

329325
const configPath = await performInstallForClient(clientName, scope, options);
330326

331-
clientSpinner.stop(`Successfully installed in ${clientName} (${configPath})`);
327+
// clientSpinner.stop(`Successfully installed in ${clientName} (${configPath})`);
332328

333329
return { configPath, clientName, scope };
334330
}

packages/cli-v3/src/mcp/formatters.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
} from "@trigger.dev/core/v3/schemas";
66
import type { CursorPageResponse } from "@trigger.dev/core/v3/zodfetch";
77

8+
const DEFAULT_MAX_TRACE_LINES = 500;
9+
810
export function formatRun(run: RetrieveRunResponse): string {
911
const lines: string[] = [];
1012

@@ -170,23 +172,35 @@ function formatRelatedRuns(relatedRuns: RetrieveRunResponse["relatedRuns"]): str
170172
return parts.length > 0 ? `Related: ${parts.join("; ")}` : null;
171173
}
172174

173-
export function formatRunTrace(trace: RetrieveRunTraceResponseBody["trace"]): string {
175+
export function formatRunTrace(
176+
trace: RetrieveRunTraceResponseBody["trace"],
177+
maxTraceLines: number = DEFAULT_MAX_TRACE_LINES
178+
): string {
174179
const lines: string[] = [];
175180

176181
lines.push(`Trace ID: ${trace.traceId}`);
177182
lines.push("");
178183

179184
// Format the root span and its children recursively
180-
formatSpan(trace.rootSpan, lines, 0);
185+
const reachedMaxLines = formatSpan(trace.rootSpan, lines, 0, maxTraceLines);
186+
187+
if (reachedMaxLines) {
188+
lines.push(`(truncated logs to ${maxTraceLines} lines)`);
189+
}
181190

182191
return lines.join("\n");
183192
}
184193

185194
function formatSpan(
186195
span: RetrieveRunTraceResponseBody["trace"]["rootSpan"],
187196
lines: string[],
188-
depth: number
189-
): void {
197+
depth: number,
198+
maxLines: number
199+
): boolean {
200+
if (lines.length >= maxLines) {
201+
return true;
202+
}
203+
190204
const indent = " ".repeat(depth);
191205
const prefix = depth === 0 ? "└─" : "├─";
192206

@@ -230,7 +244,7 @@ function formatSpan(
230244
}
231245

232246
// Show output if it exists
233-
if (span.data.output && Object.keys(span.data.output).length > 0) {
247+
if (span.data.output) {
234248
lines.push(
235249
`${indent} Output: ${JSON.stringify(span.data.output, null, 2).replace(
236250
/\n/g,
@@ -263,14 +277,20 @@ function formatSpan(
263277

264278
// Recursively format children
265279
if (span.children) {
266-
span.children.forEach((child, index) => {
267-
formatSpan(child, lines, depth + 1);
280+
const reachedMaxLines = span.children.some((child, index) => {
281+
const reachedMaxLines = formatSpan(child, lines, depth + 1, maxLines);
268282
// Add spacing between sibling spans (except for the last one)
269-
if (index < span.children.length - 1) {
283+
if (index < span.children.length - 1 && !reachedMaxLines) {
270284
lines.push("");
271285
}
286+
287+
return reachedMaxLines;
272288
});
289+
290+
return reachedMaxLines;
273291
}
292+
293+
return false;
274294
}
275295

276296
function getStatusIndicator(

packages/cli-v3/src/mcp/schemas.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ export const CommonRunsInput = CommonProjectsInput.extend({
123123

124124
export type CommonRunsInput = z.output<typeof CommonRunsInput>;
125125

126-
export const GetRunDetailsInput = CommonRunsInput.extend({});
126+
export const GetRunDetailsInput = CommonRunsInput.extend({
127+
maxTraceLines: z
128+
.number()
129+
.int()
130+
.describe("The maximum number of lines to show in the trace. Defaults to 500")
131+
.optional(),
132+
});
127133

128134
export type GetRunDetailsInput = z.output<typeof GetRunDetailsInput>;
129135

packages/cli-v3/src/mcp/tools/deploys.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export const deployTool = {
7474
cwd: cwd.cwd,
7575
env: {
7676
TRIGGER_MCP_SERVER: "1",
77-
CI: "true",
7877
},
7978
},
8079
});

packages/cli-v3/src/mcp/tools/runs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const getRunDetailsTool = {
3535
]);
3636

3737
const formattedRun = formatRun(runResult);
38-
const formattedTrace = formatRunTrace(traceResult.trace);
38+
const formattedTrace = formatRunTrace(traceResult.trace, input.maxTraceLines);
3939

4040
const runUrl = await ctx.getDashboardUrl(`/projects/v3/${projectRef}/runs/${runResult.id}`);
4141

packages/cli-v3/src/rules/manifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class GithubRulesManifestLoader implements RulesManifestLoader {
126126

127127
async loadRulesFile(relativePath: string): Promise<string> {
128128
const response = await fetch(
129-
`https://raw.githubusercontent.com/triggerdotdev/trigger.dev/refs/heads/${this.branch}/${relativePath}`
129+
`https://raw.githubusercontent.com/triggerdotdev/trigger.dev/refs/heads/${this.branch}/rules/${relativePath}`
130130
);
131131

132132
if (!response.ok) {

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@
187187
"execa": "^8.0.1",
188188
"humanize-duration": "^3.27.3",
189189
"jose": "^5.4.0",
190-
"lodash.get": "^4.4.2",
191190
"nanoid": "3.3.8",
192191
"prom-client": "^15.1.0",
193192
"socket.io": "4.7.4",

0 commit comments

Comments
 (0)