Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: refresh mcp session from dev build (#5845)
Oleg Isonen6bf973d5d88c
diff --git a/packages/cli/src/commands/mcp.test.ts b/packages/cli/src/commands/mcp.test.tsindex b4ed074db7..d5ff351f0a 100644--- a/packages/cli/src/commands/mcp.test.ts+++ b/packages/cli/src/commands/mcp.test.ts@@ -1,5 +1,6 @@import { expect, test, vi } from "vitest";-import { mcpOptions } from "./mcp";+import { builderNamespaces } from "@webstudio-is/project-build/contracts/namespaces";+import { mcpOptions, prepareMcpProjectSession } from "./mcp";test("documents MCP stdio startup and discovery tools", () => {const yargs = {@@ -20,4 +21,19 @@ test("documents MCP stdio startup and discovery tools", () => {expect(yargs.epilogue).toHaveBeenCalledWith(expect.stringContaining("tools/list"));+ expect(yargs.epilogue).toHaveBeenCalledWith(+ expect.stringContaining("current Builder dev build")+ );+});++test("marks cached namespaces stale before serving MCP tools", async () => {+ const session = {+ initialize: vi.fn(async () => undefined),+ markStale: vi.fn(async () => undefined),+ };++ await prepareMcpProjectSession(session);++ expect(session.initialize).toHaveBeenCalled();+ expect(session.markStale).toHaveBeenCalledWith(builderNamespaces);});diff --git a/packages/cli/src/commands/mcp.ts b/packages/cli/src/commands/mcp.tsindex e7a2202255..537fefaf8b 100644--- a/packages/cli/src/commands/mcp.ts+++ b/packages/cli/src/commands/mcp.ts@@ -4,6 +4,10 @@ import {connectProjectSessionMcpServer,createMcpStdioTransport,} from "@webstudio-is/project-build/mcp";+import {+ builderNamespaces,+ type BuilderNamespace,+} from "@webstudio-is/project-build/contracts/namespaces";import { diffPngFiles } from "@webstudio-is/project-build/visual/screenshot-diff";import { publicApiOperations } from "@webstudio-is/protocol";import { importProjectBundleWithAssets } from "@webstudio-is/http-client";@@ -27,6 +31,18 @@ import { apiCompatibilityHeaders } from "./api";import { importProject as importProjectCommand } from "./import";import type { CommonYargsArgv } from "./yargs-types";+type StartableProjectSession = {+ initialize: () => Promise<unknown>;+ markStale: (namespaces: readonly BuilderNamespace[]) => Promise<unknown>;+};++export const prepareMcpProjectSession = async (+ session: StartableProjectSession+) => {+ await session.initialize();+ await session.markStale(builderNamespaces);+};+export const mcpOptions = (yargs: CommonYargsArgv) =>yargs.example(@@ -44,6 +60,7 @@ export const mcpOptions = (yargs: CommonYargsArgv) =>.epilogue(["Plain `webstudio mcp` starts the stdio MCP server.",+ "Startup marks cached ProjectSession data stale so MCP tools read the current Builder dev build.","After startup, MCP clients discover capabilities with tools/list, resources/list, meta.index, meta.guide, and meta.get_more_tools.","stdout is reserved for MCP JSON-RPC messages while the server is running.",].join("\n")@@ -66,6 +83,7 @@ export const mcp = async () => {},};const session = createCliProjectSession({ connection: apiConnection });+ await prepareMcpProjectSession(session);const preview = createPreviewController({ host: "127.0.0.1", port: 5173 });await connectProjectSessionMcpServer({operations: publicApiOperations,