Skip to content

Commit 6bf973d

Browse files
authored
fix: refresh mcp session from dev build (#5845)
1 parent 9b0cedf commit 6bf973d

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

packages/cli/src/commands/mcp.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect, test, vi } from "vitest";
2-
import { mcpOptions } from "./mcp";
2+
import { builderNamespaces } from "@webstudio-is/project-build/contracts/namespaces";
3+
import { mcpOptions, prepareMcpProjectSession } from "./mcp";
34

45
test("documents MCP stdio startup and discovery tools", () => {
56
const yargs = {
@@ -20,4 +21,19 @@ test("documents MCP stdio startup and discovery tools", () => {
2021
expect(yargs.epilogue).toHaveBeenCalledWith(
2122
expect.stringContaining("tools/list")
2223
);
24+
expect(yargs.epilogue).toHaveBeenCalledWith(
25+
expect.stringContaining("current Builder dev build")
26+
);
27+
});
28+
29+
test("marks cached namespaces stale before serving MCP tools", async () => {
30+
const session = {
31+
initialize: vi.fn(async () => undefined),
32+
markStale: vi.fn(async () => undefined),
33+
};
34+
35+
await prepareMcpProjectSession(session);
36+
37+
expect(session.initialize).toHaveBeenCalled();
38+
expect(session.markStale).toHaveBeenCalledWith(builderNamespaces);
2339
});

packages/cli/src/commands/mcp.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import {
44
connectProjectSessionMcpServer,
55
createMcpStdioTransport,
66
} from "@webstudio-is/project-build/mcp";
7+
import {
8+
builderNamespaces,
9+
type BuilderNamespace,
10+
} from "@webstudio-is/project-build/contracts/namespaces";
711
import { diffPngFiles } from "@webstudio-is/project-build/visual/screenshot-diff";
812
import { publicApiOperations } from "@webstudio-is/protocol";
913
import { importProjectBundleWithAssets } from "@webstudio-is/http-client";
@@ -27,6 +31,18 @@ import { apiCompatibilityHeaders } from "./api";
2731
import { importProject as importProjectCommand } from "./import";
2832
import type { CommonYargsArgv } from "./yargs-types";
2933

34+
type StartableProjectSession = {
35+
initialize: () => Promise<unknown>;
36+
markStale: (namespaces: readonly BuilderNamespace[]) => Promise<unknown>;
37+
};
38+
39+
export const prepareMcpProjectSession = async (
40+
session: StartableProjectSession
41+
) => {
42+
await session.initialize();
43+
await session.markStale(builderNamespaces);
44+
};
45+
3046
export const mcpOptions = (yargs: CommonYargsArgv) =>
3147
yargs
3248
.example(
@@ -44,6 +60,7 @@ export const mcpOptions = (yargs: CommonYargsArgv) =>
4460
.epilogue(
4561
[
4662
"Plain `webstudio mcp` starts the stdio MCP server.",
63+
"Startup marks cached ProjectSession data stale so MCP tools read the current Builder dev build.",
4764
"After startup, MCP clients discover capabilities with tools/list, resources/list, meta.index, meta.guide, and meta.get_more_tools.",
4865
"stdout is reserved for MCP JSON-RPC messages while the server is running.",
4966
].join("\n")
@@ -66,6 +83,7 @@ export const mcp = async () => {
6683
},
6784
};
6885
const session = createCliProjectSession({ connection: apiConnection });
86+
await prepareMcpProjectSession(session);
6987
const preview = createPreviewController({ host: "127.0.0.1", port: 5173 });
7088
await connectProjectSessionMcpServer({
7189
operations: publicApiOperations,

0 commit comments

Comments
 (0)