Skip to content

feat(obd_ai): add read-only diagnostic tool surface - #12

Open
virtuscyber wants to merge 1 commit into
feature/2-obd-ai-json-serializersfrom
feature/3-obd-ai-readonly-tool-surface
Open

virtuscyber wants to merge 1 commit into
feature/2-obd-ai-json-serializersfrom
feature/3-obd-ai-readonly-tool-surface

Conversation

@virtuscyber

Copy link
Copy Markdown
Owner

Refs #3

Stacked on top of #2.

Includes:

  • read-only callable diagnostic surface for approved OBD commands
  • structured tool results for LLM and MCP consumers
  • safety-first exposure of diagnostic capabilities

@augmentcode

augmentcode Bot commented Apr 11, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR introduces a constrained, read-only diagnostic tool interface intended for LLM/MCP consumers to safely connect to an OBD adapter and run approved queries.

Changes:

  • Exports OBDAIReadOnlyToolSurface from obd_ai for public use.
  • Extends the default approved command catalog with a freeze-frame DTC read (FREEZE_DTC).
  • Adds obd_ai/tools.py implementing a structured tool surface: connect/status, list approved commands (optionally with support), read single/multiple sensors, read DTCs, freeze-frame, and emissions monitor status.
  • Returns JSON-like payloads with a consistent ok/tool/data vs ok/tool/error shape and handles timeout/null-response cases.
  • Adds unit tests validating allowlist enforcement, disconnected behavior, supported-PID checks, and diagnostic read helpers.

Technical Notes: All reads are gated through the approved catalog and supports() checks to avoid exposing write/unsafe commands.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread obd_ai/tools.py
)

self.close()
self._session = self._session_manager.open_session(**payload)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obd_ai/tools.py:56: OBDAISessionManager.open_session(**payload) can raise (e.g., serial/permission/port errors) and currently bubbles out of connect_vehicle, breaking the structured {ok: False, error: ...} contract expected by LLM/MCP callers. Consider whether connection failures should be translated into a tool error response instead of raising.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread obd_ai/tools.py
self._session = self._session_manager.open_session(**payload)

metadata = self._session.connection_metadata()
if not metadata["is_connected"]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obd_ai/tools.py:59-65: When metadata["is_connected"] is false, connect_vehicle returns an error but leaves _session set (and the underlying connection potentially open). If callers treat this as a failed connect and don’t call close(), this can keep resources open unexpectedly.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread obd_ai/tools.py
message="Timed out waiting for a response from the adapter.",
details={"command_key": command_key},
)
raise

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obd_ai/tools.py:323-331: _query_approved_command re-raises any non-timeout exception from session.query(), which can crash the tool surface instead of returning a structured error payload. This seems inconsistent with the rest of the surface returning {ok: False, error: ...} for adapter/data issues.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread obd_ai/tools.py
"""List approved commands, optionally including adapter support status."""

payload = dict(input or {})
include_support = bool(payload.get("include_support", True))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obd_ai/tools.py:89-90: bool(payload.get("include_support")) (and only_supported) will treat non-empty strings like "false" as True, which can surprise tool callers and change behavior unexpectedly. If these inputs can come from loosely-typed sources, stricter type validation may be needed to preserve intent.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant