@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-cli.js CHANGED
@@ -1958,7 +1958,7 @@ function outcomeCode(result) {
1958
1958
  // package.json
1959
1959
  var package_default = {
1960
1960
  name: "@tinycloud/mcp",
1961
- version: "0.8.7-beta.3",
1961
+ version: "0.9.0-beta.4",
1962
1962
  description: "TinyCloud delegated operations MCP server",
1963
1963
  keywords: [
1964
1964
  "tinycloud",
@@ -2055,6 +2055,7 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2055
2055
 
2056
2056
  // src/http.ts
2057
2057
  var REQUIRED_SCOPE = "tinycloud:mcp";
2058
+ var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2058
2059
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2059
2060
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2060
2061
  function createHostedMcpApp(config) {
@@ -2375,8 +2376,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2375
2376
  if (url.pathname === callbackPath) {
2376
2377
  if (request.method === "OPTIONS") return callbackCors(new Response(null, { status: 204 }), config.openkeyHost);
2377
2378
  if (request.method !== "POST") return methodNotAllowed("POST");
2378
- const originFailure2 = validateCallbackOrigin(request, config.openkeyHost);
2379
- if (originFailure2 !== void 0) return callbackCors(originFailure2, config.openkeyHost);
2379
+ const originFailure = validateCallbackOrigin(request, config.openkeyHost);
2380
+ if (originFailure !== void 0) return callbackCors(originFailure, config.openkeyHost);
2380
2381
  try {
2381
2382
  await store.completeApproval(requiredState(url), request);
2382
2383
  return callbackCors(json({ success: true }), config.openkeyHost);
@@ -2470,11 +2471,9 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2470
2471
  });
2471
2472
  }
2472
2473
  if (url.pathname !== resourceUrl.pathname) return json({ error: "Not found" }, 404);
2473
- const originFailure = validateOrigin(request, config.allowedOrigins);
2474
- if (originFailure !== void 0) return originFailure;
2474
+ if (request.method === "OPTIONS") return mcpCors(new Response(null, { status: 204 }), request);
2475
2475
  const auth = await authenticate(request);
2476
- if (auth instanceof Response) return auth;
2477
- return handler.fetch(request, { authInfo: auth });
2476
+ return mcpCors(auth instanceof Response ? auth : await handler.fetch(request, { authInfo: auth }), request);
2478
2477
  },
2479
2478
  close: () => handler.close()
2480
2479
  };
@@ -2562,11 +2561,16 @@ function requiredState(url) {
2562
2561
  if (state.length > 512) throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
2563
2562
  return state;
2564
2563
  }
2565
- function validateOrigin(request, allowed) {
2566
- const origin = request.headers.get("origin");
2567
- if (origin === null) return void 0;
2568
- const allowlist = allowed ?? [];
2569
- return allowlist.includes(origin) ? void 0 : json({ error: "Origin is not allowed." }, 403);
2564
+ function mcpCors(response, request) {
2565
+ const headers = new Headers(response.headers);
2566
+ headers.append("vary", "Origin");
2567
+ if (request.headers.has("origin")) {
2568
+ headers.set("access-control-allow-origin", "*");
2569
+ headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2570
+ headers.set("access-control-expose-headers", "WWW-Authenticate");
2571
+ if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2572
+ }
2573
+ return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
2570
2574
  }
2571
2575
  function validateCallbackOrigin(request, openkeyHost) {
2572
2576
  const origin = request.headers.get("origin");
@@ -2679,7 +2683,6 @@ async function main() {
2679
2683
  openkeyHost,
2680
2684
  approvalTtlSeconds: positiveInteger(process.env.TC_MCP_APPROVAL_TTL_SECONDS, 300),
2681
2685
  delegationExpiry: process.env.TC_MCP_DELEGATION_EXPIRY ?? "1h",
2682
- allowedOrigins: commaList(process.env.TC_MCP_ALLOWED_ORIGINS),
2683
2686
  ...process.env.TC_MCP_NATIVE_SERVICE_CREDENTIAL === void 0 ? {} : { nativeServiceCredential: process.env.TC_MCP_NATIVE_SERVICE_CREDENTIAL },
2684
2687
  oauthMetadata,
2685
2688
  introspection: {
@@ -2731,10 +2734,6 @@ function positiveInteger(value, fallback) {
2731
2734
  if (!Number.isInteger(parsed) || parsed <= 0) throw new Error("Expected a positive integer environment value.");
2732
2735
  return parsed;
2733
2736
  }
2734
- function commaList(value) {
2735
- if (value === void 0) return void 0;
2736
- return value.split(",").map((entry) => entry.trim()).filter(Boolean);
2737
- }
2738
2737
  void main().catch(() => {
2739
2738
  process.stderr.write("[tinycloud-mcp-http] Startup failed.\n");
2740
2739
  process.exitCode = 1;