Skip to content
Back to search

dominics-bakery-mcp

Custom MCP server (Python) on Azure Functions for Dominic's Bakery, tested with VS Code, MCP Inspector and a Microsoft Foundry agent

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/dominicnike--dominics-bakery-mcp/badge.svg)](/listings/dominicnike--dominics-bakery-mcp)

HTML

<a href="/listings/dominicnike--dominics-bakery-mcp"><img src="/api/listings/dominicnike--dominics-bakery-mcp/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

winget install -e --id Python.Python.3.13

> ⚠️ **Use Python 3.13.** The package `azure-functions` 2.x requires Python **≥ 3.13**. We first tried 3.12 and `pip install` failed (see [Troubleshooting](#troubleshooting--every-error-we-hit-and-how-we-fixed-it)).

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 912 lines
  1. # 🥐 Dominic's Bakery – Build a Custom MCP Server on Azure Functions and Connect it to Microsoft Foundry
  2. This repository is a **complete, step-by-step record** of a live classroom demo. Starting from a Windows PC with nothing installed, we:
  3. 1. Installed every prerequisite
  4. 2. Signed in to Azure
  5. 3. Created Azure Blob Storage in the **Azure Portal** and uploaded bakery products
  6. 4. Ran a **Python MCP server on Azure Functions** locally
  7. 5. Tested it locally with **VS Code GitHub Copilot Chat** and the **MCP Inspector**
  8. 6. Created a **Function App** in the Azure Portal and **deployed** the code
  9. 7. Tested the **remote (Azure)** MCP server from VS Code and the MCP Inspector
  10. 8. Connected the MCP server to an **AI agent in Microsoft Foundry** and tested it in the Playground
  11. 9. Pushed the code to GitHub
  12. Every command below is one that **was actually run successfully** during the demo, together with the output you should expect and the fixes for every error we hit.
  13. > 🎥 Based on the video: <https://youtu.be/cDGBGHXal9M>
  14. ---
  15. ## 📚 Table of contents
  16. - [What is MCP and what are we building?](#what-is-mcp-and-what-are-we-building)
  17. - [Architecture](#architecture)
  18. - [Names used in this demo](#names-used-in-this-demo)
  19. - [Project files explained](#project-files-explained)
  20. - [Part 0 – Install the prerequisites](#part-0--install-the-prerequisites)
  21. - [Part 1 – Get the project and open it in VS Code](#part-1--get-the-project-and-open-it-in-vs-code)
  22. - [Part 2 – Sign in to Azure (CLI)](#part-2--sign-in-to-azure-cli)
  23. - [Part 3 – Create the Resource Group and Storage Account (Portal)](#part-3--create-the-resource-group-and-storage-account-portal)
  24. - [Part 4 – Configure local.settings.json](#part-4--configure-localsettingsjson)
  25. - [Part 5 – Create the Python virtual environment and install packages](#part-5--create-the-python-virtual-environment-and-install-packages)
  26. - [Part 6 – Run the MCP server locally](#part-6--run-the-mcp-server-locally)
  27. - [Part 7 – Test locally in VS Code Copilot Chat](#part-7--test-locally-in-vs-code-copilot-chat)
  28. - [Part 8 – Test locally with the MCP Inspector](#part-8--test-locally-with-the-mcp-inspector)
  29. - [Part 9 – Create the Function App in Azure (Portal)](#part-9--create-the-function-app-in-azure-portal)
  30. - [Part 10 – Configure app settings](#part-10--configure-app-settings)
  31. - [Part 11 – Deploy (publish) the code to Azure](#part-11--deploy-publish-the-code-to-azure)
  32. - [Part 12 – Get the MCP key and prove the endpoint is protected](#part-12--get-the-mcp-key-and-prove-the-endpoint-is-protected)
  33. - [Part 13 – Test the remote server in VS Code](#part-13--test-the-remote-server-in-vs-code)
  34. - [Part 14 – Test the remote server in the MCP Inspector](#part-14--test-the-remote-server-in-the-mcp-inspector)
  35. - [Part 15 – Create a Microsoft Foundry project and deploy a model](#part-15--create-a-microsoft-foundry-project-and-deploy-a-model)
  36. - [Part 16 – Create the Foundry agent and connect the MCP server](#part-16--create-the-foundry-agent-and-connect-the-mcp-server)
  37. - [Part 17 – Test the agent in the Foundry Playground](#part-17--test-the-agent-in-the-foundry-playground)
  38. - [Part 18 – Push the code to GitHub](#part-18--push-the-code-to-github)
  39. - [Part 19 – Clean up](#part-19--clean-up)
  40. - [Troubleshooting – every error we hit and how we fixed it](#troubleshooting--every-error-we-hit-and-how-we-fixed-it)
  41. - [Security checklist](#security-checklist)
  42. - [References](#references)
  43. ---
  44. ## What is MCP and what are we building?
  45. **Model Context Protocol (MCP)** is an open standard that lets AI applications (VS Code Copilot, Claude, Microsoft Foundry agents, …) discover and call **tools** on a server – like a USB-C port for AI.
  46. **Dominic's Bakery** exposes its business as an MCP server with **4 tools**:
  47. | Tool | What it does | Inputs |
  48. |---|---|---|
  49. | `hello_mcp` | Health check – returns *"Hello, I am the Dominic's Bakery MCP tool!"* | – |
  50. | `list_products` | Reads all 10 product JSON files from the `products` blob container | – |
  51. | `place_order` | Checks the item exists, calculates the total and saves a new order JSON into the `orders` container | `customer_name` (text), `item` (text), `quantity` (integer) |
  52. | `list_orders` | Reads all orders from the `orders` container | – |
  53. Because it is a standard MCP server, **the same code** works with VS Code, the MCP Inspector and Microsoft Foundry – without changes.
  54. ---
  55. ## Architecture
  56. ```
  57. MCP over Streamable HTTP
  58. ┌──────────────────────┐ POST /runtime/webhooks/mcp ┌───────────────────────────────┐ ┌──────────────────────────────┐
  59. │ MCP clients │ ──────────────────────────────▶ │ Azure Functions (Python 3.13) │ ─────▶ │ Azure Blob Storage │
  60. │ • VS Code Copilot │ header: x-functions-key │ Flex Consumption plan │ │ stdominicsmcpserverdemo │
  61. │ • MCP Inspector │ │ 4 × mcpToolTrigger functions │ │ ├─ products/ (10 × JSON) │
  62. │ • Foundry agent │ ◀────────────────────────────── │ func-dominics-bakery-demo │ ◀───── │ └─ orders/ (new orders) │
  63. └──────────────────────┘ tool results └───────────────────────────────┘ └──────────────────────────────┘
  64. ```
  65. | Where | MCP endpoint | Key needed? |
  66. |---|---|---|
  67. | Local (your PC) | `http://localhost:7071/runtime/webhooks/mcp` | No |
  68. | Azure | `https://<your-function-app-default-domain>/runtime/webhooks/mcp` | Yes – `mcp_extension` system key in header `x-functions-key` |
  69. ---
  70. ## Names used in this demo
  71. Replace these with your own names if you rebuild it.
  72. | Resource | Name used |
  73. |---|---|
  74. | Project folder | `C:\Users\<you>\dominics-bakery-mcp` |
  75. | Resource group | `rg-dominics-bakery` |
  76. | Region | **East US 2** (`eastus2`) |
  77. | Storage account | `stdominicsmcpserverdemo` |
  78. | Blob containers | `products`, `orders` |
  79. | Function App | `func-dominics-bakery-demo` |
  80. | Function App default domain | `func-dominics-bakery-demo-drgdeyhuc7dcczar.eastus2-01.azurewebsites.net` |
  81. | Foundry project | `dominics-bakery-project` |
  82. | Foundry model deployment | `gpt-5.4-mini` |
  83. | Foundry agent | `dominics-bakery-agent` |
  84. | Foundry MCP tool / connection | `dominics-bakery-mcp` |
  85. ---
  86. ## Project files explained
  87. ```
  88. dominics-bakery-mcp/
  89. ├── function_app.py # The 4 MCP tools (Python v2 programming model)
  90. ├── requirements.txt # Python packages: azure-functions, azure-storage-blob
  91. ├── host.json # Functions host config + extension bundle (contains the MCP extension)
  92. ├── local.settings.sample.json # Template – copy to local.settings.json and paste your connection string
  93. ├── products/ # 10 product JSON files to upload to Blob Storage
  94. ├── .vscode/mcp.json # MCP server definitions for VS Code (local + remote)
  95. ├── .funcignore # Files NOT uploaded to Azure when publishing
  96. └── .gitignore # Keeps secrets (local.settings.json) and .venv out of GitHub
  97. ```
  98. ### `function_app.py` – how an MCP tool is written
  99. ```python
  100. app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
  101. @app.mcp_tool()
  102. def hello_mcp() -> str:
  103. """Simple hello-world tool to confirm the MCP server is working."""
  104. return "Hello, I am the Dominic's Bakery MCP tool!"
  105. @app.mcp_tool()
  106. @app.mcp_tool_property(arg_name="customer_name", description="Name of the customer placing the order.")
  107. @app.mcp_tool_property(arg_name="item", description="Exact product name to order, e.g. 'Snickerdoodle Cookie'.")
  108. @app.mcp_tool_property(arg_name="quantity", description="How many of the item to order.",
  109. property_type=McpPropertyType.INTEGER)
  110. def place_order(customer_name: str, item: str, quantity: int) -> str:
  111. """Place a new order at Dominic's Bakery for a customer."""
  112. ...
  113. ```
  114. Teaching points:
  115. - `@app.mcp_tool()` turns an ordinary Python function into an MCP tool.
  116. - The **docstring** becomes the tool **description** – the AI reads it to decide *when* to call the tool.
  117. - `@app.mcp_tool_property(...)` describes each **input** so the AI knows *what* to send.
  118. - Storage is reached with `BlobServiceClient.from_connection_string(os.environ["AzureWebJobsStorage"])` – the same setting works locally (from `local.settings.json`) and in Azure (from the Function App settings).
  119. ### `requirements.txt`
  120. ```text
  121. azure-functions>=2.2.0
  122. azure-storage-blob
  123. ```
  124. ### `host.json` – extension bundle (includes the MCP extension)
  125. ```json
  126. "extensionBundle": {
  127. "id": "Microsoft.Azure.Functions.ExtensionBundle",
  128. "version": "[4.*, 5.0.0)"
  129. }
  130. ```
  131. ### A product file (`products/cinnamon-roll.json`)
  132. ```json
  133. { "id": "cinnamon-roll", "name": "Cinnamon Roll", "category": "pastry", "price": 4.0, "in_stock": true }
  134. ```
  135. ---
  136. ## Part 0 – Install the prerequisites
  137. Open **VS Code → Terminal → New Terminal** (`Ctrl+``) – this is a **PowerShell** terminal. Run each command **one at a time**.
  138. ### 0.1 Check what is already installed
  139. ```powershell
  140. py --list
  141. func --version
  142. az --version
  143. node --version
  144. git --version
  145. gh --version
  146. ```
  147. In the demo, **Azure CLI 2.91**, **Node.js v24**, **Git** and **GitHub CLI** were already installed. **Python 3.13** and **Azure Functions Core Tools** were missing (`func` was "not recognized").
  148. ### 0.2 Install Python 3.13
  149. ```powershell
  150. winget install -e --id Python.Python.3.13
  151. ```
  152. > ⚠️ **Use Python 3.13.** The package `azure-functions` 2.x requires Python **≥ 3.13**. We first tried 3.12 and `pip install` failed (see [Troubleshooting](#troubleshooting--every-error-we-hit-and-how-we-fixed-it)).
  153. ### 0.3 Install Azure Functions Core Tools
  154. ```powershell
  155. winget install -e --id Microsoft.Azure.FunctionsCoreTools
  156. ```
  157. ### 0.4 (If missing) Azure CLI, Node.js, Git, GitHub CLI
  158. ```powershell
  159. winget install -e --id Microsoft.AzureCLI
  160. winget install -e --id OpenJS.NodeJS.LTS
  161. winget install -e --id Git.Git
  162. winget install -e --id GitHub.cli
  163. ```
  164. ### 0.5 Reload the PATH
  165. After `winget` installs, the open terminal still has the **old PATH** (`func : The term 'func' is not recognized…`). Either **close VS Code completely (File → Exit) and reopen it**, or reload the PATH in the current terminal:
  166. ```powershell
  167. $env:Path = [Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [Environment]::GetEnvironmentVariable("Path","User")
  168. ```
  169. ### 0.6 Verify
  170. ```powershell
  171. py -3.13 --version # Python 3.13.x
  172. func --version # 4.16.0 (any 4.x)
  173. az --version # azure-cli 2.x
  174. node --version # v18 or newer (demo: v24)
  175. ```
  176. ### 0.7 Install the VS Code extensions
  177. ```powershell
  178. code --install-extension ms-python.python
  179. code --install-extension ms-azuretools.vscode-azurefunctions
  180. code --install-extension GitHub.copilot-chat
  181. ```
  182. You also need a **GitHub Copilot** subscription signed in to VS Code, and an **Azure subscription**.
  183. ---
  184. ## Part 1 – Get the project and open it in VS Code
  185. ```powershell
  186. cd $HOME
  187. git clone https://github.com/dominicnike/dominics-bakery-mcp.git
  188. cd dominics-bakery-mcp
  189. code .
  190. ```
  191. In the **new VS Code window**, open a terminal (`Ctrl+``). All following commands run **inside the `dominics-bakery-mcp` folder**.
  192. > 💡 Copy **only the lines inside the grey code boxes**. In the demo, part of an instruction sentence was pasted into the terminal and PowerShell tried to run it as a command – harmless, just re-run the correct line.
  193. ---
  194. ## Part 2 – Sign in to Azure (CLI)
  195. ```powershell
  196. az login
  197. ```
  198. A browser opens – sign in. When the subscription list appears, **type the number** of the subscription to use (or press **Enter** to keep the default).
  199. If your subscription lives in a tenant that requires **MFA**, sign in to that tenant directly:
  200. ```powershell
  201. az login --tenant <your-tenant-id>
  202. # or, if the browser/MFA does not work:
  203. az login --tenant <your-tenant-id> --use-device-code
  204. ```
  205. Check which subscriptions you have and which one is active:
  206. ```powershell
  207. az account list --query "[].{name:name, tenant:tenantId, default:isDefault}" -o table
  208. az account show --query "{name:name, tenant:tenantId}" -o table
  209. ```
  210. Switch subscription if needed:
  211. ```powershell
  212. az account set --subscription "<subscription-name-or-id>"
  213. ```
  214. > ℹ️ Messages like *"Authentication failed against tenant … AADSTS50076 … must use multi-factor authentication"* refer to **other** tenants you belong to. They can be ignored as long as the correct subscription is active.
  215. >
  216. > ℹ️ At the subscription prompt you can **only** type a number or press Enter – typing a command there gives *"Invalid selection"*. Press Enter first, then run the next command.
  217. ---
  218. ## Part 3 – Create the Resource Group and Storage Account (Portal)
  219. We used the **Azure Portal** for this part so non-coders can follow. Go to <https://portal.azure.com> and check the correct directory/subscription in the top-right corner.
  220. ### 3.1 Resource group
  221. 1. Search **Resource groups → + Create**.
  222. 2. Subscription: *your subscription*.
  223. 3. Resource group: **`rg-dominics-bakery`** · Region: **East US 2**.
  224. 4. **Review + create → Create**.
  225. ### 3.2 Storage account
  226. 1. Search **Storage accounts → + Create**.
  227. 2. Resource group: **`rg-dominics-bakery`**.
  228. 3. Storage account name: **`stdominicsmcpserverdemo`** (lowercase letters and numbers only, must be globally unique).
  229. 4. Region: **East US 2**.
  230. 5. Primary service: **Azure Blob Storage or Azure Data Lake Storage Gen 2**.
  231. 6. Primary workload / *Compare workloads*: choose **General purpose**.
  232. - ❌ Not *AI Agent inferencing* – it uses Premium storage (more expensive, not supported by Functions).
  233. - ❌ Not *Big Data Analytics* – enables hierarchical namespace, not needed.
  234. 7. Performance: **Standard**.
  235. 8. Redundancy: change **RA-GRS** to **LRS (Locally-redundant storage)** – cheapest, fine for a demo.
  236. 9. **Review + create → Create → Go to resource**.
  237. ### 3.3 Create the blob containers
  238. 1. Storage account → **Data storage → Containers → + Container**.
  239. 2. Name **`products`** → **Create**.
  240. 3. **+ Container** again → Name **`orders`** → **Create**.
  241. ### 3.4 Upload the 10 product files
  242. 1. Open the **`products`** container → **Upload**.
  243. 2. Browse to the project's **`products`** folder (e.g. `C:\Users\<you>\dominics-bakery-mcp\products`).
  244. 3. Select **all 10** files (`Ctrl+A`):
  245. `banana-bread.json`, `butter-croissant.json`, `chocolate-chip-cookie.json`, `cinnamon-roll.json`, `fudgy-chocolate-brownie.json`, `oatmeal-raisin-cookie.json`, `red-velvet-cupcake.json`, `snickerdoodle-cookie.json`, `sourdough-loaf.json`, `whole-wheat-bread.json`
  246. 4. **Upload**.
  247. > ⚠️ Upload **only** the files inside `products/` – never upload `local.settings.json` or other project files. Leave the **`orders`** container **empty**; `place_order` fills it.
  248. ### 3.5 Copy the connection string
  249. 1. Storage account → **Security + networking → Access keys**.
  250. 2. Under **key1 → Connection string**, click **Show** then **Copy**.
  251. ---
  252. ## Part 4 – Configure `local.settings.json`
  253. Create your local settings from the template:
  254. ```powershell
  255. Copy-Item local.settings.sample.json local.settings.json
  256. ```
  257. Open `local.settings.json` and replace `<PASTE-YOUR-STORAGE-ACCOUNT-CONNECTION-STRING>` with the copied value (keep the quotes):
  258. ```json
  259. {
  260. "IsEncrypted": false,
  261. "Values": {
  262. "FUNCTIONS_WORKER_RUNTIME": "python",
  263. "PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1",
  264. "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=stdominicsmcpserverdemo;AccountKey=****;EndpointSuffix=core.windows.net"
  265. }
  266. }
  267. ```
  268. Save the file.
  269. > 🔒 `local.settings.json` contains your storage key. It is listed in `.gitignore` so it is **never pushed to GitHub**. Never share it.
  270. ---
  271. ## Part 5 – Create the Python virtual environment and install packages
  272. Run each line separately:
  273. ```powershell
  274. py -3.13 -m venv .venv
  275. ```
  276. ```powershell
  277. .\.venv\Scripts\Activate.ps1
  278. ```
  279. Your prompt now starts with **`(.venv)`**.
  280. > If you see *"running scripts is disabled on this system"*:
  281. > ```powershell
  282. > Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
  283. > ```
  284. > Answer **Y**, then run `.\.venv\Scripts\Activate.ps1` again. If asked *"Do you want to run software from this untrusted publisher?"* press **A** (Always run).
  285. ```powershell
  286. python --version # Python 3.13.x
  287. python -m pip install --upgrade pip
  288. pip install -r requirements.txt
  289. ```
  290. Expected: `Successfully installed azure-functions-2.x … azure-storage-blob-12.x …`
  291. > 💡 VS Code popups:
  292. > - **"Select an environment manager" / "Quick Create"** – press **Esc**, or choose **Enter Interpreter Path…** and select `.venv\Scripts\python.exe`. Don't use *Quick Create* – it may create an environment with a different Python version.
  293. > - **Pylance "enable type checking?"** – answer **No** (not needed for this demo).
  294. ---
  295. ## Part 6 – Run the MCP server locally
  296. ```powershell
  297. func start
  298. ```
  299. Expected output:
  300. ```
  301. Azure Functions Core Tools
  302. Core Tools Version: 4.16.0
  303. Function Runtime Version: 4.1054.x
  304. MCP server endpoint: http://localhost:7071/runtime/webhooks/mcp
  305. MCP server legacy SSE endpoint: http://localhost:7071/runtime/webhooks/mcp/sse
  306. Functions:
  307. hello_mcp: mcpToolTrigger
  308. list_orders: mcpToolTrigger
  309. list_products: mcpToolTrigger
  310. place_order: mcpToolTrigger
  311. Worker process started and initialized.
  312. Host lock lease acquired by instance ID '...'.
  313. ```
  314. > ⚠️ If `func start` fails while **downloading the extension bundle** (a network blip), download it once and retry:
  315. > ```powershell
  316. > func bundles download
  317. > func start
  318. > ```
  319. >
  320. > ℹ️ Sometimes the `Functions:` list is not printed. If you see the **MCP server endpoint** line and *Host lock lease acquired*, the server is running.
  321. **Leave this terminal running** for Parts 7 and 8.
  322. ---
  323. ## Part 7 – Test locally in VS Code Copilot Chat
  324. ### 7.1 Register the local server
  325. The repo already contains `.vscode/mcp.json`:
  326. ```json
  327. {
  328. "servers": {
  329. "my-mcp-local-server": {
  330. "url": "http://localhost:7071/runtime/webhooks/mcp",
  331. "type": "http"
  332. },
  333. "my-remote-mcp-server": {
  334. "url": "https://<your-function-app-default-domain>/runtime/webhooks/mcp",
  335. "type": "http",
  336. "headers": { "x-functions-key": "${input:functions-mcp-extension-system-key}" }
  337. }
  338. },
  339. "inputs": [
  340. {
  341. "type": "promptString",
  342. "id": "functions-mcp-extension-system-key",
  343. "description": "Azure Functions mcp_extension system key",
  344. "password": true
  345. }
  346. ]
  347. }
  348. ```
  349. To add it yourself exactly like in the video: **Ctrl+Shift+P → MCP: Add Server… → HTTP** → URL `http://localhost:7071/runtime/webhooks/mcp` → name `my-mcp-local-server` → **Workspace**.
  350. > ⚠️ Keep **one** config file: `.vscode/mcp.json`. In the demo, *Add Server* once created a second `.mcp.json` in the project root and moved entries into it – we deleted the root file and kept `.vscode/mcp.json`.
  351. ### 7.2 Start the server in VS Code
  352. 1. Open `.vscode/mcp.json`.
  353. 2. Above `"my-mcp-local-server"` click **▷ Start** → it shows **Running · 4 tools**.
  354. - No *Start* link? **Ctrl+Shift+P → MCP: List Servers → my-mcp-local-server → Start Server**.
  355. - Shows *Error*? Make sure `func start` is running, then click **Start** again. Click **Error** to open the log.
  356. ### 7.3 Chat with the tools
  357. 1. Open **Copilot Chat** (`Ctrl+Alt+I`) → start a **new chat (+)** → select **Agent** mode.
  358. 2. Choose the tools:
  359. - Older layout: click the 🛠 **tools icon** in the chat box and tick only `my-mcp-local-server`.
  360. - Newer layout (no tools icon): **Ctrl+Shift+P → Chat: Configure Tools** and tick only `my-mcp-local-server`.
  361. - Or type `#` in the chat box and pick a tool, e.g. `#list_products`.
  362. 3. Prompts used in the demo (click **Allow / Continue** when Copilot asks to run a tool):
  363. ```text
  364. Say hello using the bakery MCP server.
  365. ```
  366. ```text
  367. List the products for Dominic's Bakery.
  368. ```
  369. ```text
  370. Create a new order for Mason for 5 Snickerdoodle Cookies.
  371. ```
  372. ```text
  373. List the orders.
  374. ```
  375. ### 7.4 Show the proof
  376. Azure Portal → **stdominicsmcpserverdemo → Containers → orders** → a new `<order_id>.json` file appears. The AI agent wrote real data through your tool.
  377. > ℹ️ A message such as *"Foundry MCP … unable to sign in"* comes from the **AI Toolkit** extension's own server – unrelated to this project.
  378. ---
  379. ## Part 8 – Test locally with the MCP Inspector
  380. With `func start` still running, open a **second terminal** (`+` in the terminal panel):
  381. ```powershell
  382. npx @modelcontextprotocol/inspector
  383. ```
  384. Answer **y** if npx asks to install the package. The Inspector opens in your browser (if not, open the printed `http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=…` link).
  385. 1. **Add server** / connection settings:
  386. - Transport type: **Streamable HTTP**
  387. - URL: `http://localhost:7071/runtime/webhooks/mcp`
  388. 2. **Connect** → status **Connected**.
  389. 3. **Tools → List Tools** → `hello_mcp`, `list_orders`, `list_products`, `place_order`.
  390. 4. Run the tools:
  391. - `hello_mcp` → *Hello, I am the Dominic's Bakery MCP tool!*
  392. - `list_products` → JSON list of 10 products
  393. - `place_order` → `customer_name` = `Ada`, `item` = `Banana Bread`, `quantity` = `1` → *Order placed*
  394. - `list_orders` → shows Mason's and Ada's orders
  395. Press **Ctrl+C** in the Inspector terminal when done.
  396. ---
  397. ## Part 9 – Create the Function App in Azure (Portal)
  398. 1. Portal → search **Function App → + Create**.
  399. 2. Hosting plan: **Flex Consumption** → **Select**.
  400. 3. **Basics**
  401. - Subscription: *your subscription*
  402. - Resource group: **`rg-dominics-bakery`**
  403. - Function App name: **`func-dominics-bakery-demo`**
  404. - Region: **East US 2**
  405. - Runtime stack: **Python** · Version: **3.13** (match your local Python)
  406. - Instance size: **2048 MB** (default)
  407. 4. **Storage** tab: Storage account → **`stdominicsmcpserverdemo`** (the one from Part 3).
  408. 5. **Monitoring** tab: Application Insights → **Yes** (default).
  409. 6. **Review + create → Create** (≈1–2 min) → **Go to resource**.
  410. 7. On **Overview**, copy the **Default domain**. Flex Consumption adds a random suffix, e.g.
  411. `func-dominics-bakery-demo-drgdeyhuc7dcczar.eastus2-01.azurewebsites.net`
  412. > ⚠️ Always use the **exact Default domain** – `func-dominics-bakery-demo.azurewebsites.net` (without the suffix) does not work for Flex Consumption apps.
  413. ---
  414. ## Part 10 – Configure app settings
  415. Add the recommended Python setting (back in the VS Code terminal):
  416. ```powershell
  417. az functionapp config appsettings set -g rg-dominics-bakery -n func-dominics-bakery-demo --settings PYTHON_ISOLATE_WORKER_DEPENDENCIES=1
  418. ```
  419. Portal alternative: **Function App → Settings → Environment variables → + Add** → Name `PYTHON_ISOLATE_WORKER_DEPENDENCIES`, Value `1` → **Apply → Apply → Confirm**.
  420. List the settings:
  421. ```powershell
  422. az functionapp config appsettings list -g rg-dominics-bakery -n func-dominics-bakery-demo --query "[].name" -o tsv
  423. ```
  424. Expected (order may vary):
  425. ```
  426. DEPLOYMENT_STORAGE_CONNECTION_STRING
  427. APPLICATIONINSIGHTS_CONNECTION_STRING
  428. AzureWebJobsStorage
  429. PYTHON_ISOLATE_WORKER_DEPENDENCIES
  430. ```
  431. > ✅ `AzureWebJobsStorage` **must** be present – our code uses it to reach the `products` and `orders` containers. The portal created it automatically because we chose our storage account in Part 9.
  432. ---
  433. ## Part 11 – Deploy (publish) the code to Azure
  434. From the project folder, with `(.venv)` active:
  435. ```powershell
  436. func azure functionapp publish func-dominics-bakery-demo
  437. ```
  438. Output from the demo (shortened):
  439. ```
  440. Getting site publishing info...
  441. Starting the function app deployment...
  442. Creating archive for current directory...
  443. Performing remote build for functions project.
  444. Uploading 2.11 KB [###########################]
  445. Deployment in progress, please wait...
  446. [Kudu-OryxBuildStep] completed.
  447. [Kudu-UploadPackageStep] completed. Uploaded package to storage successfully.
  448. Checking the app health... done
  449. Host status: {"state":"Running", ... "extensionBundle":{"id":"Microsoft.Azure.Functions.ExtensionBundle","version":"4.41.2"}}
  450. The deployment was successful!
  451. Functions in func-dominics-bakery-demo:
  452. hello_mcp - [mcpToolTrigger]
  453. list_orders - [mcpToolTrigger]
  454. list_products - [mcpToolTrigger]
  455. place_order - [mcpToolTrigger]
  456. ```
  457. > ℹ️ The warning *"Local python version '3.13.x' is different from the version expected for your deployed Function App … '3.14'"* is safe here – the remote build succeeded. Best practice: keep local and Azure Python versions identical.
  458. Confirm in the portal: **Function App → Overview → Functions** tab lists the 4 functions.
  459. ---
  460. ## Part 12 – Get the MCP key and prove the endpoint is protected
  461. ### 12.1 Without a key → 401
  462. ```powershell
  463. curl.exe -s -o NUL -w "%{http_code}" -X POST https://<your-function-app-default-domain>/runtime/webhooks/mcp
  464. ```
  465. Expected: **`401`** (Unauthorized) – the server is protected. 🎓 Great moment to show students.
  466. ### 12.2 Get the `mcp_extension` system key
  467. ```powershell
  468. az functionapp keys list -g rg-dominics-bakery -n func-dominics-bakery-demo --query systemKeys.mcp_extension -o tsv
  469. ```
  470. Portal alternative: **Function App → Functions → App keys → System keys → `mcp_extension`** → show/copy.
  471. > 🔒 Treat this key like a password. Don't paste it in chats, screenshots or GitHub.
  472. ---
  473. ## Part 13 – Test the remote server in VS Code
  474. 1. **Stop the local server** so you are sure the answers come from Azure:
  475. - Press **Ctrl+C** in the `func start` terminal.
  476. - In `.vscode/mcp.json` click **Stop** above `my-mcp-local-server`.
  477. 2. **Add / check the remote server** (as in the video): **Ctrl+Shift+P → MCP: Add Server… → HTTP** → paste
  478. `https://<your-function-app-default-domain>/runtime/webhooks/mcp` → name **`my-remote-mcp-server`** → **Workspace**.
  479. Then add the `headers` block so it looks like the `my-remote-mcp-server` entry in [Part 7.1](#71-register-the-local-server):
  480. ```json
  481. "headers": { "x-functions-key": "${input:functions-mcp-extension-system-key}" }
  482. ```
  483. > The video pastes the key directly (`"x-functions-key": "<mcp-extension-key>"`). That works, but then the key is saved in the file. Using `${input:…}` makes VS Code **ask for the key** in a password box instead – safer when you push to GitHub.
  484. 3. Click **▷ Start** above `my-remote-mcp-server` → paste the key in the prompt at the top → **Enter** → **Running · 4 tools**.
  485. - No prompt? **Ctrl+Shift+P → MCP: Reset Cached Inputs**, then **Start** again.
  486. - Check status: **Ctrl+Shift+P → MCP: List Servers**.
  487. 4. Copilot Chat → **new chat (+)** → **Agent** mode → **Chat: Configure Tools** → tick only `my-remote-mcp-server`.
  488. 5. Ask:
  489. ```text
  490. #list_orders List all the orders for Dominic's Bakery.
  491. ```
  492. You see the orders created locally (Mason, Ada) – now served by **Azure**.
  493. ---
  494. ## Part 14 – Test the remote server in the MCP Inspector
  495. ```powershell
  496. npx @modelcontextprotocol/inspector
  497. ```
  498. 1. Transport type: **Streamable HTTP**
  499. 2. URL: `https://<your-function-app-default-domain>/runtime/webhooks/mcp`
  500. 3. 🎓 Click **Connect** first **without** a header → connection fails with **401**.
  501. 4. Open **Authentication / Headers / Custom Headers** (name depends on Inspector version) → add:
  502. - Header name: `x-functions-key`
  503. - Value: *your `mcp_extension` key*
  504. 5. **Connect** → **Tools → List Tools** → 4 tools.
  505. 6. Run `list_products`, `place_order` (e.g. `Ada`, `Banana Bread`, `1`) and `list_orders`.
  506. ---
  507. ## Part 15 – Create a Microsoft Foundry project and deploy a model
  508. ### 15.1 Create the project
  509. 1. Go to <https://ai.azure.com> and sign in with the **same account** as Azure.
  510. 2. Turn **New Foundry** **on** (toggle at the top).
  511. 3. Project picker (top-left) → **Create new project**:
  512. - Project name: **`dominics-bakery-project`**
  513. - Subscription: *your subscription*
  514. - Resource group: **`rg-dominics-bakery`**
  515. - Region: **East US 2**
  516. 4. **Create** (≈1–2 minutes). This also creates a Foundry resource (`dominics-bakery-project-resource`) in the resource group.
  517. ### 15.2 Deploy a chat model
  518. **Models → Deploy a model** (or **Catalog**) → search **`gpt-5.4-mini`** → **Deploy** → **Global Standard** → **Deploy**.
  519. CLI alternative (what we ran in the demo):
  520. ```powershell
  521. az cognitiveservices account deployment create -g rg-dominics-bakery -n dominics-bakery-project-resource `
  522. --deployment-name gpt-5.4-mini --model-name gpt-5.4-mini --model-version 2026-03-17 `
  523. --model-format OpenAI --sku-name GlobalStandard --sku-capacity 50
  524. ```
  525. Expected: `Name: gpt-5.4-mini State: Succeeded`.
  526. > ⚠️ **Use a dedicated model – not `model-router`.** Our agent first used the default **model-router** and every request failed with *"There was an issue with your request. Please check your inputs and try again"*. Switching the agent to **gpt-5.4-mini** fixed it immediately.
  527. >
  528. > ⚠️ `gpt-4o-mini` could not be deployed (*ServiceModelDeprecating*). Choose a current model from the catalog.
  529. ---
  530. ## Part 16 – Create the Foundry agent and connect the MCP server
  531. ### 16.1 Create the agent
  532. **Build → Agents → Create agent**
  533. - Name: **`dominics-bakery-agent`**
  534. - Model: **`gpt-5.4-mini`**
  535. - Instructions:
  536. ```text
  537. You are the friendly assistant for Dominic's Bakery.
  538. Use the bakery tools to list products, place orders and list orders.
  539. Always confirm the customer's name and the items before placing an order.
  540. Only offer products returned by the list_products tool.
  541. ```
  542. **Save**.
  543. ### 16.2 Add the MCP server as a tool
  544. In the agent's **Playground** → left panel → **Tools → Add → Custom → Model Context Protocol (MCP) → Create**:
  545. | Field | Value |
  546. |---|---|
  547. | Name | `dominics-bakery-mcp` |
  548. | Remote MCP Server endpoint | `https://<your-function-app-default-domain>/runtime/webhooks/mcp` |
  549. | Authentication | **Key-based** |
  550. | Credential name | `x-functions-key` (lowercase, with hyphens) |
  551. | Credential value | your `mcp_extension` key (no quotes or spaces) |
  552. **Connect** → **Save** the agent.
  553. The tool now also appears under **Tools** (left menu) → **Tools** tab as `dominics-bakery-mcp – Model Context Protocol (MCP)`. **Do not delete it there** – that is your working connection.
  554. ### 16.3 Remove the automatic toolbox (if present)
  555. In the demo the portal also attached **`dominics-bakery-agent-toolbox` v1** to the agent. That toolbox did not exist anymore (404) and every chat failed with *"A user error occurred while executing a tool call."*
  556. Fix: agent → **Playground → Tools** → on **`dominics-bakery-agent-toolbox`** open **⋯ → Remove** → keep **`dominics-bakery-mcp (https://func-dominics-bakery-…)`** → **Save**.
  557. ### 16.4 Make sure the agent uses the dedicated model
  558. Agent → **Playground** → **Model:** select **`gpt-5.4-mini`** (not `model-router`) → **Save** (a new version is created, e.g. *Version 6*).
  559. ---
  560. ## Part 17 – Test the agent in the Foundry Playground
  561. Click **⊕ (new chat)** in the chat pane, then send:
  562. ```text
  563. List all Dominic's Bakery products and prices.
  564. ```
  565. 1. Foundry shows an **approval** request for `list_products` → click **Approve**. 🎓 *Human-in-the-loop*: the agent can't use a tool without your permission.
  566. 2. Expected answer:
  567. | Product | Price |
  568. |---|---|
  569. | Banana Bread | $7.25 |
  570. | Butter Croissant | $3.25 |
  571. | Chocolate Chip Cookie | $1.75 |
  572. | Cinnamon Roll | $4.00 |
  573. | Fudgy Chocolate Brownie | $3.00 |
  574. | Oatmeal Raisin Cookie | $1.50 |
  575. | Red Velvet Cupcake | $3.50 |
  576. | Snickerdoodle Cookie | $1.75 |
  577. | Sourdough Loaf | $6.50 |
  578. | Whole Wheat Bread | $5.00 |
  579. Continue the conversation:
  580. ```text
  581. I'm Grace, please order 2 Cinnamon Roll and 1 Banana Bread.
  582. ```
  583. ```text
  584. Show me all the orders.
  585. ```
  586. Approve each `place_order` / `list_orders` call.
  587. **Proof for students:** Azure Portal → **stdominicsmcpserverdemo → Containers → orders** → Grace's new order files are there.
  588. 🎉 **The same MCP server now powers VS Code Copilot, the MCP Inspector and a Microsoft Foundry agent.**
  589. ---
  590. ## Part 18 – Push the code to GitHub
  591. ### 18.1 Sign in to GitHub CLI
  592. ```powershell
  593. gh auth status
  594. gh auth login # only if not signed in
  595. ```
  596. ### 18.2 Make sure no secrets will be pushed
  597. `.gitignore` contains:
  598. ```text
  599. .venv/
  600. __pycache__/
  601. *.pyc
  602. local.settings.json
  603. .python_packages/
  604. bin/
  605. obj/
  606. ```
  607. and `.vscode/mcp.json` uses `${input:…}` instead of a real key.
  608. ### 18.3 Commit and push
  609. ```powershell
  610. git init -b main
  611. git add -A
  612. git status # local.settings.json and .venv must NOT be listed
  613. git commit -m "Dominic's Bakery MCP server on Azure Functions with Foundry agent guide"
  614. gh repo create dominics-bakery-mcp --public --source . --remote origin --push
  615. ```
  616. Result: <https://github.com/dominicnike/dominics-bakery-mcp>
  617. Later changes:
  618. ```powershell
  619. git add -A
  620. git commit -m "Describe your change"
  621. git push
  622. ```
  623. ---
  624. ## Part 19 – Clean up
  625. After the class, delete everything to stop charges:
  626. ```powershell
  627. az group delete -n rg-dominics-bakery --yes --no-wait
  628. ```
  629. This removes the storage account, Function App, Application Insights, Foundry resource/project and model deployment.
  630. ---
  631. ## Troubleshooting – every error we hit and how we fixed it
  632. | # | Symptom | Cause | Fix |
  633. |---|---|---|---|
  634. | 1 | `py -3.12 --version` → *No suitable Python runtime found* | Python not installed | `winget install -e --id Python.Python.3.13` |
  635. | 2 | `func : The term 'func' is not recognized` right after installing | Terminal still has the old PATH | Restart VS Code, or reload PATH (Part 0.5) |
  636. | 3 | `az login` → *AADSTS50076 … must use multi-factor authentication* | Other tenants require MFA | Ignore if the right subscription is active, or `az login --tenant <id> --use-device-code` |
  637. | 4 | Typing a command at the subscription prompt → *Invalid selection* | Prompt only accepts a number / Enter | Press Enter, then run the command |
  638. | 5 | Terminal error after pasting instructions | Instruction text pasted together with the command | Copy only the code box lines, one at a time |
  639. | 6 | `pip install -r requirements.txt` fails – *requires Python >=3.13* | venv was created with Python 3.12 | `deactivate` → `Remove-Item -Recurse -Force .venv` → install 3.13 → `py -3.13 -m venv .venv` → activate → install |
  640. | 7 | `Activate.ps1 … running scripts is disabled` | PowerShell execution policy | `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned` |
  641. | 8 | VS Code popup *Quick Create venv* | Python extension suggestion | Press Esc, or *Enter Interpreter Path…* → `.venv\Scripts\python.exe` |
  642. | 9 | `func start` fails downloading the extension bundle | Temporary network issue | `func bundles download`, then `func start` |
  643. | 10 | `func start` doesn't print the function list | Normal for some Core Tools runs | Server is running if you see the *MCP server endpoint* line |
  644. | 11 | `mcp.json` shows **Error** above the server | VS Code connected before `func start` was ready | Click **Start** again; click **Error** to read the log |
  645. | 12 | No **Start** link / entries moved to a new root `.mcp.json` | *MCP: Add Server* wrote a second config file | Keep only `.vscode/mcp.json`; use **MCP: List Servers → Start Server** |
  646. | 13 | *Foundry MCP … unable to sign in* in VS Code | AI Toolkit extension's own server | Unrelated – ignore |
  647. | 14 | No 🛠 tools icon in Copilot Chat | Newer Copilot Chat layout | **Ctrl+Shift+P → Chat: Configure Tools**, or type `#tool_name` |
  648. | 15 | Copilot keeps using the local server / tool call *Failed* | Local server stopped but still selected | Stop local server, tick only `my-remote-mcp-server`, start a new chat |
  649. | 16 | Remote endpoint returns **401** | Missing or wrong `x-functions-key` | Use the `mcp_extension` **system** key |
  650. | 17 | `<app>.azurewebsites.net` doesn't resolve | Flex Consumption domain has a random suffix | Copy the exact **Default domain** from Overview |
  651. | 18 | Publish warning: local Python 3.13 vs expected 3.14 | Version mismatch | Safe if the remote build succeeds; ideally match versions |
  652. | 19 | Foundry: *"I can't access Dominic's Bakery's product list"* / *"A user error occurred while executing a tool call."* | A broken auto-created **toolbox** was attached to the agent | Remove the toolbox from the agent's Tools, keep `dominics-bakery-mcp`, Save |
  653. | 20 | Foundry: *"There was an issue with your request. Please check your inputs and try again"* | Agent used **model-router** | Deploy `gpt-5.4-mini` and select it as the agent's model |
  654. | 21 | `gpt-4o-mini` deployment → *ServiceModelDeprecating* | Model retired for new deployments | Use a current model, e.g. `gpt-5.4-mini` |
  655. ---
  656. ## Security checklist
  657. - 🔒 `local.settings.json` (storage key) is **git-ignored** – never commit it.
  658. - 🔒 `.vscode/mcp.json` uses `${input:functions-mcp-extension-system-key}` – VS Code prompts for the key; nothing secret is stored in the repo.
  659. - 🔒 The Foundry connection stores the key securely in the project connection.
  660. - 🔄 If a key is ever exposed: **Function App → App keys → System keys → `mcp_extension` → Renew key value**, then update VS Code, Inspector and the Foundry tool.
  661. - 🏭 For production, use **Microsoft Entra ID (OAuth)** authentication instead of shared keys.
  662. ---
  663. ## References
  664. - 🎥 Video: <https://youtu.be/cDGBGHXal9M>
  665. - [Azure Functions MCP bindings](https://learn.microsoft.com/azure/azure-functions/functions-bindings-mcp)
  666. - [Model Context Protocol](https://modelcontextprotocol.io)
  667. - [MCP Inspector](https://github.com/modelcontextprotocol/inspector)
  668. - [Use MCP servers in VS Code](https://code.visualstudio.com/docs/copilot/chat/mcp-servers)
  669. - [Microsoft Foundry – Connect agents to MCP servers](https://learn.microsoft.com/azure/ai-foundry/agents/how-to/tools/model-context-protocol)
  670. - [Azure Functions Flex Consumption plan](https://learn.microsoft.com/azure/azure-functions/flex-consumption-plan)

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.