@@ -340,6 +340,8 @@ function formatRunResponse(run: any) {
340340 runByScheduleId : run . runByScheduleId ,
341341 runByAPI : run . runByAPI ,
342342 runBySDK : run . runBySDK ,
343+ runByMCP : run . runByMCP ,
344+ runByCLI : run . runByCLI ,
343345 data : {
344346 textData : { } ,
345347 listData : { } ,
@@ -477,7 +479,7 @@ router.get("/robots/:id/runs/:runId", requireAPIKey, async (req: Request, res: R
477479 }
478480} ) ;
479481
480- async function createWorkflowAndStoreMetadata ( id : string , userId : string , isSDK : boolean ) {
482+ async function createWorkflowAndStoreMetadata ( id : string , userId : string , runSource : 'api' | 'sdk' | 'mcp' | 'cli' ) {
481483 try {
482484 const recording = await Robot . findOne ( {
483485 where : {
@@ -522,8 +524,10 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string, isSDK:
522524 log : '' ,
523525 runId,
524526 runByUserId : userId ,
525- runByAPI : ! isSDK ,
526- runBySDK : isSDK ,
527+ runByAPI : runSource === 'api' ,
528+ runBySDK : runSource === 'sdk' ,
529+ runByMCP : runSource === 'mcp' ,
530+ runByCLI : runSource === 'cli' ,
527531 serializableOutput : { } ,
528532 binaryOutput : { } ,
529533 retryCount : 0
@@ -1194,11 +1198,11 @@ async function executeRun(id: string, userId: string, requestedFormats?: string[
11941198 }
11951199}
11961200
1197- export async function handleRunRecording ( id : string , userId : string , isSDK : boolean = false , requestedFormats ?: string [ ] ) {
1201+ export async function handleRunRecording ( id : string , userId : string , runSource : 'api' | 'sdk' | 'mcp' | 'cli' = 'api' , requestedFormats ?: string [ ] ) {
11981202 let socket : Socket | null = null ;
11991203
12001204 try {
1201- const result = await createWorkflowAndStoreMetadata ( id , userId , isSDK ) ;
1205+ const result = await createWorkflowAndStoreMetadata ( id , userId , runSource ) ;
12021206 const { browserId, runId : newRunId } = result ;
12031207
12041208 if ( ! browserId || ! newRunId || ! userId ) {
@@ -1378,7 +1382,8 @@ router.post("/robots/:id/runs", requireAPIKey, async (req: AuthenticatedRequest,
13781382 }
13791383
13801384 const requestedFormats = req . body ?. formats ;
1381- const runId = await handleRunRecording ( req . params . id , req . user . id , false , requestedFormats ) ;
1385+ const runSource = req . headers [ 'x-run-source' ] === 'mcp' ? 'mcp' : 'api' ;
1386+ const runId = await handleRunRecording ( req . params . id , req . user . id , runSource , requestedFormats ) ;
13821387
13831388 if ( ! runId ) {
13841389 throw new Error ( 'Run ID is undefined' ) ;
0 commit comments