Here it is (implemented as Mixin):

Class MyNamespace.Pooled Extends Ens.Host [ Abstract ]
{

Property PoolIndex As %Integer [ Calculated ];

Method PoolIndexGet() As %Integer
{
    #Dim cn as %String
    Set cn = ..%ConfigName  

    #Dim statement as %SQL.Statement
    Set statement = ##class(%SQL.Statement).%New()
    Set status = statement.%PrepareClassQuery("Ens.Job","Enumerate")
    $$$ThrowOnError(status)

    #Dim rs as %SQL.StatementResult
    Set rs = statement.%Execute()
    #Dim i as %Integer = -1

    While (rs.%Next()) 
    {
        #Dim jobId as %String 
        Set jobId = rs.%Get("Job")
        If (rs.%Get("ConfigName") = cn)
        {
            Set i = i + 1
            If (jobId = $JOB) 
            {
                Kill rs
                Return i
            }
        }
    }
    Kill rs
    Return i
}

Property PoolSize As %Integer [Calculated];

Method PoolSizeGet() As %Integer
{
    #Dim cn as %String
    Set cn = ..%ConfigName
    #Dim statement as %SQL.Statement
    Set statement = ##class(%SQL.Statement).%New()
    Set status = statement.%PrepareClassQuery("Ens.Job","Enumerate")
    $$$ThrowOnError(status)

    #Dim rs as %SQL.StatementResult
    Set rs = statement.%Execute()
    #Dim i as %Integer = 0

    While (rs.%Next()) 
    {
        If (rs.%Get("ConfigName") = cn)
        {
            Set i = i + 1
        }
    }
    Kill rs
    Return i
}

}

I faced similar issues with Postgres linked tables because of different SQL syntax and also poorly implemented translation from IRIS dialect to your linked server dialect. The workaround is to add an instance of EnsLib.SQL.Operation.GenericOperation to your production and to execute SQL queries via ODBC/JDBC bypassing IRIS, something like:

Set operation = ##class(EnsLib.SQL.Operation.GenericOperation).%New("NameOfYourProductionComponent")
#Dim rs as EnsLib.SQL.GatewayResultSet
Set status = operation.Adapter.ExecuteQuery(.rs, "select 1", .args)
While (rs.Next()) {
   ...
}
Do rs.Close()

To be honest... no :) Actually I think I badly need a standalone terminal (but Studio is discontinued) or a Python/Java/C#/whatever library which is able to invoke arbitrary commands on a remote server and I'm just wondering if such libraries exist.

PS leveraging WebTerminal API looks attractive but it seems to me it doesn't expose Swagger/OpenAPI definitions

Great, thanks a lot, it works.

The real error messages are "ERROR #6162: Unable to create HTTP Authorization header for NTLM scheme." and "ERROR #6162: Unable to create HTTP Authorization header for Negotiate scheme." for both NTLM and Negotiate schemes respectively.

Does it mean that IRIS is unable to deal with these authentication schemes? The documentation says that NTLM is supported.

You have to cast your %CharacterStream to a specific implementation, say, to %GlobalCharacterStream. The latter one implements %GlobalStreamAdaptor, which inherits from %AbstractStream and %Stream.Object. Finally, the %Stream.Object class exposes the CopyFrom method which allows you to copy data from your %Stream.GlobalBinary instance (and vice versa)