From 852023b5c8d477d7631a3fa738213fc8fc784fb0 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Sun, 15 Nov 2026 15:39:58 +0000 Subject: [PATCH] fix: keep MCP publish inputs valid and finish superseded builds --- .../publish/publish-progress.test.tsx | 37 +++++++++++++++++++ .../features/publish/publish-progress.tsx | 9 +++++ packages/cli/src/commands/mcp.test.ts | 15 ++++++++ packages/project-build/src/mcp.test.ts | 33 +++++++++++++++++ packages/project-build/src/mcp.ts | 16 ++++++-- 5 files changed, 107 insertions(+), 3 deletions(-) diff --git a/apps/builder/app/builder/features/publish/publish-progress.test.tsx b/apps/builder/app/builder/features/publish/publish-progress.test.tsx index 178e60918e..a09dde2894 100644 --- a/apps/builder/app/builder/features/publish/publish-progress.test.tsx +++ b/apps/builder/app/builder/features/publish/publish-progress.test.tsx @@ -135,6 +135,43 @@ test("static status waits for the matching runner before download readiness", as expect(getJob).toHaveBeenCalledTimes(2); }); +test.each(["site", "static"] as const)( + "finishes an accepted %s publish when a newer build becomes latest", + async (target) => { + vi.useFakeTimers(); + const newerBuild = { + buildId: "build-2", + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + publishStatus: "PUBLISHED", + }; + const refresh = vi.fn( + async () => + ({ + latestBuildVirtual: target === "site" ? newerBuild : null, + latestStaticBuild: target === "static" ? newerBuild : null, + }) as Project + ); + const getJob = vi.fn(async () => ({ status: "success" })); + const waiting = waitForPublishStatus( + refresh, + () => true, + undefined, + { + projectId: "project", + buildId: "build-1", + logHandle: "handle-1", + target, + }, + getJob + ); + + await vi.runAllTimersAsync(); + expect((await waiting)?.status).toBe("PUBLISHED"); + expect(refresh).toHaveBeenCalledOnce(); + } +); + test("reopening refresh retries after a rejected status request", async () => { vi.useFakeTimers(); const errorLog = vi.spyOn(console, "error").mockImplementation(() => {}); diff --git a/apps/builder/app/builder/features/publish/publish-progress.tsx b/apps/builder/app/builder/features/publish/publish-progress.tsx index a59b088f55..9b42df7e6a 100644 --- a/apps/builder/app/builder/features/publish/publish-progress.tsx +++ b/apps/builder/app/builder/features/publish/publish-progress.tsx @@ -36,6 +36,7 @@ export const waitForPublishStatus = async ( const timeToFinish = Date.now() + PENDING_TIMEOUT + 2 * sleepTime; while (Date.now() < timeToFinish && isCurrentProject()) { + let runnerSucceeded = false; try { let runnerPending = false; if (execution?.logHandle !== undefined) { @@ -56,6 +57,7 @@ export const waitForPublishStatus = async ( }; } runnerPending = job.status === "pending"; + runnerSucceeded = job.status === "success"; } catch (error) { console.error("Could not refresh publish status", error); } @@ -95,6 +97,13 @@ export const waitForPublishStatus = async ( // A failed status request should not stop watching an ongoing publish. console.error("Could not refresh publish status", error); } + if (runnerSucceeded && isCurrentProject()) { + return { + status: "PUBLISHED" as const, + statusContent: + execution?.target === "static" ? "Downloaded" : "Published", + }; + } await new Promise((resolve) => setTimeout(resolve, sleepTime)); sleepTime = Math.max(5000, sleepTime - 5000); diff --git a/packages/cli/src/commands/mcp.test.ts b/packages/cli/src/commands/mcp.test.ts index 44e89007b2..84c215ef90 100644 --- a/packages/cli/src/commands/mcp.test.ts +++ b/packages/cli/src/commands/mcp.test.ts @@ -2617,6 +2617,21 @@ test("exposes asset content editing through MCP discovery", () => { }); }); +test("exposes valid inputs for both publish targets through MCP discovery", () => { + const tool = listProjectSessionMcpTools(publicApiOperations).find( + ({ name }) => name === "publish" + ); + + expect(tool?.inputSchema).toMatchObject({ + additionalProperties: true, + required: ["target"], + oneOf: [ + { properties: { target: expect.any(Object) } }, + { properties: { target: expect.any(Object) } }, + ], + }); +}); + test("exposes a client-valid update-props schema", () => { const tool = listProjectSessionMcpTools(publicApiOperations).find( ({ name }) => name === "update-props" diff --git a/packages/project-build/src/mcp.test.ts b/packages/project-build/src/mcp.test.ts index 5d3d62face..98e7db9ba9 100644 --- a/packages/project-build/src/mcp.test.ts +++ b/packages/project-build/src/mcp.test.ts @@ -1323,6 +1323,39 @@ describe("project session mcp adapter", () => { expect(tool?.inputSchema.properties).not.toHaveProperty("runtime"); }); + test("keeps discriminated publish inputs valid in the MCP tool schema", () => { + const [tool] = listProjectSessionMcpTools([ + publicOperation({ + command: "publish", + id: "build.publish", + description: "Publish a site or static export", + localCapable: false, + serverOnly: true, + inputSchema: getTestInputSchema( + z.discriminatedUnion("target", [ + z.object({ + target: z.literal("production"), + domains: z.array(z.string()), + }), + z.object({ + target: z.literal("static"), + templates: z.array(z.string()), + }), + ]) + ), + }), + ]); + + expect(tool?.inputSchema).toMatchObject({ + oneOf: [ + { properties: { target: { const: "production" } } }, + { properties: { target: { const: "static" } } }, + ], + required: ["target"], + additionalProperties: true, + }); + }); + test("defers oversized input schemas until focused discovery", async () => { const description = "x".repeat(25_000); const operation = publicOperation({ diff --git a/packages/project-build/src/mcp.ts b/packages/project-build/src/mcp.ts index 291944be0c..dbbedf4ab3 100644 --- a/packages/project-build/src/mcp.ts +++ b/packages/project-build/src/mcp.ts @@ -683,9 +683,16 @@ const getOperationInputSchema = ( operation.inputSchema ); const properties = getInputJsonSchemaProperties(operation.inputSchema); + const hasComposedBranches = + operation.inputSchema.oneOf !== undefined || + operation.inputSchema.anyOf !== undefined || + operation.inputSchema.allOf !== undefined; const additionalProperties = - operation.inputSchema.additionalProperties ?? - (properties === undefined || Object.keys(properties).length === 0); + hasComposedBranches && + Object.keys(operation.inputSchema.properties ?? {}).length === 0 + ? true + : (operation.inputSchema.additionalProperties ?? + (properties === undefined || Object.keys(properties).length === 0)); return { ...emptyInputSchema, ...operation.inputSchema, @@ -2010,7 +2017,10 @@ const getMcpOperationInputSchema = ( const properties = getInputJsonSchemaProperties(schema); if ( schema.additionalProperties === true && - (properties === undefined || Object.keys(properties).length === 0) + (properties === undefined || Object.keys(properties).length === 0) && + schema.oneOf === undefined && + schema.anyOf === undefined && + schema.allOf === undefined ) { schema = { ...schema, additionalProperties: false }; }