@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/index.js CHANGED
@@ -485,7 +485,7 @@ function outcomeCode(result) {
485
485
  // package.json
486
486
  var package_default = {
487
487
  name: "@tinycloud/mcp",
488
- version: "0.8.7-beta.3",
488
+ version: "0.9.0-beta.4",
489
489
  description: "TinyCloud delegated operations MCP server",
490
490
  keywords: [
491
491
  "tinycloud",
@@ -2186,6 +2186,7 @@ function samePendingRequest(pending, expected) {
2186
2186
 
2187
2187
  // src/http.ts
2188
2188
  var REQUIRED_SCOPE = "tinycloud:mcp";
2189
+ var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2189
2190
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2190
2191
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2191
2192
  function createHostedMcpApp(config) {
@@ -2506,8 +2507,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2506
2507
  if (url.pathname === callbackPath) {
2507
2508
  if (request.method === "OPTIONS") return callbackCors(new Response(null, { status: 204 }), config.openkeyHost);
2508
2509
  if (request.method !== "POST") return methodNotAllowed("POST");
2509
- const originFailure2 = validateCallbackOrigin(request, config.openkeyHost);
2510
- if (originFailure2 !== void 0) return callbackCors(originFailure2, config.openkeyHost);
2510
+ const originFailure = validateCallbackOrigin(request, config.openkeyHost);
2511
+ if (originFailure !== void 0) return callbackCors(originFailure, config.openkeyHost);
2511
2512
  try {
2512
2513
  await store.completeApproval(requiredState(url), request);
2513
2514
  return callbackCors(json({ success: true }), config.openkeyHost);
@@ -2601,11 +2602,9 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2601
2602
  });
2602
2603
  }
2603
2604
  if (url.pathname !== resourceUrl.pathname) return json({ error: "Not found" }, 404);
2604
- const originFailure = validateOrigin(request, config.allowedOrigins);
2605
- if (originFailure !== void 0) return originFailure;
2605
+ if (request.method === "OPTIONS") return mcpCors(new Response(null, { status: 204 }), request);
2606
2606
  const auth = await authenticate(request);
2607
- if (auth instanceof Response) return auth;
2608
- return handler.fetch(request, { authInfo: auth });
2607
+ return mcpCors(auth instanceof Response ? auth : await handler.fetch(request, { authInfo: auth }), request);
2609
2608
  },
2610
2609
  close: () => handler.close()
2611
2610
  };
@@ -2693,11 +2692,16 @@ function requiredState(url) {
2693
2692
  if (state.length > 512) throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
2694
2693
  return state;
2695
2694
  }
2696
- function validateOrigin(request, allowed) {
2697
- const origin = request.headers.get("origin");
2698
- if (origin === null) return void 0;
2699
- const allowlist = allowed ?? [];
2700
- return allowlist.includes(origin) ? void 0 : json({ error: "Origin is not allowed." }, 403);
2695
+ function mcpCors(response, request) {
2696
+ const headers = new Headers(response.headers);
2697
+ headers.append("vary", "Origin");
2698
+ if (request.headers.has("origin")) {
2699
+ headers.set("access-control-allow-origin", "*");
2700
+ headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2701
+ headers.set("access-control-expose-headers", "WWW-Authenticate");
2702
+ if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2703
+ }
2704
+ return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
2701
2705
  }
2702
2706
  function validateCallbackOrigin(request, openkeyHost) {
2703
2707
  const origin = request.headers.get("origin");