Skip to content

Add filtering and pagination to reduce LLM context consumption #31

Description

@key

Background

When an LLM calls sigrok-mcp-server tools, every token in the response consumes context window budget. Several tools return large unfiltered datasets that waste tokens.

Current State

  • list_supported_hardware (handlers.go:71-74) — returns ALL 160+ drivers, no filtering
  • list_supported_decoders (handlers.go:76-79) — returns ALL 110+ decoders, no filtering
  • list_input_formats / list_output_formats — returns complete lists (smaller, ~10-20 items)
  • show_decoder_details (handlers.go:104-124) — includes full multi-line documentation text
  • show_driver_details (handlers.go:126-146) — includes both parsed fields AND RawOutput
  • decode_protocol (handlers.go:310-382) — returns potentially megabytes of raw decoded text
  • All list tools call sigrok-cli -L and parse sections via runListSection (handlers.go:91-102)

Problem

  • An LLM looking for "spi" decoder gets all 110+ decoders dumped into context
  • Driver details include redundant RawOutput field alongside parsed data
  • decode_protocol output can be extremely large with no truncation or summary
  • No tool supports filtering by keyword, limiting results, or pagination

Proposed Changes

  1. Add optional filter string parameter to list_supported_hardware and list_supported_decoders
    • Filter by substring match on id and description
  2. Remove RawOutput field from DriverDetails response (parsed data is sufficient)
  3. Add optional include_documentation boolean to show_decoder_details (default: false)
  4. Add max_lines or limit parameter to decode_protocol for truncating large outputs
  5. Include result count in all list responses so LLM knows the full dataset size

Acceptance Criteria

  • list_supported_hardware and list_supported_decoders accept optional filter param
  • Filtered results return only matching items with total count
  • show_driver_details no longer returns RawOutput
  • show_decoder_details documentation is opt-in
  • decode_protocol supports output size limiting
  • Existing tests updated; new tests for filter behavior

Affected Files

  • internal/tools/tools.go — add filter/limit params to tool definitions
  • internal/tools/handlers.go — implement filtering logic
  • internal/sigrok/parser.go — update DriverDetails struct (remove RawOutput)
  • internal/tools/handlers_test.go — update tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions