@trylighthouse/mcp-server 0.2.20 → 0.2.23
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/build/index.js +5 -4
- package/build/server.js +188 -187
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -11,7 +11,7 @@ async function main() {
|
|
|
11
11
|
const sessions = new Map();
|
|
12
12
|
const httpServer = createHttpServer(async (req, res) => {
|
|
13
13
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
14
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type, mcp-session-id");
|
|
14
|
+
res.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type, mcp-session-id");
|
|
15
15
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
16
16
|
res.setHeader("Access-Control-Expose-Headers", "mcp-session-id");
|
|
17
17
|
if (req.method === "OPTIONS") {
|
|
@@ -30,10 +30,11 @@ async function main() {
|
|
|
30
30
|
res.end("Not found. Use /mcp");
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const authorization = req.headers.authorization ?? "";
|
|
34
|
+
const apiKey = authorization.startsWith("Bearer ") ? authorization.slice("Bearer ".length).trim() : "";
|
|
34
35
|
if (!apiKey) {
|
|
35
36
|
res.writeHead(401, { "Content-Type": "application/json" });
|
|
36
|
-
res.end(JSON.stringify({ error: "
|
|
37
|
+
res.end(JSON.stringify({ error: "Send your API key in an Authorization header: Bearer <key>" }));
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
const sessionId = req.headers["mcp-session-id"];
|
|
@@ -41,7 +42,7 @@ async function main() {
|
|
|
41
42
|
const session = sessions.get(sessionId);
|
|
42
43
|
if (session.apiKey !== apiKey) {
|
|
43
44
|
res.writeHead(403, { "Content-Type": "application/json" });
|
|
44
|
-
res.end(JSON.stringify({ error: "This session belongs to a different
|
|
45
|
+
res.end(JSON.stringify({ error: "This session belongs to a different API key" }));
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
47
48
|
await session.transport.handleRequest(req, res);
|