fix(cli): keep CDP MCP env reads at serve boundaries

This commit is contained in:
yiliang114 2026-07-09 11:07:01 +08:00
parent 6e48077532
commit 9a2569e891
5 changed files with 27 additions and 14 deletions

View file

@ -102,7 +102,7 @@ function buildChromeDevToolsMcpRuntimeConfig(
) {
return undefined;
}
const command = resolveCdpMcpCommand();
const command = resolveCdpMcpCommand(process.env);
if (!command) {
writeStderrLine(
`qwen serve: set ${QWEN_CDP_MCP_COMMAND_ENV} to enable browser automation MCP (no adapter is bundled)`,

View file

@ -6,22 +6,26 @@
/** Stdio MCP adapter command used by the optional CDP browser automation bridge. */
export const QWEN_CDP_MCP_COMMAND_ENV = 'QWEN_CDP_MCP_COMMAND';
const QWEN_SERVE_ACP_HTTP_ENV = 'QWEN_SERVE_ACP_HTTP';
export function resolveCdpMcpCommand(
env: NodeJS.ProcessEnv = process.env,
env: Readonly<NodeJS.ProcessEnv>,
): string | undefined {
const command = env[QWEN_CDP_MCP_COMMAND_ENV]?.trim();
return command ? command : undefined;
}
export function isBrowserAutomationMcpAvailable(opts: {
cdpTunnelOverWs?: boolean;
token?: string;
}): boolean {
export function isBrowserAutomationMcpAvailable(
opts: {
cdpTunnelOverWs?: boolean;
token?: string;
},
env: Readonly<NodeJS.ProcessEnv>,
): boolean {
return (
opts.cdpTunnelOverWs === true &&
!opts.token &&
process.env['QWEN_SERVE_ACP_HTTP'] !== '0' &&
resolveCdpMcpCommand() !== undefined
env[QWEN_SERVE_ACP_HTTP_ENV] !== '0' &&
resolveCdpMcpCommand(env) !== undefined
);
}

View file

@ -1516,10 +1516,13 @@ describe('runQwenServe runtime startup failures', () => {
it('does not enable browser automation MCP on bearer-protected endpoints', () => {
expect(
isBrowserAutomationMcpAvailable({
cdpTunnelOverWs: true,
token: 'secret-token',
}),
isBrowserAutomationMcpAvailable(
{
cdpTunnelOverWs: true,
token: 'secret-token',
},
process.env,
),
).toBe(false);
});

View file

@ -854,7 +854,10 @@ function currentServeFeaturesForRunQwenServe(
// so the bootstrap `/capabilities` window doesn't briefly under-report them.
clientMcpOverWsEnabled: opts.clientMcpOverWs === true,
cdpTunnelOverWsEnabled: opts.cdpTunnelOverWs === true,
browserAutomationMcpAvailable: isBrowserAutomationMcpAvailable(opts),
browserAutomationMcpAvailable: isBrowserAutomationMcpAvailable(
opts,
process.env,
),
});
}

View file

@ -95,7 +95,10 @@ export function createServeFeatures(
multiWorkspaceSessionsEnabled,
clientMcpOverWsEnabled: opts.clientMcpOverWs === true,
cdpTunnelOverWsEnabled: opts.cdpTunnelOverWs === true,
browserAutomationMcpAvailable: isBrowserAutomationMcpAvailable(opts),
browserAutomationMcpAvailable: isBrowserAutomationMcpAvailable(
opts,
process.env,
),
voiceTranscriptionAvailable: getCachedVoiceTranscriptionAvailable(),
// Advertised whenever the `/voice/stream` WS endpoint exists (ACP HTTP
// on). A configured token no longer suppresses it — the browser carries