@runsnative/mcp-server 0.1.1 → 0.1.3

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.
@@ -1,4 +1,13 @@
1
- import sharp from 'sharp';
1
+ async function loadSharp() {
2
+ try {
3
+ // sharp is CJS: under ESM dynamic import the callable is mod.default.
4
+ const mod = (await import('sharp'));
5
+ return mod.default;
6
+ }
7
+ catch {
8
+ return null;
9
+ }
10
+ }
2
11
  const MAX_PIXELS = 10_000;
3
12
  const MAX_ITER = 20;
4
13
  function toHex(r, g, b) {
@@ -11,6 +20,10 @@ function sqDist(ar, ag, ab, br, bg, bb) {
11
20
  }
12
21
  export async function extractImageColors(buffer, sourceType, k = 5) {
13
22
  const extractedAt = new Date().toISOString();
23
+ const sharp = await loadSharp();
24
+ if (sharp === null) {
25
+ throw new Error('sharp is not installed — image color extraction requires it.');
26
+ }
14
27
  const { data, info } = await sharp(buffer)
15
28
  .flatten({ background: '#ffffff' })
16
29
  .removeAlpha()
@@ -1,4 +1,12 @@
1
- import { chromium } from 'playwright';
1
+ export async function loadChromium() {
2
+ try {
3
+ const playwright = await import('playwright');
4
+ return playwright.chromium;
5
+ }
6
+ catch {
7
+ return null;
8
+ }
9
+ }
2
10
  const VIEWPORT = { width: 1280, height: 800 };
3
11
  export async function fetchAndRender(url) {
4
12
  let parsed;
@@ -11,6 +19,17 @@ export async function fetchAndRender(url) {
11
19
  if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
12
20
  return { ok: false, error: { code: 'FETCH_ERROR', message: `Unsupported scheme: ${parsed.protocol}`, url } };
13
21
  }
22
+ const chromium = await loadChromium();
23
+ if (chromium === null) {
24
+ return {
25
+ ok: false,
26
+ error: {
27
+ code: 'FETCH_ERROR',
28
+ message: 'playwright is not installed — infer_brand_theme requires it. Install playwright, or use infer_theme for HTML-only analysis.',
29
+ url,
30
+ },
31
+ };
32
+ }
14
33
  const browser = await chromium.launch({ headless: true });
15
34
  try {
16
35
  const page = await browser.newPage();
@@ -1,8 +1,12 @@
1
- import { chromium } from 'playwright';
1
+ import { loadChromium } from './page-fetcher.js';
2
2
  const SAMPLE_SELECTORS = 'body,h1,h2,h3,h4,h5,h6,p,a,button,input,select,textarea,' +
3
3
  'div,span,header,footer,nav,main,section,article,aside,ul,ol,li';
4
4
  const MAX_ELEMENTS = 200;
5
5
  export async function extractStyles(snapshot) {
6
+ const chromium = await loadChromium();
7
+ if (chromium === null) {
8
+ throw new Error('playwright is not installed — style extraction requires it.');
9
+ }
6
10
  const browser = await chromium.launch({ headless: true });
7
11
  try {
8
12
  const page = await browser.newPage();
package/package.json CHANGED
@@ -1,36 +1,37 @@
1
- {
2
- "name": "@runsnative/mcp-server",
3
- "version": "0.1.1",
4
- "type": "module",
5
- "files": [
6
- "dist/"
7
- ],
8
- "publishConfig": {
9
- "access": "public"
10
- },
11
- "engines": {
12
- "node": ">=18"
13
- },
14
- "bin": {
15
- "runsnative-mcp": "./dist/index.js"
16
- },
17
- "scripts": {
18
- "build": "tsc",
19
- "dev": "tsc --watch",
20
- "start": "node dist/index.js",
21
- "http-server": "node dist/http-server.js",
22
- "validate": "node dist/test/validate.js",
23
- "test": "vitest run"
24
- },
25
- "dependencies": {
26
- "@modelcontextprotocol/sdk": "^1.0.0"
27
- },
28
- "devDependencies": {
29
- "@types/node": "^25.6.0",
30
- "playwright": "^1.58.2",
31
- "sharp": "^0.33.0",
32
- "typescript": "^5.5.3",
33
- "vitest": "^4.1.2",
34
- "zod": "*"
35
- }
36
- }
1
+ {
2
+ "name": "@runsnative/mcp-server",
3
+ "version": "0.1.3",
4
+ "type": "module",
5
+ "files": [
6
+ "dist/"
7
+ ],
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "engines": {
12
+ "node": ">=18"
13
+ },
14
+ "bin": {
15
+ "runsnative-mcp": "./dist/index.js"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "dev": "tsc --watch",
20
+ "start": "node dist/index.js",
21
+ "http-server": "node dist/http-server.js",
22
+ "validate": "node dist/test/validate.js",
23
+ "test": "vitest run"
24
+ },
25
+ "dependencies": {
26
+ "@modelcontextprotocol/sdk": "^1.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^25.6.0",
30
+ "playwright": "^1.58.2",
31
+ "sharp": "^0.33.0",
32
+ "typescript": "^5.5.3",
33
+ "vitest": "^4.1.2",
34
+ "zod": "*"
35
+ },
36
+ "license": "MIT"
37
+ }