@tinycloud/mcp 0.8.7-beta.3 → 0.9.0-beta.4

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/http.cjs CHANGED
@@ -1943,7 +1943,7 @@ function outcomeCode(result) {
1943
1943
  // package.json
1944
1944
  var package_default = {
1945
1945
  name: "@tinycloud/mcp",
1946
- version: "0.8.7-beta.3",
1946
+ version: "0.9.0-beta.4",
1947
1947
  description: "TinyCloud delegated operations MCP server",
1948
1948
  keywords: [
1949
1949
  "tinycloud",
@@ -2040,6 +2040,7 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2040
2040
 
2041
2041
  // src/http.ts
2042
2042
  var REQUIRED_SCOPE = "tinycloud:mcp";
2043
+ var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2043
2044
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2044
2045
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2045
2046
  function createHostedMcpApp(config) {
@@ -2360,8 +2361,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2360
2361
  if (url.pathname === callbackPath) {
2361
2362
  if (request.method === "OPTIONS") return callbackCors(new Response(null, { status: 204 }), config.openkeyHost);
2362
2363
  if (request.method !== "POST") return methodNotAllowed("POST");
2363
- const originFailure2 = validateCallbackOrigin(request, config.openkeyHost);
2364
- if (originFailure2 !== void 0) return callbackCors(originFailure2, config.openkeyHost);
2364
+ const originFailure = validateCallbackOrigin(request, config.openkeyHost);
2365
+ if (originFailure !== void 0) return callbackCors(originFailure, config.openkeyHost);
2365
2366
  try {
2366
2367
  await store.completeApproval(requiredState(url), request);
2367
2368
  return callbackCors(json({ success: true }), config.openkeyHost);
@@ -2455,11 +2456,9 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2455
2456
  });
2456
2457
  }
2457
2458
  if (url.pathname !== resourceUrl.pathname) return json({ error: "Not found" }, 404);
2458
- const originFailure = validateOrigin(request, config.allowedOrigins);
2459
- if (originFailure !== void 0) return originFailure;
2459
+ if (request.method === "OPTIONS") return mcpCors(new Response(null, { status: 204 }), request);
2460
2460
  const auth = await authenticate(request);
2461
- if (auth instanceof Response) return auth;
2462
- return handler.fetch(request, { authInfo: auth });
2461
+ return mcpCors(auth instanceof Response ? auth : await handler.fetch(request, { authInfo: auth }), request);
2463
2462
  },
2464
2463
  close: () => handler.close()
2465
2464
  };
@@ -2547,11 +2546,16 @@ function requiredState(url) {
2547
2546
  if (state.length > 512) throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
2548
2547
  return state;
2549
2548
  }
2550
- function validateOrigin(request, allowed) {
2551
- const origin = request.headers.get("origin");
2552
- if (origin === null) return void 0;
2553
- const allowlist = allowed ?? [];
2554
- return allowlist.includes(origin) ? void 0 : json({ error: "Origin is not allowed." }, 403);
2549
+ function mcpCors(response, request) {
2550
+ const headers = new Headers(response.headers);
2551
+ headers.append("vary", "Origin");
2552
+ if (request.headers.has("origin")) {
2553
+ headers.set("access-control-allow-origin", "*");
2554
+ headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2555
+ headers.set("access-control-expose-headers", "WWW-Authenticate");
2556
+ if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2557
+ }
2558
+ return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
2555
2559
  }
2556
2560
  function validateCallbackOrigin(request, openkeyHost) {
2557
2561
  const origin = request.headers.get("origin");