Workspace/Coding labs
Loading progress

Collect an opaque-cursor tool catalog

Intermediate65 min

Implement collect_catalog(pages, start). This is an offline application fixture, not an MCP transport implementation. pages maps opaque string cursors to objects with tools (list of unique nonempty tool-name strings) and next (another cursor or None). Follow from start, preserving discovery order. Reject missing pages, repeated cursors, malformed pages, and duplicate tool names across pages with ValueError. An empty page with a new next cursor must be followed.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputcollect_catalog({"root":{"tools":["a"],"next":"x"},"x":{"tools":["b"],"next":null}},"root")

Output["a", "b"]

All pages contribute to discovery.
EXAMPLE 2

Inputcollect_catalog({"root":{"tools":[],"next":null}},"root")

Output[]

A valid server can expose an empty catalog.
solution.pyPython 3.12