fetchsandbox-mcp 0.5.5 → 0.5.7
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/dist/client.js +14 -4
- package/dist/client.js.map +1 -1
- package/dist/http.d.ts +1 -0
- package/dist/http.js +249 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +200 -159
- package/dist/index.js.map +1 -1
- package/dist/request_context.d.ts +30 -0
- package/dist/request_context.js +74 -0
- package/dist/request_context.js.map +1 -0
- package/dist/signin.js +30 -0
- package/dist/signin.js.map +1 -1
- package/dist/tools/fix_bug.js +3 -2
- package/dist/tools/fix_bug.js.map +1 -1
- package/dist/tools/prove_fix.d.ts +1 -1
- package/dist/tools/prove_fix.js +18 -1
- package/dist/tools/prove_fix.js.map +1 -1
- package/dist/tools/scenarios.d.ts +56 -0
- package/dist/tools/scenarios.js +115 -0
- package/dist/tools/scenarios.js.map +1 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { detectIde, getSessionId } from "./session.js";
|
|
11
11
|
import { readCredentials } from "./auth.js";
|
|
12
|
+
import { currentIdentity } from "./request_context.js";
|
|
12
13
|
import { VERSION } from "./version.js";
|
|
13
14
|
const DEFAULT_BASE_URL = "https://fetchsandbox.com";
|
|
14
15
|
const REQUEST_TIMEOUT_MS = 30_000;
|
|
@@ -42,13 +43,22 @@ export function buildHeaders(extra) {
|
|
|
42
43
|
const sid = getSessionId();
|
|
43
44
|
if (sid)
|
|
44
45
|
headers["x-mcp-session-id"] = sid;
|
|
45
|
-
|
|
46
|
+
// A hosted request knows its platform from Origin; stdio knows its editor
|
|
47
|
+
// from env. Whichever is present is the truthful answer.
|
|
48
|
+
headers["x-mcp-client"] = currentIdentity()?.platform || ide;
|
|
46
49
|
// The session id IS the install id (see auth.ts) and the backend already
|
|
47
50
|
// reads that header everywhere, so a key is the only thing to add. Absent
|
|
48
51
|
// credentials send nothing and the request behaves exactly as it did before.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
//
|
|
53
|
+
// ORDER MATTERS. A hosted request carries its OWN caller's key in the async
|
|
54
|
+
// context, and that must beat anything cached on disk or in the module —
|
|
55
|
+
// otherwise one tenant's key serves another tenant's request. stdio and CI
|
|
56
|
+
// never enter a request scope, so they fall through to exactly the source
|
|
57
|
+
// they used before. See request_context.ts for the leak this prevents.
|
|
58
|
+
const perRequest = currentIdentity()?.apiKey;
|
|
59
|
+
const apiKey = perRequest || readCredentials()?.apiKey;
|
|
60
|
+
if (apiKey)
|
|
61
|
+
headers["authorization"] = `Bearer ${apiKey}`;
|
|
52
62
|
return headers;
|
|
53
63
|
}
|
|
54
64
|
async function readErrorMessage(res) {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AACpD,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,wEAAwE;AACxE,gEAAgE;AAChE,6EAA6E;AAC7E,gFAAgF;AAChF,8EAA8E;AAC9E,yEAAyE;AACzE,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAChD,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,MAAM,CAAU;IAChB,YAAY,OAAe,EAAE,MAAe;QAC1C,KAA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TED entry point. Same tools, same handlers, over streamable HTTP.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
*
|
|
6
|
+
* Lovable, Bolt, Replit and Base44 all require a remote MCP URL. None of them
|
|
7
|
+
* can spawn a local process, so `npx fetchsandbox-mcp` — the only transport we
|
|
8
|
+
* had — means those users literally cannot add us. Verified 2026-09-19 against
|
|
9
|
+
* each platform's own documentation, and by sending a real MCP `initialize` to
|
|
10
|
+
* /mcp, /api/mcp, /sse and /api/mcp/sse, which answered 405/404/404/404.
|
|
11
|
+
*
|
|
12
|
+
* All four accept a static bearer or header instead of OAuth, so this one
|
|
13
|
+
* build serves all four and OAuth stays a later, directory-specific concern.
|
|
14
|
+
*
|
|
15
|
+
* WHAT IT IS NOT
|
|
16
|
+
*
|
|
17
|
+
* Not a second implementation. It imports `createServer` and
|
|
18
|
+
* `registerHandlers` from index.ts, so the 14 tool definitions, their
|
|
19
|
+
* annotations and their dispatch are the SAME objects stdio uses. A
|
|
20
|
+
* hand-written tool list here would drift within weeks and the drift would be
|
|
21
|
+
* invisible — hosted users silently getting a different product. The parity
|
|
22
|
+
* test pins it.
|
|
23
|
+
*
|
|
24
|
+
* STATELESS, DELIBERATELY
|
|
25
|
+
*
|
|
26
|
+
* `sessionIdGenerator: undefined`. Every piece of state we have already lives
|
|
27
|
+
* server-side and is addressed by `sandbox_id`, which the tools pass
|
|
28
|
+
* explicitly. There is nothing for a session to hold. Stateless means no
|
|
29
|
+
* session store, no sticky routing, and horizontal scale for free; stateful
|
|
30
|
+
* would add a failure mode for state we do not have.
|
|
31
|
+
*
|
|
32
|
+
* AUTH FORWARDS, IT NEVER DECIDES
|
|
33
|
+
*
|
|
34
|
+
* The caller's Authorization header is passed through to the backend, which
|
|
35
|
+
* runs IdentityMiddleware and RequireAuthMiddleware exactly as it does for the
|
|
36
|
+
* stdio client. This process holds no user table and validates no key. One
|
|
37
|
+
* source of truth for auth, so a hosted caller and a local caller can never
|
|
38
|
+
* get different answers about who may spend.
|
|
39
|
+
*/
|
|
40
|
+
import { randomUUID } from "node:crypto";
|
|
41
|
+
import { createServer as createHttpServer } from "node:http";
|
|
42
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
43
|
+
import { createServer, registerHandlers } from "./index.js";
|
|
44
|
+
import { withRequestIdentity } from "./request_context.js";
|
|
45
|
+
import { VERSION } from "./version.js";
|
|
46
|
+
const PORT = Number(process.env.PORT || 8787);
|
|
47
|
+
const PATH = process.env.MCP_HTTP_PATH || "/mcp/v1";
|
|
48
|
+
/**
|
|
49
|
+
* Bind LOOPBACK by default.
|
|
50
|
+
*
|
|
51
|
+
* The MCP security guidance is explicit: an HTTP MCP server running locally
|
|
52
|
+
* binds 127.0.0.1, not 0.0.0.0, or any process on the network can drive it.
|
|
53
|
+
* In a container the orchestrator needs 0.0.0.0, so it is overridable — but
|
|
54
|
+
* the default is the safe one, because the unsafe default is the one people
|
|
55
|
+
* ship by accident.
|
|
56
|
+
*/
|
|
57
|
+
const HOST = process.env.MCP_HTTP_HOST || "127.0.0.1";
|
|
58
|
+
/**
|
|
59
|
+
* Hard ceiling on a single tool call.
|
|
60
|
+
*
|
|
61
|
+
* Measured 2026-09-19: verify_behavior took 53.9s against prod and returned
|
|
62
|
+
* 504 on a first attempt; Cloudflare cuts at ~100s. A request with no ceiling
|
|
63
|
+
* of our own becomes a zombie holding a connection until the edge kills it,
|
|
64
|
+
* and the caller sees an opaque gateway error instead of ours. Ending it
|
|
65
|
+
* ourselves, just inside the edge's limit, means the agent gets a JSON-RPC
|
|
66
|
+
* error it can act on.
|
|
67
|
+
*/
|
|
68
|
+
const REQUEST_TIMEOUT_MS = Number(process.env.MCP_REQUEST_TIMEOUT_MS || 90_000);
|
|
69
|
+
/**
|
|
70
|
+
* Origins allowed to drive this endpoint.
|
|
71
|
+
*
|
|
72
|
+
* The MCP spec requires an HTTP server to validate Origin: without it a
|
|
73
|
+
* hostile page in a user's browser can drive a local or credentialed MCP
|
|
74
|
+
* server (DNS rebinding). A request with no Origin at all is a server-to-
|
|
75
|
+
* server call and is allowed — that is how every one of these platforms
|
|
76
|
+
* actually calls us.
|
|
77
|
+
*/
|
|
78
|
+
const ALLOWED_ORIGINS = (process.env.MCP_ALLOWED_ORIGINS ||
|
|
79
|
+
"https://lovable.dev,https://bolt.new,https://replit.com,https://app.base44.com,https://fetchsandbox.com")
|
|
80
|
+
.split(",").map((s) => s.trim()).filter(Boolean);
|
|
81
|
+
/**
|
|
82
|
+
* Which platform is calling.
|
|
83
|
+
*
|
|
84
|
+
* `detectIde()` reads process ENV VARS, which the editor sets when it spawns
|
|
85
|
+
* the stdio client. A container has no such env, so every hosted request
|
|
86
|
+
* would report the same thing and Lovable, Bolt and Replit would land in one
|
|
87
|
+
* undifferentiated bucket — you could not tell which platform retains.
|
|
88
|
+
*
|
|
89
|
+
* Origin is the signal we already validate, so it costs nothing to reuse. The
|
|
90
|
+
* backend records `x-mcp-client` today, so setting it here splits retention by
|
|
91
|
+
* platform with no telemetry change at all.
|
|
92
|
+
*/
|
|
93
|
+
function callerPlatform(req) {
|
|
94
|
+
const origin = (req.headers.origin || "").toLowerCase();
|
|
95
|
+
const ua = String(req.headers["user-agent"] || "").toLowerCase();
|
|
96
|
+
const hay = origin + " " + ua;
|
|
97
|
+
for (const [needle, name] of [
|
|
98
|
+
["lovable", "lovable"], ["bolt.new", "bolt"], ["stackblitz", "bolt"],
|
|
99
|
+
["replit", "replit"], ["base44", "base44"],
|
|
100
|
+
["claude", "claude"], ["cursor", "cursor"], ["openai", "chatgpt"],
|
|
101
|
+
]) {
|
|
102
|
+
if (hay.includes(needle))
|
|
103
|
+
return name;
|
|
104
|
+
}
|
|
105
|
+
// Honest default. "unknown" is a real answer; guessing a platform would
|
|
106
|
+
// put made-up rows in the retention split.
|
|
107
|
+
return "hosted-unknown";
|
|
108
|
+
}
|
|
109
|
+
function originAllowed(req) {
|
|
110
|
+
const origin = req.headers.origin;
|
|
111
|
+
if (!origin)
|
|
112
|
+
return true; // server-to-server, no browser
|
|
113
|
+
return ALLOWED_ORIGINS.includes(origin);
|
|
114
|
+
}
|
|
115
|
+
function json(res, status, body) {
|
|
116
|
+
const payload = JSON.stringify(body);
|
|
117
|
+
res.writeHead(status, { "content-type": "application/json" });
|
|
118
|
+
res.end(payload);
|
|
119
|
+
}
|
|
120
|
+
/** A JSON-RPC error, which is what an MCP client can actually parse. */
|
|
121
|
+
function rpcError(res, status, code, message, data) {
|
|
122
|
+
res.writeHead(status, { "content-type": "application/json" });
|
|
123
|
+
res.end(JSON.stringify({ jsonrpc: "2.0", id: null,
|
|
124
|
+
error: { code, message, ...(data ? { data } : {}) } }));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A FRESH server + transport per request. This is what stateless actually means.
|
|
128
|
+
*
|
|
129
|
+
* The first version connected one server to one transport at startup and
|
|
130
|
+
* reused both. `initialize` worked; the very next `tools/call` returned 500 in
|
|
131
|
+
* 0ms — the transport had already been consumed by the previous exchange and
|
|
132
|
+
* rejected the new one before any tool ran. A shared transport is a single
|
|
133
|
+
* request/response pair, not a server.
|
|
134
|
+
*
|
|
135
|
+
* Per-request construction is cheap (the tool definitions are module-level
|
|
136
|
+
* objects; only the wiring is rebuilt) and it is what makes round-robin load
|
|
137
|
+
* balancing correct: no instance holds anything another instance would need.
|
|
138
|
+
*/
|
|
139
|
+
/** The caller's bearer, or "" — never a cached or on-disk key. */
|
|
140
|
+
function bearerOf(req) {
|
|
141
|
+
const h = req.headers.authorization || "";
|
|
142
|
+
const [scheme, ...rest] = h.split(" ");
|
|
143
|
+
return scheme?.toLowerCase() === "bearer" ? rest.join(" ").trim() : "";
|
|
144
|
+
}
|
|
145
|
+
async function handleMcp(req, res, reqId) {
|
|
146
|
+
const server = createServer();
|
|
147
|
+
registerHandlers(server);
|
|
148
|
+
const transport = new StreamableHTTPServerTransport({
|
|
149
|
+
sessionIdGenerator: undefined, // stateless: no session ids, no affinity
|
|
150
|
+
});
|
|
151
|
+
// Close both when the response ends, or every request leaks a server.
|
|
152
|
+
res.on("close", () => { void transport.close(); void server.close(); });
|
|
153
|
+
await server.connect(transport);
|
|
154
|
+
// EVERY tool call for this request runs inside this identity. buildHeaders()
|
|
155
|
+
// reads it at the single chokepoint, so no tool can accidentally reach for a
|
|
156
|
+
// shared credential. Absent bearer => no key => the backend answers 401,
|
|
157
|
+
// which is the correct, fail-closed outcome for a hosted caller.
|
|
158
|
+
await withRequestIdentity({ apiKey: bearerOf(req), requestId: reqId, platform: callerPlatform(req) }, () => transport.handleRequest(req, res));
|
|
159
|
+
}
|
|
160
|
+
async function main() {
|
|
161
|
+
const http = createHttpServer(async (req, res) => {
|
|
162
|
+
const started = Date.now();
|
|
163
|
+
const reqId = randomUUID().slice(0, 8);
|
|
164
|
+
const url = new URL(req.url || "/", `http://${req.headers.host || "localhost"}`);
|
|
165
|
+
// ONE LINE PER REQUEST, to stderr.
|
|
166
|
+
//
|
|
167
|
+
// A hosted endpoint whose failures are invisible is one nobody can trust.
|
|
168
|
+
// This repo already records the cost of that: mcp telemetry had no way to
|
|
169
|
+
// reach a user for months, so "who is failing" was unanswerable while both
|
|
170
|
+
// halves of the data existed. Structured, greppable, no PII — method, path,
|
|
171
|
+
// status, duration.
|
|
172
|
+
const done = (status, note = "") => {
|
|
173
|
+
process.stderr.write(`[mcp-http] id=${reqId} ${req.method} ${url.pathname} ` +
|
|
174
|
+
`status=${status} ms=${Date.now() - started} ` +
|
|
175
|
+
`client=${callerPlatform(req)}${note ? " " + note : ""}\n`);
|
|
176
|
+
};
|
|
177
|
+
res.on("finish", () => done(res.statusCode));
|
|
178
|
+
// Liveness, deliberately OUTSIDE the MCP path so a health checker never
|
|
179
|
+
// has to speak the protocol.
|
|
180
|
+
if (url.pathname === "/healthz") {
|
|
181
|
+
// Outside the MCP path on purpose: a readiness probe must never have to
|
|
182
|
+
// speak the protocol, and a load balancer must be able to check liveness
|
|
183
|
+
// without a valid session or key.
|
|
184
|
+
return json(res, 200, { ok: true, version: VERSION, path: PATH });
|
|
185
|
+
}
|
|
186
|
+
if (url.pathname !== PATH) {
|
|
187
|
+
return json(res, 404, {
|
|
188
|
+
error: "not found",
|
|
189
|
+
hint: `the MCP endpoint is ${PATH}`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
// Reverse proxies buffer by default, which holds a streamed response until
|
|
193
|
+
// it completes — turning an incremental stream into a long silence and
|
|
194
|
+
// then a gateway timeout. Cloudflare sits in front of this and cuts at
|
|
195
|
+
// ~100s, which is how verify_behavior produced a 504 at 54s. Telling the
|
|
196
|
+
// proxy not to buffer is the half we control from here; the nginx side
|
|
197
|
+
// needs proxy_buffering off.
|
|
198
|
+
res.setHeader("X-Accel-Buffering", "no");
|
|
199
|
+
if (!originAllowed(req)) {
|
|
200
|
+
// Refuse rather than silently serve: a rejected origin is a security
|
|
201
|
+
// event, and a 403 that says why is easier to debug than a hang.
|
|
202
|
+
return json(res, 403, {
|
|
203
|
+
error: "origin not allowed",
|
|
204
|
+
origin: req.headers.origin,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
// A ceiling of our own, just inside the edge's. Without it a stuck tool
|
|
208
|
+
// holds the connection until Cloudflare kills it and the agent gets an
|
|
209
|
+
// opaque 504 instead of an error it can reason about.
|
|
210
|
+
const killer = setTimeout(() => {
|
|
211
|
+
if (!res.headersSent) {
|
|
212
|
+
rpcError(res, 504, -32001, `tool call exceeded ${REQUEST_TIMEOUT_MS}ms`, { request_id: reqId, hint: "long tools return a job_id; poll it instead" });
|
|
213
|
+
done(504, "timeout");
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
res.destroy();
|
|
217
|
+
}
|
|
218
|
+
}, REQUEST_TIMEOUT_MS);
|
|
219
|
+
killer.unref?.();
|
|
220
|
+
try {
|
|
221
|
+
await handleMcp(req, res, reqId);
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
// Never leak a stack to a caller; log it where an operator can see it.
|
|
225
|
+
const id = randomUUID().slice(0, 8);
|
|
226
|
+
process.stderr.write(`[fetchsandbox-mcp-http] ${id} ${String(err)}\n`);
|
|
227
|
+
if (!res.headersSent) {
|
|
228
|
+
rpcError(res, 500, -32603, "internal error", { request_id: id });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
clearTimeout(killer);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
// Zombie connections are the other way a hosted server degrades quietly:
|
|
236
|
+
// sockets accumulate, the process looks healthy, and new requests queue.
|
|
237
|
+
http.headersTimeout = REQUEST_TIMEOUT_MS + 10_000;
|
|
238
|
+
http.requestTimeout = REQUEST_TIMEOUT_MS + 10_000;
|
|
239
|
+
http.keepAliveTimeout = 65_000; // above a typical 60s LB idle timeout
|
|
240
|
+
http.listen(PORT, HOST, () => {
|
|
241
|
+
process.stderr.write(`[fetchsandbox-mcp-http ${VERSION}] listening on ${HOST}:${PORT}${PATH} ` +
|
|
242
|
+
`(stateless; timeout ${REQUEST_TIMEOUT_MS}ms; origins ${ALLOWED_ORIGINS.length})\n`);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
main().catch((err) => {
|
|
246
|
+
process.stderr.write(`[fetchsandbox-mcp-http] fatal: ${String(err)}\n`);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
});
|
|
249
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAmC,MAAM,WAAW,CAAC;AAE9F,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,EAAE,Y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CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* ONE registry, TWO transports.
|
|
5
|
+
*
|
|
6
|
+
* `server` was a module-level singleton because stdio is the only transport
|
|
7
|
+
* that has ever existed here. A hosted endpoint needs its own instance per
|
|
8
|
+
* process (and, in stateless HTTP, potentially per request), so construction
|
|
9
|
+
* moves into a factory and both entry points call it.
|
|
10
|
+
*
|
|
11
|
+
* THE POINT OF THE FACTORY is not reuse, it is preventing DRIFT. A second,
|
|
12
|
+
* hand-written tool list for the HTTP surface would diverge within weeks and
|
|
13
|
+
* the divergence would be invisible: hosted users would silently get a
|
|
14
|
+
* different product from stdio users. `tests/transport-parity.test.mjs` pins
|
|
15
|
+
* that both transports expose byte-identical tool definitions.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createServer(): Server;
|
|
3
18
|
declare const server: Server<{
|
|
4
19
|
method: string;
|
|
5
20
|
params?: {
|
|
@@ -34,4 +49,5 @@ declare const server: Server<{
|
|
|
34
49
|
} | undefined;
|
|
35
50
|
} | undefined;
|
|
36
51
|
}>;
|
|
52
|
+
export declare function registerHandlers(server: Server): void;
|
|
37
53
|
export { server };
|