lmclient guide

Protocol areas, bundled JDBC engines, memory governance, and standard lmcode_std_v3 REST and CLI interfaces in lmclient.

Overview

lmclient unifies six non-HTTP data and messaging protocol areas (JDBC databases, Redis, SMTP/IMAP mail, AMQP queues, MQTT, and MongoDB) inside one GraalVM native executable. It runs both as a direct JSON-output CLI and as an lmcode bytecode host with 28 domain signatures (2 functions and 26 methods) and the 226-signature lmcode_std_v3 standard library.

Bundled JDBC drivers and resource budgets

The native executable bundles five JDBC drivers without requiring an external JVM: SQLite-JDBC, DuckDB, H2, PostgreSQL, and Microsoft SQL Server. On the JVM distribution, additional third-party JDBC drivers can be loaded dynamically with --driver-jar and --driver-class.

Memory is governed by LMCLIENT_MAX_MEMORY_MB (default 4096 MiB, minimum 16 MiB). Up to 75 percent of the budget is allocated to the Java heap, while each active SQLite or DuckDB native engine receives a one-eighth memory-manager cap. A program may keep up to two native-engine connections and 64 total connections open concurrently, and result sets default to 10000 rows (configurable up to 1000000 via --max-rows).

JDBC Connection and Result domain objects

Inside an _lmcode_ block, connect(url) and connect_file(url, credentials_path) open a Connection handle. Connection supports transactional DDL and DML execution (begin, commit, rollback, exec), analytical queries (query, explain), and schema introspection (schemas, tables, views, columns, keys, foreign_keys, indexes, and diff against a second Connection).

program = _lmcode_ cli="lmclient" install="github:lmctl-ai/lmclient@latest";
let c = connect("jdbc:h2:mem:shop");
c.exec("CREATE TABLE items(id INT PRIMARY KEY, name VARCHAR(40), price DOUBLE);");
c.exec("INSERT INTO items VALUES (1, 'Keyboard', 79.50), (2, 'Monitor', 249.00);");
let r = c.query("SELECT name, price FROM items ORDER BY id");
file_write("items.txt", r.table());
c.close();
end _lmcode_

Protocol areas beyond JDBC

Each non-JDBC subcommand family shares the same JSON stdout contract and exit codes (0 success, 2 usage, 3 runtime failure):

Standard REST and stateless CLI interfaces

DslHost registers all 226 canonical lmcode_std_v3 signatures alongside HostApi.BINDINGS and uses Program.callIsolated() so annotated RestGet..RestOptions, RestHandler, CliCommand, and CliOption callbacks can open and query JDBC connections without registry reentry.

program = _lmcode_ cli="lmclient" install="github:lmctl-ai/lmclient@latest";
@"--table"
fn opt_table(x: RestExchange) -> void implements CliOption {
  x.set("table", x.query("table"));
}

@"count"
fn cmd_count(x: RestExchange) -> void implements CliCommand {
  let c = connect("jdbc:h2:mem:rest_cli_db;DB_CLOSE_DELAY=-1");
  let q = c.query("SELECT COUNT(*) FROM " + x.get("table"));
  x.send("count=" + q.text(0, 0));
  c.close();
}

@"/rows/:id"
fn get_row(x: RestExchange) -> void implements RestGet {
  let c = connect("jdbc:h2:mem:rest_cli_db;DB_CLOSE_DELAY=-1");
  let q = c.query("SELECT label FROM items WHERE id = " + x.param("id"));
  x.send("row=" + q.text(0, 0));
  c.close();
}

let init = connect("jdbc:h2:mem:rest_cli_db;DB_CLOSE_DELAY=-1");
init.exec("CREATE TABLE items(id INT PRIMARY KEY, label VARCHAR(20)); INSERT INTO items VALUES (1, 'alpha'), (2, 'beta');");
init.close();

rest_config("prefix", "/api");
let cli_out = rest_cli(str_split("--table items count", " "));
let get_out = rest_cli(str_split("/api/rows/2", " "));
file_write("rest_cli.txt", cli_out + "|" + get_out);
end _lmcode_