portals-mcp 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/dist/auth.js +61 -32
  2. package/package.json +1 -1
package/dist/auth.js CHANGED
@@ -2,39 +2,69 @@ import { createServer } from "node:http";
2
2
  import { exec } from "node:child_process";
3
3
  import { validateAccessKey } from "./api.js";
4
4
  const PORTAL_URL = "https://theportal.to/mcp";
5
+ const SUCCESS_HTML = `<!DOCTYPE html>
6
+ <html lang="en">
7
+ <head>
8
+ <meta charset="UTF-8">
9
+ <title>Portals MCP — Authenticated</title>
10
+ <style>
11
+ * { box-sizing: border-box; margin: 0; padding: 0; }
12
+ body { font-family: system-ui, sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #0f172a; color: #e2e8f0; }
13
+ .card { background: #1e293b; border-radius: 12px; padding: 2rem; width: 100%; max-width: 400px; box-shadow: 0 4px 24px rgba(0,0,0,.4); text-align: center; }
14
+ h1 { font-size: 1.25rem; margin-bottom: 0.5rem; color: #4ade80; }
15
+ p { font-size: 0.875rem; color: #94a3b8; }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <div class="card">
20
+ <h1>Authenticated!</h1>
21
+ <p>You can close this tab and return to Claude Code.</p>
22
+ </div>
23
+ </body>
24
+ </html>`;
25
+ const ERROR_HTML = (msg) => `<!DOCTYPE html>
26
+ <html lang="en">
27
+ <head>
28
+ <meta charset="UTF-8">
29
+ <title>Portals MCP — Error</title>
30
+ <style>
31
+ * { box-sizing: border-box; margin: 0; padding: 0; }
32
+ body { font-family: system-ui, sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #0f172a; color: #e2e8f0; }
33
+ .card { background: #1e293b; border-radius: 12px; padding: 2rem; width: 100%; max-width: 400px; box-shadow: 0 4px 24px rgba(0,0,0,.4); text-align: center; }
34
+ h1 { font-size: 1.25rem; margin-bottom: 0.5rem; color: #f87171; }
35
+ p { font-size: 0.875rem; color: #94a3b8; }
36
+ </style>
37
+ </head>
38
+ <body>
39
+ <div class="card">
40
+ <h1>Authentication Failed</h1>
41
+ <p>${msg}</p>
42
+ </div>
43
+ </body>
44
+ </html>`;
5
45
  export function authenticateViaBrowser() {
6
46
  return new Promise((resolve, reject) => {
7
47
  const httpServer = createServer(async (req, res) => {
8
- res.setHeader("Access-Control-Allow-Origin", "*");
9
- res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
10
- res.setHeader("Access-Control-Allow-Headers", "Content-Type");
11
- if (req.method === "OPTIONS") {
12
- res.writeHead(204);
13
- res.end();
14
- return;
15
- }
16
- if (req.method === "POST" && req.url === "/callback") {
17
- let body = "";
18
- req.on("data", (chunk) => { body += chunk.toString(); });
19
- req.on("end", async () => {
20
- let ok = false;
21
- try {
22
- const { accessKey } = JSON.parse(body);
23
- const uid = await validateAccessKey(accessKey);
24
- res.writeHead(200, { "Content-Type": "application/json", "Connection": "close" });
25
- res.end(JSON.stringify({ message: "Authenticated! You can close this tab." }));
26
- ok = true;
27
- resolve({ uid, accessKey });
28
- }
29
- catch (err) {
30
- const message = err instanceof Error ? err.message : "Invalid access key.";
31
- res.writeHead(401, { "Content-Type": "application/json" });
32
- res.end(JSON.stringify({ message }));
33
- }
34
- if (ok) {
35
- httpServer.close();
36
- }
37
- });
48
+ const url = new URL(req.url ?? "/", `http://localhost`);
49
+ if (req.method === "GET" && url.pathname === "/callback") {
50
+ const accessKey = url.searchParams.get("accessKey");
51
+ if (!accessKey) {
52
+ res.writeHead(400, { "Content-Type": "text/html" });
53
+ res.end(ERROR_HTML("Missing access key."));
54
+ return;
55
+ }
56
+ try {
57
+ const uid = await validateAccessKey(accessKey);
58
+ res.writeHead(200, { "Content-Type": "text/html", "Connection": "close" });
59
+ res.end(SUCCESS_HTML);
60
+ resolve({ uid, accessKey });
61
+ httpServer.close();
62
+ }
63
+ catch (err) {
64
+ const message = err instanceof Error ? err.message : "Invalid access key.";
65
+ res.writeHead(401, { "Content-Type": "text/html" });
66
+ res.end(ERROR_HTML(message));
67
+ }
38
68
  return;
39
69
  }
40
70
  res.writeHead(404);
@@ -46,8 +76,7 @@ export function authenticateViaBrowser() {
46
76
  reject(new Error("Failed to start auth server"));
47
77
  return;
48
78
  }
49
- const callbackPort = addr.port;
50
- exec(`open "${PORTAL_URL}?callbackPort=${callbackPort}"`);
79
+ exec(`open "${PORTAL_URL}?callbackPort=${addr.port}"`);
51
80
  });
52
81
  });
53
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "portals-mcp",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",