chore: respect server settings from config (#502)

This commit is contained in:
Pavel Feldman
2025-05-30 18:17:51 -07:00
committed by GitHub
parent eec177d3ac
commit 656779531c
4 changed files with 37 additions and 11 deletions

View File

@@ -68,6 +68,7 @@ const defaultConfig: FullConfig = {
allowedOrigins: undefined,
blockedOrigins: undefined,
},
server: {},
outputDir: path.join(os.tmpdir(), 'playwright-mcp-output', sanitizeForFilePath(new Date().toISOString())),
};
@@ -81,6 +82,7 @@ export type FullConfig = Config & {
},
network: NonNullable<Config['network']>,
outputDir: string;
server: NonNullable<Config['server']>,
};
export async function resolveConfig(config: Config): Promise<FullConfig> {
@@ -256,6 +258,10 @@ function mergeConfig(base: FullConfig, overrides: Config): FullConfig {
network: {
...pickDefined(base.network),
...pickDefined(overrides.network),
}
},
server: {
...pickDefined(base.server),
...pickDefined(overrides.server),
},
} as FullConfig;
}

View File

@@ -56,8 +56,8 @@ program
const server = new Server(config);
server.setupExitWatchdog();
if (options.port)
startHttpTransport(server, +options.port, options.host);
if (config.server.port !== undefined)
startHttpTransport(server);
else
await startStdioTransport(server);

View File

@@ -96,7 +96,7 @@ async function handleStreamable(server: Server, req: http.IncomingMessage, res:
res.end('Invalid request');
}
export function startHttpTransport(server: Server, port: number, hostname: string | undefined) {
export function startHttpTransport(server: Server) {
const sseSessions = new Map<string, SSEServerTransport>();
const streamableSessions = new Map<string, StreamableHTTPServerTransport>();
const httpServer = http.createServer(async (req, res) => {
@@ -106,7 +106,8 @@ export function startHttpTransport(server: Server, port: number, hostname: strin
else
await handleSSE(server, req, res, url, sseSessions);
});
httpServer.listen(port, hostname, () => {
const { host, port } = server.config.server;
httpServer.listen(port, host, () => {
const address = httpServer.address();
assert(address, 'Could not bind server socket');
let url: string;