Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions extensions/cli/src/stream/handleToolCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { filterExcludedTools } from "../permissions/index.js";
import {
getService,
getServiceSync,
MCPServiceState,
MCPTool,
Expand Down Expand Up @@ -182,22 +183,36 @@

let mcpTools: MCPTool[] = [];
let mcpToolNames: string[] = [];
const mcpServiceResult = getServiceSync<MCPServiceState>(SERVICE_NAMES.MCP);
if (mcpServiceResult.state === "ready") {

// Check if we're in headless mode
const permissionsServiceResult = getServiceSync<ToolPermissionServiceState>(
SERVICE_NAMES.TOOL_PERMISSIONS,
);
const isHeadless = permissionsServiceResult.value?.isHeadless ?? false;

// In headless mode, wait for MCP service to be ready
// In TUI mode, allow lazy loading
let mcpServiceResult = getServiceSync<MCPServiceState>(SERVICE_NAMES.MCP);

Check failure on line 195 in extensions/cli/src/stream/handleToolCalls.ts

View workflow job for this annotation

GitHub Actions / lint

'mcpServiceResult' is never reassigned. Use 'const' instead

if (isHeadless && mcpServiceResult.state !== "ready") {
logger.debug("Waiting for MCP service to be ready in headless mode");
try {
const mcpState = await getService<MCPServiceState>(SERVICE_NAMES.MCP);
mcpTools = mcpState?.tools ?? [];
mcpToolNames = mcpTools.map((t) => t.name);
} catch (error) {
logger.warn("Failed to wait for MCP service in headless mode", error);
}
} else if (mcpServiceResult.state === "ready") {
mcpTools = mcpServiceResult?.value?.tools ?? [];
mcpToolNames = mcpTools.map((t) => t.name);
} else {
// MCP is lazy
// throw new Error("MCP Service not initialized");
// MCP service not ready in TUI mode - allow lazy loading
logger.debug("MCP service not ready, continuing without MCP tools");
}

const allToolNames = [...builtinToolNames, ...mcpToolNames];

// Check if the ToolPermissionService is ready
const permissionsServiceResult = getServiceSync<ToolPermissionServiceState>(
SERVICE_NAMES.TOOL_PERMISSIONS,
);

let allowedToolNames: string[];
if (
permissionsServiceResult.state === "ready" &&
Expand Down
Loading