Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ app.use(express.json());

app.post(["/", "/mcp"], handleRequest);

app.get("/", (_req, res) => {
app.get(["/", "/mcp"], (req, res) => {
// Redirecting SSE clients to HTML can cause an endless reconnect loop.
if (req.accepts(["html", "text/event-stream"]) === "text/event-stream") {
res.set("Allow", "POST").sendStatus(405);
return;
}
res.redirect(302, "https://developer.mozilla.org/en-US/mcp");
});

Expand Down
31 changes: 27 additions & 4 deletions test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,33 @@ describe("server", () => {
assert.deepEqual(ping, {});
});

it("should redirect get requests to the repo", async () => {
const res = await fetch(`http://localhost:${server.port}`);
assert.ok(res.redirected);
assert.strictEqual(res.url, "https://developer.mozilla.org/en-US/mcp");
it("should redirect ordinary visits to the landing page", async () => {
for (const path of ["/", "/mcp"]) {
for (const accept of ["*/*", "text/html"]) {
const res = await fetch(`http://localhost:${server.port}${path}`, {
headers: { Accept: accept },
});
assert.ok(res.redirected);
assert.strictEqual(res.url, "https://developer.mozilla.org/en-US/mcp");
}
}
});

it("should reject optional MCP notification streams without redirecting", async () => {
for (const path of ["/", "/mcp"]) {
for (const accept of [
"text/event-stream",
"application/json, text/event-stream",
]) {
const res = await fetch(`http://localhost:${server.port}${path}`, {
headers: { Accept: accept },
redirect: "manual",
});
assert.equal(res.status, 405);
assert.equal(res.headers.get("allow"), "POST");
assert.equal(res.headers.get("location"), null);
}
}
});

after(() => {
Expand Down
Loading