@plitzi/sdk-mcp 0.34.1 → 0.35.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # @plitzi/sdk-mcp
2
2
 
3
+ ## 0.35.2
4
+
5
+ ### Patch Changes
6
+
7
+ - v0.35.2
8
+ - Updated dependencies [470aaf8]
9
+ - Updated dependencies
10
+ - Updated dependencies [470aaf8]
11
+ - @plitzi/sdk-elements@0.35.2
12
+ - @plitzi/plitzi-sdk@0.35.2
13
+ - @plitzi/sdk-interactions@0.35.2
14
+ - @plitzi/sdk-schema@0.35.2
15
+ - @plitzi/sdk-server@0.35.2
16
+ - @plitzi/sdk-shared@0.35.2
17
+ - @plitzi/sdk-style@0.35.2
18
+
19
+ ## 0.35.1
20
+
21
+ ### Patch Changes
22
+
23
+ - v0.35.1
24
+ - Updated dependencies
25
+ - @plitzi/plitzi-sdk@0.35.1
26
+ - @plitzi/sdk-elements@0.35.1
27
+ - @plitzi/sdk-interactions@0.35.1
28
+ - @plitzi/sdk-schema@0.35.1
29
+ - @plitzi/sdk-server@0.35.1
30
+ - @plitzi/sdk-shared@0.35.1
31
+ - @plitzi/sdk-style@0.35.1
32
+
33
+ ## 0.35.0
34
+
35
+ ### Minor Changes
36
+
37
+ - v0.35.0
38
+ - f5f6a97: Screenshots take a colour scheme, and a page that answers with an error is a failed capture rather than a picture.
39
+
40
+ - **`colorScheme` on `ScreenshotInput`** (`'light' | 'dark'`, optional). It is emulated as `prefers-color-scheme`
41
+ before the page loads — the HTTP client forwards it to the browser service, the local client applies it through
42
+ Playwright's `emulateMedia` or Puppeteer's `emulateMediaFeatures`. A space on the `system` theme follows it; a space
43
+ that forces a theme keeps its own. Left out, captures stay in the browser's default, which is light.
44
+ - **`RENDER_FAILED`.** An error page paints as well as any other, so a capture of "Space not found" came back as a valid
45
+ PNG and the thumbnail endpoint cached it for an hour. The browser service now refuses a page answering ≥ 400 with
46
+ `502 { error: 'RENDER_FAILED', status }`, and the HTTP client reports that as `RENDER_FAILED` instead of
47
+ `SCREENSHOT_FAILED`. The local client checks the navigation's status the same way.
48
+
49
+ ### Patch Changes
50
+
51
+ - Updated dependencies
52
+ - @plitzi/plitzi-sdk@0.35.0
53
+ - @plitzi/sdk-elements@0.35.0
54
+ - @plitzi/sdk-interactions@0.35.0
55
+ - @plitzi/sdk-schema@0.35.0
56
+ - @plitzi/sdk-server@0.35.0
57
+ - @plitzi/sdk-shared@0.35.0
58
+ - @plitzi/sdk-style@0.35.0
59
+
3
60
  ## 0.34.1
4
61
 
5
62
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { ScreenshotClient } from './types';
1
+ import { ScreenshotClient, ScreenshotInput } from './types';
2
2
  /**
3
3
  * A capture that needs no service to be running.
4
4
  *
@@ -11,9 +11,13 @@ import { ScreenshotClient } from './types';
11
11
  * whole thing is absent when it has neither. Nothing is added to this package's dependency tree, nothing is
12
12
  * downloaded on install, and a deployment that never captures anything never loads a line of it.
13
13
  */
14
+ type ColorScheme = NonNullable<ScreenshotInput['colorScheme']>;
14
15
  /** The narrow slice of a browser driver this uses. Both drivers satisfy it; neither is imported at build time. */
15
16
  type Page = {
16
- goto: (url: string, options?: Record<string, unknown>) => Promise<unknown>;
17
+ /** `null` for a same-document navigation, which carries no status of its own. */
18
+ goto: (url: string, options?: Record<string, unknown>) => Promise<{
19
+ status: () => number;
20
+ } | null>;
17
21
  setViewportSize?: (size: {
18
22
  width: number;
19
23
  height: number;
@@ -22,6 +26,15 @@ type Page = {
22
26
  width: number;
23
27
  height: number;
24
28
  }) => Promise<void>;
29
+ /** Playwright's. */
30
+ emulateMedia?: (options: {
31
+ colorScheme: ColorScheme;
32
+ }) => Promise<void>;
33
+ /** Puppeteer's. */
34
+ emulateMediaFeatures?: (features: {
35
+ name: string;
36
+ value: string;
37
+ }[]) => Promise<void>;
25
38
  evaluate: <T>(fn: () => T) => Promise<T>;
26
39
  screenshot: (options: Record<string, unknown>) => Promise<Buffer | Uint8Array>;
27
40
  };
@@ -38,6 +38,13 @@ var resolveLocalBrowser = async () => await importDriver("playwright") ?? await
38
38
  var setViewport = async (page, size) => {
39
39
  await (page.setViewportSize ? page.setViewportSize(size) : page.setViewport?.(size));
40
40
  };
41
+ /** Before the navigation: a space on the `system` theme paints from `prefers-color-scheme` from its first frame. */
42
+ var emulateColorScheme = async (page, colorScheme) => {
43
+ await (page.emulateMedia ? page.emulateMedia({ colorScheme }) : page.emulateMediaFeatures?.([{
44
+ name: "prefers-color-scheme",
45
+ value: colorScheme
46
+ }]));
47
+ };
41
48
  /**
42
49
  * A `ScreenshotClient` backed by a browser on this machine, or `undefined` when there is none.
43
50
  *
@@ -48,7 +55,7 @@ var setViewport = async (page, size) => {
48
55
  var createLocalScreenshotClient = async ({ renderBaseUrl, ignoreHttpsErrors = true }) => {
49
56
  const driver = await resolveLocalBrowser();
50
57
  if (!driver) return;
51
- return { async capture({ pagePath, token, viewports, fullPage = true }) {
58
+ return { async capture({ pagePath, token, viewports, fullPage = true, colorScheme }) {
52
59
  const url = new URL(pagePath, renderBaseUrl);
53
60
  if (token) url.searchParams.set(PREVIEW_TOKEN_PARAM, token);
54
61
  /**
@@ -68,7 +75,13 @@ var createLocalScreenshotClient = async ({ renderBaseUrl, ignoreHttpsErrors = tr
68
75
  for (const viewport of viewports) {
69
76
  const page = await browser.newPage();
70
77
  await setViewport(page, viewport);
71
- await page.goto(url.toString(), { waitUntil: "networkidle0" });
78
+ if (colorScheme) await emulateColorScheme(page, colorScheme);
79
+ const response = await page.goto(url.toString(), { waitUntil: "networkidle0" });
80
+ if (response && response.status() >= 400) return {
81
+ ok: false,
82
+ error: "RENDER_FAILED",
83
+ message: `The page answered ${response.status()}.`
84
+ };
72
85
  await page.evaluate(FONTS_READY);
73
86
  if (fullPage) {
74
87
  const height = Math.min(await page.evaluate(CONTENT_HEIGHT), MAX_HEIGHT);
@@ -5,10 +5,25 @@ var composeUrl = (base, pagePath, token) => {
5
5
  if (token) url.searchParams.set(PREVIEW_TOKEN_PARAM, token);
6
6
  return url.toString();
7
7
  };
8
+ /**
9
+ * The service's answer when the PAGE failed rather than the browser: `502 { error: 'RENDER_FAILED', status }`.
10
+ *
11
+ * Told apart because the two call for different things. A browser that failed may do better in a minute; a page that
12
+ * answered 404 will answer it again, and a caller that keeps images must never keep a picture of one.
13
+ */
14
+ var readRefusal = async (res) => {
15
+ if (res.status !== 502) return;
16
+ try {
17
+ const body = await res.json();
18
+ return body.error === "RENDER_FAILED" && typeof body.status === "number" ? { status: body.status } : void 0;
19
+ } catch {
20
+ return;
21
+ }
22
+ };
8
23
  /** Default `ScreenshotClient`: composes the navigable preview URL (renderBaseUrl + pagePath + `?__pt=token`) and
9
24
  * POSTs it to the browser service. Any network/HTTP failure surfaces as `ok:false` so the tool can fall back to
10
25
  * the HTML preview instead of hard-failing. */
11
- var createHttpScreenshotClient = ({ serviceUrl, renderBaseUrl, fetchImpl = fetch }) => ({ async capture({ pagePath, token, viewports, fullPage }) {
26
+ var createHttpScreenshotClient = ({ serviceUrl, renderBaseUrl, fetchImpl = fetch }) => ({ async capture({ pagePath, token, viewports, fullPage, colorScheme }) {
12
27
  const url = composeUrl(renderBaseUrl, pagePath, token);
13
28
  let res;
14
29
  try {
@@ -18,7 +33,8 @@ var createHttpScreenshotClient = ({ serviceUrl, renderBaseUrl, fetchImpl = fetch
18
33
  body: JSON.stringify({
19
34
  url,
20
35
  viewports,
21
- fullPage
36
+ fullPage,
37
+ colorScheme
22
38
  })
23
39
  });
24
40
  } catch (err) {
@@ -28,11 +44,19 @@ var createHttpScreenshotClient = ({ serviceUrl, renderBaseUrl, fetchImpl = fetch
28
44
  message: `Browser service unreachable: ${String(err)}`
29
45
  };
30
46
  }
31
- if (!res.ok) return {
32
- ok: false,
33
- error: "SCREENSHOT_FAILED",
34
- message: `Browser service returned ${res.status}.`
35
- };
47
+ if (!res.ok) {
48
+ const refusal = await readRefusal(res);
49
+ if (refusal) return {
50
+ ok: false,
51
+ error: "RENDER_FAILED",
52
+ message: `The page answered ${refusal.status}.`
53
+ };
54
+ return {
55
+ ok: false,
56
+ error: "SCREENSHOT_FAILED",
57
+ message: `Browser service returned ${res.status}.`
58
+ };
59
+ }
36
60
  const body = await res.json();
37
61
  if (!body.images || body.images.length === 0) return {
38
62
  ok: false,
@@ -0,0 +1 @@
1
+ export {};
@@ -61,7 +61,7 @@ var createMcpServer = async ({ adapters, getGrant, preview, screenshot, logger,
61
61
  const getSpace = () => spacePromise ??= loadSpace();
62
62
  const server = new McpServer({
63
63
  name: "plitzi-mcp",
64
- version: "0.34.1"
64
+ version: "0.35.2"
65
65
  }, { instructions: hasSpace ? serverInstructions : widgetsOnlyInstructions });
66
66
  registerResources(server, getSpace, MCP_ENV, log, hasSpace);
67
67
  registerApps(server, {
@@ -1,3 +1,4 @@
1
+ import { ColorScheme } from '@plitzi/sdk-shared';
1
2
  export type Viewport = {
2
3
  label: string;
3
4
  width: number;
@@ -21,6 +22,11 @@ export type ScreenshotInput = {
21
22
  token?: string;
22
23
  viewports: Viewport[];
23
24
  fullPage?: boolean;
25
+ /**
26
+ * The scheme the browser reports through `prefers-color-scheme`. A space on the `system` theme follows it, one that
27
+ * forces a theme keeps its own; left out, the browser's default applies, which is light.
28
+ */
29
+ colorScheme?: ColorScheme;
24
30
  };
25
31
  /** How plitzi_screenshot reaches the headless-browser service. The consumer injects an implementation (an HTTP
26
32
  * client to the dedicated browser pod); absent → the tool is not registered. A capture that fails (pod down)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-mcp",
3
- "version": "0.34.1",
3
+ "version": "0.35.2",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist",
@@ -30,13 +30,13 @@
30
30
  "dependencies": {
31
31
  "@modelcontextprotocol/ext-apps": "^1.7.5",
32
32
  "@modelcontextprotocol/sdk": "^1.30.0",
33
- "@plitzi/plitzi-sdk": "0.34.1",
34
- "@plitzi/sdk-elements": "0.34.1",
35
- "@plitzi/sdk-interactions": "0.34.1",
36
- "@plitzi/sdk-schema": "0.34.1",
37
- "@plitzi/sdk-server": "0.34.1",
38
- "@plitzi/sdk-shared": "0.34.1",
39
- "@plitzi/sdk-style": "0.34.1",
33
+ "@plitzi/plitzi-sdk": "0.35.2",
34
+ "@plitzi/sdk-elements": "0.35.2",
35
+ "@plitzi/sdk-interactions": "0.35.2",
36
+ "@plitzi/sdk-schema": "0.35.2",
37
+ "@plitzi/sdk-server": "0.35.2",
38
+ "@plitzi/sdk-shared": "0.35.2",
39
+ "@plitzi/sdk-style": "0.35.2",
40
40
  "ejs": "^6.0.1",
41
41
  "esbuild": "^0.28.2",
42
42
  "zod": "^4.6.4"