diff --git a/deno.json b/deno.json index 4ec27cd..52ed44e 100644 --- a/deno.json +++ b/deno.json @@ -14,13 +14,13 @@ ] }, "tasks": { - "proxy:start": "deno run --allow-env --allow-read --allow-sys --allow-run=open --allow-write=\"$HOME/.mcp-auth/mcp-remote-deno-1.0.0\" --allow-net=0.0.0.0,localhost src/proxy.ts", - "proxy:watch": "deno run --watch --allow-env --allow-read --allow-sys --allow-run=open --allow-write=\"$HOME/.mcp-auth/mcp-remote-deno-1.0.0\" --allow-net=0.0.0.0,localhost src/proxy.ts", - "client:start": "deno run --allow-env --allow-read --allow-sys --allow-run=open --allow-write=\"$HOME/.mcp-auth/mcp-remote-deno-1.0.0\" --allow-net=0.0.0.0,localhost src/client.ts", - "client:watch": "deno run --watch --allow-env --allow-read --allow-sys --allow-run=open --allow-write=\"$HOME/.mcp-auth/mcp-remote-deno-1.0.0\" --allow-net=0.0.0.0,localhost src/client.ts", - "test": "deno test --allow-net --allow-env --allow-read tests/", - "test:watch": "deno test --watch --allow-net --allow-env --allow-read tests/", - "test:coverage": "deno test --coverage=coverage --allow-net --allow-env --allow-read tests/ && deno coverage coverage" + "proxy:start": "deno run --allow-env --allow-read --allow-sys=homedir --allow-run=open --allow-write=\"$HOME/.mcp-auth/mcp-remote-deno-1.0.0\" --allow-net=0.0.0.0,127.0.0.1,localhost src/proxy.ts", + "proxy:watch": "deno run --watch --allow-env --allow-read --allow-sys=homedir --allow-run=open --allow-write=\"$HOME/.mcp-auth/mcp-remote-deno-1.0.0\" --allow-net=0.0.0.0,127.0.0.1,localhost src/proxy.ts", + "client:start": "deno run --allow-env --allow-read --allow-sys=homedir --allow-run=open --allow-write=\"$HOME/.mcp-auth/mcp-remote-deno-1.0.0\" --allow-net=0.0.0.0,127.0.0.1,localhost src/client.ts", + "client:watch": "deno run --watch --allow-env --allow-read --allow-sys=homedir --allow-run=open --allow-write=\"$HOME/.mcp-auth/mcp-remote-deno-1.0.0\" --allow-net=0.0.0.0,127.0.0.1,localhost src/client.ts", + "test": "deno test --allow-net=0.0.0.0,127.0.0.1,localhost --allow-env --allow-read --allow-sys=homedir tests/", + "test:watch": "deno test --watch --allow-net=0.0.0.0,127.0.0.1,localhost --allow-env --allow-read --allow-sys=homedir tests/", + "test:coverage": "deno test --coverage=coverage --allow-net=0.0.0.0,127.0.0.1,localhost --allow-env --allow-read --allow-sys=homedir tests/ && deno coverage coverage" }, "imports": { "std/": "https://deno.land/std@0.224.0/", diff --git a/src/lib/coordination.ts b/src/lib/coordination.ts index d81d3ba..60c28c2 100644 --- a/src/lib/coordination.ts +++ b/src/lib/coordination.ts @@ -159,7 +159,7 @@ export async function coordinateAuth( log("Authentication completed by another instance"); // Setup a dummy server - the client will use tokens directly from disk - const dummyServer = express().listen(0, "localhost"); // Listen on any available port on localhost only + const dummyServer = express().listen(0, "127.0.0.1"); // Listen on any available port on localhost only // This shouldn't actually be called in normal operation, but provide it for API compatibility const dummyWaitForAuthCode = () => { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 346448f..44b823d 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -247,7 +247,7 @@ export function setupOAuthCallbackServerWithLongPoll( options.events.emit("auth-code-received", code); }); - const server = app.listen(options.port, "localhost", () => { + const server = app.listen(options.port, "127.0.0.1", () => { log(`OAuth callback server running at http://127.0.0.1:${options.port}`); }); @@ -281,7 +281,7 @@ export function findAvailablePort( server.on("error", (err: NodeJS.ErrnoException) => { if (err.code === "EADDRINUSE") { // If preferred port is in use, get a random port - server.listen({ port: 0, hostname: "localhost" }); + server.listen({ port: 0, hostname: "127.0.0.1" }); } else { reject(err); } @@ -295,7 +295,7 @@ export function findAvailablePort( }); // Try preferred port first, or get a random port - server.listen({ port: preferredPort || 0, hostname: "localhost" }); + server.listen({ port: preferredPort || 0, hostname: "127.0.0.1" }); }); } diff --git a/tests/deno-http-server_test.ts b/tests/deno-http-server_test.ts index becd256..9c78fa8 100644 --- a/tests/deno-http-server_test.ts +++ b/tests/deno-http-server_test.ts @@ -76,9 +76,9 @@ describe("DenoHttpServer", () => { try { serverInstance = server.listen(localTestPort, "localhost"); - // Use the port property directly - we know our implementation returns an object with port - const port = (serverInstance as unknown as { port: number }).port; - assertEquals(port, localTestPort); + // Our implementation returns an object with address() that returns {port} + const addr = serverInstance.address() as { port: number }; + assertEquals(localTestPort, addr.port); } finally { if (serverInstance) { server.close();