remote: implement ListTools RPC and fix CallTool routing

remote.Server.ListTools() now calls the remote via a list_tools RPC
method instead of returning nil. This ensures the model receives
proper tool definitions through the API.

remote.Server.CallTool() now passes the actual tool name (execute_code,
call_tool, pipe) as the RPC method instead of hardcoding execute.
Simplified result handling since resp.Result is already json.RawMessage.
This commit is contained in:
ollie 2026-07-19 19:49:31 +02:00
parent 160e285e68
commit 609e399219
1 changed files with 31 additions and 12 deletions

View File

@ -117,20 +117,44 @@ func (s *Server) Close() error {
// --- tools.Server interface ---
func (s *Server) ListTools() ([]tools.ToolInfo, error) {
// The remote server has the same tools as what's configured.
// We return a minimal set — the real tool list comes from the
// local execute.Decl during prompt assembly.
return nil, nil
id := s.nextID.Add(1)
req := rpcRequest{
JSONRPC: "2.0",
ID: id,
Method: "list_tools",
}
s.mu.Lock()
if err := s.enc.Encode(req); err != nil {
s.mu.Unlock()
return nil, fmt.Errorf("remote list_tools write: %w", err)
}
var resp rpcResponse
if err := s.dec.Decode(&resp); err != nil {
s.mu.Unlock()
return nil, fmt.Errorf("remote list_tools read: %w", err)
}
s.mu.Unlock()
if resp.Error != nil {
return nil, fmt.Errorf("remote list_tools: %s", resp.Error.Message)
}
var infos []tools.ToolInfo
if err := json.Unmarshal(resp.Result, &infos); err != nil {
return nil, fmt.Errorf("remote list_tools unmarshal: %w", err)
}
return infos, nil
}
func (s *Server) CallTool(ctx context.Context, tool string, args json.RawMessage) (json.RawMessage, error) {
// Forward the call as an "execute" RPC
// Forward the call with the tool name as the RPC method.
id := s.nextID.Add(1)
req := rpcRequest{
JSONRPC: "2.0",
ID: id,
Method: "execute",
Method: tool,
Params: args,
}
@ -151,12 +175,7 @@ func (s *Server) CallTool(ctx context.Context, tool string, args json.RawMessage
return nil, fmt.Errorf("remote error: %s", resp.Error.Message)
}
// The result is the execute server's JSON output
resultJSON, err := json.Marshal(resp.Result)
if err != nil {
return nil, fmt.Errorf("remote result marshal: %w", err)
}
return resultJSON, nil
return resp.Result, nil
}
// ping verifies the remote server is responsive.