@plitzi/sdk-mcp 0.34.1 → 0.35.1
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 +41 -0
- package/dist/modules/mcp/localScreenshotClient.d.ts +15 -2
- package/dist/modules/mcp/localScreenshotClient.js +15 -2
- package/dist/modules/mcp/screenshotClient.js +31 -7
- package/dist/modules/mcp/screenshotClient.test.d.ts +1 -0
- package/dist/modules/mcp/server.js +1 -1
- package/dist/modules/mcp/types/screenshotTypes.d.ts +6 -0
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @plitzi/sdk-mcp
|
|
2
2
|
|
|
3
|
+
## 0.35.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- v0.35.1
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @plitzi/plitzi-sdk@0.35.1
|
|
10
|
+
- @plitzi/sdk-elements@0.35.1
|
|
11
|
+
- @plitzi/sdk-interactions@0.35.1
|
|
12
|
+
- @plitzi/sdk-schema@0.35.1
|
|
13
|
+
- @plitzi/sdk-server@0.35.1
|
|
14
|
+
- @plitzi/sdk-shared@0.35.1
|
|
15
|
+
- @plitzi/sdk-style@0.35.1
|
|
16
|
+
|
|
17
|
+
## 0.35.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- v0.35.0
|
|
22
|
+
- f5f6a97: Screenshots take a colour scheme, and a page that answers with an error is a failed capture rather than a picture.
|
|
23
|
+
|
|
24
|
+
- **`colorScheme` on `ScreenshotInput`** (`'light' | 'dark'`, optional). It is emulated as `prefers-color-scheme`
|
|
25
|
+
before the page loads — the HTTP client forwards it to the browser service, the local client applies it through
|
|
26
|
+
Playwright's `emulateMedia` or Puppeteer's `emulateMediaFeatures`. A space on the `system` theme follows it; a space
|
|
27
|
+
that forces a theme keeps its own. Left out, captures stay in the browser's default, which is light.
|
|
28
|
+
- **`RENDER_FAILED`.** An error page paints as well as any other, so a capture of "Space not found" came back as a valid
|
|
29
|
+
PNG and the thumbnail endpoint cached it for an hour. The browser service now refuses a page answering ≥ 400 with
|
|
30
|
+
`502 { error: 'RENDER_FAILED', status }`, and the HTTP client reports that as `RENDER_FAILED` instead of
|
|
31
|
+
`SCREENSHOT_FAILED`. The local client checks the navigation's status the same way.
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Updated dependencies
|
|
36
|
+
- @plitzi/plitzi-sdk@0.35.0
|
|
37
|
+
- @plitzi/sdk-elements@0.35.0
|
|
38
|
+
- @plitzi/sdk-interactions@0.35.0
|
|
39
|
+
- @plitzi/sdk-schema@0.35.0
|
|
40
|
+
- @plitzi/sdk-server@0.35.0
|
|
41
|
+
- @plitzi/sdk-shared@0.35.0
|
|
42
|
+
- @plitzi/sdk-style@0.35.0
|
|
43
|
+
|
|
3
44
|
## 0.34.1
|
|
4
45
|
|
|
5
46
|
### 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
|
-
|
|
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
|
-
|
|
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)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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.
|
|
64
|
+
version: "0.35.1"
|
|
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.
|
|
3
|
+
"version": "0.35.1",
|
|
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
|
-
"@plitzi/sdk-elements": "0.
|
|
35
|
-
"@plitzi/sdk-interactions": "0.
|
|
36
|
-
"@plitzi/sdk-schema": "0.
|
|
37
|
-
"@plitzi/sdk-server": "0.
|
|
38
|
-
"@plitzi/sdk-shared": "0.
|
|
39
|
-
"@plitzi/sdk-style": "0.
|
|
33
|
+
"@plitzi/plitzi-sdk": "0.35.1",
|
|
34
|
+
"@plitzi/sdk-elements": "0.35.1",
|
|
35
|
+
"@plitzi/sdk-interactions": "0.35.1",
|
|
36
|
+
"@plitzi/sdk-schema": "0.35.1",
|
|
37
|
+
"@plitzi/sdk-server": "0.35.1",
|
|
38
|
+
"@plitzi/sdk-shared": "0.35.1",
|
|
39
|
+
"@plitzi/sdk-style": "0.35.1",
|
|
40
40
|
"ejs": "^6.0.1",
|
|
41
41
|
"esbuild": "^0.28.2",
|
|
42
42
|
"zod": "^4.6.4"
|