Skip to content

Commit 83ddfc7

Browse files
committed
Added getRunDetails tools
1 parent 365a866 commit 83ddfc7

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
registerListProjectsTool,
1515
registerSearchDocsTool,
1616
registerTriggerTaskTool,
17+
registerGetRunDetailsTool,
1718
} from "../mcp/tools.js";
1819
import { logger } from "../utilities/logger.js";
1920

@@ -75,6 +76,7 @@ export async function mcpCommand(options: McpCommandOptions) {
7576
registerInitializeProjectTool(context);
7677
registerGetTasksTool(context);
7778
registerTriggerTaskTool(context);
79+
registerGetRunDetailsTool(context);
7880
registerListProjectsTool(context);
7981
registerListOrgsTool(context);
8082
registerCreateProjectTool(context);

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,85 @@ export function registerTriggerTaskTool(context: McpContext) {
509509
);
510510
}
511511

512+
export function registerGetRunDetailsTool(context: McpContext) {
513+
context.server.registerTool(
514+
"get_run_details",
515+
{
516+
description: "Get the details of a run",
517+
inputSchema: {
518+
projectRef: ProjectRefSchema,
519+
configPath: z
520+
.string()
521+
.describe(
522+
"The path to the trigger.config.ts file. Only used when the trigger.config.ts file is not at the root dir (like in a monorepo setup). If not provided, we will try to find the config file in the current working directory"
523+
)
524+
.optional(),
525+
environment: z
526+
.enum(["dev", "staging", "preview", "production"])
527+
.describe("The environment to trigger the task in")
528+
.default("dev"),
529+
branch: z
530+
.string()
531+
.describe("The branch to trigger the task in, only used for preview environments")
532+
.optional(),
533+
runId: z.string().describe("The ID of the run to get the details of, starts with run_"),
534+
},
535+
},
536+
async ({ projectRef, configPath, environment, branch, runId }) => {
537+
context.logger?.log("calling get_run_details", {
538+
projectRef,
539+
configPath,
540+
environment,
541+
branch,
542+
runId,
543+
});
544+
545+
if (context.options.devOnly && environment !== "dev") {
546+
return respondWithError(
547+
`This MCP server is only available for the dev environment. You tried to access the ${environment} environment. Remove the --dev-only flag to access other environments.`
548+
);
549+
}
550+
551+
const projectRefResult = await resolveExistingProjectRef(context, projectRef, configPath);
552+
553+
if (projectRefResult.status === "error") {
554+
return respondWithError(projectRefResult.error);
555+
}
556+
557+
const $projectRef = projectRefResult.projectRef;
558+
559+
context.logger?.log("get_run_details projectRefResult", { projectRefResult });
560+
561+
const auth = await mcpAuth({
562+
server: context.server,
563+
defaultApiUrl: context.options.apiUrl,
564+
profile: context.options.profile,
565+
context,
566+
});
567+
568+
if (!auth.ok) {
569+
return respondWithError(auth.error);
570+
}
571+
572+
const apiClient = await createApiClientWithPublicJWT(auth, $projectRef, environment, [
573+
`read:runs:${runId}`,
574+
]);
575+
576+
if (!apiClient) {
577+
return respondWithError("Failed to create API client with public JWT");
578+
}
579+
580+
const result = await apiClient.retrieveRun(runId);
581+
582+
const runUrl = `${auth.dashboardUrl}/projects/v3/${$projectRef}/runs/${result.id}`;
583+
584+
return {
585+
content: [{ type: "text", text: JSON.stringify({ ...result, runUrl }, null, 2) }],
586+
};
587+
}
588+
);
589+
}
590+
512591
async function resolveCwd(context: McpContext) {
513592
const response = await context.server.server.listRoots();
514593

0 commit comments

Comments
 (0)