---
title: "Plug in a tool without rewriting chat"
lesson_id: "05"
---

# Plug in a tool without rewriting chat

- **Lesson ID:** 05
- **Goal:** Register one new MCP tool and prove the UI and respond call do not change.
- **Human lesson:** [05-plug-a-tool.html](05-plug-a-tool.html)

## Prerequisites

Lesson 04, or a working bridge.

## Inputs, outputs, and artifacts

- **Inputs:** A new MCPTool and the existing makeSession helper.
- **Outputs:** A checklist for adding tools at runtime.
- **Artifacts:** A lookup_order registration sketch, a checklist, and primary-source links.

## Agent build steps

1. Register one new MCPTool on the server.
2. Refresh the session from tools/list.
3. Call the same session.respond path.
4. List the six checklist items, including sandbox and guardrail follow-on.
5. Cite the MCP spec, Foundation Models docs, and [WWDC26 session 242](https://developer.apple.com/videos/play/wwdc2026/242/). Link [Run tools in a safe box](../on-device-sandboxed-tools/), [Stop prompt attacks and leaks](../on-device-guardrails/), and [Core AI vs Core ML vs MLX](../core-ai-vs-core-ml-vs-mlx/).

## Constraints

iOS 27 or later, or macOS 27 or later, and Xcode 27. Plain spoken English. No metaphor, quizzes, Mermaid, or em dashes. Do not invent a first-party Foundation Models MCP adapter. Show raw JSON-RPC 2.0. Confirm Tool and DynamicGenerationSchema names in the installed SDK docs.

## Key concepts

- Register a new MCP tool on the server, refresh the list, and keep the same `respond` call.
- The view still sends user text into `respond`.
- Do not edit tools while the session is responding.
- Put file, network, and private-data tools through sandbox and guardrail courses before shipping.

## Takeaways

- Add another MCP tool tomorrow and leave the SwiftUI chat view alone.
- The model sees the new tool because `tools/list` returned it.
- MCP adds tools at runtime. Your bridge is the join.

## Acceptance checks

- A new tool is added by register, not by editing the chat view.
- Primary sources are linked.
- Sibling links, progressive .flow diagrams, and the Agent brief link are present.

