Let’s Get Certified
Module 05 / 12 · Tool design and MCP integration

Tool contracts and recovery

Give similar tools distinct jobs and return enough information to recover from failure.

Make the tool catalog legible

An operations assistant has access to both a live dispatch database and an archive of signed manifests. Staff use the word “shipment” for records in both systems. A description that repeats that word cannot tell the model which source answers a question.

2.1 · Draw the boundary between similar tools

Call one tool read_current_dispatch. Describe its input as an exact dispatch ID and its output as the current operational state and update time. Call the other find_signed_manifest. Specify that it accepts a carrier and date range and returns signed document references, including zero matches. Include a representative request and a near miss for each. If a request asks who signed, the archive owns the answer.

Break a catch-all document tool into operations when extraction, summarization, and claim checking have different inputs or evidence requirements. Trace misroutes to the tool descriptions and the system prompt. A rule that sends every mention of “shipment” to the live database will override a carefully written archive description.

Route a request with two meanings of “manifest”

Dispatch operators use “manifest” for both a live view and a signed historical document. Draft tool descriptions for “Where is dispatch A17 now?” and “Show what the carrier signed last Friday.” Then decide what should happen when someone asks only for “the A17 manifest.”

Compare two tool descriptions

Describe the live tool as accepting a dispatch ID and returning current state with observation time. Describe the archive tool as accepting an ID or a carrier and date range and returning signed versions, signing dates and document references. Include an example for a previously amended dispatch. Neither description should imply that a current record proves what the carrier signed.

For the ambiguous request, ask whether the operator wants current status or the signed copy. Test all three requests against the routing trace. If both tools are clear but “manifest” always triggers the live tool, inspect the system instruction for a keyword shortcut. A precise tool name cannot correct conflicting routing instructions by itself.

Official reference · MCP connections and scope

2.2 · Return a recovery decision with the error

For an MCP tool execution failure, return isError: true and a structured payload inside the tool result. Include a category, retryability, a safe explanation, and any partial work. A malformed date needs corrected input. An unavailable service may warrant a bounded retry. An access denial needs an authorized path. A closed claim period needs policy handling. Retrying the identical request helps only a transient condition.

{"isError": true, "content": [{"type": "text",
 "text": "Archive timed out after page 2. Pages 1 and 2 are available."}]}

For automated recovery, encode the category, completed pages, and resume cursor as structured fields as well. A successful search returning zero documents is valid evidence about that query. A timeout leaves the search incomplete. After a bounded local recovery attempt, send the coordinator the affected query and remaining options.

Distinguish an empty archive from an unread one

An archive worker receives three outcomes in succession. A valid query for Monday finds zero results. A Tuesday request stops on page 3 after returning two pages. A request for a restricted collection is denied. Design outcomes the coordinator could use without parsing the worker’s narration.

Decode three outcomes

Monday succeeds with an empty result and its query scope. For Tuesday, attempt bounded local recovery on the transient read. If recovery fails, mark the execution error with MCP’s isError, a category, retry guidance, completed pages and the next cursor. Preserve the two verified pages. For the denied collection report the permission condition and an authorized route for resolving it. Repeating the unchanged request with the same rights wastes its budget.

A malformed date calls for a corrected input, while a policy rejection can require a different business decision. In both cases state who can change the condition. An unavailable source cannot support the coordinator’s claim that no matching records exist.

Video background · freeCodeCamp at 3:19:46 · Returning structured error context

Contract test

Try the requests “current location”, “who signed last Tuesday”, and “signed copy for an unknown ID”. Check the selected tool, its inputs, and how the agent explains a successful miss. Repeat with a simulated outage and compare the explanation.

Further reading · Official CCAR-F exam guide, sample questions and practice exercises · MCP connections and scope

Knowledge check

Tool contracts and recovery quiz

Answer 6 questions. Check each answer for an explanation.