Skip to main content
Glama

peek_bag_samples

Read up to a requested number of recent messages from a topic in recorded ROS bag files (MCAP, rosbag2 SQLite, ROS 1 .bag) for post-mortem analysis.

Instructions

Peek up to count samples from a recorded bag file. Unlike peek_dds_samples (live DDS) and sample_messages (live ROS 2 graph), this reads offline bag content for post-mortem analysis. Supported formats: MCAP (.mcap), ROS 2 rosbag2 SQLite (.db3), ROS 1 legacy chunked binary (.bag), detected from the file extension. Returns a SampleResult in the same shape as peek_dds_samples: each sample's payload carries a _decode_status annotation (full / partial / raw). count defaults to 5 and is silently clamped to 50. Requires the rosbags library (pip install topicforge[bags]) and the ROS 2 side of the runtime: on a DDS-only setup it raises an error. The mock backend returns fixture samples on canned bag paths. Bags that embed no message definitions (rosbag2 .db3 from Humble) are decoded with the type definitions of the bag's recorded distro, or Humble when it records none; note says which. Arrays over 4096 elements are cut and note lists the fields. Read-only by architecture: nothing writes to the bag file. Raises an MCP error when the bag path does not exist, the topic is not present in the bag, or rosbags is not installed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to a bag: a file ending in `.mcap` or `.db3`, or a `rosbag2_*` directory. `peek_bag_samples` also reads ROS 1 `.bag` files; `analyze_bag` does not (`ros2 bag info` cannot open them). Leading/trailing whitespace is stripped. Null bytes and otherwise malformed filesystem paths are rejected. Existence and bag format are validated by the live adapter (mock mode accepts any well-formed path).
countNoMaximum number of recent messages to return. Defaults to 5; silently clamped to 50 (the hard cap that keeps tool output bounded; read it from `health_check.max_sample_count`). Negative values raise an error. The returned `SampleResult.count` reflects the actual number of samples produced: it can be lower than the request (empty topic, timeout, mock fixture shorter than requested).
topicYesFully qualified ROS2 topic name starting with `/`, e.g. `/cmd_vel` or `/camera/image_raw`. Each `/`-separated segment must start with a letter or underscore and contain only letters, digits, and underscores; everything else (whitespace, quotes, shell metacharacters, `//`, trailing `/`) is rejected before reaching the `ros2` CLI.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
noteNoWhy `samples` is empty or limited, when the cause is not obvious (for example payload decoding is disabled for DDS user topics). `None` when there is nothing to add.
countYesNumber of samples actually returned. May be 0 (no publisher active in live mode, or empty mock fixture), less than the requested count (topic yielded fewer messages within the timeout), or capped by the the silent maximum of 50: request `count > 50` and you will receive at most 50 without warning.
topicYesTopic the samples were taken from, echoed from the request.
samplesYesThe sampled messages, ordered as received from the backend.
mode_effectiveYesRuntime mode the adapter served this response in: `live` (real ROS2 introspection) or `mock` (deterministic fixtures). Lets a caller tell a real graph from a demo one without calling `health_check`.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.5.6

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and delivers: read-only by architecture, library dependency, explicit MCP error conditions (missing path, absent topic, missing library), silent clamping to 50, mock-backend behavior, decode-status annotation shape, and array truncation with `note`. This is the behavioral context an agent needs before calling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads purpose and the sibling differentiation before drilling into formats and error behavior, and every sentence carries operational information. It is dense and long, but little of it is redundant.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given a rich output schema, the description need not explain return values, and it still covers the reader's prerequisites, error cases, decode-status semantics, mock behavior, and format support. Nothing an agent needs to call it correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds cross-parameter error semantics not in the schema (raises an MCP error when the bag path does not exist or the topic is not present) and reinforces the format-detection-by-extension behavior tied to `path`.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Peek up to `count` samples from a recorded bag file') and immediately distinguishes itself from two named siblings, `peek_dds_samples` (live DDS) and `sample_messages` (live ROS 2 graph). An agent can tell exactly what this does without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly frames the use case ('reads offline bag content for post-mortem analysis') and names the alternatives it is not, with the condition that selects each. It also discloses the environment prerequisite (rosbags library, ROS 2 side of the runtime) and that it errors on a DDS-only setup.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.