Skip to content

Configure Backends

mcpyvisa supports four backend types for connecting to instruments: ar488 (GPIB via serial or TCP), pyvisa-py (USB-TMC, LAN/VXI-11), system (NI-VISA or Keysight IO Libraries), and sim (simulated instruments via YAML definitions). Each backend gets its own [[backend]] section in the TOML configuration file, and instruments can be given friendly aliases through [instruments.*] sections.

mcpyvisa searches for its config file in this order:

  1. The path in the $MCPYVISA_CONFIG environment variable
  2. ./mcpyvisa.toml in the current working directory
  3. ~/.config/mcpyvisa/config.toml

If no file is found, mcpyvisa starts with no backends configured.

Serial is the simplest and most reliable transport for AR488/Prologix GPIB adapters. Connect the ESP32 to your machine with a USB cable.

mcpyvisa.toml
[[backend]]
name = "bench-a"
type = "ar488"
transport = "serial"
port = "/dev/ttyUSB0"
baudrate = 115200

Required fields:

FieldDescription
nameUnique identifier for this backend. Alphanumeric with hyphens and underscores.
typeSet to "ar488".
transportSet to "serial".
portSerial port path.
baudrateBaud rate matching the AR488 firmware (default 115200).

Finding your serial port:

  • Linux: ls /dev/ttyUSB* or ls /dev/ttyACM*
  • macOS: ls /dev/cu.usbserial-* or ls /dev/cu.usbmodem*
  • Windows: Check Device Manager for COM ports (e.g., COM3)

Instead of using full VISA resource strings in every tool call, you can define friendly aliases in [instruments.*] sections. Each alias maps a short name to a resource string and backend.

mcpyvisa.toml
[instruments.dmm]
resource = "GPIB0::22::INSTR"
backend = "bench-a"
[instruments.psu]
resource = "GPIB0::5::INSTR"
backend = "bench-a"
[instruments.scope]
resource = "TCPIP::192.168.1.100::INSTR"
backend = "lan-bench"

With these aliases configured, tool calls become concise:

instrument_query("dmm", "MEAS:VOLT:DC?")
instrument_write("psu", "OUTP ON")
instrument_identify("scope")

You can always use the full VISA resource string instead of an alias:

instrument_query("GPIB0::22::INSTR", "MEAS:VOLT:DC?")

These fields are optional and apply to AR488 backends. They control timing and auto-discovery behavior.

mcpyvisa.toml
[[backend]]
name = "bench-a"
type = "ar488"
transport = "serial"
port = "/dev/ttyUSB0"
baudrate = 115200
auto_discover = true
auto_identify = true
read_timeout_ms = 3000
inter_command_delay_ms = 10
FieldDefaultDescription
auto_discovertrueDiscover instruments on the bus immediately after connecting.
auto_identifytrueSend *IDN? to each discovered instrument during discovery.
read_timeout_ms3000How long to wait for an instrument response (1—32000 ms).
inter_command_delay_ms10Pause between consecutive bus commands (0—1000 ms).

The right timeout depends on your instruments and transport:

Scenarioread_timeout_msinter_command_delay_ms
Serial, fast instruments (34401A, 2000)300010
Serial, slow instruments (electrometer, source measure)1000010
TCP, typical bench500020
TCP, high-latency network1000030

Set auto_discover = false when:

  • You want faster connection times and will discover instruments manually later
  • The bus has instruments that behave unpredictably when polled (some older instruments respond to findlstn inconsistently)
  • You are connecting to an empty backend for diagnostic purposes

Set auto_identify = false (while keeping auto_discover = true) when:

  • You want to discover listener addresses quickly without the overhead of *IDN? queries
  • Your instruments do not support IEEE 488.2 identification

Add multiple [[backend]] sections to manage separate instrument buses from a single mcpyvisa instance:

mcpyvisa.toml
[server]
log_level = "INFO"
auto_discover = true
auto_identify = true
[[backend]]
name = "bench-a"
type = "ar488"
transport = "serial"
port = "/dev/ttyUSB0"
baudrate = 115200
[[backend]]
name = "bench-b"
type = "ar488"
transport = "tcp"
host = "192.168.1.50"
tcp_port = 23
read_timeout_ms = 5000
inter_command_delay_ms = 20
[[backend]]
name = "lan-bench"
type = "pyvisa-py"
# Sim backend for testing prompts while real instruments are in use
[[backend]]
name = "sim-bench"
type = "sim"
sim_file = "./gpib-catalog/sim/all_instruments.yaml"
[instruments.dmm]
resource = "GPIB0::22::INSTR"
backend = "bench-a"
[instruments.scope]
resource = "TCPIP::192.168.1.100::INSTR"
backend = "lan-bench"
[instruments.sim-dmm]
resource = "GPIB0::22::INSTR"
backend = "sim-bench"

Each backend operates independently with its own connection, lock, and state. Operations on different backends run concurrently. The name field must be unique across all backends. A sim backend can run alongside real backends — useful for developing prompts and workflows against simulated instruments while your physical equipment handles other tasks.

The [server] section sets defaults that apply to all backends:

mcpyvisa.toml
[server]
log_level = "INFO"
auto_discover = true
auto_identify = true
FieldDefaultDescription
log_level"INFO"Logging verbosity: DEBUG, INFO, WARNING, ERROR.
auto_discovertrueDefault auto-discovery setting, overridden per backend.
auto_identifytrueDefault auto-identify setting, overridden per backend.

Some AR488 backend settings can be changed after connecting without editing the config file:

> Set the read timeout on bench-a to 10 seconds

The LLM calls configure_ar488("bench-a", read_timeout_ms=10000). Runtime-configurable parameters:

ParameterDescription
read_timeout_msRead timeout in milliseconds
auto_modeAuto-read mode (0=off, 1=prologix, 2=on-query, 3=continuous)
eosEnd-of-send character (0=CRLF, 1=CR, 2=LF, 3=None)
eoiWhether to assert EOI on the last byte sent

If you move an AR488 adapter from USB to WiFi (or vice versa), update the transport and its associated fields in the config:

Before: serial
[[backend]]
name = "bench-a"
type = "ar488"
transport = "serial"
port = "/dev/ttyUSB0"
baudrate = 115200
After: TCP
[[backend]]
name = "bench-a"
type = "ar488"
transport = "tcp"
host = "192.168.1.50"
tcp_port = 23
read_timeout_ms = 5000
inter_command_delay_ms = 20

Keep the name the same so that any instrument aliases, scripts, or saved conversations referencing "bench-a" continue to work. Restart mcpyvisa after changing the config file.