﻿{
    "cells":  [
                  {
                      "cell_type":  "markdown",
                      "metadata":  {

                                   },
                      "source":  [
                                     "# Module 6 Self-Driven Lab\n",
                                     "\n",
                                     "Use this notebook as your workspace for **MCP Integration**. The answer-key notebook sits next to this file. Work through each checkpoint before comparing against the completed version.\n"
                                 ]
                  },
                  {
                      "cell_type":  "markdown",
                      "metadata":  {

                                   },
                      "source":  "# Module 6 â€” MCP Integration\n\n\u003e âš ï¸ **Heads up: this module is currently broken.** The MCP Connector example does not run end-to-end as written. Read through for the concepts, but expect to adjust the code before it works against a live server. Fix in progress.\n\nThe **MCP Connector** (`mcp-client-2025-11-20` beta) wires an MCP server in as a tool source directly inside a `/v1/messages` request â€” no separate MCP client process required. Claude calls MCP tools just like any other tool.\n\n\u003e **ZDR note:** the MCP Connector is **not ZDR-eligible** (server-side routing).\n\n### Free public MCP server for the lab\n\nWe hit Hugging Face\u0027s official MCP server at **`https://huggingface.co/mcp`**. It\u0027s public, supports anonymous access, and fits the prospecting narrative: Claude can check whether a target prospect has published models, datasets, or papers on the Hub as a signal of their AI maturity. An optional `HF_TOKEN` raises rate limits but isn\u0027t required."
                  },
                  {
                      "cell_type":  "markdown",
                      "metadata":  {

                                   },
                      "source":  [
                                     "## Setup"
                                 ]
                  },
                  {
                      "cell_type":  "code",
                      "execution_count":  null,
                      "metadata":  {

                                   },
                      "outputs":  [

                                  ],
                      "source":  [
                                     "# Setup cell. Run this before the exercise cells below.\n",
                                     "import anthropic\n",
                                     "from dotenv import load_dotenv\n",
                                     "\n",
                                     "load_dotenv()\n",
                                     "client = anthropic.Anthropic()"
                                 ]
                  },
                  {
                      "cell_type":  "markdown",
                      "metadata":  {

                                   },
                      "source":  "## 1. Call the Hugging Face MCP server inline\n\nThe MCP Connector splits the request into two pieces:\n\n- **`mcp_servers`** â€” connection details for each remote server (URL, type, auth token).\n- **`tools`** with `type: \"mcp_toolset\"` â€” references a server by name and enables specific tools via `configs`. This is your deny-by-default safety boundary: only tools with `{\"enabled\": True}` are exposed to Claude.\n\nNote that `authorization_token` lives on the server entry, not on the toolset entry."
                  },
                  {
                      "cell_type":  "markdown",
                      "metadata":  {

                                   },
                      "source":  [
                                     "## Checkpoint 1\n",
                                     "\n",
                                     "Implement this step yourself. Use the preceding explanation and the module page as your guide, then compare your approach with the answer key after you have a working version.\n"
                                 ]
                  },
                  {
                      "cell_type":  "code",
                      "execution_count":  null,
                      "metadata":  {

                                   },
                      "outputs":  [

                                  ],
                      "source":  [
                                     "# TODO: Implement checkpoint 1 for Module 6.\n",
                                     "# Keep the cell focused, run it, inspect the output, then move to the next checkpoint.\n",
                                     "\n",
                                     "raise NotImplementedError(\u0027Complete checkpoint 1\u0027)\n"
                                 ]
                  },
                  {
                      "cell_type":  "markdown",
                      "metadata":  {

                                   },
                      "source":  [
                                     "## 2. Secure credentials with env-var substitution\n",
                                     "\n",
                                     "Use `${VAR_NAME}` placeholders in `.mcp.json` so secrets stay out of source control. Values resolve from the runtime environment at startup. The cell below scaffolds the file."
                                 ]
                  },
                  {
                      "cell_type":  "code",
                      "execution_count":  null,
                      "metadata":  {

                                   },
                      "outputs":  [

                                  ],
                      "source":  [
                                     "# Setup cell. Run this before the exercise cells below.\n",
                                     "from pathlib import Path\n",
                                     "\n",
                                     "mcp_config = \u0027\u0027\u0027{\n",
                                     "  \"mcpServers\": {\n",
                                     "    \"crm\": {\n",
                                     "      \"command\": \"node\",\n",
                                     "      \"args\": [\"./mcp-servers/crm-server.js\"],\n",
                                     "      \"env\": {\n",
                                     "        \"CRM_API_KEY\": \"${CRM_API_KEY}\",\n",
                                     "        \"CRM_BASE_URL\": \"${CRM_BASE_URL}\"\n",
                                     "      }\n",
                                     "    }\n",
                                     "  }\n",
                                     "}\n",
                                     "\u0027\u0027\u0027\n",
                                     "\n",
                                     "Path(\"module6_demo\").mkdir(exist_ok=True)\n",
                                     "Path(\"module6_demo/.mcp.json\").write_text(mcp_config, encoding=\"utf-8\")\n",
                                     "print(\"wrote module6_demo/.mcp.json â€” add it to .gitignore if it ever holds real values\")"
                                 ]
                  },
                  {
                      "cell_type":  "markdown",
                      "metadata":  {

                                   },
                      "source":  [
                                     "## Reflection\n",
                                     "\n",
                                     "Before opening the answer key, write down what worked, what failed, and which API behavior or agent-design rule you would rely on in production.\n"
                                 ]
                  }
              ],
    "metadata":  {
                     "kernelspec":  {
                                        "display_name":  "Python 3",
                                        "language":  "python",
                                        "name":  "python3"
                                    },
                     "language_info":  {
                                           "name":  "python",
                                           "version":  "3.9"
                                       }
                 },
    "nbformat":  4,
    "nbformat_minor":  5
}
