Let’s Get Certified
Module 08 / 14 · Integration

Connect services and recover from failed calls

Select an integration mechanism, load capabilities on demand, and handle ambiguous outcomes.

A scheduling service coordinates inventory lookups, specialist reviews, and booking writes. It must operate both interactively and in unattended jobs.

3.6 · Select MCP, a direct integration, or an agent handoff

A direct API call fits a known low-latency operation with a stable typed contract. A pinned CLI can be appropriate for a local, controlled build step with known inputs and parseable output. MCP can expose discoverable tools and resources to different model clients with common integration semantics. An agent-to-agent handoff fits a separately owned, potentially long-running task with progress, status, and result contracts. Specify identity, timeout, cancellation, and state ownership for whichever boundary you select.

Choose the boundary for each call

A scheduler needs a slot lookup within 250 ms, a browsable family of reference tools shared by three assistant clients, and an accessibility review that can take a day and may ask for clarification. The existing slot API measures 90 ms p95. Design a connection for each need and state who retains progress when the scheduler restarts.

Compare the interface contracts

Use the measured direct API for the known slot operation and budget the remaining latency for the rest of the path. An MCP server can expose the shared references and actions with typed descriptions. Require caller authorization at the server regardless of how tools are discovered. A day-long review needs a durable task ID, status, deadline, cancellation semantics and a result owner. An agent handoff can implement that contract.

Persist the remote review ID before acknowledging acceptance. After a restart, query its state. A successful transport handshake or a text reply saying that work started cannot establish whether the long-running review finished.

Video background · freeCodeCamp at 11:31:32 · distinguishing MCP resources and tools

Negotiate a capability before assigning work

An MCP server offers a quote review. The desktop client supports elicitation, which lets the server ask the user for information. The overnight client has no interactive handler. During initialization, check the client capabilities and the operations the server advertises. If a material detail is missing overnight, persist a pending request for an authorized operator or return a clear incomplete result. A timeout cannot supply the customer’s decision.

Sampling lets a server request model work through a capable client. Roots describe workspace locations the client exposes to the server. Enforce file and network boundaries separately. A listed root, a successful protocol handshake, and a user’s answer to a data-entry question each establish different things. The application still checks authority at commit.

Further study · freeCodeCamp at 1:35:29 · roots, sampling and elicitation · MCP lifecycle specification

3.7 · Choose progressive or upfront discovery

Compare costs across the actual workload. Loading 100 descriptions of 200 tokens uses 20,000 tokens on every request. A 500-token catalog plus four 200-token descriptions costs 1,300 before discovery exchanges. Measure the extra round trips and failure rate. For three small tools needed on almost every call, upfront loading can win on latency. An on-demand broker must filter discovery and execution by access scope.

Count the cost of finding a tool

Each of 100 requests needs two common tool definitions of 150 tokens each. Ten requests also need one rare definition from a catalog of 40, each 200 tokens long. A broker directory costs 100 tokens per request and rare discovery adds one 180 ms round trip. Compare input tokens for loading everything with loading the common pair plus the directory. Ignore response and protocol overhead for this estimate.

Calculate the workload trade-off

Loading everything takes 8,300 × 100 = 830,000 tokens. Loading the pair and directory takes 400 × 100, plus 10 × 200 for rare definitions, or 42,000 tokens. Ten requests incur the extra round trip. The average added delay is 18 ms, but the affected requests each wait 180 ms. With a strict tail target, inspect the measured p95 of the whole path.

Authorize both the catalog entry and the final invocation. If a single rare tool becomes common, preload that definition for the affected workflow and remeasure. A catalog of three tiny tools with tight deadlines could favor a different decision.

Video background · freeCodeCamp at 11:29:55 · inspecting tools loaded at connection time

3.8 · Recover reliably from integration failures

Classify failures first. A rate limit calls for respecting the service’s retry guidance, bounded exponential backoff with jitter, and queue or concurrency limits. A validation rejection needs changed input. An ambiguous timeout after a booking write requires reconciliation with a stable operation key. Have the server persist the key, request identity, and outcome atomically so replay returns the original result.

Use a retry budget to prevent cascading load. A fallback route must satisfy the same access, quality, and residency constraints. If cancellation arrives after an external commit, consult operation state and perform only an authorized compensation. Log the outcome and communicate the unresolved state to the operator.

Reconcile a booking whose reply disappeared

A booking service receives operation B-27 for seat S4. Its caller times out. A second worker receives the same queue message, and the customer later changes the request to seat S5. Describe what the server should do for the duplicate and what the application should do with the changed request.

Trace the two possible commit states

Namespace the key by caller or tenant and operation. Persist a digest of the material input and the outcome atomically with the reservation, or use the downstream provider’s equivalent idempotent operation. If S4 was committed, replaying B-27 returns the existing result. If it was never committed, a safe same-key retry can complete it. An in-progress or unknown status calls for reconciliation, with a bounded wait.

S5 changes the intent. Reusing B-27 with different input should fail the payload check. Resolve S4, confirm the desired change, and issue a separate authorized amendment. A 429 on a read may justify delayed retry. It provides no evidence about the outcome of a previous write.

Design exercise

A booking times out after the inventory service reserves a seat. Draw both possible commit states. In each branch show how an operation-status read or a same-key retry converges to one reservation. A fresh key on retry leaves both reservations possible.

Further reading · Building effective agents · MCP authorization specification

Knowledge check

Connect services and recover from failed calls quiz

Answer 10 questions. Check each answer for an explanation.