Getting started with the Mach5 KQL Client
This guide demonstrates how to run a KQL query against a Mach5 mdx endpoint from Node.js. The CLI demonstrates how to
- configure the private
@mach5-io/kql-clientpackage, - send queries through the client, and
- stream the Apache Arrow results back as JSON so you can hook the output into automation, observability, or reporting scripts.
Prerequisites
- Access to the https://github.com/mach5-io/mach5-sdk-ts repository. Contact the Mach5 Search Administrator to get access to this repository.
- Node.js 16+ (ensure
node/npmare on yourPATH).tsxis used to execute the TypeScript entry point without a build step. - Mach5 deployment with an accessible
mdxservice endpoint. - Access to
@mach5-io/kql-clientinnpm.pkg.github.com. You need a GitHub token with read access to the package.
Setup
-
Enable the private registry for npm by appending your token to
~/.npmrc:cat <<'EOF' >> ~/.npmrc //npm.pkg.github.com/:_authToken=github_token_here @mach5-io:registry=https://npm.pkg.github.com/ EOFReplace
github_token_herewith a token that can install@mach5-io/kql-client. -
Clone the repository: https://github.com/mach5-io/mach5-sdk-ts. Change the working directory:
cd mach5-sdk-ts/packages/kql-client/examples/kql-node-ts -
Install dependencies in the mach5-sdk-ts/packages/kql-client/examples/kql-node-ts directory:
npm install -
Copy and edit the
.envtemplate:cp .env.example .envThen fill in the values:
MACH5_ENDPOINT: the base URL for your Mach5mdxservice (e.g.,https://mdx.mach5.local:50561).MACH5_KQL_QUERY: the KQL statement to execute (for example,tables | take 5).MACH5_BEARER_TOKEN(optional): include this if your endpoint requiresAuthorization: Bearerheaders.
Running queries
- Start the CLI with
npm run dev(it runstsx src/index.ts). - The client prints
Running query: ..., streams the Arrow record batches, and logs each row as a normalized JSON object. - Once the stream completes, you’ll see the total batch and row counts on the final line.
Set MACH5_KQL_QUERY to any valid KQL command. The CLI can be rerun after updating .env or by overriding env vars inline, e.g.: MACH5_KQL_QUERY="MyTable | limit 10" npm run dev.
What the example shows
- Client setup – instantiates
@mach5-io/kql-clientwith the endpoint fromMACH5_ENDPOINT. - Optional auth – includes a bearer token via metadata when
MACH5_BEARER_TOKENis present. - Streaming Arrow batches – iterates over
for await (const table of result)to process each Apache Arrow table. - JSON normalization – converts Arrow vectors, nested records, and arrays to plain JSON so the logs are easy to consume.
- Telemetry – reports the number of batches and rows processed before exiting.