---
title: "Map MCP tools into Foundation Models"
lesson_id: "04"
---

# Map MCP tools into Foundation Models

- **Lesson ID:** 04
- **Goal:** List MCP tools and wrap each one as a Foundation Models Tool using a runtime schema.
- **Human lesson:** [04-client-maps-to-tools.html](04-client-maps-to-tools.html)

## Prerequisites

Lesson 03, or a working tools/list and tools/call server.

## Inputs, outputs, and artifacts

- **Inputs:** MCP tool list JSON and LanguageModelSession.
- **Outputs:** A session whose tools come from the server list.
- **Artifacts:** MCPClient and MCPBridgedTool sketches.

## Agent build steps

1. Send tools/list and tools/call through the server.
2. Explain why @Generable cannot describe runtime MCP tools.
3. Map each listed tool with DynamicGenerationSchema or the installed runtime schema API.
4. Keep session.respond as the only chat call.
5. 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

- The client sends JSON-RPC to the server.
- A bridged `Tool` wraps each listed MCP tool with a runtime schema.
- MCP tools use a dynamic schema from MCP JSON Schema, not `@Generable`.
- Create the session after `tools/list`.

## Takeaways

- Refresh or rebuild the session if the server adds tools later.
- Do not mutate tools on a session that is responding.
- Confirm dynamic schema initializer names in the Xcode 27 docs.

## Acceptance checks

- Runtime schema is named. Compiled @Generable is marked as the wrong fit for MCP lists.
- The chat loop is still session.respond.
- Sibling links, progressive .flow diagrams, and the Agent brief link are present.
- [ ] Proceed to [lesson brief](05-plug-a-tool.llms.md).
