Workspace/Coding labs
Loading progress

Correlate and classify invocation results

Intermediate65 min

Implement correlate_results(pending, responses) for an offline fixture. Pending is a list of unique nonempty string IDs. Each response has exactly id plus either error, or result. An error value yields kind protocol_error. A result must contain exact boolean isError and a value; classify it as tool_error or success. Return normalized records in pending order. Every pending ID must have exactly one response; reject unknown, duplicate, missing or malformed responses. This simplified envelope is not a complete current MCP result model.

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

Inputcorrelate_results(["a","b"], [{"id":"b","error":"bad_method"},{"id":"a","result":{"isError":false,"value":3}}])

Output[{"id":"a","kind":"success","value":3},{"id":"b","kind":"protocol_error","value":"bad_method"}]

Arrival order does not determine association.
solution.pyPython 3.12