Phase 4: Local MCP Tool Execution via WebSocket #126
Labels
No labels
Epic 5
MCP
P1
PR-0
PR-1
api
api-layer
architecture
area:backend
area:frontend
arrow
authentication
backend
bug
chat
client
clipboard
common-module
compose
cross-cutting
cross-cutting-requirement
data-layer
data-models
database
desktop-client
documentation
duplicate
enhancement
epic
epic-1
epic-2
epic-3
epic-4
epic-5
epic-6
epic-7
epic-llm-config
error-handling
feature
frontend
good first issue
help wanted
implementation
infrastructure
installer
invalid
kotlin
ktor
llm
medium-priority
message
multiplatform
needs-review
needs-triage
packaging
performance
phase-1
phase-2
phase-3
phase-4
phase-5
phase3
phase:3
priority: high
question
refactor
refactoring
resource-sharing
security
server
server-module
services
session
session-management
settings
setup
shutdown
state
storage
streaming
sub-issue
tests
tooling
type:task
ui
ui/ux
user-accounts
user-management
ux
viewmodel
websocket
windows
windows-integration
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Torvian.eu/chatbot#126
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Phase 4: Local MCP Tool Execution via WebSocket
Epic:
NF.EA1 - Local MCP ServersDescription
This issue details the implementation of the end-to-end tool execution flow. When an LLM decides to call a tool hosted on a local MCP server, the request must be securely routed from the main server to the correct client, executed locally on the user's machine, and the result sent back to the LLM.
This requires upgrading the primary chat message endpoint from a standard HTTP request/response model to a persistent WebSocket connection to facilitate real-time, bidirectional communication.
User Stories & Acceptance Criteria
✅ Task Checklist
US4.1: Implement Local MCP Tool Executor (Client-Side)
LocalMCPToolExecutor.execute(toolCallRequest), which takes the details of the tool call from the server.executemethod will orchestrate the entire local execution process:LocalMCPServerManagerto ensure the correct MCP server process is running.MCPClientServiceto send the tool call parameters to the local process via MCP.US4.2: Implement WebSocket Message Processing Integration (Server-Side)
POST /api/v1/sessions/{sessionId}/messagesendpoint to support WebSocket connections.ToolCallRequest(server-to-client) andToolCallResult(client-to-server).ToolCallRequestmessage to that client.ToolCallResultmessage from the client.US4.3: Implement Client-Side WebSocket Handler for Tool Execution
ToolCallRequestmessage is received, the handler must invoke theLocalMCPToolExecutorwith the request payload.LocalMCPToolExecutorcompletes, the handler must take the result, wrap it in aToolCallResultmessage, and send it back to the server over the WebSocket.Architectural Context
Shift to WebSockets: The core architectural change in this phase is the move from a stateless HTTP API to a stateful WebSocket connection for chat sessions. This is non-negotiable for tool calling, as the server needs to be able to push a tool execution request to the client at any time and wait for a response.
Separation of Roles: This implementation solidifies the roles of the server and client in the tool-calling process:
End-to-End Flow:
search_web(query='AI')".ToolCallRequestWebSocket message to the Client.LocalMCPToolExecutor.stdin.stdout.ToolCallResultWebSocket message back to the Server.