mcp-proxy 6.4.4 → 6.4.5
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/bin/mcp-proxy.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{stdio-BmURZCbz.mjs → stdio-_93Y9W6l.mjs} +6 -3
- package/dist/{stdio-BmURZCbz.mjs.map → stdio-_93Y9W6l.mjs.map} +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/startHTTPServer.test.ts +54 -0
- package/src/startHTTPServer.ts +11 -6
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -692,6 +692,60 @@ it("does not require auth for OPTIONS requests", async () => {
|
|
|
692
692
|
await httpServer.close();
|
|
693
693
|
});
|
|
694
694
|
|
|
695
|
+
it("allows onUnhandledRequest to serve routes without auth", async () => {
|
|
696
|
+
const port = await getRandomPort();
|
|
697
|
+
const apiKey = "test-api-key-unhandled";
|
|
698
|
+
|
|
699
|
+
const httpServer = await startHTTPServer({
|
|
700
|
+
apiKey,
|
|
701
|
+
createServer: async () => {
|
|
702
|
+
const mcpServer = new Server(
|
|
703
|
+
{ name: "test", version: "1.0.0" },
|
|
704
|
+
{ capabilities: {} },
|
|
705
|
+
);
|
|
706
|
+
return mcpServer;
|
|
707
|
+
},
|
|
708
|
+
onUnhandledRequest: async (req, res) => {
|
|
709
|
+
if (req.url === "/health") {
|
|
710
|
+
res.writeHead(200).end("ok");
|
|
711
|
+
} else if (req.url === "/ready") {
|
|
712
|
+
res.writeHead(200).end("ready");
|
|
713
|
+
}
|
|
714
|
+
// Don't write response for unknown paths — fall through to MCP handlers
|
|
715
|
+
},
|
|
716
|
+
port,
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
// /health works without auth
|
|
720
|
+
const healthResponse = await fetch(`http://localhost:${port}/health`);
|
|
721
|
+
expect(healthResponse.status).toBe(200);
|
|
722
|
+
expect(await healthResponse.text()).toBe("ok");
|
|
723
|
+
|
|
724
|
+
// /ready works without auth
|
|
725
|
+
const readyResponse = await fetch(`http://localhost:${port}/ready`);
|
|
726
|
+
expect(readyResponse.status).toBe(200);
|
|
727
|
+
expect(await readyResponse.text()).toBe("ready");
|
|
728
|
+
|
|
729
|
+
// POST /mcp without auth still returns 401
|
|
730
|
+
const mcpResponse = await fetch(`http://localhost:${port}/mcp`, {
|
|
731
|
+
body: JSON.stringify({
|
|
732
|
+
id: 1,
|
|
733
|
+
jsonrpc: "2.0",
|
|
734
|
+
method: "initialize",
|
|
735
|
+
params: {
|
|
736
|
+
capabilities: {},
|
|
737
|
+
clientInfo: { name: "test", version: "1.0.0" },
|
|
738
|
+
protocolVersion: "2025-03-26",
|
|
739
|
+
},
|
|
740
|
+
}),
|
|
741
|
+
headers: { "Content-Type": "application/json" },
|
|
742
|
+
method: "POST",
|
|
743
|
+
});
|
|
744
|
+
expect(mcpResponse.status).toBe(401);
|
|
745
|
+
|
|
746
|
+
await httpServer.close();
|
|
747
|
+
});
|
|
748
|
+
|
|
695
749
|
// Stateless OAuth 2.0 JWT Bearer Token Authentication Tests (PR #37)
|
|
696
750
|
|
|
697
751
|
it("accepts requests with valid Bearer token in stateless mode", async () => {
|
package/src/startHTTPServer.ts
CHANGED
|
@@ -938,7 +938,16 @@ export const startHTTPServer = async <T extends ServerLike>({
|
|
|
938
938
|
return;
|
|
939
939
|
}
|
|
940
940
|
|
|
941
|
-
//
|
|
941
|
+
// Let non-MCP routes (e.g. /health, /ready, OAuth metadata) be handled
|
|
942
|
+
// before auth — API key auth protects MCP protocol endpoints, not custom routes.
|
|
943
|
+
if (onUnhandledRequest) {
|
|
944
|
+
await onUnhandledRequest(req, res);
|
|
945
|
+
if (res.writableEnded) {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// Check authentication for MCP protocol endpoints
|
|
942
951
|
if (!authMiddleware.validateRequest(req)) {
|
|
943
952
|
const authResponse = authMiddleware.getUnauthorizedResponse();
|
|
944
953
|
res.writeHead(401, authResponse.headers);
|
|
@@ -982,11 +991,7 @@ export const startHTTPServer = async <T extends ServerLike>({
|
|
|
982
991
|
return;
|
|
983
992
|
}
|
|
984
993
|
|
|
985
|
-
|
|
986
|
-
await onUnhandledRequest(req, res);
|
|
987
|
-
} else {
|
|
988
|
-
res.writeHead(404).end();
|
|
989
|
-
}
|
|
994
|
+
res.writeHead(404).end();
|
|
990
995
|
};
|
|
991
996
|
|
|
992
997
|
let httpServer;
|