Julia: BentrixMCP.connect, and every tool is a function with positional and keyword arguments.
The client is the package BentrixMCP. It finds the Bentrix running on this computer through the agents folder Bentrix writes at every start, pairs with it under the name you give — the name the person sees in ☰ › Settings › Agents, where the pairing's scopes are set — and talks to it over MCP. Nothing is typed: no address, no key.
01What you need
Julia 1.6 or later, and Bentrix open on the same computer.
02Install
The client is the package BentrixMCP of the SDK. Its source is github.com/bentrixhq/bentrix-julia, under the MIT licence; a clone of it is the SDK on your computer:
git clone https://github.com/bentrixhq/bentrix-julia
and add the package once:
using Pkg
Pkg.develop(path = "bentrix-julia/BentrixMCP")
03Connect
using BentrixMCP
b = BentrixMCP.connect("my-agent")
bench = b.workspace.get_state()["laboratories"][1]["benches"][1]["uri"]
p = split(replace(bench, "bentrix://" => ""), '/')
book = b.trade.book(p[1], p[2], p[4])
04How a call looks
Every tool of the catalogue is a method, grouped by its domain: b.workspace, b.chart, b.study, b.trade …. A method takes the tool's arguments as arguments — the required ones by position, the optional ones by keyword, and answers the tool's answer as a Dict. The whole list is at the end of this page; each method links to its tool's full entry — the arguments with their types and defaults, the scope a pairing must grant, and the plan.
05When Bentrix says no
A tool that runs and refuses throws a ToolError carrying the product's own sentence in msg. The client also checks, when it connects, that the catalogue it was generated from is the one the running Bentrix serves: a different major version is refused before any call, so a program never calls a tool with arguments that no longer fit.
Busy is waited out, not raised. Bentrix answers one program at most 20 calls a second (a burst of 60), and answers a call past that busy (-40001, with the wait in retryAfterMs) before running anything. The client waits that long and sends the call again — so an order is never sent twice by it — up to ten times, each wait at most five seconds, and only then raises the refusal: BentrixMCP.BUSY (-40001), BUSY_RETRIES (10) and BUSY_WAIT_MAX_S (5).
06Long work and streams
A tool that starts long work — a strategy run, a batch, a question put to the person in Bentrix's own window — answers a job; its handle is read with job_get until it ends. A stream (bars as they close, ticks, quotes, deals, the Journal) is followed with wait_for, which answers what came after the cursor it is given and the cursor to give next.
Your first program
Save this as a file, with Bentrix open on this computer. It connects, lists your laboratories and their workbenches, and prints the selected workbench’s markets.
using BentrixMCP
client = BentrixMCP.connect("my-agent")
# Every laboratory, and the workbenches in it.
state = client.workspace.get_state(; depth = "benches")
for lab in state["laboratories"]
println("laboratory:", " ", lab["name"])
for bench in lab["benches"]
println(" workbench:", " ", bench["uri"])
end
endRun it
julia my_agent.jlThe first run pairs the program: it appears in ☰ › Settings › Agents under the name it gave (my-agent), with the scopes read, lab and paper. If it says Bentrix is not running, open Bentrix and run it again.
A larger program, the one the tests run
This is the program Bentrix’s own tests run in Julia against a running Bentrix: it reads the workspace and a workbench’s book, is refused in the product’s words, and runs a reinforcement-learning episode through the tools.
using BentrixMCP
check(held, what) = held || (println(stderr, "FAILED: ", what); exit(1))
b = BentrixMCP.connect("julia-walk")
bench = b.workspace.get_state()["laboratories"][1]["benches"][1]["uri"]
p = split(replace(bench, "bentrix://" => ""), '/')
book = b.trade.book(p[1], p[2], p[4])
check(book["positions"] isa AbstractVector, "the book did not read: $book")
said = try
BentrixMCP.call(b, "no_such_tool")
""
catch e
sprint(showerror, e)
end
check(occursin("no_such_tool", said), "a refusal did not say its tool: $said")
made = b.strategy.env_make(bench; interval = "H1", window = 8, episode = "window", episode_bars = 12)
env = made["env"]
start = b.strategy.env_reset(env; seed = 5)
check(length(start["obs"]["market"]) == 8, "the observation is not shaped as declared")
rewards = Float64[]
hashes = String[start["info"]["ledger_hash"]]
for a in (1, 1, 2, 0, 2, 2, 1, 0, 1, 2, 0, 1)
s = b.strategy.env_step(env, a)
push!(rewards, s["reward"])
push!(hashes, s["info"]["ledger_hash"])
(s["terminated"] || s["truncated"]) && break
end
b.strategy.env_close(env)
# A tool's own refusal (isError), not a request the wire refused.
refusal = try
b.strategy.env_step(env, 0)
nothing
catch e
e
end
check(refusal isa ToolError && occursin("No environment", refusal.msg), "a closed environment's step was not refused in its words: $refusal")
check(length(unique(hashes)) > 1, "the episode traded nothing")
# Julia prints a Float64 in the shortest digits that read back as the same double.
println(BentrixMCP.JSON.write(Dict("start_ms" => Int64(start["info"]["start_ms"]), "rewards" => rewards, "hashes" => hashes)))
println("PASS")