webcake-landing-mcp 1.6.2 → 1.8.0
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/README.md +17 -4
- package/README.vi.md +16 -4
- package/dist/auth/oauth-server.js +18 -1
- package/dist/auth/renew.js +48 -0
- package/dist/changelog.json +14 -14
- package/dist/http.js +15 -11
- package/dist/index.js +1 -1
- package/dist/install.js +96 -47
- package/dist/persistence/config.js +14 -1
- package/dist/server.js +2 -0
- package/dist/smoke.js +26 -1
- package/dist/web-guide-scene.js +617 -0
- package/dist/web-guide.js +15 -64
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,19 +101,32 @@ Pick **one**. Both hand your AI tool (Claude, Cursor, …) the full Webcake land
|
|
|
101
101
|
Zero install, always the latest version, needs Node.js 18+. **One line** grabs your token *and* writes the IDE config:
|
|
102
102
|
|
|
103
103
|
```bash
|
|
104
|
-
#
|
|
104
|
+
# Opens the browser — click Connect, your installed IDEs are configured (prod)
|
|
105
105
|
npx -y webcake-landing-mcp install
|
|
106
106
|
|
|
107
|
-
#
|
|
108
|
-
npx -y webcake-landing-mcp install --
|
|
107
|
+
# Developers only — step by step: environment, login or JWT, org, IDE(s)
|
|
108
|
+
npx -y webcake-landing-mcp install --dev
|
|
109
|
+
|
|
110
|
+
# Scripts and CI — every supported IDE, even ones not installed yet
|
|
111
|
+
npx -y webcake-landing-mcp install --ide all --jwt <your-jwt>
|
|
109
112
|
|
|
110
113
|
# Remove the server from every IDE config
|
|
111
114
|
npx -y webcake-landing-mcp uninstall
|
|
112
115
|
```
|
|
113
116
|
|
|
117
|
+
**`install` asks nothing.** It connects to production, opens your browser so you can click *Connect*, then adds the server
|
|
118
|
+
to every AI app it finds on this computer. Your other servers are kept, and any config file it changes is backed up next to
|
|
119
|
+
the original as `<file>.webcake-landing-backup`. No AI app found? It says so and exits with an error: install one and run it again,
|
|
120
|
+
or name it with `--ide`.
|
|
121
|
+
|
|
122
|
+
Need staging or local? `--dev` opens the step-by-step wizard, or skip it with `--env staging` / `--env local`.
|
|
123
|
+
|
|
124
|
+
> **Installed with an older version?** Run `install` again. Older versions wrote VS Code's config under the wrong key, so the
|
|
125
|
+
> server never appeared there, and registered Claude Code for the current folder only.
|
|
126
|
+
|
|
114
127
|
It writes a `webcake-landing` entry into the right config file for each target: `claude-desktop`,
|
|
115
128
|
`claude-code`, `cursor`, `windsurf`, `augment` (VS Code), `codex`, `antigravity`, `gemini` (Gemini CLI),
|
|
116
|
-
`cline`, `kiro`, `opencode`, or `all`. Flags: `--ide`, `--env`, `--jwt`, `--org-id`,
|
|
129
|
+
`cline`, `kiro`, `opencode`, or `all`. Flags: `--dev`, `--ide`, `--env`, `--jwt`, `--org-id`,
|
|
117
130
|
`--api-base`/`--app-base`, `--npx`/`--local`, `-y` — see `install --help`.
|
|
118
131
|
|
|
119
132
|
Just want to run the server (configure by hand later)? `npx -y webcake-landing-mcp`
|
package/README.vi.md
CHANGED
|
@@ -101,19 +101,31 @@ Chọn **một** trong hai. Cả hai đều đưa toàn bộ bộ công cụ d
|
|
|
101
101
|
Không cần cài đặt, luôn bản mới nhất, cần Node.js 18+. **Một dòng** vừa lấy token vừa ghi cấu hình IDE:
|
|
102
102
|
|
|
103
103
|
```bash
|
|
104
|
-
#
|
|
104
|
+
# Mở trình duyệt — bấm Kết nối, các IDE trên máy được cấu hình tự động (prod)
|
|
105
105
|
npx -y webcake-landing-mcp install
|
|
106
106
|
|
|
107
|
-
#
|
|
108
|
-
npx -y webcake-landing-mcp install --
|
|
107
|
+
# Chỉ dành cho dev — từng bước: môi trường, đăng nhập hoặc JWT, org, IDE
|
|
108
|
+
npx -y webcake-landing-mcp install --dev
|
|
109
|
+
|
|
110
|
+
# Script và CI — mọi IDE được hỗ trợ, kể cả IDE chưa cài
|
|
111
|
+
npx -y webcake-landing-mcp install --ide all --jwt <your-jwt>
|
|
109
112
|
|
|
110
113
|
# Gỡ server khỏi mọi cấu hình IDE
|
|
111
114
|
npx -y webcake-landing-mcp uninstall
|
|
112
115
|
```
|
|
113
116
|
|
|
117
|
+
**`install` không hỏi gì cả.** Lệnh kết nối tới production, mở trình duyệt để bạn bấm *Kết nối*, rồi thêm server vào mọi ứng dụng AI
|
|
118
|
+
tìm thấy trên máy. Các server khác của bạn được giữ nguyên, và file cấu hình nào bị đổi đều có bản sao lưu ngay cạnh, tên
|
|
119
|
+
`<file>.webcake-landing-backup`. Không tìm thấy ứng dụng AI nào? Lệnh báo rõ và thoát với lỗi: hãy cài một ứng dụng rồi chạy lại, hoặc chỉ định bằng `--ide`.
|
|
120
|
+
|
|
121
|
+
Cần staging hoặc local? `--dev` mở các bước hỏi lần lượt, hoặc bỏ qua bằng `--env staging` / `--env local`.
|
|
122
|
+
|
|
123
|
+
> **Đã cài bằng bản cũ?** Hãy chạy lại `install`. Bản cũ ghi cấu hình VS Code sai khóa nên server không hiện trong VS Code, và chỉ đăng ký
|
|
124
|
+
> Claude Code cho đúng thư mục lúc chạy lệnh.
|
|
125
|
+
|
|
114
126
|
Nó ghi entry `webcake-landing` vào đúng file cấu hình của từng IDE: `claude-desktop`, `claude-code`,
|
|
115
127
|
`cursor`, `windsurf`, `augment` (VS Code), `codex`, `antigravity`, `gemini` (Gemini CLI), `cline`,
|
|
116
|
-
`kiro`, `opencode`, hoặc `all`. Cờ: `--ide`, `--env`, `--jwt`, `--org-id`, `--api-base`/`--app-base`,
|
|
128
|
+
`kiro`, `opencode`, hoặc `all`. Cờ: `--dev`, `--ide`, `--env`, `--jwt`, `--org-id`, `--api-base`/`--app-base`,
|
|
117
129
|
`--npx`/`--local`, `-y` — xem `install --help`.
|
|
118
130
|
|
|
119
131
|
Chỉ muốn chạy server (tự cấu hình sau)? `npx -y webcake-landing-mcp`
|
|
@@ -29,6 +29,20 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import { randomBytes, createHash } from "node:crypto";
|
|
31
31
|
import { getPg, ensureOAuthSchema } from "../persistence/postgres.js";
|
|
32
|
+
import { jwtExpired } from "../persistence/config.js";
|
|
33
|
+
// ---- Dead Webcake sessions -------------------------------------------------
|
|
34
|
+
// The OAuth tokens outlive the Webcake JWT they wrap. Once that JWT is expired (or the
|
|
35
|
+
// backend rejected it), refreshing would just re-issue the dead JWT; refusing it makes the
|
|
36
|
+
// client restart the full flow, i.e. open the Connect page again.
|
|
37
|
+
// ponytail: in-memory set, per process; move to Postgres/Redis if the server is scaled out.
|
|
38
|
+
const deadJwts = new Set();
|
|
39
|
+
export function markJwtDead(jwt) {
|
|
40
|
+
if (jwt)
|
|
41
|
+
deadJwts.add(jwt);
|
|
42
|
+
}
|
|
43
|
+
export function isDeadJwt(jwt) {
|
|
44
|
+
return !!jwt && (deadJwts.has(jwt) || jwtExpired(jwt));
|
|
45
|
+
}
|
|
32
46
|
// ---- TTLs (override via env where useful) ---------------------------------
|
|
33
47
|
const TEN_MIN = 10 * 60 * 1000;
|
|
34
48
|
const ACCESS_TTL = Number(process.env.WEBCAKE_OAUTH_ACCESS_TTL_MS) || 60 * 60 * 1000; // 1h
|
|
@@ -373,6 +387,9 @@ export async function exchangeToken(p) {
|
|
|
373
387
|
if (!r) {
|
|
374
388
|
return { ok: false, status: 400, error: "invalid_grant", error_description: "Unknown or expired refresh token." };
|
|
375
389
|
}
|
|
390
|
+
if (isDeadJwt(r.ljwt)) {
|
|
391
|
+
return { ok: false, status: 400, error: "invalid_grant", error_description: "Webcake session expired — sign in again (Connect)." };
|
|
392
|
+
}
|
|
376
393
|
return { ok: true, body: await issueTokens(store, r.ljwt, r.client_id, r.scope) };
|
|
377
394
|
}
|
|
378
395
|
return { ok: false, status: 400, error: "unsupported_grant_type", error_description: "grant_type must be authorization_code or refresh_token." };
|
|
@@ -383,7 +400,7 @@ export async function resolveAccessToken(accessToken) {
|
|
|
383
400
|
if (!accessToken)
|
|
384
401
|
return undefined;
|
|
385
402
|
const a = await (await getStore()).getAccess(accessToken);
|
|
386
|
-
return a
|
|
403
|
+
return a && !isDeadJwt(a.ljwt) ? a.ljwt : undefined;
|
|
387
404
|
}
|
|
388
405
|
/** Revoke an access or refresh token (best-effort; for /revoke). */
|
|
389
406
|
export async function revokeToken(t) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { configFromHeaders, jwtExpired, readConfig } from "../persistence/config.js";
|
|
2
|
+
import { markJwtDead } from "./oauth-server.js";
|
|
3
|
+
import { runLogin } from "./login.js";
|
|
4
|
+
// One browser Connect at a time; after a failed/abandoned one, wait before reopening so a
|
|
5
|
+
// looping agent doesn't spam tabs. ponytail: process-wide, fine for one stdio user.
|
|
6
|
+
let renewing = null;
|
|
7
|
+
let lastFail = 0;
|
|
8
|
+
export function renewInBrowser() {
|
|
9
|
+
if (!renewing && Date.now() - lastFail > 120_000) {
|
|
10
|
+
console.error("[webcake-landing] Token hết hạn — mở trình duyệt để Kết nối lại…");
|
|
11
|
+
renewing = runLogin([])
|
|
12
|
+
.then(() => true)
|
|
13
|
+
.catch((e) => {
|
|
14
|
+
lastFail = Date.now();
|
|
15
|
+
console.error("[webcake-landing] gia hạn token thất bại:", e?.message || e);
|
|
16
|
+
return false;
|
|
17
|
+
})
|
|
18
|
+
.finally(() => {
|
|
19
|
+
renewing = null;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return renewing ?? Promise.resolve(false);
|
|
23
|
+
}
|
|
24
|
+
/** Every backend call reports auth failures as "Backend returned 401…" in the tool result. */
|
|
25
|
+
export function isUnauthorized(result) {
|
|
26
|
+
return !!result?.content?.some((c) => typeof c?.text === "string" && /Backend returned 401\b/.test(c.text));
|
|
27
|
+
}
|
|
28
|
+
const jwtOf = (extra) => readConfig(configFromHeaders(extra?.requestInfo?.headers)).config?.jwt;
|
|
29
|
+
export function renewAuthOnExpiry(server, stdio) {
|
|
30
|
+
const tool = server.tool.bind(server);
|
|
31
|
+
server.tool = (...args) => {
|
|
32
|
+
const handler = args[args.length - 1];
|
|
33
|
+
args[args.length - 1] = async (...call) => {
|
|
34
|
+
const extra = call[call.length - 1];
|
|
35
|
+
if (stdio && jwtExpired(jwtOf(extra)))
|
|
36
|
+
await renewInBrowser();
|
|
37
|
+
const result = await handler(...call);
|
|
38
|
+
if (!isUnauthorized(result))
|
|
39
|
+
return result;
|
|
40
|
+
if (!stdio) {
|
|
41
|
+
markJwtDead(jwtOf(extra));
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
return (await renewInBrowser()) ? handler(...call) : result;
|
|
45
|
+
};
|
|
46
|
+
return tool(...args);
|
|
47
|
+
};
|
|
48
|
+
}
|
package/dist/changelog.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "1.8.0",
|
|
4
|
+
"d": "19/11/2026",
|
|
5
|
+
"type": "Added",
|
|
6
|
+
"en": "The stdio server now detects an expired or backend-rejected WEBCAKE_JWT and automatically reopens the browser Connect page, then retries the failing…",
|
|
7
|
+
"vi": "Server stdio nay tự phát hiện WEBCAKE_JWT đã hết hạn hoặc bị backend từ chối, tự mở lại trang Connect trên trình duyệt, rồi thử lại tool bị lỗi một…"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"v": "1.7.0",
|
|
11
|
+
"d": "05/11/2026",
|
|
12
|
+
"type": "Added",
|
|
13
|
+
"en": "install gained a --dev flag that reopens the old step-by-step wizard (choose environment, log in or paste a JWT, pick an organization, pick IDEs)…",
|
|
14
|
+
"vi": "install nay có thêm cờ --dev để mở lại wizard từng bước kiểu cũ (chọn environment, đăng nhập hoặc dán JWT, chọn organization, chọn IDE) cho ai vẫn…"
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"v": "1.6.2",
|
|
4
18
|
"d": "27/10/2026",
|
|
@@ -26,19 +40,5 @@
|
|
|
26
40
|
"type": "Fixed",
|
|
27
41
|
"en": "The HTTP server now answers HEAD requests the same way it answers GET on every public read-only route (/privacy, /privacy-policy, /terms, /tos,…",
|
|
28
42
|
"vi": "HTTP server nay trả lời request HEAD giống như GET trên mọi route công khai chỉ-đọc (/privacy, /privacy-policy, /terms, /tos, /favicon.ico,…"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"v": "1.5.10",
|
|
32
|
-
"d": "13/10/2026",
|
|
33
|
-
"type": "Changed",
|
|
34
|
-
"en": "Rewrote every tool and parameter description (new_element, new_page_skeleton, validate_page, layout, ingest_html, ingest_url, search_images,…",
|
|
35
|
-
"vi": "Viết lại toàn bộ mô tả tool và tham số (new_element, new_page_skeleton, validate_page, layout, ingest_html, ingest_url, search_images, get_icon_svg,…"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"v": "1.5.9",
|
|
39
|
-
"d": "13/10/2026",
|
|
40
|
-
"type": "Fixed",
|
|
41
|
-
"en": "The HTTP server now answers a request carrying an unknown mcp-session-id with 404 instead of 400, so clients re-initialize instead of staying stuck…",
|
|
42
|
-
"vi": "HTTP server nay trả về 404 (thay vì 400) khi nhận request với mcp-session-id không xác định, giúp client tự re-initialize thay vì bị kẹt ở trạng…"
|
|
43
43
|
}
|
|
44
44
|
]
|
package/dist/http.js
CHANGED
|
@@ -24,7 +24,7 @@ import { searchPexels, resolvePexelsKey } from "./persistence/pexels-client.js";
|
|
|
24
24
|
import { captureWithPlaywright, captureTilesWithPlaywright, isAllowedScreenshotUrl } from "./persistence/screenshot-playwright.js";
|
|
25
25
|
import { resolveEnv, ENVIRONMENTS, stripTrailingSlash } from "./persistence/config.js";
|
|
26
26
|
import { buildConnectUrl } from "./auth/login.js";
|
|
27
|
-
import { registerClient, startAuthorize, completeAuthorize, exchangeToken, resolveAccessToken, revokeToken, authServerMetadata, protectedResourceMetadata, } from "./auth/oauth-server.js";
|
|
27
|
+
import { registerClient, startAuthorize, completeAuthorize, exchangeToken, resolveAccessToken, isDeadJwt, revokeToken, authServerMetadata, protectedResourceMetadata, } from "./auth/oauth-server.js";
|
|
28
28
|
const MCP_PATH = "/mcp";
|
|
29
29
|
const IMAGES_PATH = "/api/images/search";
|
|
30
30
|
const RENDER_SCREENSHOT_PATH = "/api/render/screenshot";
|
|
@@ -474,24 +474,28 @@ export async function startHttpServer(port) {
|
|
|
474
474
|
// Accept credentials via ?jwt=/?api_base=/... (for clients that can't set headers).
|
|
475
475
|
applyQueryAuth(req);
|
|
476
476
|
// OAuth access token → resolve to the user's landing JWT and inject it as the
|
|
477
|
-
// normal x-webcake-jwt header, so persistence/config.ts is unchanged.
|
|
478
|
-
//
|
|
477
|
+
// normal x-webcake-jwt header, so persistence/config.ts is unchanged. It WINS over a
|
|
478
|
+
// ?jwt= / x-webcake-jwt: a Bearer from our OAuth flow is what the last Connect issued,
|
|
479
|
+
// so it's the renewed credential when the URL still carries an old, expired JWT.
|
|
479
480
|
const bearer = bearerFrom(req);
|
|
480
481
|
const oauthLjwt = await resolveAccessToken(bearer);
|
|
481
|
-
if (oauthLjwt
|
|
482
|
+
if (oauthLjwt) {
|
|
482
483
|
req.headers["x-webcake-jwt"] = oauthLjwt;
|
|
483
484
|
req.rawHeaders.push("x-webcake-jwt", oauthLjwt);
|
|
484
485
|
}
|
|
485
|
-
// Enforcement
|
|
486
|
-
//
|
|
487
|
-
//
|
|
488
|
-
//
|
|
489
|
-
|
|
486
|
+
// Enforcement: no credential, or an expired/rejected Webcake JWT, gets a 401 +
|
|
487
|
+
// WWW-Authenticate so Claude/ChatGPT (re)open the Connect page by themselves. In
|
|
488
|
+
// enforced mode a raw JWT must use x-webcake-jwt / ?jwt=, since Bearer is reserved
|
|
489
|
+
// for OAuth access tokens.
|
|
490
|
+
const given = req.headers["x-webcake-jwt"];
|
|
491
|
+
const dead = isDeadJwt(Array.isArray(given) ? given[0] : given);
|
|
492
|
+
if (OAUTH_ENFORCED && (given == null || dead)) {
|
|
490
493
|
res.writeHead(401, {
|
|
491
|
-
"www-authenticate": `Bearer resource_metadata="${publicBase(req)}${WELL_KNOWN_PR}"`,
|
|
494
|
+
"www-authenticate": `Bearer error="invalid_token", resource_metadata="${publicBase(req)}${WELL_KNOWN_PR}"`,
|
|
492
495
|
"content-type": "application/json",
|
|
493
496
|
});
|
|
494
|
-
|
|
497
|
+
const why = dead ? "Webcake session expired — reconnect (Connect) to renew it." : "Authentication required — connect via OAuth.";
|
|
498
|
+
return res.end(JSON.stringify({ error: "invalid_token", error_description: why }));
|
|
495
499
|
}
|
|
496
500
|
const sidHeader = req.headers["mcp-session-id"];
|
|
497
501
|
const sessionId = Array.isArray(sidHeader) ? sidHeader[0] : sidHeader;
|
package/dist/index.js
CHANGED
|
@@ -58,7 +58,7 @@ function printHelp() {
|
|
|
58
58
|
"",
|
|
59
59
|
"Commands:",
|
|
60
60
|
" (none) start the stdio MCP server (use this in IDE configs)",
|
|
61
|
-
" install
|
|
61
|
+
" install connect to prod via the browser and configure your IDE(s) (--dev: wizard with env choice)",
|
|
62
62
|
" uninstall remove the server from your IDE configs",
|
|
63
63
|
" login grab your Webcake token via the browser (saved to ~/.webcake-landing-mcp/auth.json)",
|
|
64
64
|
" serve [--port N] run the remote Streamable-HTTP server (default port 8787; or PORT env)",
|
package/dist/install.js
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
* to clone anything.
|
|
9
9
|
*
|
|
10
10
|
* Two modes:
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
11
|
+
* - Default (no --ide flag, TTY or not): no questions — prod, browser connect, every detected IDE.
|
|
12
|
+
* - --dev on a TTY: the step-by-step wizard (environment, login/JWT, org, IDEs).
|
|
13
|
+
* - Flag-driven (--ide present): non-interactive, no browser.
|
|
13
14
|
*
|
|
14
15
|
* The launch command written into configs is `npx -y webcake-landing-mcp` when
|
|
15
16
|
* this installer itself was run via npx (path-independent), or
|
|
16
17
|
* `node <abs path>/dist/index.js` when run from a local clone. Override with
|
|
17
18
|
* --npx / --local.
|
|
18
19
|
*/
|
|
19
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
20
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
20
21
|
import { homedir, platform } from "node:os";
|
|
21
22
|
import { dirname, join } from "node:path";
|
|
22
23
|
import { fileURLToPath } from "node:url";
|
|
@@ -59,6 +60,8 @@ function parseArgs(argv) {
|
|
|
59
60
|
o.npx = true;
|
|
60
61
|
else if (a === "--local")
|
|
61
62
|
o.local = true;
|
|
63
|
+
else if (a === "--dev")
|
|
64
|
+
o.dev = true;
|
|
62
65
|
else if (is("--ide"))
|
|
63
66
|
o.ide = next();
|
|
64
67
|
else if (is("--api-base"))
|
|
@@ -96,7 +99,20 @@ function resolveLaunch(o) {
|
|
|
96
99
|
return { command: "npx", args: ["-y", PKG] };
|
|
97
100
|
}
|
|
98
101
|
// ── JSON config (Claude Desktop, Claude Code, Cursor, Windsurf, VS Code) ──────
|
|
99
|
-
|
|
102
|
+
// These are the user's own files: an unchanged one isn't touched, a changed one keeps
|
|
103
|
+
// its previous version alongside so the install can be undone.
|
|
104
|
+
function writeConfig(file, next) {
|
|
105
|
+
if (existsSync(file)) {
|
|
106
|
+
if (readFileSync(file, "utf8") === next)
|
|
107
|
+
return;
|
|
108
|
+
const backup = `${file}.${NAME}-backup`;
|
|
109
|
+
copyFileSync(file, backup);
|
|
110
|
+
info(`Previous file saved as ${backup}`);
|
|
111
|
+
}
|
|
112
|
+
writeFileSync(file, next);
|
|
113
|
+
}
|
|
114
|
+
// VS Code is the one client that keeps servers under `servers` (and requires `type`).
|
|
115
|
+
function mergeJson(file, launch, env, key = "mcpServers") {
|
|
100
116
|
mkdirSync(dirname(file), { recursive: true });
|
|
101
117
|
let cfg = {};
|
|
102
118
|
if (existsSync(file)) {
|
|
@@ -111,14 +127,15 @@ function mergeJson(file, launch, env) {
|
|
|
111
127
|
}
|
|
112
128
|
}
|
|
113
129
|
}
|
|
114
|
-
if (typeof cfg
|
|
115
|
-
cfg
|
|
116
|
-
cfg
|
|
130
|
+
if (typeof cfg[key] !== "object" || !cfg[key])
|
|
131
|
+
cfg[key] = {};
|
|
132
|
+
cfg[key][NAME] = {
|
|
133
|
+
...(key === "servers" ? { type: "stdio" } : {}),
|
|
117
134
|
command: launch.command,
|
|
118
135
|
args: launch.args,
|
|
119
136
|
...(Object.keys(env).length ? { env } : {}),
|
|
120
137
|
};
|
|
121
|
-
|
|
138
|
+
writeConfig(file, JSON.stringify(cfg, null, 2) + "\n");
|
|
122
139
|
return true;
|
|
123
140
|
}
|
|
124
141
|
// ── OpenCode config (its own shape, not mcpServers) ─────────────────────────
|
|
@@ -146,7 +163,7 @@ function mergeOpencodeJson(file, launch, env) {
|
|
|
146
163
|
enabled: true,
|
|
147
164
|
...(Object.keys(env).length ? { environment: env } : {}),
|
|
148
165
|
};
|
|
149
|
-
|
|
166
|
+
writeConfig(file, JSON.stringify(cfg, null, 2) + "\n");
|
|
150
167
|
return true;
|
|
151
168
|
}
|
|
152
169
|
// ── TOML config (Codex) ──────────────────────────────────────────────────────
|
|
@@ -154,16 +171,15 @@ function configureCodex(launch, env) {
|
|
|
154
171
|
const dir = join(HOME, ".codex");
|
|
155
172
|
const cfg = join(dir, "config.toml");
|
|
156
173
|
mkdirSync(dir, { recursive: true });
|
|
157
|
-
const argsToml = launch.args.map((a) =>
|
|
174
|
+
const argsToml = launch.args.map((a) => JSON.stringify(a)).join(", ");
|
|
158
175
|
const envParts = Object.entries(env)
|
|
159
|
-
.map(([k, v]) =>
|
|
176
|
+
.map(([k, v]) => `${JSON.stringify(k)} = ${JSON.stringify(v)}`)
|
|
160
177
|
.join(", ");
|
|
161
178
|
const envLine = envParts ? `env = { ${envParts} }\n` : "";
|
|
162
|
-
const block = `\n[mcp_servers.${NAME}]\ncommand =
|
|
179
|
+
const block = `\n[mcp_servers.${NAME}]\ncommand = ${JSON.stringify(launch.command)}\nargs = [${argsToml}]\n${envLine}`;
|
|
163
180
|
let content = existsSync(cfg) ? readFileSync(cfg, "utf8") : "# Webcake Landing MCP\n";
|
|
164
181
|
content = content.replace(new RegExp(`\\n?\\[mcp_servers\\.${NAME}\\][\\s\\S]*?(?=\\n\\[|$)`), "");
|
|
165
|
-
|
|
166
|
-
writeFileSync(cfg, content);
|
|
182
|
+
writeConfig(cfg, content.trimEnd() + "\n" + block);
|
|
167
183
|
}
|
|
168
184
|
// ── IDE config-file locations ────────────────────────────────────────────────
|
|
169
185
|
function claudeDesktopPath() {
|
|
@@ -196,10 +212,7 @@ function vscodeUserDir() {
|
|
|
196
212
|
const mac = join(HOME, "Library", "Application Support", "Code", "User");
|
|
197
213
|
if (existsSync(mac))
|
|
198
214
|
return mac;
|
|
199
|
-
|
|
200
|
-
if (existsSync(lin))
|
|
201
|
-
return lin;
|
|
202
|
-
return join(HOME, ".vscode");
|
|
215
|
+
return join(HOME, ".config", "Code", "User");
|
|
203
216
|
}
|
|
204
217
|
const vscodeUserPath = () => join(vscodeUserDir(), "mcp.json");
|
|
205
218
|
const cursorPath = () => join(HOME, ".cursor", "mcp.json");
|
|
@@ -220,13 +233,31 @@ function hasClaudeCli() {
|
|
|
220
233
|
});
|
|
221
234
|
return probe.status === 0;
|
|
222
235
|
}
|
|
236
|
+
// Installed = its config dir exists (Claude Code: also the CLI on PATH), so a normal
|
|
237
|
+
// install needs no IDE question and never creates config for an app the user lacks.
|
|
238
|
+
function detectIdes() {
|
|
239
|
+
const marks = {
|
|
240
|
+
"claude-desktop": dirname(claudeDesktopPath()),
|
|
241
|
+
"claude-code": claudeJsonPath(),
|
|
242
|
+
cursor: join(HOME, ".cursor"),
|
|
243
|
+
windsurf: join(HOME, ".codeium", "windsurf"),
|
|
244
|
+
augment: vscodeUserDir(),
|
|
245
|
+
codex: join(HOME, ".codex"),
|
|
246
|
+
antigravity: dirname(antigravityPath()),
|
|
247
|
+
gemini: geminiPath(),
|
|
248
|
+
cline: dirname(dirname(clinePath())),
|
|
249
|
+
kiro: join(HOME, ".kiro"),
|
|
250
|
+
opencode: dirname(opencodePath()),
|
|
251
|
+
};
|
|
252
|
+
return Object.keys(marks).filter((id) => existsSync(marks[id]) || (id === "claude-code" && hasClaudeCli()));
|
|
253
|
+
}
|
|
223
254
|
// ── per-IDE configure ────────────────────────────────────────────────────────
|
|
224
255
|
function configureClaudeCode(launch, env) {
|
|
225
256
|
info("Claude Code…");
|
|
226
257
|
if (hasClaudeCli()) {
|
|
227
258
|
spawnSync("claude", ["mcp", "remove", NAME], { stdio: "ignore" });
|
|
228
259
|
const envFlags = Object.entries(env).flatMap(([k, v]) => ["-e", `${k}=${v}`]);
|
|
229
|
-
const r = spawnSync("claude", ["mcp", "add", NAME, ...envFlags, "--", launch.command, ...launch.args], { stdio: "inherit" });
|
|
260
|
+
const r = spawnSync("claude", ["mcp", "add", "--scope", "user", NAME, ...envFlags, "--", launch.command, ...launch.args], { stdio: "inherit" });
|
|
230
261
|
if (r.status === 0) {
|
|
231
262
|
ok("Claude Code configured via CLI — verify: claude mcp list");
|
|
232
263
|
return;
|
|
@@ -255,7 +286,7 @@ function configureWindsurf(launch, env) {
|
|
|
255
286
|
}
|
|
256
287
|
function configureAugment(launch, env) {
|
|
257
288
|
info("Augment / VS Code…");
|
|
258
|
-
if (mergeJson(vscodeUserPath(), launch, env))
|
|
289
|
+
if (mergeJson(vscodeUserPath(), launch, env, "servers"))
|
|
259
290
|
ok(`VS Code configured (${vscodeUserPath()})`);
|
|
260
291
|
}
|
|
261
292
|
function configureCodexIde(launch, env) {
|
|
@@ -327,10 +358,17 @@ function runConfigure(ides, launch, env) {
|
|
|
327
358
|
const targets = set.has("all") ? Object.keys(CONFIGURATORS) : [...set];
|
|
328
359
|
for (const id of targets) {
|
|
329
360
|
const configure = CONFIGURATORS[id];
|
|
330
|
-
if (configure)
|
|
331
|
-
configure(launch, env);
|
|
332
|
-
else
|
|
361
|
+
if (!configure) {
|
|
333
362
|
warn(`Unknown IDE: ${id}`);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
// One broken client must not leave the others unconfigured.
|
|
366
|
+
try {
|
|
367
|
+
configure(launch, env);
|
|
368
|
+
}
|
|
369
|
+
catch (e) {
|
|
370
|
+
warn(`${id} skipped: ${e?.message ?? e}`);
|
|
371
|
+
}
|
|
334
372
|
}
|
|
335
373
|
}
|
|
336
374
|
// ── uninstall ────────────────────────────────────────────────────────────────
|
|
@@ -339,8 +377,10 @@ function removeFromJson(file) {
|
|
|
339
377
|
return;
|
|
340
378
|
try {
|
|
341
379
|
const cfg = JSON.parse(readFileSync(file, "utf8"));
|
|
342
|
-
|
|
343
|
-
|
|
380
|
+
const holders = [cfg.mcpServers, cfg.servers].filter((s) => s && s[NAME]);
|
|
381
|
+
if (holders.length) {
|
|
382
|
+
for (const s of holders)
|
|
383
|
+
delete s[NAME];
|
|
344
384
|
writeFileSync(file, JSON.stringify(cfg, null, 2) + "\n");
|
|
345
385
|
ok(`Cleaned ${file}`);
|
|
346
386
|
}
|
|
@@ -360,6 +400,7 @@ function uninstall() {
|
|
|
360
400
|
cursorPath(),
|
|
361
401
|
windsurfPath(),
|
|
362
402
|
vscodeUserPath(),
|
|
403
|
+
join(HOME, ".vscode", "mcp.json"), // older versions wrote here; nothing reads it
|
|
363
404
|
antigravityPath(),
|
|
364
405
|
geminiPath(),
|
|
365
406
|
clinePath(),
|
|
@@ -394,7 +435,8 @@ function printHelp() {
|
|
|
394
435
|
${c.bold}webcake-landing-mcp install${c.reset} — configure the MCP server in your IDE(s)
|
|
395
436
|
|
|
396
437
|
${c.bold}Usage${c.reset}
|
|
397
|
-
npx -y ${PKG} install #
|
|
438
|
+
npx -y ${PKG} install # opens the browser: click Connect, installed IDEs get configured (prod)
|
|
439
|
+
npx -y ${PKG} install --dev # step by step: pick environment, log in (or paste a JWT), org, IDEs
|
|
398
440
|
npx -y ${PKG} install --ide all # non-interactive, all IDEs (defaults to --env prod)
|
|
399
441
|
npx -y ${PKG} install --ide claude-code --env local --jwt <JWT>
|
|
400
442
|
npx -y ${PKG} uninstall # remove from every IDE config
|
|
@@ -402,6 +444,7 @@ ${c.bold}Usage${c.reset}
|
|
|
402
444
|
${c.bold}Flags${c.reset}
|
|
403
445
|
--ide <list> comma list: claude-desktop, claude-code, cursor, windsurf, augment,
|
|
404
446
|
codex, antigravity, gemini, cline, kiro, opencode, all
|
|
447
|
+
--dev developer wizard (asks environment, auth, org, IDEs)
|
|
405
448
|
--env <name> WEBCAKE_ENV: local | staging | prod (default prod) — sets the API + app base URLs
|
|
406
449
|
--jwt <token> WEBCAKE_JWT (account token; optional — or log in via the browser interactively)
|
|
407
450
|
--org-id <id> WEBCAKE_ORG_ID (optional default organization)
|
|
@@ -422,11 +465,12 @@ export async function runInstaller(argv) {
|
|
|
422
465
|
log(`\n${c.cyan}${c.bold}Webcake Landing MCP — installer${c.reset}`);
|
|
423
466
|
log(`${c.gray}Build & edit Webcake landing pages from a prompt.${c.reset}`);
|
|
424
467
|
const interactive = !o.ide && process.stdin.isTTY && process.stdout.isTTY;
|
|
468
|
+
const wizard = interactive && o.dev;
|
|
425
469
|
// 1) environment — one choice sets the API + app base URLs (replaces the old
|
|
426
470
|
// separate WEBCAKE_API_BASE / WEBCAKE_APP_BASE prompts). The global --env flag
|
|
427
471
|
// / WEBCAKE_ENV is already validated in index.ts (applyEnvFlag).
|
|
428
472
|
let envName = isEnvName(process.env.WEBCAKE_ENV) ? process.env.WEBCAKE_ENV : "prod";
|
|
429
|
-
if (
|
|
473
|
+
if (wizard && !isEnvName(process.env.WEBCAKE_ENV)) {
|
|
430
474
|
log(`\n${c.bold}1) Environment${c.reset} ${c.gray}(sets the Webcake API + app URLs)${c.reset}`);
|
|
431
475
|
log(` 1) prod ${c.gray}${ENVIRONMENTS.prod.apiBase}${c.reset} ${c.gray}(default)${c.reset}`);
|
|
432
476
|
log(` 2) staging ${c.gray}${ENVIRONMENTS.staging.apiBase}${c.reset}`);
|
|
@@ -440,14 +484,17 @@ export async function runInstaller(argv) {
|
|
|
440
484
|
// saved to ~/.webcake-landing-mcp/auth.json) or a pasted JWT. An explicit --jwt
|
|
441
485
|
// skips the prompt; a non-TTY falls back to the WEBCAKE_JWT env var (for scripted
|
|
442
486
|
// installs). Reference/validation tools work with no auth at all.
|
|
443
|
-
let jwt = o.jwt ?? "";
|
|
444
|
-
let authNote = jwt ? "JWT (from --jwt)" : "";
|
|
445
|
-
if (
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
487
|
+
let jwt = o.jwt ?? (wizard ? "" : process.env.WEBCAKE_JWT ?? "");
|
|
488
|
+
let authNote = o.jwt ? "JWT (from --jwt)" : "";
|
|
489
|
+
if (!o.ide && !jwt) {
|
|
490
|
+
let pick = "1";
|
|
491
|
+
if (wizard) {
|
|
492
|
+
log(`\n${c.bold}2) Authentication${c.reset} ${c.gray}(only needed to save pages to your account)${c.reset}`);
|
|
493
|
+
log(` 1) Log in via browser ${c.gray}(recommended — opens Webcake, saves a token)${c.reset}`);
|
|
494
|
+
log(` 2) Paste a JWT token`);
|
|
495
|
+
log(` 3) Skip for now ${c.gray}(reference/validation tools still work)${c.reset}`);
|
|
496
|
+
pick = (await ask(" Select [1]: ")).trim() || "1";
|
|
497
|
+
}
|
|
451
498
|
if (pick === "1") {
|
|
452
499
|
info(`Connecting to ${preset.appBase} …`);
|
|
453
500
|
try {
|
|
@@ -455,22 +502,20 @@ export async function runInstaller(argv) {
|
|
|
455
502
|
authNote = "browser login (saved to auth.json)";
|
|
456
503
|
}
|
|
457
504
|
catch (e) {
|
|
458
|
-
warn(`Login didn't complete (${e?.message ?? e}).
|
|
459
|
-
|
|
505
|
+
warn(`Login didn't complete (${e?.message ?? e}). Run \`npx -y ${PKG} login\` to connect later.`);
|
|
506
|
+
if (wizard)
|
|
507
|
+
jwt = (await ask(" WEBCAKE_JWT (or Enter to skip): ")).trim();
|
|
460
508
|
}
|
|
461
509
|
}
|
|
462
510
|
else if (pick === "2") {
|
|
463
511
|
jwt = (await ask(" WEBCAKE_JWT: ")).trim();
|
|
464
512
|
}
|
|
465
513
|
}
|
|
466
|
-
else if (!interactive) {
|
|
467
|
-
jwt = jwt || process.env.WEBCAKE_JWT || ""; // scripted / CI: fall back to ambient env
|
|
468
|
-
}
|
|
469
514
|
if (!authNote)
|
|
470
515
|
authNote = jwt ? "JWT" : "none — reference tools only";
|
|
471
516
|
// 3) optional default organization for create_page
|
|
472
517
|
let orgId = o.orgId ?? process.env.WEBCAKE_ORG_ID ?? "";
|
|
473
|
-
if (
|
|
518
|
+
if (wizard && !orgId) {
|
|
474
519
|
orgId = (await ask(`\n${c.bold}3) WEBCAKE_ORG_ID${c.reset} ${c.gray}(optional, Enter to skip): ${c.reset}`)).trim();
|
|
475
520
|
}
|
|
476
521
|
// env block written into IDE configs: WEBCAKE_ENV drives the URLs. A pasted JWT is
|
|
@@ -493,7 +538,7 @@ export async function runInstaller(argv) {
|
|
|
493
538
|
.map((s) => IDE_ALIASES[s.trim().toLowerCase()])
|
|
494
539
|
.filter(Boolean);
|
|
495
540
|
}
|
|
496
|
-
else if (
|
|
541
|
+
else if (wizard) {
|
|
497
542
|
log(`\n${c.bold}4) Which IDE(s) to configure?${c.reset}`);
|
|
498
543
|
log(" 1) Claude Desktop 2) Claude Code (CLI) 3) Cursor");
|
|
499
544
|
log(" 4) Windsurf 5) Augment (VS Code) 6) Codex");
|
|
@@ -521,17 +566,21 @@ export async function runInstaller(argv) {
|
|
|
521
566
|
.filter(Boolean);
|
|
522
567
|
}
|
|
523
568
|
else {
|
|
524
|
-
|
|
525
|
-
printHelp();
|
|
526
|
-
return;
|
|
569
|
+
ides = detectIdes();
|
|
527
570
|
}
|
|
528
571
|
if (!ides.length) {
|
|
529
|
-
|
|
572
|
+
if (wizard) {
|
|
573
|
+
warn("No IDE selected — skipping configuration.");
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
warn("No AI app found on this computer (Claude, Cursor, VS Code…).");
|
|
577
|
+
log(`${c.gray} Install one and run this again, or name it: npx -y ${PKG} install --ide <name>${c.reset}\n`);
|
|
578
|
+
process.exitCode = 1;
|
|
530
579
|
return;
|
|
531
580
|
}
|
|
532
581
|
// 5) write
|
|
533
582
|
const launch = resolveLaunch(o);
|
|
534
|
-
log(`\n${c.bold}
|
|
583
|
+
log(`\n${c.bold}Writing config${c.reset} ${c.gray}(launch: ${launch.command} ${launch.args.join(" ")})${c.reset}`);
|
|
535
584
|
runConfigure(ides, launch, env);
|
|
536
585
|
// 6) summary
|
|
537
586
|
log(`\n${c.green}${c.bold}✓ Done.${c.reset}`);
|
|
@@ -43,6 +43,16 @@ export const ENVIRONMENTS = {
|
|
|
43
43
|
staging: { apiBase: "https://api.staging.webcake.io", appBase: "https://staging.webcake.io", builderBase: "https://builder.staging.webcake.io", previewBase: "https://staging.webcake.me", buildBase: undefined },
|
|
44
44
|
prod: { apiBase: "https://api.webcake.io", appBase: "https://webcake.io", builderBase: "https://builder.webcake.io", previewBase: "https://www.webcake.me", buildBase: "https://build.webcake.io" },
|
|
45
45
|
};
|
|
46
|
+
/** True when `token` is a JWT whose `exp` is past (with `skewSec` margin). Non-JWTs never count as expired. */
|
|
47
|
+
export function jwtExpired(token, skewSec = 30) {
|
|
48
|
+
try {
|
|
49
|
+
const exp = JSON.parse(Buffer.from(String(token).split(".")[1], "base64url").toString()).exp;
|
|
50
|
+
return typeof exp === "number" && exp * 1000 < Date.now() + skewSec * 1000;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
46
56
|
export function stripTrailingSlash(s) {
|
|
47
57
|
return s?.replace(/\/+$/, "");
|
|
48
58
|
}
|
|
@@ -77,7 +87,10 @@ export function readConfig(overrides = {}) {
|
|
|
77
87
|
// A named environment supplies default base URLs; explicit values still win.
|
|
78
88
|
const preset = resolveEnv(overrides.env ?? process.env.WEBCAKE_ENV);
|
|
79
89
|
const base = overrides.base ?? process.env.WEBCAKE_API_BASE ?? preset?.apiBase ?? saved.base;
|
|
80
|
-
|
|
90
|
+
// An expired env JWT (pinned in the IDE config) loses to a fresher one saved by a re-login.
|
|
91
|
+
const envJwt = process.env.WEBCAKE_JWT;
|
|
92
|
+
const renewed = !!envJwt && jwtExpired(envJwt) && !!saved.jwt && !jwtExpired(saved.jwt);
|
|
93
|
+
const jwt = overrides.jwt ?? (renewed ? saved.jwt : envJwt) ?? saved.jwt;
|
|
81
94
|
const missing = [];
|
|
82
95
|
if (!base)
|
|
83
96
|
missing.push("WEBCAKE_API_BASE");
|
package/dist/server.js
CHANGED
|
@@ -10,6 +10,7 @@ import { readFileSync } from "node:fs";
|
|
|
10
10
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
11
|
import { landingDomain } from "./domains/landing/index.js";
|
|
12
12
|
import { registerTools } from "./tools/index.js";
|
|
13
|
+
import { renewAuthOnExpiry } from "./auth/renew.js";
|
|
13
14
|
import { ICON_DATA_URI, ICON_MIME, BRAND } from "./branding.js";
|
|
14
15
|
/**
|
|
15
16
|
* The published package version, read at runtime from package.json so the MCP
|
|
@@ -45,6 +46,7 @@ export function createServer({ allowLocalFiles = true } = {}) {
|
|
|
45
46
|
websiteUrl: BRAND.websiteUrl,
|
|
46
47
|
icons: [{ src: ICON_DATA_URI, mimeType: ICON_MIME, sizes: ["any"] }],
|
|
47
48
|
}, { instructions: landingDomain.instructions });
|
|
49
|
+
renewAuthOnExpiry(server, allowLocalFiles); // allowLocalFiles ⇔ stdio (the user's own machine)
|
|
48
50
|
registerTools(server, landingDomain, { allowLocalFiles });
|
|
49
51
|
return server;
|
|
50
52
|
}
|