@@ -302,27 +302,9 @@ export type CloudRunDeployRegistration = {
302302 waitMs : number ;
303303} ;
304304
305- export type CloudRunDeployNextStepAction =
306- | "getDeployLog"
307- | "getProcessLog"
308- | "getDeployRecords" ;
309-
310- /**
311- * Follow-up next_step after getDeployLog is unavailable (CODING login / image
312- * deploy). Must never suggest getDeployLog again.
313- */
314- export type CloudRunDeployFollowUpAction = "getProcessLog" | "getDeployRecords" ;
315-
316305export type CloudRunDeployNextStep = {
317306 tool : "queryCloudRun" ;
318- action : CloudRunDeployNextStepAction ;
319- suggested_args : Record < string , string | number > ;
320- note ?: string ;
321- } ;
322-
323- export type CloudRunDeployFollowUpNextStep = {
324- tool : "queryCloudRun" ;
325- action : CloudRunDeployFollowUpAction ;
307+ action : "getDeployLog" | "getProcessLog" | "getDeployRecords" ;
326308 suggested_args : Record < string , string | number > ;
327309 note ?: string ;
328310} ;
@@ -339,110 +321,6 @@ export function isValidCloudRunRunId(value: unknown): value is string {
339321 return typeof value === "string" && value . trim ( ) . length > 0 ;
340322}
341323
342- /**
343- * DescribeCloudRunBuildLog / getBuildLog fails when the Tencent Cloud account
344- * has no CODING user. Agents should switch to getProcessLog (RunId) instead of
345- * retrying getDeployLog.
346- */
347- export function isCloudRunCodingBuildLogError ( error : unknown ) : boolean {
348- const message = error instanceof Error ? error . message : String ( error ) ;
349- return / D e s c r i b e C l o u d R u n B u i l d L o g | p l e a s e l o g i n C O D I N G | l o g i n C O D I N G | U s e r n o t c r e a t e d o r m a y n o t q c l o u d u s e r / i. test (
350- message ,
351- ) ;
352- }
353-
354- export type CloudRunGetProcessLogNextAction = {
355- tool : "queryCloudRun" ;
356- action : CloudRunDeployFollowUpAction ;
357- args : {
358- action : CloudRunDeployFollowUpAction ;
359- detailServerName : string ;
360- runId ?: string ;
361- } ;
362- } ;
363-
364- export function buildGetDeployLogCodingFallback ( options : {
365- serverName : string ;
366- runId ?: string ;
367- upstreamError ?: string ;
368- reason : "coding" | "image_no_build" ;
369- } ) : {
370- success : false ;
371- error : string ;
372- message : string ;
373- nextActions : CloudRunGetProcessLogNextAction [ ] ;
374- data : {
375- runId ?: string ;
376- next_step : CloudRunDeployFollowUpNextStep ;
377- upstreamError ?: string ;
378- } ;
379- } {
380- const runId = isValidCloudRunRunId ( options . runId ) ? options . runId . trim ( ) : undefined ;
381- // Narrow to follow-up actions only — never suggest getDeployLog again.
382- const next_step : CloudRunDeployFollowUpNextStep = runId
383- ? {
384- tool : "queryCloudRun" ,
385- action : "getProcessLog" ,
386- suggested_args : {
387- action : "getProcessLog" ,
388- detailServerName : options . serverName ,
389- runId,
390- } ,
391- note : "getDeployLog needs CODING / DescribeCloudRunBuildLog. Use getProcessLog for deploy-step and runtime logs." ,
392- }
393- : {
394- tool : "queryCloudRun" ,
395- action : "getDeployRecords" ,
396- suggested_args : {
397- action : "getDeployRecords" ,
398- detailServerName : options . serverName ,
399- } ,
400- note : "Read latestDeploy.RunId from getDeployRecords, then queryCloudRun(action=\"getProcessLog\"). Skip retrying getDeployLog for CODING login errors." ,
401- } ;
402-
403- const nextActions : CloudRunGetProcessLogNextAction [ ] = [
404- {
405- tool : "queryCloudRun" ,
406- action : next_step . action ,
407- args : {
408- action : next_step . action ,
409- detailServerName : options . serverName ,
410- ...( runId ? { runId } : { } ) ,
411- } ,
412- } ,
413- ] ;
414- if ( next_step . action === "getDeployRecords" ) {
415- nextActions . push ( {
416- tool : "queryCloudRun" ,
417- action : "getProcessLog" ,
418- args : {
419- action : "getProcessLog" ,
420- detailServerName : options . serverName ,
421- } ,
422- } ) ;
423- }
424-
425- const message =
426- options . reason === "image_no_build"
427- ? `Service '${ options . serverName } ' has no cloud source build (BuildId=0). Skip getDeployLog; use queryCloudRun(action="getProcessLog"${ runId ? `, runId="${ runId } "` : "" } ) for deploy-step and runtime logs.`
428- : `getDeployLog (DescribeCloudRunBuildLog) failed because this account is not a CODING user. Do not retry getDeployLog. Use queryCloudRun(action="getProcessLog", detailServerName="${ options . serverName } "${ runId ? `, runId="${ runId } "` : "" } ) — RunId comes from getDeployRecords/latestDeploy.` ;
429-
430- return {
431- success : false ,
432- error :
433- options . reason === "image_no_build"
434- ? "NO_CODING_BUILD_FOR_IMAGE_DEPLOY"
435- : "CODING_BUILD_LOG_UNAVAILABLE" ,
436- message,
437- nextActions,
438- data : {
439- ...( runId ? { runId } : { } ) ,
440- next_step,
441- ...( options . upstreamError ? { upstreamError : options . upstreamError } : { } ) ,
442- } ,
443- } ;
444- }
445-
446324function extractServerManageTaskInfo ( resp : unknown ) : {
447325 taskId ?: number ;
448326 taskStatus ?: string ;
@@ -1290,62 +1168,13 @@ export function registerCloudRunTools(server: ExtendedMcpServer) {
12901168 }
12911169
12921170 const buildId = input . buildId ?? latestDeploy . BuildId ;
1293- const latestRunId = isValidCloudRunRunId ( latestDeploy . RunId )
1294- ? latestDeploy . RunId . trim ( )
1295- : undefined ;
1296-
1297- // Image deploys typically have BuildId=0 and no CODING build.
1298- if ( ! isValidCloudRunBuildId ( buildId ) ) {
1299- return {
1300- content : [
1301- {
1302- type : "text" ,
1303- text : JSON . stringify (
1304- buildGetDeployLogCodingFallback ( {
1305- serverName,
1306- runId : latestRunId ,
1307- reason : "image_no_build" ,
1308- } ) ,
1309- null ,
1310- 2 ,
1311- ) ,
1312- } ,
1313- ] ,
1314- } ;
1315- }
1316-
13171171 // Build log (CODING / DescribeCloudRunBuildLog). Meaningful only for
1318- // cloud source builds. Accounts without a CODING user fail here —
1319- // rewrite to getProcessLog instead of bubbling the raw English error.
1320- let buildLogResult : unknown ;
1321- try {
1322- buildLogResult = await cloudrunService . getBuildLog ( {
1323- serverName,
1324- buildId,
1325- } ) ;
1326- } catch ( error ) {
1327- if ( isCloudRunCodingBuildLogError ( error ) ) {
1328- const upstreamError = error instanceof Error ? error . message : String ( error ) ;
1329- return {
1330- content : [
1331- {
1332- type : "text" ,
1333- text : JSON . stringify (
1334- buildGetDeployLogCodingFallback ( {
1335- serverName,
1336- runId : latestRunId ,
1337- upstreamError,
1338- reason : "coding" ,
1339- } ) ,
1340- null ,
1341- 2 ,
1342- ) ,
1343- } ,
1344- ] ,
1345- } ;
1346- }
1347- throw error ;
1348- }
1172+ // cloud source builds; image deploys have no build process. Accounts
1173+ // without a CODING user may fail here — use getProcessLog for runtime logs.
1174+ const buildLogResult : any = await cloudrunService . getBuildLog ( {
1175+ serverName,
1176+ buildId,
1177+ } ) ;
13491178
13501179 let processLogs : unknown [ ] = [ ] ;
13511180 let processLogsWarning : string | undefined ;
@@ -1361,11 +1190,7 @@ export function registerCloudRunTools(server: ExtendedMcpServer) {
13611190 }
13621191 }
13631192
1364- const buildLogRecord =
1365- buildLogResult && typeof buildLogResult === "object"
1366- ? ( buildLogResult as { Log ?: { Text ?: string } } )
1367- : undefined ;
1368- const buildLogText = typeof buildLogRecord ?. Log ?. Text === 'string' ? buildLogRecord . Log . Text : '' ;
1193+ const buildLogText = typeof buildLogResult ?. Log ?. Text === 'string' ? buildLogResult . Log . Text : '' ;
13691194 const processLogText = Array . isArray ( processLogs ) && processLogs . length > 0 ? normalizeProcessLogText ( processLogs ) : '' ;
13701195 const combinedLogText = [ buildLogText , processLogText ] . filter ( Boolean ) . join ( '\n' ) ;
13711196
@@ -1378,7 +1203,7 @@ export function registerCloudRunTools(server: ExtendedMcpServer) {
13781203 data : {
13791204 buildId,
13801205 deployRecord : latestDeploy ,
1381- buildLog : buildLogRecord ?. Log || null ,
1206+ buildLog : buildLogResult ?. Log || null ,
13821207 // Optional best-effort attach; prefer dedicated getProcessLog for runtime diagnosis
13831208 processLogs,
13841209 combinedLogText,
0 commit comments