Fix tests, permissions

This commit is contained in:
Minoru Mizutani 2025-04-29 11:30:51 +09:00
parent 8be8e20efa
commit baedc1f32a
No known key found for this signature in database
8 changed files with 74 additions and 36 deletions

View file

@ -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); // Listen on any available port
const dummyServer = express().listen(0, "localhost"); // 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 = () => {

View file

@ -48,12 +48,25 @@ export class DenoHttpServer {
/**
* Start the server listening on the specified port
* @param port The port to listen on
* @param hostname Optional hostname to bind to
* @param callback Optional callback when server is ready
*/
listen(port: number, callback?: () => void): Server {
listen(port: number, hostname?: string | (() => void), callback?: () => void): Server {
// Handle optional hostname parameter
let hostnameStr: string | undefined;
let callbackFn = callback;
if (typeof hostname === 'function') {
callbackFn = hostname;
hostnameStr = undefined;
} else {
hostnameStr = hostname;
}
this.server = Deno.serve({
port,
onListen: callback ? () => callback() : undefined,
hostname: hostnameStr,
onListen: callbackFn ? () => callbackFn() : undefined,
handler: async (request: Request) => {
const url = new URL(request.url);
const path = url.pathname;
@ -73,6 +86,7 @@ export class DenoHttpServer {
// This is needed to maintain API compatibility
return {
close: () => this.close(),
address: () => ({ port }),
} as unknown as Server;
}

View file

@ -98,7 +98,7 @@ export function getConfigDir(): string {
const baseConfigDir = Deno.env.get("MCP_REMOTE_CONFIG_DIR") ||
path.join(os.homedir(), ".mcp-auth");
// Add a version subdirectory so we don't need to worry about backwards/forwards compatibility yet
return path.join(baseConfigDir, `mcp-remote-${MCP_REMOTE_VERSION}`);
return path.join(baseConfigDir, `mcp-remote-deno-${MCP_REMOTE_VERSION}`);
}
/**

View file

@ -247,7 +247,7 @@ export function setupOAuthCallbackServerWithLongPoll(
options.events.emit("auth-code-received", code);
});
const server = app.listen(options.port, () => {
const server = app.listen(options.port, "localhost", () => {
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(0);
server.listen({ port: 0, hostname: "localhost" });
} else {
reject(err);
}
@ -295,7 +295,7 @@ export function findAvailablePort(
});
// Try preferred port first, or get a random port
server.listen(preferredPort || 0);
server.listen({ port: preferredPort || 0, hostname: "localhost" });
});
}