Connect any UI
Use @midscene/connect to connect any screen or custom hardware to Midscene—such as robotic arms, capture cards with HID modules, in-vehicle displays, IoT devices, or remote machines.
Describe the device in one .mjs file, serve it over HTTP, and drive it with the Agent SDK, the CLI, or the Playground without writing an AbstractInterface class.
Real-world examples
See the midscene-test-everything repository for real-world hardware and platform integrations built on @midscene/connect:
- Robot arm × physical touchscreen (
mg400-service,arm-kit,robotics-vision): camera capture, ArUco screen calibration, coordinate mapping, and a DOBOT MG400 reference setup for car screens and industrial panels. - Bluetooth HID × physical iPhone (
ios-airlink): driving physical iPhones from macOS over Bluetooth HID with USB, AirPlay, or camera screen capture, without jailbreaking or enabling Developer Mode.
Set up API keys for model
The following example uses qwen3.7-plus through Alibaba Cloud:
Replace your-api-key with your API Key.
To use another model, such as Doubao, GLM, Gemini, or GPT-5, see Use a model API key.
For all configuration options, see Model configuration.
1. Define a device
One .mjs file describes one kind of device, and options selects a concrete instance. Keys in actions that match a built-in input primitive are plain functions; any other key is a custom action.
import { defineDevice } from '@midscene/connect' adds editor type hints, but a plain default export works without it.
size() is optional in the object returned by connect(). When omitted, screen dimensions are read from the current screenshot.
Built-in primitives
The function signatures match @midscene/core's InputPrimitives. Coordinates are in screenshot pixels.
Parameter schemas
Custom action params and device options use a JSON Schema subset:
string(enum,minLength,maxLength)number/integer(minimum,maximum)booleanarray(items,minItems,maxItems)object(properties,required)description
A top-level property marked { "x-midscene-locate": true } is an element located by the AI model. Your call function receives { description, center, rect }.
serve rejects any keyword outside this subset at startup. Request bodies are validated strictly, so unknown keys fail.
2. Serve the device
Start the device service first. It keeps the device connected and exposes an HTTP API with Swagger UI at /api/docs/:
- Each
serveprocess holds one device instance. Pass--portto serve additional devices. - When
--hostis not a loopback address, the server requires bearer token authentication. Pass--token <token>, or use the token generated and printed at startup.
3. Drive the device
Agent SDK
Create an Agent connected to the served device with agentOverConnectProtocol:
urldefaults toMIDSCENE_CONNECT_URL, thenhttp://127.0.0.1:5820.tokendefaults toMIDSCENE_CONNECT_TOKEN.- If the device defines
descriptionandagentOptionsdoes not set anaiActcontext,descriptionis automatically added toaiContexts.aiAct.
CLI and Playground
The CLI builds its subcommands dynamically from the served device's action space:
playground supports --url, --token, --port (default 5800), and --no-open.
Embed in an existing server
To mount the Connect protocol inside an existing Node HTTP server:
HTTP API
The server executes actions one at a time. Errors return { error, code }.
Low-level AbstractInterface integration
If you maintain an existing custom interface class or need the low-level AbstractInterface and defineAction reference, see Integrate with any interface.

