1010 * --no-max-duration disable duration ceiling
1111 * --max-turns <n> maximum agent turns
1212 * --no-max-turns disable turns ceiling
13+ * --max-concurrent-jobs <n> max concurrent running jobs
14+ * --max-concurrent-jobs-per-workflow <n> max concurrent running jobs for this workflow
1315 * --hitl <strategy> HITL strategy: elicit | auto | fail (default: elicit)
1416 * --name <name> MCP server name (default: workflow name)
1517 * --log-file <path> write stderr log to a file
2426import fs from "node:fs" ;
2527import path from "node:path" ;
2628import type { WorkflowDef } from "@ageflow/core" ;
27- import type { CliCeilings , HitlStrategy } from "@ageflow/mcp-server" ;
29+ import type {
30+ CliCeilings ,
31+ ConcurrencyConfig ,
32+ HitlStrategy ,
33+ } from "@ageflow/mcp-server" ;
2834import {
2935 createHttpTransport ,
3036 createSingleWorkflowServer ,
@@ -39,6 +45,8 @@ export interface McpServeArgs {
3945 readonly maxCostUsd ?: number | null ;
4046 readonly maxDurationSec ?: number | null ;
4147 readonly maxTurns ?: number | null ;
48+ readonly maxConcurrentJobs ?: number ;
49+ readonly maxConcurrentJobsPerWorkflow ?: number ;
4250 readonly hitlStrategy : HitlStrategy ;
4351 readonly serverName ?: string ;
4452 readonly logFile ?: string ;
@@ -86,6 +94,8 @@ export function parseMcpServeArgs(argv: readonly string[]): McpServeArgs {
8694 let maxCostUsd : number | null | undefined = undefined ;
8795 let maxDurationSec : number | null | undefined = undefined ;
8896 let maxTurns : number | null | undefined = undefined ;
97+ let maxConcurrentJobs : number | undefined = undefined ;
98+ let maxConcurrentJobsPerWorkflow : number | undefined = undefined ;
8999 let hitlStrategy : HitlStrategy = "elicit" ;
90100 let serverName : string | undefined = undefined ;
91101 let logFile : string | undefined = undefined ;
@@ -155,6 +165,38 @@ export function parseMcpServeArgs(argv: readonly string[]): McpServeArgs {
155165 maxTurns = null ;
156166 break ;
157167
168+ case "--max-concurrent-jobs" : {
169+ const val = args [ ++ i ] ;
170+ if ( val === undefined || val . startsWith ( "--" ) ) {
171+ throw new Error ( "--max-concurrent-jobs requires a numeric argument" ) ;
172+ }
173+ const n = Number ( val ) ;
174+ if ( ! Number . isInteger ( n ) || n <= 0 ) {
175+ throw new Error (
176+ `--max-concurrent-jobs must be a positive integer, got: ${ val } ` ,
177+ ) ;
178+ }
179+ maxConcurrentJobs = n ;
180+ break ;
181+ }
182+
183+ case "--max-concurrent-jobs-per-workflow" : {
184+ const val = args [ ++ i ] ;
185+ if ( val === undefined || val . startsWith ( "--" ) ) {
186+ throw new Error (
187+ "--max-concurrent-jobs-per-workflow requires a numeric argument" ,
188+ ) ;
189+ }
190+ const n = Number ( val ) ;
191+ if ( ! Number . isInteger ( n ) || n <= 0 ) {
192+ throw new Error (
193+ `--max-concurrent-jobs-per-workflow must be a positive integer, got: ${ val } ` ,
194+ ) ;
195+ }
196+ maxConcurrentJobsPerWorkflow = n ;
197+ break ;
198+ }
199+
158200 case "--hitl" : {
159201 const val = args [ ++ i ] ;
160202 if ( val !== "elicit" && val !== "auto" && val !== "fail" ) {
@@ -273,9 +315,13 @@ export function parseMcpServeArgs(argv: readonly string[]): McpServeArgs {
273315 asyncMode !== true &&
274316 ( jobTtlMs !== undefined ||
275317 jobCheckpointTtlMs !== undefined ||
276- jobDb !== undefined )
318+ jobDb !== undefined ||
319+ maxConcurrentJobs !== undefined ||
320+ maxConcurrentJobsPerWorkflow !== undefined )
277321 ) {
278- throw new Error ( "--job-ttl / --checkpoint-ttl / --job-db requires --async" ) ;
322+ throw new Error (
323+ "--job-ttl / --checkpoint-ttl / --job-db / --max-concurrent-jobs / --max-concurrent-jobs-per-workflow requires --async" ,
324+ ) ;
279325 }
280326
281327 if ( httpPort !== undefined && httpMode !== true ) {
@@ -311,6 +357,10 @@ export function parseMcpServeArgs(argv: readonly string[]): McpServeArgs {
311357 ...( maxCostUsd !== undefined ? { maxCostUsd } : { } ) ,
312358 ...( maxDurationSec !== undefined ? { maxDurationSec } : { } ) ,
313359 ...( maxTurns !== undefined ? { maxTurns } : { } ) ,
360+ ...( maxConcurrentJobs !== undefined ? { maxConcurrentJobs } : { } ) ,
361+ ...( maxConcurrentJobsPerWorkflow !== undefined
362+ ? { maxConcurrentJobsPerWorkflow }
363+ : { } ) ,
314364 ...( serverName !== undefined ? { serverName } : { } ) ,
315365 ...( logFile !== undefined ? { logFile } : { } ) ,
316366 ...( asyncMode !== undefined ? { async : asyncMode } : { } ) ,
@@ -370,6 +420,21 @@ async function runMcpServe(rawArgv: string[]): Promise<void> {
370420 : { } ) ,
371421 ...( parsed . maxTurns !== undefined ? { maxTurns : parsed . maxTurns } : { } ) ,
372422 } ;
423+ const concurrency : ConcurrencyConfig | undefined =
424+ parsed . maxConcurrentJobs !== undefined ||
425+ parsed . maxConcurrentJobsPerWorkflow !== undefined
426+ ? {
427+ ...( parsed . maxConcurrentJobs !== undefined
428+ ? { maxConcurrentJobs : parsed . maxConcurrentJobs }
429+ : { } ) ,
430+ ...( parsed . maxConcurrentJobsPerWorkflow !== undefined
431+ ? {
432+ maxConcurrentJobsPerWorkflow :
433+ parsed . maxConcurrentJobsPerWorkflow ,
434+ }
435+ : { } ) ,
436+ }
437+ : undefined ;
373438
374439 // Determine server name
375440 const serverName = parsed . serverName ?? workflow . name ;
@@ -390,6 +455,7 @@ async function runMcpServe(rawArgv: string[]): Promise<void> {
390455 workflow,
391456 cliCeilings,
392457 hitlStrategy : parsed . hitlStrategy ,
458+ ...( concurrency !== undefined ? { concurrency } : { } ) ,
393459 stderr,
394460 ...( parsed . async === true ? { async : true } : { } ) ,
395461 ...( parsed . jobTtlMs !== undefined ? { jobTtlMs : parsed . jobTtlMs } : { } ) ,
@@ -474,6 +540,8 @@ export function registerMcpCommand(program: Command): void {
474540 " --no-max-duration disable duration ceiling\n" +
475541 " --max-turns <n> max agent turns\n" +
476542 " --no-max-turns disable turns ceiling\n" +
543+ " --max-concurrent-jobs <n> max concurrent running jobs\n" +
544+ " --max-concurrent-jobs-per-workflow <n> max concurrent running jobs for this workflow\n" +
477545 " --hitl <strategy> elicit | auto | fail (default: elicit)\n" +
478546 " --name <name> MCP server name\n" +
479547 " --log-file <path> log stderr to file\n" +
0 commit comments