@@ -329,7 +329,7 @@ export function registerGetTasksTool(context: McpContext) {
329329 return respondWithError ( auth . error ) ;
330330 }
331331
332- const cliApiClient = new CliApiClient ( auth . auth . apiUrl , auth . auth . accessToken ) ;
332+ const cliApiClient = new CliApiClient ( auth . auth . apiUrl , auth . auth . accessToken , branch ) ;
333333
334334 // TODO: support other tags and preview branches
335335 const worker = await cliApiClient . getWorkerByTag ( $projectRef , environment , "current" ) ;
@@ -471,9 +471,13 @@ export function registerTriggerTaskTool(context: McpContext) {
471471 return respondWithError ( auth . error ) ;
472472 }
473473
474- const apiClient = await createApiClientWithPublicJWT ( auth , $projectRef , environment , [
475- "write:tasks" ,
476- ] ) ;
474+ const apiClient = await createApiClientWithPublicJWT (
475+ auth ,
476+ $projectRef ,
477+ environment ,
478+ [ "write:tasks" ] ,
479+ branch
480+ ) ;
477481
478482 if ( ! apiClient ) {
479483 return respondWithError ( "Failed to create API client with public JWT" ) ;
@@ -583,9 +587,13 @@ export function registerGetRunDetailsTool(context: McpContext) {
583587 return respondWithError ( auth . error ) ;
584588 }
585589
586- const apiClient = await createApiClientWithPublicJWT ( auth , $projectRef , environment , [
587- `read:runs:${ runId } ` ,
588- ] ) ;
590+ const apiClient = await createApiClientWithPublicJWT (
591+ auth ,
592+ $projectRef ,
593+ environment ,
594+ [ `read:runs:${ runId } ` ] ,
595+ branch
596+ ) ;
589597
590598 if ( ! apiClient ) {
591599 return respondWithError ( "Failed to create API client with public JWT" ) ;
@@ -680,10 +688,13 @@ export function registerCancelRunTool(context: McpContext) {
680688 return respondWithError ( auth . error ) ;
681689 }
682690
683- const apiClient = await createApiClientWithPublicJWT ( auth , $projectRef , environment , [
684- `write:runs:${ runId } ` ,
685- `read:runs:${ runId } ` ,
686- ] ) ;
691+ const apiClient = await createApiClientWithPublicJWT (
692+ auth ,
693+ $projectRef ,
694+ environment ,
695+ [ `write:runs:${ runId } ` , `read:runs:${ runId } ` ] ,
696+ branch
697+ ) ;
687698
688699 if ( ! apiClient ) {
689700 return respondWithError ( "Failed to create API client with public JWT" ) ;
@@ -823,9 +834,13 @@ export function registerListRunsTool(context: McpContext) {
823834 return respondWithError ( auth . error ) ;
824835 }
825836
826- const apiClient = await createApiClientWithPublicJWT ( auth , $projectRef , environment , [
827- "read:runs" ,
828- ] ) ;
837+ const apiClient = await createApiClientWithPublicJWT (
838+ auth ,
839+ $projectRef ,
840+ environment ,
841+ [ "read:runs" ] ,
842+ branch
843+ ) ;
829844
830845 if ( ! apiClient ) {
831846 return respondWithError ( "Failed to create API client with public JWT" ) ;
@@ -1065,9 +1080,13 @@ export function registerListDeploymentsTool(context: McpContext) {
10651080 return respondWithError ( auth . error ) ;
10661081 }
10671082
1068- const apiClient = await createApiClientWithPublicJWT ( auth , $projectRef , environment , [
1069- "read:deployments" ,
1070- ] ) ;
1083+ const apiClient = await createApiClientWithPublicJWT (
1084+ auth ,
1085+ $projectRef ,
1086+ environment ,
1087+ [ "read:deployments" ] ,
1088+ branch
1089+ ) ;
10711090
10721091 if ( ! apiClient ) {
10731092 return respondWithError ( "Failed to create API client with public JWT" ) ;
@@ -1089,6 +1108,64 @@ export function registerListDeploymentsTool(context: McpContext) {
10891108 ) ;
10901109}
10911110
1111+ export function registerListPreviewBranchesTool ( context : McpContext ) {
1112+ context . server . registerTool (
1113+ "list_preview_branches" ,
1114+ {
1115+ description : "List all preview branches in the project" ,
1116+ inputSchema : {
1117+ projectRef : ProjectRefSchema ,
1118+ configPath : z
1119+ . string ( )
1120+ . describe (
1121+ "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"
1122+ )
1123+ . optional ( ) ,
1124+ } ,
1125+ } ,
1126+ async ( { projectRef, configPath } ) => {
1127+ context . logger ?. log ( "calling list_preview_branches" , { projectRef, configPath } ) ;
1128+
1129+ if ( context . options . devOnly ) {
1130+ return respondWithError ( `This MCP server is only available for the dev environment. ` ) ;
1131+ }
1132+
1133+ const projectRefResult = await resolveExistingProjectRef ( context , projectRef , configPath ) ;
1134+
1135+ if ( projectRefResult . status === "error" ) {
1136+ return respondWithError ( projectRefResult . error ) ;
1137+ }
1138+
1139+ const $projectRef = projectRefResult . projectRef ;
1140+
1141+ context . logger ?. log ( "list_preview_branches projectRefResult" , { projectRefResult } ) ;
1142+
1143+ const auth = await mcpAuth ( {
1144+ server : context . server ,
1145+ defaultApiUrl : context . options . apiUrl ,
1146+ profile : context . options . profile ,
1147+ context,
1148+ } ) ;
1149+
1150+ if ( ! auth . ok ) {
1151+ return respondWithError ( auth . error ) ;
1152+ }
1153+
1154+ const cliApiClient = new CliApiClient ( auth . auth . apiUrl , auth . auth . accessToken ) ;
1155+
1156+ const branches = await cliApiClient . listBranches ( $projectRef ) ;
1157+
1158+ if ( ! branches . success ) {
1159+ return respondWithError ( branches . error ) ;
1160+ }
1161+
1162+ return {
1163+ content : [ { type : "text" , text : JSON . stringify ( branches . data , null , 2 ) } ] ,
1164+ } ;
1165+ }
1166+ ) ;
1167+ }
1168+
10921169async function resolveCLIExec ( context : McpContext , cwd : string ) : Promise < [ string , string ] > {
10931170 // Lets first try to get the version of the CLI package
10941171 const installedCLI = await tryResolveTriggerCLIPath ( context , cwd ) ;
@@ -1415,28 +1492,3 @@ To view the project dashboard, visit: ${auth.dashboardUrl}/projects/v3/${project
14151492
14161493${ text } `;
14171494}
1418-
1419- async function getWritingTasksGuide ( prompt : string ) {
1420- const urls = [
1421- "https://trigger.dev/docs/tasks/overview.md" ,
1422- "https://trigger.dev/docs/tasks/schemaTask.md" ,
1423- "https://trigger.dev/docs/tasks/scheduled.md" ,
1424- "https://trigger.dev/docs/triggering.md" ,
1425- "https://trigger.dev/docs/writing-tasks-introduction.md" ,
1426- ] ;
1427-
1428- const responses = await Promise . all ( urls . map ( ( url ) => fetch ( url ) ) ) ;
1429- const texts = await Promise . all ( responses . map ( ( response ) => response . text ( ) ) ) ;
1430-
1431- const text = texts . join ( "\n\n" ) ;
1432-
1433- return `
1434- ## Trigger.dev Task Writing Guide:
1435-
1436- ${ text }
1437-
1438- ## Now please write the tasks based on the following prompt:
1439-
1440- ${ prompt }
1441- ` ;
1442- }
0 commit comments