Configure JS220 frontend
configure_frontendConfigure current and voltage range modes for the JS220 precision energy analyzer, using auto for typical measurements.
Instructions
Configure JS220 current and voltage range modes. Use auto for normal agent measurements.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_path | No | ||
| current_range_mode | No | auto | |
| voltage_range_mode | No | auto | |
| current_range | No | ||
| voltage_range | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/joulescope_mcp/service.py:199-232 (handler)Actual implementation of configure_frontend. Validates allowed modes (auto/manual/off), builds driver topic commands for current/voltage range mode and range selection, publishes them via the driver, and returns the list of published topics.
def configure_frontend( self, device_path: str | None = None, current_range_mode: str | None = "auto", voltage_range_mode: str | None = "auto", current_range: str | None = None, voltage_range: str | None = None, ) -> dict[str, Any]: allowed_mode = {"auto", "manual", "off"} if current_range_mode is not None and current_range_mode not in allowed_mode: raise JoulescopeMcpError(f"current_range_mode must be one of {sorted(allowed_mode)}") if voltage_range_mode is not None and voltage_range_mode not in allowed_mode: raise JoulescopeMcpError(f"voltage_range_mode must be one of {sorted(allowed_mode)}") published: list[dict[str, Any]] = [] with self._driver_session() as driver: device = self._select_device(driver, device_path=device_path) driver.open(device, mode="restore") try: commands: list[tuple[str, Any]] = [] if current_range_mode is not None: commands.append((f"{device}/s/i/range/mode", current_range_mode)) if voltage_range_mode is not None: commands.append((f"{device}/s/v/range/mode", voltage_range_mode)) if current_range is not None: commands.append((f"{device}/s/i/range/select", current_range)) if voltage_range is not None: commands.append((f"{device}/s/v/range/select", voltage_range)) for topic, value in commands: driver.publish(topic, value) published.append({"topic": topic, "value": value}) finally: driver.close(device) return {"device_path": device, "published": published} - src/joulescope_mcp/server.py:115-137 (registration)MCP tool registration for configure_frontend using @mcp.tool decorator. Defines the tool schema (title, description, annotations with config_tool, structured_output) and parameter types including Literal constraints. Delegates to service.configure_frontend.
@mcp.tool( title="Configure JS220 frontend", description="Configure JS220 current and voltage range modes. Use auto for normal agent measurements.", annotations=config_tool, structured_output=True, ) def configure_frontend( device_path: str | None = None, current_range_mode: Literal["auto", "manual", "off"] | None = "auto", voltage_range_mode: Literal["auto", "manual", "off"] | None = "auto", current_range: str | None = None, voltage_range: str | None = None, ) -> dict[str, Any]: try: return service.configure_frontend( device_path=device_path, current_range_mode=current_range_mode, voltage_range_mode=voltage_range_mode, current_range=current_range, voltage_range=voltage_range, ) except JoulescopeMcpError as exc: raise _tool_error(exc) from exc - src/joulescope_mcp/server.py:34-34 (schema)config_tool annotation definition used for configure_frontend: readOnlyHint=False, destructiveHint=False, idempotentHint=True (configuring frontend is idempotent).
config_tool = ToolAnnotations(readOnlyHint=False, destructiveHint=False, idempotentHint=True) - tests/test_service.py:177-183 (helper)Unit test for configure_frontend verifying that publishing the expected topics ('s/i/range/mode' and 's/v/range/mode') with values 'auto' works correctly.
def test_configure_frontend_publishes_expected_topics() -> None: driver = FakeDriver() result = service_with(driver).configure_frontend(current_range_mode="auto", voltage_range_mode="auto") assert result["published"] == [ {"topic": "u/js220/005920/s/i/range/mode", "value": "auto"}, {"topic": "u/js220/005920/s/v/range/mode", "value": "auto"}, ]