+9
packages/mcp/hono.ts
+9
packages/mcp/hono.ts
···
1
1
import { Hono } from "hono";
2
2
import { cors } from "hono/cors";
3
+
import { bearerAuth } from "hono/bearer-auth";
3
4
import { createConsumer } from "@cistern/consumer";
4
5
import { getLogger, withContext } from "@logtape/logtape";
5
6
import { toFetchResponse, toReqRes } from "fetch-to-node";
···
12
13
const logger = getLogger(["cistern", "http"]);
13
14
const sessions = new Map<string, StreamableHTTPServerTransport>();
14
15
16
+
const token = Deno.env.get("CISTERN_MCP_BEARER_TOKEN");
17
+
18
+
if (!token) {
19
+
logger.error("http mode requires CISTERN_MCP_BEARER_TOKEN to be set");
20
+
return Deno.exit(1);
21
+
}
22
+
23
+
app.use("*", bearerAuth({ token }));
15
24
app.use("*", async (c, next) => {
16
25
const requestId = crypto.randomUUID();
17
26
const startTime = Date.now();