@superblocksteam/gateway 2.0.155-next.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/LICENSE.txt +87 -0
- package/README.md +170 -0
- package/dist/agents/resolve-orchestrator-url.d.ts +22 -0
- package/dist/agents/resolve-orchestrator-url.js +38 -0
- package/dist/agents/resolve-orchestrator-url.js.map +1 -0
- package/dist/capabilities/import-prompt.d.ts +11 -0
- package/dist/capabilities/import-prompt.js +96 -0
- package/dist/capabilities/import-prompt.js.map +1 -0
- package/dist/capabilities/lifecycle.d.ts +73 -0
- package/dist/capabilities/lifecycle.js +2531 -0
- package/dist/capabilities/lifecycle.js.map +1 -0
- package/dist/capabilities/persisted-progress.d.ts +46 -0
- package/dist/capabilities/persisted-progress.js +246 -0
- package/dist/capabilities/persisted-progress.js.map +1 -0
- package/dist/capabilities/types.d.ts +446 -0
- package/dist/capabilities/types.js +47 -0
- package/dist/capabilities/types.js.map +1 -0
- package/dist/capture/browser-contract.d.ts +36 -0
- package/dist/capture/browser-contract.js +24 -0
- package/dist/capture/browser-contract.js.map +1 -0
- package/dist/capture/browser-instructions.d.ts +9 -0
- package/dist/capture/browser-instructions.js +17 -0
- package/dist/capture/browser-instructions.js.map +1 -0
- package/dist/capture/capture-library-probe.d.ts +55 -0
- package/dist/capture/capture-library-probe.js +177 -0
- package/dist/capture/capture-library-probe.js.map +1 -0
- package/dist/capture/capture-library.d.ts +52 -0
- package/dist/capture/capture-library.js +249 -0
- package/dist/capture/capture-library.js.map +1 -0
- package/dist/capture/classify-library-paint.d.ts +21 -0
- package/dist/capture/classify-library-paint.js +13 -0
- package/dist/capture/classify-library-paint.js.map +1 -0
- package/dist/capture/host-mcp-scan.d.ts +16 -0
- package/dist/capture/host-mcp-scan.js +64 -0
- package/dist/capture/host-mcp-scan.js.map +1 -0
- package/dist/capture/library-parent-script.d.ts +34 -0
- package/dist/capture/library-parent-script.js +82 -0
- package/dist/capture/library-parent-script.js.map +1 -0
- package/dist/capture/mode.d.ts +22 -0
- package/dist/capture/mode.js +45 -0
- package/dist/capture/mode.js.map +1 -0
- package/dist/config.d.ts +141 -0
- package/dist/config.js +109 -0
- package/dist/config.js.map +1 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.js +9 -0
- package/dist/debug.js.map +1 -0
- package/dist/deps.d.ts +36 -0
- package/dist/deps.js +2 -0
- package/dist/deps.js.map +1 -0
- package/dist/events/cursor.d.ts +43 -0
- package/dist/events/cursor.js +78 -0
- package/dist/events/cursor.js.map +1 -0
- package/dist/events/memory-event-store.d.ts +34 -0
- package/dist/events/memory-event-store.js +110 -0
- package/dist/events/memory-event-store.js.map +1 -0
- package/dist/events/merge.d.ts +23 -0
- package/dist/events/merge.js +97 -0
- package/dist/events/merge.js.map +1 -0
- package/dist/events/normalized-collector.d.ts +62 -0
- package/dist/events/normalized-collector.js +156 -0
- package/dist/events/normalized-collector.js.map +1 -0
- package/dist/events/schema.d.ts +9 -0
- package/dist/events/schema.js +93 -0
- package/dist/events/schema.js.map +1 -0
- package/dist/events/snapshot.d.ts +32 -0
- package/dist/events/snapshot.js +57 -0
- package/dist/events/snapshot.js.map +1 -0
- package/dist/events/stream-key.d.ts +2 -0
- package/dist/events/stream-key.js +31 -0
- package/dist/events/stream-key.js.map +1 -0
- package/dist/events/types.d.ts +179 -0
- package/dist/events/types.js +66 -0
- package/dist/events/types.js.map +1 -0
- package/dist/health/readiness.d.ts +99 -0
- package/dist/health/readiness.js +202 -0
- package/dist/health/readiness.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/filters.d.ts +8 -0
- package/dist/integrations/filters.js +40 -0
- package/dist/integrations/filters.js.map +1 -0
- package/dist/integrations/map.d.ts +26 -0
- package/dist/integrations/map.js +43 -0
- package/dist/integrations/map.js.map +1 -0
- package/dist/integrations/profile-key.d.ts +19 -0
- package/dist/integrations/profile-key.js +35 -0
- package/dist/integrations/profile-key.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -0
- package/dist/orchestrator/client.d.ts +62 -0
- package/dist/orchestrator/client.js +160 -0
- package/dist/orchestrator/client.js.map +1 -0
- package/dist/playwright/ensure-chromium.d.ts +26 -0
- package/dist/playwright/ensure-chromium.js +60 -0
- package/dist/playwright/ensure-chromium.js.map +1 -0
- package/dist/preview/capture-screenshot.d.ts +52 -0
- package/dist/preview/capture-screenshot.js +158 -0
- package/dist/preview/capture-screenshot.js.map +1 -0
- package/dist/preview/viewer-url.d.ts +82 -0
- package/dist/preview/viewer-url.js +128 -0
- package/dist/preview/viewer-url.js.map +1 -0
- package/dist/process/fault-barrier.d.ts +55 -0
- package/dist/process/fault-barrier.js +113 -0
- package/dist/process/fault-barrier.js.map +1 -0
- package/dist/resume/memory-progress-store.d.ts +39 -0
- package/dist/resume/memory-progress-store.js +82 -0
- package/dist/resume/memory-progress-store.js.map +1 -0
- package/dist/resume/memory-recent-app-store.d.ts +14 -0
- package/dist/resume/memory-recent-app-store.js +27 -0
- package/dist/resume/memory-recent-app-store.js.map +1 -0
- package/dist/resume/memory-turn-store.d.ts +18 -0
- package/dist/resume/memory-turn-store.js +73 -0
- package/dist/resume/memory-turn-store.js.map +1 -0
- package/dist/resume/progress-key.d.ts +21 -0
- package/dist/resume/progress-key.js +58 -0
- package/dist/resume/progress-key.js.map +1 -0
- package/dist/resume/stores.d.ts +14 -0
- package/dist/resume/stores.js +18 -0
- package/dist/resume/stores.js.map +1 -0
- package/dist/resume/types.d.ts +124 -0
- package/dist/resume/types.js +13 -0
- package/dist/resume/types.js.map +1 -0
- package/dist/sabs/agent-facing-text.d.ts +33 -0
- package/dist/sabs/agent-facing-text.js +125 -0
- package/dist/sabs/agent-facing-text.js.map +1 -0
- package/dist/sabs/browser-context.d.ts +53 -0
- package/dist/sabs/browser-context.js +91 -0
- package/dist/sabs/browser-context.js.map +1 -0
- package/dist/sabs/editor-client-methods.d.ts +147 -0
- package/dist/sabs/editor-client-methods.js +715 -0
- package/dist/sabs/editor-client-methods.js.map +1 -0
- package/dist/sabs/recent-tool-runs.d.ts +14 -0
- package/dist/sabs/recent-tool-runs.js +61 -0
- package/dist/sabs/recent-tool-runs.js.map +1 -0
- package/dist/sabs/session-peer.d.ts +351 -0
- package/dist/sabs/session-peer.js +2 -0
- package/dist/sabs/session-peer.js.map +1 -0
- package/dist/sabs/turn-collector.d.ts +152 -0
- package/dist/sabs/turn-collector.js +573 -0
- package/dist/sabs/turn-collector.js.map +1 -0
- package/dist/sabs/websocket-session-peer.d.ts +514 -0
- package/dist/sabs/websocket-session-peer.js +2487 -0
- package/dist/sabs/websocket-session-peer.js.map +1 -0
- package/dist/security/constant-time.d.ts +9 -0
- package/dist/security/constant-time.js +13 -0
- package/dist/security/constant-time.js.map +1 -0
- package/dist/server/client.d.ts +371 -0
- package/dist/server/client.js +572 -0
- package/dist/server/client.js.map +1 -0
- package/dist/server/identity-reads.d.ts +76 -0
- package/dist/server/identity-reads.js +209 -0
- package/dist/server/identity-reads.js.map +1 -0
- package/dist/start.d.ts +14 -0
- package/dist/start.js +75 -0
- package/dist/start.js.map +1 -0
- package/dist/telemetry/metrics.d.ts +32 -0
- package/dist/telemetry/metrics.js +57 -0
- package/dist/telemetry/metrics.js.map +1 -0
- package/dist/transports/mcp/admin-tools.d.ts +47 -0
- package/dist/transports/mcp/admin-tools.js +164 -0
- package/dist/transports/mcp/admin-tools.js.map +1 -0
- package/dist/transports/mcp/app-status-html.d.ts +15 -0
- package/dist/transports/mcp/app-status-html.js +563 -0
- package/dist/transports/mcp/app-status-html.js.map +1 -0
- package/dist/transports/mcp/decision-elicitation.d.ts +74 -0
- package/dist/transports/mcp/decision-elicitation.js +233 -0
- package/dist/transports/mcp/decision-elicitation.js.map +1 -0
- package/dist/transports/mcp/dispatch-probe.d.ts +24 -0
- package/dist/transports/mcp/dispatch-probe.js +48 -0
- package/dist/transports/mcp/dispatch-probe.js.map +1 -0
- package/dist/transports/mcp/format-tool-content.d.ts +25 -0
- package/dist/transports/mcp/format-tool-content.js +48 -0
- package/dist/transports/mcp/format-tool-content.js.map +1 -0
- package/dist/transports/mcp/mount.d.ts +9 -0
- package/dist/transports/mcp/mount.js +469 -0
- package/dist/transports/mcp/mount.js.map +1 -0
- package/dist/transports/mcp/progress-notifier.d.ts +39 -0
- package/dist/transports/mcp/progress-notifier.js +52 -0
- package/dist/transports/mcp/progress-notifier.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { registerAppResource, registerAppTool, RESOURCE_MIME_TYPE, } from "@modelcontextprotocol/ext-apps/server";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { ElicitResultSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { checkAppProgress, editApp, getApp, importApp, previewApp, publishApp, startApp, } from "../../capabilities/lifecycle.js";
|
|
7
|
+
import { IMPORT_ZIP_BASE64_MAX_CHARS } from "../../capabilities/types.js";
|
|
8
|
+
import { BROWSER_DRIVER_INSTRUCTIONS } from "../../capture/browser-instructions.js";
|
|
9
|
+
import { captureLibraryScreenshotWithPlaywright } from "../../capture/capture-library.js";
|
|
10
|
+
import { gatewayDebug, gatewayDebugStack } from "../../debug.js";
|
|
11
|
+
import { EVENT_CURSOR_VERSION, parseEventCursor } from "../../events/cursor.js";
|
|
12
|
+
import { EVENT_PRODUCERS } from "../../events/types.js";
|
|
13
|
+
import { capturePreviewScreenshotWithPlaywright } from "../../preview/capture-screenshot.js";
|
|
14
|
+
import { registerAdminTools } from "./admin-tools.js";
|
|
15
|
+
import { APP_STATUS_HTML, APP_STATUS_RESOURCE_URI } from "./app-status-html.js";
|
|
16
|
+
import { clientSupportsFormElicitation, pendingDecision, resolveDecisionByElicitation, } from "./decision-elicitation.js";
|
|
17
|
+
import { formatMcpToolContent } from "./format-tool-content.js";
|
|
18
|
+
import { createProgressNotifier } from "./progress-notifier.js";
|
|
19
|
+
/**
|
|
20
|
+
* Optional composite progress cursor a host may hand back on
|
|
21
|
+
* `check_app_progress`.
|
|
22
|
+
*
|
|
23
|
+
* Kept deliberately loose at the schema boundary: `parseEventCursor` is the
|
|
24
|
+
* authority for version and per-producer positions. A foreign or corrupt
|
|
25
|
+
* cursor must fall through to the caller's stored place rather than fail the
|
|
26
|
+
* tool call — otherwise a host that cached an older shape would permanently
|
|
27
|
+
* stall.
|
|
28
|
+
*/
|
|
29
|
+
const eventCursorInputSchema = z
|
|
30
|
+
.object({
|
|
31
|
+
streams: z.record(z.string(), z.unknown()).optional(),
|
|
32
|
+
version: z.unknown().optional(),
|
|
33
|
+
})
|
|
34
|
+
.passthrough()
|
|
35
|
+
.describe(`Optional composite resume cursor from a previous check_app_progress or get_app result. Shape: { version: ${EVENT_CURSOR_VERSION}, streams: { ${EVENT_PRODUCERS.join("?: number, ")}?: number } }. There is no global sequence — each producer (dev_server, sabs) has its own position. Omit to resume from the gateway's per-caller stored place. A cursor from an older contract or with bad positions is ignored and the stored place is used instead.`);
|
|
36
|
+
/**
|
|
37
|
+
* Builds the principal from the CLI session this Gateway was started with.
|
|
38
|
+
* Identity is the already-logged-in Superblocks user; there is no second PAT
|
|
39
|
+
* and no OAuth authInfo on stdio.
|
|
40
|
+
*
|
|
41
|
+
* When `cliIdentity` is already known, it is handed over fully resolved so no
|
|
42
|
+
* capability spends a `/users/me` round trip (ENG-5806). Otherwise
|
|
43
|
+
* `ensurePrincipal` resolves it once through the guarded identity read.
|
|
44
|
+
*/
|
|
45
|
+
function principalFrom(deps) {
|
|
46
|
+
return {
|
|
47
|
+
apiKey: deps.cliApiKey,
|
|
48
|
+
...(deps.cliIdentity ?? {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Who is polling, for the purpose of keeping their place in a build's stream.
|
|
53
|
+
*
|
|
54
|
+
* Stdio is a single-user process owned by the MCP host, so every tool call
|
|
55
|
+
* shares this stable id. The value is never stored as-is; the progress store
|
|
56
|
+
* hashes it.
|
|
57
|
+
*/
|
|
58
|
+
function callerFrom() {
|
|
59
|
+
return { channel: "mcp", id: "cli" };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Told to the model on connect, so it can match what a user actually says
|
|
63
|
+
* against these tools.
|
|
64
|
+
*
|
|
65
|
+
* People refer to this one system as the product and builder ("Superblocks")
|
|
66
|
+
* or by an older name for that same builder ("Clark"). Listing that accepted
|
|
67
|
+
* alias here is what lets "get Clark to build me a to-do app" reach
|
|
68
|
+
* `start_app`. Recognizing a name and using it are different things: the alias
|
|
69
|
+
* is input-only, because a client that reads "Clark" here repeats it back and
|
|
70
|
+
* reintroduces the retired name to the user.
|
|
71
|
+
*/
|
|
72
|
+
const SERVER_INSTRUCTIONS = `Superblocks builds, edits, and publishes internal web applications. Prompts sent through these tools are handed to Superblocks, which writes the application code in a live-edit session.
|
|
73
|
+
|
|
74
|
+
Name the builder "Superblocks" in every word you write. Users sometimes call it "Clark", an older name for this same system: understand them, and answer about Superblocks. Never write "Clark" yourself — not as a name, not as an aside, not even when the user just used it, and never as a separate agent or persona. If Superblocks' own words come back naming Clark, relay the substance and say Superblocks.
|
|
75
|
+
|
|
76
|
+
Use these tools whenever the user asks to build, change, import, or ship an app, whichever of those names they reach for.
|
|
77
|
+
|
|
78
|
+
- start_app: create a new application and hand a prompt to Superblocks. Returns as soon as Superblocks accepts, with status "building". Superblocks names it unless a name is given.
|
|
79
|
+
- import_app: import an existing app from a ZIP (or .tgz/.gz) into Superblocks and start a Superblocks migration. Pass the archive's file name as zipPath — the gateway opens the file on this machine itself. Archives larger than 1 MB are rejected — they almost certainly include node_modules; re-export without install artifacts. Optional prompt carries extra intent (e.g. "make it more secure"). Returns like start_app with status "building".
|
|
80
|
+
- edit_app: send a follow-up prompt (including the answer when Superblocks asked a question) for an existing application. Also returns at status "building". Defaults to the most recent app, so an applicationId is only needed to target a different app.
|
|
81
|
+
- check_app_progress: wait for the next thing Superblocks does and return it. It returns the moment Superblocks says anything, and after ~10 seconds of silence at the latest. "activity" holds Superblocks' own words since the previous call, in order; a quiet poll still returns a short heartbeat with elapsedSeconds.
|
|
82
|
+
- get_app: return editor and preview URLs for the recent or specified app (builds a private preview when needed). Prefer this after status "ready" so the user can open the live app. Hosts that support MCP Apps show the status card (Open editor / Open preview) on this call — not on check_app_progress or preview_app — so only one card opens. When Superblocks has written code the tool includes a screenshot: the live Vite canvas (library peer) if a held session exists, otherwise the signed-in preview. Never open canvas.doNotOpen (the edit URL) to take that screenshot. It refuses to build a preview of an app Superblocks has not written yet: while a plan or question is outstanding it returns status "needs_decision" with "pendingAction", while a turn is running it returns status "building", and when the last turn ended without writing anything it returns that turn's status ("timeout", "live_edit_terminated", "no_changes" or "cancelled") with pendingAction "retry_build". In each case there are no preview URLs and no screenshot — do the pendingAction first rather than calling get_app again.
|
|
83
|
+
- preview_app: build the application's current work and return a URL that runs it, without deploying it — the editor's Preview button. Nobody else can reach a preview. Text/markdown only (no MCP Apps widget); use get_app instead when you want the status card.
|
|
84
|
+
- publish_app: deploy an application and wait until it is live. It commits the current work first, so a commitId is only needed to publish an earlier commit.
|
|
85
|
+
|
|
86
|
+
A build takes two to four minutes, and start_app/edit_app/import_app return within seconds — long before it is done. After any of them, call check_app_progress within about 10 seconds so a plan or question surfaces quickly. Once the plan is approved and Superblocks is building the app, space later polls about 30 seconds apart (honor "nextPollAfterMs" when present) — a 10-second cadence on a multi-minute build burns through the host's tool-call budget. A "nextPollAfterMs" of 0 means nothing is in flight: stop polling rather than calling again immediately. "remainingTurnBudgetMs" appears only while this gateway is following the turn itself and can see its clock, so never read a missing budget as a fresh one — but do not read it as a reason to stop either. A build this gateway is not itself timing reports "building" with no budget, and "status" and "nextPollAfterMs" are what say whether to keep polling. Never claim the app is built while status is "building".
|
|
87
|
+
|
|
88
|
+
The user sees nothing at all while a tool call is outstanding, so between two calls always write out the new "activity" lines as a short message in your own reply — quote or paraphrase them, oldest first, before calling check_app_progress again. Do not batch them up for a summary at the end, and do not go two calls in a row without writing something: the point of the loop is that the user watches the build happen. When a call comes back with only a heartbeat (no new Superblocks words), say Superblocks is still working and how long it has been going, then poll again.
|
|
89
|
+
|
|
90
|
+
status "ready" means the turn finished: report the "reply" field, then call get_app (not preview_app as well — calling both used to open two widgets) so the user gets Open preview / an https link or a screenshot. status "needs_decision" means Superblocks is waiting — often with a plan — so stop polling and put the decision to the user. When "decision.kind" is "plan", show the plan markdown, then invite them to build it as written or say what to change — the same fork the editor's Build-it button offers. Ask that as an ordinary closing question in your own words; do not turn it into a numbered or bulleted menu, and do not wrap the choices in quotation marks. When they say "Build it", "approve", "looks good", or "go ahead", you MUST call edit_app with planAction "approve" and omit prompt (do not re-send the plan, and do not put "approve" or "Build it" in the prompt field — that is refine feedback to Superblocks, not the editor Build-it path). When they want changes, call edit_app with planAction "refine" and their feedback as prompt. When "decision.kind" is "multi_choice", relay the question and options and send their answer with edit_app. Do not claim the app is built while status is "needs_decision". status "no_changes" means the Superblocks job ended without building anything: relay reply, say no app was built, and do not present the edit URL as a finished app. status "live_edit_terminated" means the live-edit session that was to run the turn died before it built anything, or never opened at all — the prompt was fine and nothing timed out, so relay reply, tell the user the session did not survive, and offer to send the same instruction again with edit_app. status "detached" means Superblocks is still working but the gateway can no longer see it — usually because the app is open in a browser editor, which takes over Superblocks updates. Stop polling, say so, and point the user at the edit URL. status "unknown" means nothing is in flight for that app. A checkpointCommitId means Superblocks work is saved and the edit URL opens the finished app; when viewStatus is unknown, say the app may still be finishing in the editor.
|
|
91
|
+
|
|
92
|
+
start_app, edit_app, and import_app default to Plan mode (Superblocks proposes a plan before writing). Pass mode "BUILD" only when the user asks to skip planning and build immediately. Approving a plan after start_app or import_app is always a follow-up edit_app with planAction "approve" — never a second start_app/import_app with prompt "approve". Once the app has run in Build mode, later edit_app calls stay in Build mode on their own: you do not need to re-send mode "BUILD", and a new instruction is not a fresh planning round. Send mode "PLAN" only when the user explicitly asks to plan again before building. Every start_app / edit_app / import_app result reports the "mode" the turn ran in, so you can tell the user whether Superblocks is planning or building rather than guessing — and if a result comes back "PLAN" after a long gap, the build session was recycled rather than the user asking to plan, so pass mode "BUILD" again to carry on building. editUrl / previewUrl / publishUrl may appear in structured JSON for openLink buttons — do not dump raw URLs (especially preview JWTs) into the chat. Prefer the MCP Apps Open editor / Open preview buttons from get_app. Claude Desktop can only openLink https URLs; when previewUrl is http, say so briefly and rely on any screenshot image the tool returned rather than pasting the URL.
|
|
93
|
+
|
|
94
|
+
Once a build reaches "ready", call get_app so the user can open the app, then offer publish_app to deploy for their organization when they ask. Prefer get_app over preview_app after a build — get_app already ensures a private preview and is the only tool that opens the MCP Apps status card. Only publish when the user asks. If preview_app or get_app comes back with status "building", the URL is already correct; tell the user it is still building and call again to check.
|
|
95
|
+
|
|
96
|
+
There is nothing to preview until Superblocks has written code, so get_app is not the way out of a plan, a question, or a turn that failed. When it answers status "needs_decision" (pendingAction "approve_plan" or "answer_question"), the app is still the empty starter template: put the decision to the user, send their answer with edit_app, and only call get_app once a turn has finished. When it answers "timeout", "live_edit_terminated", "no_changes" or "cancelled" with pendingAction "retry_build", that turn built nothing: tell the user so plainly, and send the instruction again with edit_app if they want to retry. Repeating get_app instead opens another status card and tells the user nothing new.
|
|
97
|
+
|
|
98
|
+
Superblocks tests what it builds: it opens the app in a browser and runs its APIs, and the test run arrives as ordinary "activity" lines ("Testing the orders page", "Test passed: …", "Tests failed: …"). Relay those lines like any other activity, and say which cases passed and which failed — a test run is the only evidence the user has that the app actually works. A failing test is a build signal, not an auth problem: it means the app has a bug Superblocks is about to work on, so keep polling and never tell the user to sign in again or re-enter credentials over one.
|
|
99
|
+
|
|
100
|
+
A failed call still names the application it was working on. start_app and import_app create the application before the build can start, so an error from either one leaves an application that exists and belongs to this conversation, and the error says which: read the "applicationId" field, never a UUID out of the message text. Never take an error to mean nothing happened. Do not answer a failed start_app with a second start_app — that abandons the app you already have and creates a duplicate. When the error carries pendingAction "retry_build" — a "live_edit_unavailable" session that would not open, or a turn that ran out of budget — send the same prompt again with edit_app and that applicationId. A failed import_app carries no such recovery, because edit_app cannot resupply the archive the migration prompt reads: that application is empty and nothing can continue it in place, so name it to the user and let them decide whether to import again. Every edit_app error names its applicationId too, which is the one place to see which app a call that omitted the id actually ran on.
|
|
101
|
+
|
|
102
|
+
Prompts are forwarded to Superblocks verbatim — pass the user's wording rather than a summary.
|
|
103
|
+
|
|
104
|
+
This connector is the single Superblocks MCP: Builder tools (start_app, import_app, edit_app, check_app_progress, get_app, preview_app, publish_app) and Admin tools (integrations, apps, users, folders, deploy_application, and the rest of the customer Admin surface) share this endpoint. Prefer create_integration / update_integration / list_integrations here when Superblocks needs a missing Postgres, REST, or other datasource — do not send the user to a second MCP. create_integration is Admin CRUD for org datasources; start_app creates a new application and hands a prompt to Superblocks. deploy_application is Admin deploy of an existing commit; publish_app is the Builder path that commits current work and waits until the app is live. Omit base_url on Admin tools unless targeting a different control plane — the gateway injects its configured Server URL. checkout_application is not exposed on this network surface (host filesystem writes); use the CLI/workspace checkout path instead.
|
|
105
|
+
|
|
106
|
+
This connection is already authenticated and already pointed at one Superblocks Server, so there is no setup, login, or auth-status call to make first. Call the tool that does the job — list_integrations to see the org's datasources, start_app to create an application — and read its error if something is genuinely wrong. Do not look for a tool that reports credentials or environments; there is none, and asking for one costs the user a turn.
|
|
107
|
+
|
|
108
|
+
This MCP also discovers integrations mid-build and runs live integration queries (username/password and other stored credentials) through the orchestrator. When an integration needs interactive IdP/OAuth login, the tool error will say to authenticate in the Superblocks editor (edit URL) and retry — only follow that when the error says so. A 401 AuthorizationError from an orchestrator execute path is Superblocks/orchestrator auth (the scoped JWT or selected profile), not Snowflake username/password — never advise verifying or re-entering the Snowflake password, account, or other stored credentials in the integrations UI for that error. Only advise credential edits when an error from Snowflake itself clearly says stored credentials failed or a connection test failed. Do not tell the user to re-authenticate for Snowflake SQL permission wording ("does not exist or not authorized") or OpenAI API key failures. If status later reaches "ready" and the user can open the app, do not lead with or alarm on mid-build testApi orchestrator 401s unless the user asks about data or API failures — prefer "build succeeded" and mention a transient API check only if asked.
|
|
109
|
+
|
|
110
|
+
For import_app, the archive never travels through you. A file the user attached to the chat sits in your own sandbox, which this gateway cannot read, but the user downloaded that same file to this machine and the gateway looks for it by name where downloads land. So pass zipPath — the full path if you have a real one for this machine, otherwise the attachment's file name, which is all the gateway needs. The gateway only opens archives that sit in the folders its operator allowed, so if it answers that it will not read the path you gave, ask the user to move the archive into one of the folders it names. Never write the archive out as base64: it costs thousands of tokens, takes minutes, and the call is rejected before it runs.
|
|
111
|
+
|
|
112
|
+
${BROWSER_DRIVER_INSTRUCTIONS}`;
|
|
113
|
+
/**
|
|
114
|
+
* The MCP server behind one stdio session.
|
|
115
|
+
*
|
|
116
|
+
* Tools run as the already-logged-in CLI user. There is no per-request OAuth
|
|
117
|
+
* token to expire independently of the process.
|
|
118
|
+
*/
|
|
119
|
+
export function createMcpServer(deps) {
|
|
120
|
+
const context = async (progress, notify, signal) => ({
|
|
121
|
+
caller: callerFrom(),
|
|
122
|
+
captureLibraryScreenshot: captureLibraryScreenshotWithPlaywright,
|
|
123
|
+
capturePreviewScreenshot: capturePreviewScreenshotWithPlaywright,
|
|
124
|
+
config: deps.config,
|
|
125
|
+
events: deps.events,
|
|
126
|
+
onProgress: (event) => {
|
|
127
|
+
progress.push(event);
|
|
128
|
+
notify?.(event.message);
|
|
129
|
+
},
|
|
130
|
+
principal: principalFrom(deps),
|
|
131
|
+
progressCursors: deps.progressCursors,
|
|
132
|
+
recentApps: deps.recentApps,
|
|
133
|
+
server: deps.server,
|
|
134
|
+
sessionPeer: deps.sessionPeer,
|
|
135
|
+
...(signal ? { signal } : {}),
|
|
136
|
+
turns: deps.turns,
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* Runs a capability and renders it as tool content. An unexpected throw
|
|
140
|
+
* becomes an error result rather than taking the process down, and carries
|
|
141
|
+
* its own message: this catch cannot tell which downstream failed, and
|
|
142
|
+
* naming one it did not diagnose points the reader at a healthy system.
|
|
143
|
+
*/
|
|
144
|
+
const run = async (toolName, capability, extra) => {
|
|
145
|
+
gatewayDebugStack("tool started", { "tool.name": toolName });
|
|
146
|
+
const progress = [];
|
|
147
|
+
const notify = createProgressNotifier(extra);
|
|
148
|
+
let result;
|
|
149
|
+
if (!deps.cliApiKey) {
|
|
150
|
+
gatewayDebug("tool short-circuited", {
|
|
151
|
+
"tool.name": toolName,
|
|
152
|
+
"tool.reason": "missing_cli_session",
|
|
153
|
+
});
|
|
154
|
+
result = {
|
|
155
|
+
kind: "error",
|
|
156
|
+
code: "unauthenticated",
|
|
157
|
+
message: "This Gateway has no CLI session. Run: superblocks login",
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
try {
|
|
162
|
+
// The SDK aborts this on `notifications/cancelled` and on a dropped
|
|
163
|
+
// connection. Handing it to the capability is what turns "the host
|
|
164
|
+
// stopped listening" into "stop waiting", instead of leaving a timer
|
|
165
|
+
// and a waiter running for an answer nobody will read.
|
|
166
|
+
const signal = extra?.signal;
|
|
167
|
+
const capabilityContext = await context(progress, notify, signal);
|
|
168
|
+
result = await capability(capabilityContext, () => {
|
|
169
|
+
for (let index = progress.length - 1; index >= 0; index -= 1) {
|
|
170
|
+
if (progress[index]?.type === "completed") {
|
|
171
|
+
progress.splice(index, 1);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error("gateway capability failed", error);
|
|
178
|
+
result = {
|
|
179
|
+
kind: "error",
|
|
180
|
+
code: "capability_failed",
|
|
181
|
+
message: error instanceof Error
|
|
182
|
+
? error.message
|
|
183
|
+
: "The gateway failed for an unknown reason.",
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const resultStatus = result.kind === "ok" &&
|
|
188
|
+
result.value &&
|
|
189
|
+
typeof result.value === "object" &&
|
|
190
|
+
"status" in result.value &&
|
|
191
|
+
typeof result.value.status === "string"
|
|
192
|
+
? result.value.status
|
|
193
|
+
: undefined;
|
|
194
|
+
gatewayDebug("tool finished", {
|
|
195
|
+
"progress.event_count": progress.length,
|
|
196
|
+
...(result.kind === "error" ? { "result.code": result.code } : {}),
|
|
197
|
+
"result.kind": result.kind,
|
|
198
|
+
...(resultStatus ? { "result.status": resultStatus } : {}),
|
|
199
|
+
"tool.name": toolName,
|
|
200
|
+
});
|
|
201
|
+
// structuredContent lets MCP Apps hosts hand the capability value to the
|
|
202
|
+
// status card without making it re-parse the JSON text block.
|
|
203
|
+
const structuredContent = result.kind === "ok" &&
|
|
204
|
+
result.value &&
|
|
205
|
+
typeof result.value === "object" &&
|
|
206
|
+
!Array.isArray(result.value)
|
|
207
|
+
? (() => {
|
|
208
|
+
const value = { ...result.value };
|
|
209
|
+
delete value.screenshotBase64;
|
|
210
|
+
return value;
|
|
211
|
+
})()
|
|
212
|
+
: undefined;
|
|
213
|
+
return {
|
|
214
|
+
content: formatMcpToolContent(result, progress),
|
|
215
|
+
...(structuredContent ? { structuredContent } : {}),
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
const server = new McpServer({
|
|
219
|
+
name: "superblocks",
|
|
220
|
+
// The product the user is thinking of, not the implementation process
|
|
221
|
+
// serving it. The client shows this string.
|
|
222
|
+
title: "Superblocks",
|
|
223
|
+
version: "0.0.1",
|
|
224
|
+
}, { instructions: SERVER_INSTRUCTIONS });
|
|
225
|
+
/**
|
|
226
|
+
* A progress poll that also puts a decision to the user as a native form when
|
|
227
|
+
* the host supports one, answering Superblocks itself and returning the turn
|
|
228
|
+
* that follows. Hosts without form elicitation (Claude Desktop today) get the
|
|
229
|
+
* decision back as data and ask the user in chat.
|
|
230
|
+
*/
|
|
231
|
+
const progressWithDecisionForm = async (context, input, extra, forgetFinishedTurn) => {
|
|
232
|
+
gatewayDebug("progress decision flow started", {
|
|
233
|
+
"application.id": input.applicationId,
|
|
234
|
+
"progress.cursor_provided": Boolean(input.cursor),
|
|
235
|
+
});
|
|
236
|
+
const result = await checkAppProgress(context, input);
|
|
237
|
+
const decision = pendingDecision(result);
|
|
238
|
+
if (!decision) {
|
|
239
|
+
gatewayDebug("progress decision flow finished", {
|
|
240
|
+
"decision.resolved": false,
|
|
241
|
+
"decision.reason": "no_pending_decision",
|
|
242
|
+
});
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
if (!clientSupportsFormElicitation(server.server.getClientCapabilities())) {
|
|
246
|
+
gatewayDebug("progress decision flow finished", {
|
|
247
|
+
"decision.kind": decision.kind,
|
|
248
|
+
"decision.resolved": false,
|
|
249
|
+
"decision.reason": "form_unsupported",
|
|
250
|
+
});
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
const resolved = await resolveDecisionByElicitation({
|
|
254
|
+
apply: (answer) => {
|
|
255
|
+
forgetFinishedTurn();
|
|
256
|
+
return editApp(context, {
|
|
257
|
+
applicationId: input.applicationId,
|
|
258
|
+
idempotencyKey: `mcp-decision:${randomUUID()}`,
|
|
259
|
+
wait: "ack",
|
|
260
|
+
...(answer.kind === "approve"
|
|
261
|
+
? { planAction: "approve" }
|
|
262
|
+
: answer.kind === "refine"
|
|
263
|
+
? { planAction: "refine", prompt: answer.feedback }
|
|
264
|
+
: { prompt: answer.prompt }),
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
decision,
|
|
268
|
+
// Sent through the tool call's own extra so it rides that call's response
|
|
269
|
+
// stream: a request the gateway raises on its own goes to the standalone
|
|
270
|
+
// stream instead, which a host that never opened one silently drops,
|
|
271
|
+
// leaving the tool call waiting for an answer that cannot arrive.
|
|
272
|
+
elicit: (request) => extra.sendRequest({ method: "elicitation/create", params: request }, ElicitResultSchema),
|
|
273
|
+
});
|
|
274
|
+
gatewayDebug("progress decision flow finished", {
|
|
275
|
+
"decision.kind": decision.kind,
|
|
276
|
+
"decision.resolved": Boolean(resolved),
|
|
277
|
+
"decision.reason": resolved ? "answered" : "left_in_chat",
|
|
278
|
+
});
|
|
279
|
+
return resolved ?? result;
|
|
280
|
+
};
|
|
281
|
+
// Cloud-Prem Admin laptop agent: this machine has no Playwright Chromium
|
|
282
|
+
// and never opens a live-edit session, so the Builder surface (start_app,
|
|
283
|
+
// edit_app, ...) is skipped entirely rather than registered and left to
|
|
284
|
+
// fail on its first call.
|
|
285
|
+
if (!deps.config.adminToolsOnly) {
|
|
286
|
+
gatewayDebug("builder tool registration selected", {
|
|
287
|
+
"gateway.admin_tools_only": false,
|
|
288
|
+
});
|
|
289
|
+
registerBuilderTools();
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
gatewayDebug("builder tool registration skipped", {
|
|
293
|
+
"gateway.admin_tools_only": true,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function registerBuilderTools() {
|
|
297
|
+
server.registerTool("start_app", {
|
|
298
|
+
description: 'Create a Superblocks application and hand a prompt to Superblocks in Plan mode by default. Returns as soon as Superblocks accepts, with status "building" and an edit URL; follow with check_app_progress until status is no longer "building". When Superblocks returns needs_decision with a plan and the user says "Build it", call edit_app with planAction "approve" (omit prompt) — do not call start_app again with prompt "approve". Pass mode "BUILD" to skip planning. Superblocks names the application unless name is given. An error from this tool does not mean nothing happened: the application is created before the build starts, so the error names it in "applicationId". Retry that app with edit_app rather than calling start_app another time, which would leave the first one abandoned.',
|
|
299
|
+
inputSchema: {
|
|
300
|
+
branch: z.string().optional(),
|
|
301
|
+
idempotencyKey: z.string().optional(),
|
|
302
|
+
mode: z.enum(["BUILD", "PLAN"]).optional(),
|
|
303
|
+
name: z.string().min(1).optional(),
|
|
304
|
+
prompt: z.string().min(1),
|
|
305
|
+
},
|
|
306
|
+
// Named for what a user asks for ("create an app"), not for the verb in
|
|
307
|
+
// the tool name: a host that ranks tools by title has to be able to find
|
|
308
|
+
// this one from the request.
|
|
309
|
+
title: "Create Superblocks App",
|
|
310
|
+
}, async ({ branch, idempotencyKey, mode, name, prompt }, extra) => run("start_app", (context) => startApp(context, {
|
|
311
|
+
branch,
|
|
312
|
+
idempotencyKey: idempotencyKey ?? `mcp-start:${randomUUID()}`,
|
|
313
|
+
mode,
|
|
314
|
+
name,
|
|
315
|
+
prompt,
|
|
316
|
+
// MCP clients get the polling loop, not a blocking call: Claude
|
|
317
|
+
// Desktop sends no progressToken, so a call that waits out the whole
|
|
318
|
+
// build shows the user nothing until it returns.
|
|
319
|
+
wait: "ack",
|
|
320
|
+
}), extra));
|
|
321
|
+
server.registerTool("import_app", {
|
|
322
|
+
description: 'Import an existing app from a ZIP/.tgz/.gz archive into Superblocks and start a Superblocks migration. Pass the archive\'s file name (or its full path on this machine) as zipPath: the gateway reads the file itself, so a path from your own sandbox is fine as long as the name matches the file the user has. Never encode the archive as base64 — zipBase64 only carries test fixtures. Archives larger than 1 MB are rejected — exclude node_modules. Optional prompt adds intent such as hardening security. Returns status "building"; follow with check_app_progress. Defaults to Plan mode — when Superblocks returns a plan and the user says "Build it", call edit_app with planAction "approve" (omit prompt); do not call import_app again with prompt "approve". An error from this tool does not mean nothing happened: the application is created before the migration starts, so the error names it in "applicationId". That application is empty — the migration never ran — and nothing can continue it in place, so say it exists and let the user decide whether to import again rather than silently retrying.',
|
|
323
|
+
inputSchema: {
|
|
324
|
+
branch: z.string().optional(),
|
|
325
|
+
idempotencyKey: z.string().optional(),
|
|
326
|
+
mode: z.enum(["BUILD", "PLAN"]).optional(),
|
|
327
|
+
name: z.string().min(1).optional(),
|
|
328
|
+
prompt: z.string().min(1).optional(),
|
|
329
|
+
source: z
|
|
330
|
+
.enum([
|
|
331
|
+
"chatgpt",
|
|
332
|
+
"claude",
|
|
333
|
+
"claude-design",
|
|
334
|
+
"lovable",
|
|
335
|
+
"replit",
|
|
336
|
+
"streamlit",
|
|
337
|
+
"v0",
|
|
338
|
+
"zip",
|
|
339
|
+
])
|
|
340
|
+
.optional(),
|
|
341
|
+
zipBase64: z
|
|
342
|
+
.string()
|
|
343
|
+
.min(1)
|
|
344
|
+
.max(IMPORT_ZIP_BASE64_MAX_CHARS)
|
|
345
|
+
.optional(),
|
|
346
|
+
zipPath: z.string().min(1).optional(),
|
|
347
|
+
},
|
|
348
|
+
title: "Import App",
|
|
349
|
+
}, async ({ branch, idempotencyKey, mode, name, prompt, source, zipBase64, zipPath, }, extra) => run("import_app", (context) => importApp(context, {
|
|
350
|
+
branch,
|
|
351
|
+
idempotencyKey: idempotencyKey ?? `mcp-import:${randomUUID()}`,
|
|
352
|
+
mode,
|
|
353
|
+
name,
|
|
354
|
+
prompt,
|
|
355
|
+
source,
|
|
356
|
+
wait: "ack",
|
|
357
|
+
zipBase64,
|
|
358
|
+
zipPath,
|
|
359
|
+
}), extra));
|
|
360
|
+
server.registerTool("edit_app", {
|
|
361
|
+
description: 'Forward a prompt to Superblocks for the recent or specified application. Defaults to Plan mode until the app has run in Build mode; after that later edits keep building directly — you do not need to pass mode again. Pass mode "PLAN" only when the user explicitly asks to plan before building. The result reports the "mode" the turn ran in; a "PLAN" result after a long gap means the build session was recycled, so pass mode "BUILD" again rather than treating it as a new planning round. When status was needs_decision with a plan and the user says "Build it" / approve / go ahead, call edit_app with planAction "approve" and omit prompt — do not put "approve" or "Build it" in prompt (that is refine feedback, not the Build-it path). Use planAction "refine" with their feedback as prompt to change the plan. Also use edit_app to answer multi_choice questions. Returns status "building"; follow with check_app_progress.',
|
|
362
|
+
inputSchema: {
|
|
363
|
+
applicationId: z.string().uuid().optional(),
|
|
364
|
+
branch: z.string().optional(),
|
|
365
|
+
idempotencyKey: z.string().optional(),
|
|
366
|
+
mode: z.enum(["BUILD", "PLAN"]).optional(),
|
|
367
|
+
planAction: z.enum(["approve", "refine"]).optional(),
|
|
368
|
+
prompt: z.string().min(1).optional(),
|
|
369
|
+
},
|
|
370
|
+
title: "Edit App",
|
|
371
|
+
}, async ({ applicationId, branch, idempotencyKey, mode, planAction, prompt }, extra) => run("edit_app", (context) => editApp(context, {
|
|
372
|
+
applicationId,
|
|
373
|
+
branch,
|
|
374
|
+
idempotencyKey: idempotencyKey ?? `mcp-edit:${randomUUID()}`,
|
|
375
|
+
mode,
|
|
376
|
+
planAction,
|
|
377
|
+
prompt,
|
|
378
|
+
wait: "ack",
|
|
379
|
+
}), extra));
|
|
380
|
+
server.registerTool("check_app_progress", {
|
|
381
|
+
description: 'Wait for the next thing Superblocks does on the recent or specified application and return it: "activity" carries Superblocks\' words since the previous call (or a short heartbeat when Superblocks is quiet), and status is "building" while the app is still being generated. Returns as soon as Superblocks says anything, and after ~10 seconds of silence at the latest. Call within about 10 seconds of start_app, import_app, or edit_app so a plan or question surfaces quickly. Once the plan is approved and Superblocks is building, space later polls about 30 seconds apart (honor "nextPollAfterMs" when present) until status is no longer "building" — a 10-second cadence on a multi-minute build burns through the host\'s tool-call budget. Relay each new activity line to the user between calls. When status becomes "needs_decision", stop polling and put the decision to the user — for a plan, show it and ask whether to build it or say what to change; for multi_choice, relay the question and options. Hosts that support form elicitation get a native picker instead, and this tool then returns the answered turn. When status becomes "ready", follow with get_app so the user can open the preview. Progress is text-only (no MCP Apps widget) so each poll does not reopen a blank card. Optional "cursor" from a prior result resumes from that composite position (per producer, no global sequence); omit it to use the gateway\'s stored place for this caller.',
|
|
382
|
+
inputSchema: {
|
|
383
|
+
applicationId: z.string().uuid().optional(),
|
|
384
|
+
cursor: eventCursorInputSchema.optional(),
|
|
385
|
+
},
|
|
386
|
+
title: "Check App Progress",
|
|
387
|
+
}, async ({ applicationId, cursor }, extra) => run("check_app_progress", (context, forgetFinishedTurn) => {
|
|
388
|
+
// Validate at the boundary so a foreign/corrupt cursor falls back
|
|
389
|
+
// to the stored place instead of failing the tool call.
|
|
390
|
+
const parsed = cursor === undefined ? undefined : parseEventCursor(cursor);
|
|
391
|
+
gatewayDebug("progress cursor parsed", {
|
|
392
|
+
"progress.cursor_provided": cursor !== undefined,
|
|
393
|
+
"progress.cursor_valid": Boolean(parsed),
|
|
394
|
+
});
|
|
395
|
+
return progressWithDecisionForm(context, {
|
|
396
|
+
applicationId,
|
|
397
|
+
...(parsed ? { cursor: parsed } : {}),
|
|
398
|
+
}, extra, forgetFinishedTurn);
|
|
399
|
+
}, extra));
|
|
400
|
+
registerAppTool(server, "get_app", {
|
|
401
|
+
description: 'Return editor and preview URLs for the recent or specified Superblocks application. Ensures a private preview build by default (same as preview_app), but only once Superblocks has something to show: while a plan or question is outstanding it returns status "needs_decision" with the "decision" and a "pendingAction" of "approve_plan" or "answer_question", while a turn is running it returns status "building", and when the last turn ended without writing anything it returns "timeout", "live_edit_terminated", "no_changes" or "cancelled" with pendingAction "retry_build" — no preview URLs and no screenshot in any of those cases, because the app is still the empty starter template. Act on "pendingAction" through edit_app instead of calling this again. Prefer this after check_app_progress reaches status "ready". Also the right call when you do not know where a build stands — after a reconnect, when no turn of yours is running, or when the conversation moved to another channel: pass wait false and read "status" and "cursor" from the result rather than guessing. Hosts that support MCP Apps show Open editor / Open preview buttons. When Superblocks has written code the result includes a screenshot of the live Vite canvas if a held session exists, otherwise the signed-in preview — never the edit URL.',
|
|
402
|
+
inputSchema: {
|
|
403
|
+
applicationId: z.string().uuid().optional(),
|
|
404
|
+
branch: z.string().optional(),
|
|
405
|
+
ensurePreview: z.boolean().optional(),
|
|
406
|
+
wait: z
|
|
407
|
+
.boolean()
|
|
408
|
+
.optional()
|
|
409
|
+
.describe('Whether to wait for the preview build. Defaults to true. Pass false to get the URLs and current status straight away, with "nextPollAfterMs" telling you when to look again — use that whenever you just need to know where things stand. This is a boolean and has nothing to do with the "ack" wait on start_app / edit_app.'),
|
|
410
|
+
},
|
|
411
|
+
title: "Get App",
|
|
412
|
+
_meta: {
|
|
413
|
+
ui: { resourceUri: APP_STATUS_RESOURCE_URI },
|
|
414
|
+
},
|
|
415
|
+
}, async ({ applicationId, branch, ensurePreview, wait }, extra) => run("get_app", (context) => getApp(context, { applicationId, branch, ensurePreview, wait }), extra));
|
|
416
|
+
server.registerTool("preview_app", {
|
|
417
|
+
description: 'Build the recent or specified Superblocks application\'s current work and return a URL that runs it, without deploying it — the same thing the editor\'s Preview button does. Only the user can open it. Status "ready" means the URL works now; "building" means the build is still running and calling again resumes watching it. Prefer get_app when you want the MCP Apps status card (Open editor / Open preview); this tool returns the same URLs as text/markdown without opening a second widget.',
|
|
418
|
+
inputSchema: {
|
|
419
|
+
applicationId: z.string().uuid().optional(),
|
|
420
|
+
branch: z.string().optional(),
|
|
421
|
+
},
|
|
422
|
+
title: "Preview App",
|
|
423
|
+
}, async ({ applicationId, branch }, extra) => run("preview_app", (context) => previewApp(context, { applicationId, branch }), extra));
|
|
424
|
+
// Nested iframes were removed (auth + Private Network Access). Empty
|
|
425
|
+
// frameDomains keeps the MCP Apps CSP shape without advertising embed origins.
|
|
426
|
+
const uiCsp = { csp: { frameDomains: [] } };
|
|
427
|
+
registerAppResource(server, "Gateway app status", APP_STATUS_RESOURCE_URI, {
|
|
428
|
+
description: "Status card with Open editor / Open preview / Publish app",
|
|
429
|
+
mimeType: RESOURCE_MIME_TYPE,
|
|
430
|
+
_meta: { ui: uiCsp },
|
|
431
|
+
}, async () => ({
|
|
432
|
+
contents: [
|
|
433
|
+
{
|
|
434
|
+
uri: APP_STATUS_RESOURCE_URI,
|
|
435
|
+
mimeType: RESOURCE_MIME_TYPE,
|
|
436
|
+
text: APP_STATUS_HTML,
|
|
437
|
+
_meta: { ui: uiCsp },
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
}));
|
|
441
|
+
server.registerTool("publish_app", {
|
|
442
|
+
description: "Publish/deploy the recent or specified Superblocks application and wait until it is live. Commits the application's current work first, so commitId is only needed to publish an earlier commit.",
|
|
443
|
+
inputSchema: {
|
|
444
|
+
applicationId: z.string().uuid().optional(),
|
|
445
|
+
branch: z.string().optional(),
|
|
446
|
+
commitId: z.string().optional(),
|
|
447
|
+
idempotencyKey: z.string().optional(),
|
|
448
|
+
prompt: z.string().min(1),
|
|
449
|
+
},
|
|
450
|
+
title: "Publish App",
|
|
451
|
+
}, async ({ applicationId, branch, commitId, idempotencyKey, prompt }, extra) => run("publish_app", (context) => publishApp(context, {
|
|
452
|
+
applicationId,
|
|
453
|
+
branch,
|
|
454
|
+
commitId,
|
|
455
|
+
idempotencyKey: idempotencyKey ?? `mcp-publish:${randomUUID()}`,
|
|
456
|
+
prompt,
|
|
457
|
+
}), extra));
|
|
458
|
+
}
|
|
459
|
+
// Customer Admin tools (integrations, apps, users, deploy_application, ...)
|
|
460
|
+
// on the same MCP surface. Credential is the CLI session this process
|
|
461
|
+
// started with; base_url defaults to this gateway's Server URL.
|
|
462
|
+
registerAdminTools(server, {
|
|
463
|
+
apiKey: deps.cliApiKey,
|
|
464
|
+
localAgentMode: deps.config.localAgentMode,
|
|
465
|
+
serverUrl: deps.config.serverUrl,
|
|
466
|
+
});
|
|
467
|
+
return server;
|
|
468
|
+
}
|
|
469
|
+
//# sourceMappingURL=mount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../../../src/transports/mcp/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GACnB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EACL,kBAAkB,GAGnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,gBAAgB,EAChB,OAAO,EACP,MAAM,EACN,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ,GAET,MAAM,iCAAiC,CAAC;AAQzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;A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AC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;gBAC3C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;gBAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;gBAC/B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;gBACrC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;aAC1B;YACD,KAAK,EAAE,aAAa;SACrB,EACD,KAAK,EACH,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,EAC3D,KAAK,EACL,EAAE,CACF,GAAG,CACD,aAAa,EACb,CAAC,OAAO,EAAE,EAAE,CACV,UAAU,CAAC,OAAO,EAAE;YAClB,aAAa;YACb,MAAM;YACN,QAAQ;YACR,cAAc,EAAE,cAAc,IAAI,eAAe,UAAU,EAAE,EAAE;YAC/D,MAAM;SACP,CAAC,EACJ,KAAK,CACN,CACJ,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,sEAAsE;IACtE,gEAAgE;IAChE,kBAAkB,CAAC,MAAM,EAAE;QACzB,MAAM,EAAE,IAAI,CAAC,SAAS;QACtB,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;QAC1C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;KACjC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ProgressToken } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The part of a tool call's `extra` a notifier needs: the token the host asked
|
|
4
|
+
* to be told about progress under, and the channel back to it.
|
|
5
|
+
*/
|
|
6
|
+
export type ProgressNotificationSender = {
|
|
7
|
+
_meta?: {
|
|
8
|
+
progressToken?: ProgressToken;
|
|
9
|
+
};
|
|
10
|
+
sendNotification: (notification: {
|
|
11
|
+
method: "notifications/progress";
|
|
12
|
+
params: {
|
|
13
|
+
message: string;
|
|
14
|
+
progress: number;
|
|
15
|
+
progressToken: ProgressToken;
|
|
16
|
+
};
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Relays a capability's progress to the host that asked for it, and survives
|
|
21
|
+
* that host going away.
|
|
22
|
+
*
|
|
23
|
+
* Progress rides the tool call's own response stream, so it lives exactly as
|
|
24
|
+
* long as the host keeps reading: cancel, disconnect, or simply walk away, and
|
|
25
|
+
* every later send on that stream fails. These sends are driven by SABS turn
|
|
26
|
+
* events, which arrive on a websocket callback - outside any request handler,
|
|
27
|
+
* and so outside the `guarded` wrapper that stops a failed request short of the
|
|
28
|
+
* top. Left alone, one such failure ends the process: the gateway dies because
|
|
29
|
+
* a single client stopped listening, taking every other session with it.
|
|
30
|
+
*
|
|
31
|
+
* Both failure shapes are handled because the SDK produces both. A transport
|
|
32
|
+
* holding no stream for the request throws before it returns a promise; one
|
|
33
|
+
* that fails mid-write rejects the promise it already returned.
|
|
34
|
+
*
|
|
35
|
+
* The first failure latches the notifier shut. A dropped stream does not come
|
|
36
|
+
* back, and a single turn emits progress continuously, so trying again only
|
|
37
|
+
* spends work to fail the same way.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createProgressNotifier(extra: ProgressNotificationSender | undefined): ((message: string) => void) | undefined;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relays a capability's progress to the host that asked for it, and survives
|
|
3
|
+
* that host going away.
|
|
4
|
+
*
|
|
5
|
+
* Progress rides the tool call's own response stream, so it lives exactly as
|
|
6
|
+
* long as the host keeps reading: cancel, disconnect, or simply walk away, and
|
|
7
|
+
* every later send on that stream fails. These sends are driven by SABS turn
|
|
8
|
+
* events, which arrive on a websocket callback - outside any request handler,
|
|
9
|
+
* and so outside the `guarded` wrapper that stops a failed request short of the
|
|
10
|
+
* top. Left alone, one such failure ends the process: the gateway dies because
|
|
11
|
+
* a single client stopped listening, taking every other session with it.
|
|
12
|
+
*
|
|
13
|
+
* Both failure shapes are handled because the SDK produces both. A transport
|
|
14
|
+
* holding no stream for the request throws before it returns a promise; one
|
|
15
|
+
* that fails mid-write rejects the promise it already returned.
|
|
16
|
+
*
|
|
17
|
+
* The first failure latches the notifier shut. A dropped stream does not come
|
|
18
|
+
* back, and a single turn emits progress continuously, so trying again only
|
|
19
|
+
* spends work to fail the same way.
|
|
20
|
+
*/
|
|
21
|
+
export function createProgressNotifier(extra) {
|
|
22
|
+
const progressToken = extra?._meta?.progressToken;
|
|
23
|
+
if (extra === undefined || progressToken === undefined) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
let progress = 0;
|
|
27
|
+
let listening = true;
|
|
28
|
+
const stopListening = (error) => {
|
|
29
|
+
listening = false;
|
|
30
|
+
// Said once per call rather than per event: a host that hung up is
|
|
31
|
+
// ordinary, but a silent gateway is what makes it hard to explain.
|
|
32
|
+
console.debug("gateway progress stream closed by the host", error);
|
|
33
|
+
};
|
|
34
|
+
return (message) => {
|
|
35
|
+
if (!listening) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
progress += 1;
|
|
39
|
+
try {
|
|
40
|
+
void extra
|
|
41
|
+
.sendNotification({
|
|
42
|
+
method: "notifications/progress",
|
|
43
|
+
params: { message, progress, progressToken },
|
|
44
|
+
})
|
|
45
|
+
.catch(stopListening);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
stopListening(error);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=progress-notifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress-notifier.js","sourceRoot":"","sources":["../../../src/transports/mcp/progress-notifier.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAA6C;IAE7C,MAAM,aAAa,GAAG,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC;IAClD,IAAI,KAAK,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QACvD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,SAAS,GAAG,IAAI,CAAC;IAErB,MAAM,aAAa,GAAG,CAAC,KAAc,EAAE,EAAE;QACvC,SAAS,GAAG,KAAK,CAAC;QAClB,mEAAmE;QACnE,mEAAmE;QACnE,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC,CAAC;IAEF,OAAO,CAAC,OAAe,EAAE,EAAE;QACzB,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO;QACT,CAAC;QACD,QAAQ,IAAI,CAAC,CAAC;QACd,IAAI,CAAC;YACH,KAAK,KAAK;iBACP,gBAAgB,CAAC;gBAChB,MAAM,EAAE,wBAAwB;gBAChC,MAAM,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE;aAC7C,CAAC;iBACD,KAAK,CAAC,aAAa,CAAC,CAAC;QAC1B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|