MCP flow
useManageMCPConnections()
read dynamic MCP config
getMcpToolsCommandsAndResources()
connectToServer()
fetchToolsForClient()
fetch commands, skills, resources
batch AppState update by server
fetchToolsForClient()
client.request(tools/list)
for each MCP tool:
create local Tool {
name, description, inputJSONSchema, mcpInfo,
concurrency/readOnly/destructive/openWorld hints,
checkPermissions,
call()
}
Tool.call()
ensure connected client
call MCP tools/call
support progress and URL elicitation retry
return tool result for query loop
Clients expose roots and elicitation capabilities
The MCP client is created with capabilities such as roots and elicitation. The roots handler returns the current working directory, allowing a server to understand the workspace context it is serving. Connection setup uses timeout handling and logs success metadata, then exposes capabilities, server version, and instructions.
External reference: Model Context Protocol intro.
MCP tools are adapted into local Tool objects
fetchToolsForClient calls the MCP tools/list method. Each returned server tool is mapped to a local tool with a namespaced name, MCP metadata, annotations for concurrency and safety, the server-provided input JSON schema, a passthrough permission policy, and a call method.
That adapter is the key integration point: after this mapping, the query loop and tool execution engine do not need to care whether the tool was built in or came from a server.
External reference: MCP server tools specification.
Calling an MCP tool supports progress and elicitation
The local tool call implementation ensures the MCP client is connected, invokes the server through callMCPToolWithUrlElicitationRetry, supports progress events, and returns the result to the normal tool_result path. URL elicitation retry lets a server ask for missing information and retry the operation.
Connection state is batched into AppState
useManageMCPConnections reads configured servers, handles channel permission callbacks, connects and fetches server data, then batches AppState updates by server. When a server reconnects or changes state, its tools, commands, skills, resources, and connection metadata are replaced as a unit.