Skip to main content
Glama

pyvisa-mcp

MCP server that puts PyVISA in front of AI tools so they can discover, learn, and drive oscilloscopes (and other SCPI instruments) over USB, GPIB, serial, and Ethernet.

This project is not affiliated with the PyVISA maintainers. It uses the public PyVISA API.

How learn works

SCPI has no “dump every menu” command. Instead the server builds a local brain per instrument (keyed by *IDN?) and reuses it next session.

Saved under ~/.local/share/pyvisa-mcp/ (override with PYVISA_MCP_MEMORY):

What is stored

Where it comes from

Identity, dialect, class

*IDN?

Options / HELP headers / setup dump

*OPT?, SYST:HELP:HEAD?, *LRN? (deep=true)

Programming manual (PDF + extracted text)

Web search, or manual_url= / a local file

SCPI that already worked or failed on this firmware

Every query / write

open_instrument  192.168.1.10
learn_instrument  deep=true  fetch_manual=true
search_scope_knowledge  query="FFT"
search_scope_knowledge  query="I2C decode"
search_scope_knowledge  query=":WAV:DATA?"

Next chat, learn_instrument reloads that brain. Pass a PDF you already have:

learn_instrument  manual_url="/path/to/DS1054Z_ProgrammingGuide.pdf"

search_scope_knowledge searches the manual text, HELP headers, and remembered commands. That is how the model reuses what it learned instead of guessing vendor SCPI.

list_learned_instruments / forget_instrument manage the store. Resources: visa://learned, visa://learned/{key}.

Writes: fail closed

After *IDN? / learn_instrument:

  • Known scope (Rigol, Keysight, Tektronix, Siglent, LeCroy) — writes allowed.

  • Anything else (unknown brand, DMM, PSU, “generic” fallback) — queries and learn only. No scale/trigger/run/stop until:

unlock_writes  confirm=true

That permission is stored on the local brain for this *IDN?. instrument_capabilities shows the gate.

Related MCP server: pyMSO5000 MCP Server

Talk to a network oscilloscope

LAN scopes often do not appear in list_instruments. Open by IP (Utility → I/O → LAN on the scope):

open_instrument resource="192.168.1.10"

that becomes TCPIP0::192.168.1.10::inst0::INSTR (VXI-11 / LXI).

If it times out, try raw SCPI (Keysight/Siglent often 5025, Rigol DS1000Z often 5555):

open_instrument resource="192.168.1.10:5025"

Then measure / capture:

learn_instrument
scope_measure kinds=["vpp","freq"]
scope_capture_waveform channel=1
export_waveform path="/tmp/ch1.csv"

Tools

Tool

Purpose

list_instruments

Local VISA resources (USB/GPIB/serial; LAN often missing)

discover_network_instruments

mDNS browse for LXI / VXI-11 / HiSLIP / SCPI-raw

open_instrument

Open by VISA name or IP (192.168.1.10, host:5025, IPv6)

learn_instrument

Identify, save/reload the local brain; deep / fetch_manual

fetch_manual

Download or ingest a programming guide into that brain

search_scope_knowledge

Search the saved manual + enumerated SCPI + remembered commands

list_learned_instruments / forget_instrument

List or delete saved brains

query / write / query_binary

Raw SCPI (successes/failures are remembered)

read_errors

Drain SYST:ERR?

scope_capture_waveform

Scaled volts-vs-time, downsampled for MCP

export_waveform

Full trace to CSV / NPY / BIN (no downsample)

scope_measure

Vpp, frequency, RMS, …

scope_configure

V/div, s/div, coupling, edge trigger

scope_acquire

run / stop / single / autoset (confirm=true for autoset)

scope_screenshot

PNG/BMP/JPEG when the vendor returns a real image

instrument_capabilities

Whether this box may receive writes

unlock_writes

Allow writes on an unknown dialect (confirm=true)

suggest_scpi

Map a known intent to SCPI; says “no mapping” instead of guessing

Resources: visa://howto, visa://scpi, visa://resource-names, visa://oscilloscope/{vendor}, visa://learned, visa://learned/{key}, visa://open, visa://backend.

High-level scope_* tools refuse DMMs / spectrum analyzers / PSUs unless you pass dialect=. Unknown dialects also cannot write / configure / capture until unlock_writes.

Install

pip install -e ".[dev]"
# or
uv sync --extra dev

Runtime dependencies include pyvisa-py. You do not need NI-VISA or Keysight IO Libraries for LAN/SOCKET instruments.

USB-TMC without a vendor VISA: pip install pyvisa-mcp[usb] (needs libusb).

Run

stdio (what Grok, Claude Desktop, Cursor, etc. spawn):

pyvisa-mcp
# python -m pyvisa_mcp

HTTP (optional):

pyvisa-mcp --transport streamable-http --port 8000
# endpoint: http://127.0.0.1:8000/mcp

Inspector:

uv run mcp dev src/pyvisa_mcp/server.py

Connect an AI host

Grok (~/.grok/config.toml)

[mcp_servers.pyvisa]
command = "uv"
args = ["run", "--directory", "/path/to/pyvisa-mcp", "pyvisa-mcp"]
env = { PYVISA_LIBRARY = "@py" }
startup_timeout_sec = 45
tool_timeout_sec = 90

After install onto PATH:

[mcp_servers.pyvisa]
command = "pyvisa-mcp"
env = { PYVISA_LIBRARY = "@py" }

Claude Desktop / Cursor (.mcp.json)

{
  "mcpServers": {
    "pyvisa": {
      "command": "pyvisa-mcp",
      "env": { "PYVISA_LIBRARY": "@py" }
    }
  }
}

Environment

Variable

Meaning

PYVISA_LIBRARY / PYVISA_MCP_BACKEND

VISA backend. @py = pyvisa-py. Path to visa.so / visa32.dll for NI/Keysight. sim.yaml@sim for pyvisa-sim.

PYVISA_MCP_TIMEOUT_MS

Default I/O timeout (ms). Default 10000.

PYVISA_MCP_ALLOW

Comma-separated globs of allowed resources, e.g. TCPIP::*.

PYVISA_MCP_READONLY

1 to allow queries only.

PYVISA_MCP_MEMORY

Path to instruments.json. Default ~/.local/share/pyvisa-mcp/instruments.json. off disables saving.

*RST and autoset need confirm=true.

Vendor dialects

learn_instrument maps *IDN? manufacturer + model class to a dialect (not a substring of HANTEK/INSTEK):

  • keysight (Agilent / HP InfiniiVision-style scopes)

  • tektronix (CURV?, MEASU:IMM:*)

  • rigol

  • siglent (C1, C1:PAVA?)

  • lecroy

  • generic — unknown vendors, and Keysight/Tek boxes that are not scopes (DMM, SA, PSU, AWG)

Firmware forks still happen. If a helper fails: search_scope_knowledge, then query / write, then read_errors.

scope_capture_waveform min/max-downsamples (default 400 points) so MCP payloads stay small. Use export_waveform for the full record.

Tests

uv run pytest

Tests use an in-memory fake oscilloscope (no hardware). Optional pyvisa-sim YAML lives in tests/sim/scope.yaml.

Safety

This process can change instrument state: timebase, trigger, acquisition, autoset, *RST. Point PYVISA_MCP_ALLOW at the instruments you mean to touch, use PYVISA_MCP_READONLY=1 when you only want to look, and do not expose the HTTP transport on an untrusted network.

Available Tools

22 tools
close_instrumentClose instrument sessionA

Close one open instrument, or all of them if resource is omitted.

Inputs: resource. Returns: result

configure_sessionConfigure VISA sessionC

Change timeout and terminators on an already-open instrument.

Inputs: resource, baud_rate, timeout_ms, read_termination, +1 more. Returns: model, notes, serial, dialect, +7 more

discover_network_instrumentsDiscover instruments on the LANA
Read-only

Browse mDNS for LXI, VXI-11, HiSLIP, and SCPI-raw services.

Many scopes do not advertise. Empty result is normal — open by IP instead.

Inputs: timeout_s. Returns: result

export_waveformExport waveform to a fileA
Read-only

Fetch a channel trace and write the full record (no downsample) to disk.

CSV columns: t_s, v. Use this for archives; scope_capture_waveform is for a short preview in the chat.

Inputs: path (required), fmt, channel, dialect, +1 more. Returns: t, v, vpp, dt_s, +14 more

fetch_manualFetch programming manualC

Download this model's user/programming guide into the local brain and index it.

Inputs: url, resource. Returns: deep, model, notes, cached, +16 more

forget_instrumentForget a learned instrumentC

Delete a saved per-scope profile from disk.

Inputs: identity (required). Returns: result

identifyIdentify instrument (*IDN?)B
Read-only

Query *IDN? and pick a vendor dialect (keysight, tektronix, rigol, ...).

Inputs: resource. Returns: model, notes, serial, dialect, +7 more

learn_instrumentLearn an instrumentB
Read-only

Build (or reload) a local brain for this exact *IDN?.

Saved under ~/.local/share/pyvisa-mcp/ (or PYVISA_MCP_MEMORY). Next session, learn_instrument returns the same profile, remembered SCPI, and manual text without probing again. Pass deep=true / fetch_manual=true to refresh.

Inputs: deep, resource, manual_url, fetch_manual. Returns: deep, model, notes, cached, +16 more

list_instrumentsList VISA instrumentsA
Read-only

Discover local VISA resources (USB, GPIB, serial, some LAN).

Network oscilloscopes frequently do NOT appear. Open them by IP with open_instrument, or call discover_network_instruments.

Inputs: query. Returns: result

list_learned_instrumentsList learned instrumentsA
Read-only

Profiles saved from previous learn_instrument calls (this machine).

Inputs: no named parameters. Returns: result

open_instrumentOpen a VISA instrumentA

Open an instrument and optionally query *IDN?.

Bare IPs become TCPIP::::INSTR. host:port becomes a raw TCP SOCKET, which is what many LAN scopes want on port 5025 (Rigol DS1000Z: 5555).

Inputs: resource (required), identify, baud_rate, timeout_ms, +2 more. Returns: model, notes, serial, dialect, +7 more

queryQuery SCPIB
Read-only

Send a SCPI query and return the ASCII response.

Inputs: command (required), confirm, resource. Returns: ok, notes, command, resource, +1 more

query_binaryQuery binary SCPI blockA
Read-only

Read an IEEE binary block. By default returns stats + a short preview.

Pass save_path= to keep the full record, or return_values=true for a capped array. For oscilloscope traces prefer scope_capture_waveform / export_waveform. Do not use query() for binary — the terminator byte can appear inside the payload.

Inputs: command (required), datatype, resource, save_path, +4 more. Returns: path, notes, values, command, +6 more

read_errorsRead instrument error queueA
Read-only

Pop SYST:ERR? until the queue is empty. Call this after any failed command.

Inputs: resource, max_errors. Returns: result

scope_acquireRun / stop / single / autosetA

Control acquisition: run, stop, single shot, or vendor autoset.

Autoset changes vertical/horizontal/trigger; pass confirm=true.

Inputs: action (required), confirm, dialect, resource. Returns: ok, notes, command, resource, +1 more

scope_capture_waveformCapture oscilloscope waveformB
Read-only

Read a scaled voltage-vs-time trace from one channel.

Uses the vendor dialect from *IDN? (or dialect=). Returns downsampled points plus vmin/vmax/vmean/vpp so the payload fits in an MCP tool result.

Inputs: channel, dialect, resource, max_points. Returns: t, v, vpp, dt_s, +14 more

scope_configureConfigure oscilloscopeB

Set channel scale/offset/coupling, timebase, and/or edge trigger.

Only provided fields are sent. Units: volts, seconds.

Inputs: probe, channel, dialect, display, +9 more. Returns: ok, notes, command, resource, +1 more

scope_measureOscilloscope measurementsC
Read-only

Ask the scope's measurement engine for Vpp, frequency, etc.

Inputs: kinds, channel, dialect, resource. Returns: notes, channel, dialect, resource, +1 more

scope_screenshotOscilloscope screenshotB
Read-only

Grab the scope display as PNG/BMP/JPEG.

Disables the VISA termchar so 0x0A inside the image is not treated as EOF. Fails if the payload is not a real image (no silent 'png' of ASCII junk).

Inputs: path, dialect, resource, timeout_ms.

search_scope_knowledgeSearch local scope knowledgeA
Read-only

Search the saved manual, HELP headers, and SCPI that already worked on this box.

Call learn_instrument / fetch_manual first. This is how the model reuses what it learned instead of guessing vendor commands.

Inputs: query (required), limit, resource. Returns: result

suggest_scpiSuggest SCPI for an intentB
Read-only

Map a natural-language intent to vendor-correct SCPI. Optionally execute it.

Uses *IDN? dialect unless you pass dialect=. Prefer this over inventing commands.

Inputs: intent (required), channel, dialect, execute, +1 more. Returns: result

writeWrite SCPIA

Send a SCPI command with no reply (settings, *RST, :RUN, ...).

Inputs: command (required), confirm, resource. Returns: ok, notes, command, resource, +1 more

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 22 tools

    Disambiguation4/5

    Tools have largely distinct purposes, with clear boundaries between generic VISA operations and oscilloscope-specific ones. Minor potential overlap exists between identify and learn_instrument, and between query and suggest_scpi (when executing), but descriptions clarify usage.

    Naming Consistency5/5

    All tool names use consistent snake_case, with a clear 'scope_' prefix for oscilloscope-specific tools. This predictable pattern aids discoverability and grouping.

    Tool Count3/5

    22 tools is on the heavy side for the stated domain, slightly exceeding the typical 3-15 range. While many tools earn their place, some could potentially be consolidated (e.g., identify and learn_instrument), making the set borderline.

    Completeness5/5

    The surface covers the full lifecycle of instrument control: discovery, connection, identification, learning, SCPI communication, error handling, configuration, and scope-specific operations like waveform capture, measurement, acquisition, and screenshot. No major gaps are apparent for the domain.

    Maintenance

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to directly control NI oscilloscopes (e.g., PXIe-5160/5164/5110) through the Model Context Protocol, including waveform acquisition, measurement, and configuration.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to control Rigol MSO5000 oscilloscopes through VISA, including acquisition, channels, trigger, timebase, waveform generator, display, and front-panel controls, with risk-based permission gating for direct SCPI operations.
      6
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      Enables agentic coding harnesses to control benchtop test equipment — waveform generator, multimeter, oscilloscope, and power supply — over SCPI, with typed tools and raw passthrough for investigating circuits.
      76
      1
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables unified discovery, query, and control of laboratory instruments (power supplies, oscilloscopes, signal generators, multimeters) via VISA/SCPI, with device-specific libraries and an MCP server exposing 19 tools for natural language interaction.
      -