Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 1.93 KB

L03.md

File metadata and controls

45 lines (33 loc) · 1.93 KB
id course-mcp-tools-l03
type course
title Validation and error isolation
summary Arguments are untrusted input: validate before execution, and never let a handler crash the transport.
lang en-US
content_version 1
status reviewed
reviewed_on 2026-09-12
hints
title body
What this checkpoint tests
`python verify.py starter` — `MCPServer` with `register_tool` and `handle_request`: validation, dispatch, and error isolation all green.
title body
Tools are untrusted
Missing required argument → `isError` content 'Missing required argument: <arg>'; unknown tool → 'Tool not found'; handler exceptions → `isError` 'Error: <e>'. A tool failing must never crash the transport.
title body
Return shapes
`tools/list` yields `result.tools` entries with name/description/inputSchema; `tools/call` yields `result.content` of type text — get the envelope exact, the suite compares structure.

Validation and error isolation

Objective

Arguments are untrusted input: validate before execution, and never let a handler crash the transport.

The lesson

Two boundaries make a tool server safe: validate required arguments against the declared input schema (missing arguments become structured results, not exceptions), and wrap every handler so its failures return isError instead of breaking the connection. 03-missing-argument.json shows the first boundary on the wire.

Exercise

  • Trace each validation test to the contract line it pins
  • Ask: what happens if a handler raises InputRequired? (Next lesson.)

Checkpoint

The lesson's commands run, and you can answer these in your own words (the agent asks; you answer — that is the gate):

  1. Which command did this lesson run, and what did it decide?
  2. What failed at the start, and why — in your own words?
  3. Before trusting a similar change next time, what would you check first?

Expected evidence

The command transcript and your answers.