Skip to content

Commit 40394eb

Browse files
committed
refactor(mcp-server): dedupe the runActions invalid-plan check into a named predicate
1 parent 201ae95 commit 40394eb

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

packages/mcp-server/src/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ export function createAppApi(ctx: AppContext, runtime: ApiRuntime = {}): AppApi
575575
plans.push({ action: name, index, source, errors });
576576
}
577577

578-
const invalid = plans.filter((p) => p.error !== undefined || (p.errors && p.errors.length > 0));
578+
const failed = (p: { error?: string; errors?: unknown[] }): boolean => p.error !== undefined || (p.errors?.length ?? 0) > 0;
579+
const invalid = plans.filter(failed);
579580
if (atomic && invalid.length > 0) {
580581
const failures = invalid.map((p) => (p.error !== undefined ? { action: p.action, index: p.index, error: p.error } : { action: p.action, index: p.index, errors: p.errors }));
581582
return { ok: false, atomic: true, failures };
@@ -586,7 +587,7 @@ export function createAppApi(ctx: AppContext, runtime: ApiRuntime = {}): AppApi
586587
const completed: { source: string; checkpoint_id: string }[] = [];
587588

588589
for (const plan of plans) {
589-
if (plan.error !== undefined || (plan.errors && plan.errors.length > 0)) {
590+
if (failed(plan)) {
590591
const failure = plan.error !== undefined ? { error: plan.error } : { errors: plan.errors };
591592
results.push({ action: plan.action, ok: false, ...failure });
592593
continue;

0 commit comments

Comments
 (0)