Ch 4 — Tools Under the Hood

JSON Schema validation, argument completion, error codes, cancellation, pagination, and SDK patterns
Under the Hood
-
Click play or press Space to begin...
Step- / 10
AJSON Schema for Tool InputsHow inputSchema defines and validates arguments
1
schema
inputSchemaJSON Schema object
defines arg types
validates
data_object
ArgumentsLLM-generated
JSON object
checked
2
verified
ValidatedServer validates
before execution
3
arrow_downward Argument auto-completion for better UX
BArgument CompletionServer suggests values as the user types
edit
User TypesPartial value
for an argument
complete
auto_awesome
completion/completeClient asks server
for suggestions
returns
list
SuggestionsMatching values
for the argument
4
arrow_downward Error handling: what happens when tools fail
CError HandlingTool errors vs protocol errors — two different things
warning
Tool ErrorisError: true
in result content
vs
error
Protocol ErrorJSON-RPC error
response object
codes
5
tag
Error Codes-32600 to -32603
+ MCP-specific
6
arrow_downward Cancellation: aborting a running tool call
DCancellationAborting a long-running tool call mid-execution
hourglass_top
Tool RunningLong operation
in progress
cancel
cancel
cancelledClient sends
cancel notification
cleanup
7
cleaning_services
Server Cleans UpStops work, frees
resources
8
arrow_downward Pagination: handling large tool lists
EPaginationCursor-based pagination for large tool lists
first_page
First Pagetools/list with
no cursor
nextCursor
navigate_next
Next Pagetools/list with
cursor param
repeat
last_page
Last PageNo nextCursor
= done
9
arrow_downward SDK patterns: defining tools in Python and TypeScript
FSDK PatternsHow you actually define tools in code
code
Python SDK@mcp.tool()
decorator pattern
or
javascript
TypeScript SDKserver.tool()
method pattern
both
10
auto_fix_high
Auto SchemaSDK generates
inputSchema from types
1
Detail