Complete "Security, Reliability, and Observability" first to unlock this lesson.Go to previous lesson

Capstone Outcome

A production-ready MCP integration is not simply an agent that can call a tool. It is an application that connects an AI agent to approved tools or data, mediates each request through an MCP client, and gives users a reliable account of what happened. In this capstone, you will design and evaluate that full path using realistic requests, including requests that are ambiguous, unsafe, or impossible to complete.

Keep the roles distinct. The host is the application that manages the agent experience and its MCP clients. An MCP client maintains a connection to an MCP server. The server exposes capabilities such as tools or resources. The model can help select an action, but the host remains responsible for policy decisions, user interaction, and reporting results. Do not treat a model instruction or a tool description as an authorization boundary.

Define the Request and Boundaries

Start with one concrete workflow, such as triaging a support ticket. Write down what the user can ask, what data the application may access, and which actions can change external state. A useful initial capability set includes a read-only ticket lookup and a state-changing action such as adding an internal note. Specify the permitted inputs, expected result, and authorization requirement for each action before connecting the agent.

Separate information gathering from decisions that have consequences. The application may retrieve a ticket and draft a suggested note without changing anything. It must not add the note or alter the ticket status until the user confirms the exact action and target. If the request does not identify a ticket, or the retrieved information leaves material uncertainty, ask a clarifying question instead of guessing. Use sandbox data for development and evaluation; do not use real customer records to make a demonstration feel realistic.

Diagram showing the user request flowing through the host policy and approval boundary, the AI agent, an MCP client, and a sandbox MCP server with separate read-only lookup and state-changing tools; show results returning through the host to the user

Build the MCP Path

Connect to the server using an MCP client supported by your chosen SDK and transport. For a local server, standard input/output can be appropriate; for a remote server, use a supported HTTP transport and configure its security deliberately. Treat the transport, SDK, and server version as explicit project dependencies. Record the expected server identity and capabilities at startup, and fail clearly if a required tool is missing or its advertised input schema is incompatible with your application.

Use MCP discovery and invocation as protocol operations, not as names invented for the model. The client can discover available tools through tools/list and invoke a selected tool through tools/call. Servers may also expose resources, which clients can discover and read through the corresponding resource operations. Request only the capabilities this workflow needs. Before invoking a tool, the host should check its own policy, validate the arguments against the application’s expectations, and obtain confirmation when required. After invocation, validate the result before passing it back to the agent or presenting it as fact.

Enforce Safety and Reliability

Tool schemas and descriptions help an agent understand a capability, but they do not prove that a call is safe. Annotations such as read-only or destructive hints are useful metadata, not substitutes for application policy. Enforce access using the server’s permissions and the host’s own authorization checks. Give the server credentials only for the operations and records it needs, store secrets outside prompts and source control, and use the remote authorization mechanisms appropriate to the selected transport.

Treat both model-generated arguments and server-returned content as untrusted input. Validate identifiers, allowed status values, text length, and any relevant user permissions. Tool output can contain incorrect data or instructions intended to manipulate the agent; it cannot override host policy. Set timeouts and provide a clear failure path. Retry only operations known to be safe to repeat, since retrying a state-changing request after an uncertain timeout can create duplicate effects. Where supported, handle cancellation and shut down client and server connections cleanly.

Evaluate End to End

Test the complete user workflow, not only whether the MCP connection opens. Include a straightforward lookup, a request that needs clarification, a request to make a change, a user who declines confirmation, and a server that times out or returns an error. Add a case where tool output contains an instruction that conflicts with application policy. For each case, specify the expected user-visible response and whether a tool call is permitted.

Measure observable behavior. Record whether the intended tool was selected, whether the arguments passed validation, whether a required approval occurred, and whether the final response matches the actual tool result. A test passes only if the application refuses unsafe calls and accurately describes failures. Review logs and traces for enough detail to diagnose a failed request, while redacting credentials and limiting sensitive user data. Report test coverage and known limitations instead of claiming that a small test suite proves general safety.

Release and Review

Before release, pin dependencies, document the MCP server and transport configuration, and ensure that the application fails closed when required configuration or capabilities are unavailable. Review access controls, credential handling, network exposure, timeouts, and log retention. Keep development, test, and production server configurations separate. Changes to a tool schema or server implementation should trigger compatibility and safety tests before deployment.

The capstone deliverable is a repeatable application, not a successful screenshot. Include setup steps, the trust boundaries, the actions that require approval, and the test results. A reviewer should be able to run the app against sandbox data, reproduce both a successful lookup and a rejected or failed action, and verify that the final message never claims a change occurred unless the server confirmed it. These standards make the integration understandable, testable, and safer to operate.

Lesson practice

Lesson Checkpoint

Review what you learned and get feedback on your work.

0/1
Answered · 0/1
Capstone: Production-Ready MCP Integration