---
title: 03-Low-Code Agent實作演練
---
# Day2 - Low-Code Agent 實作演練
---
參考資料:
+ [Download the latest Python for Windows](https://www.python.org/downloads/)
+ [Creation of virtual environments in Python](https://docs.python.org/3/library/venv.html)
+ [Azure AI Foundry for VS Code extension](https://learn.microsoft.com/en-us/azure/ai-foundry/how-to/develop/get-started-projects-vs-code)
+ [How to use the Deep Research tool](https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/deep-research-samples?pivots=python)
+ [Time MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/time)
+ [Bazi MCP (八字 MCP)](https://github.com/cantian-ai/bazi-mcp)
+ [mcp-proxy](https://github.com/sparfenyuk/mcp-proxy)
+ [Create a web app in Azure](https://learn.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=flask%2Cwindows%2Cazure-portal%2Cazure-cli-deploy%2Cdeploy-instructions-azportal%2Cterminal-bash%2Cdeploy-instructions-zip-azcli#create-a-web-app-in-azure)
+ [Deep Research in Azure AI Foundry Sgent Service](https://azure.microsoft.com/en-us/blog/introducing-deep-research-in-azure-ai-foundry-agent-service/)
+ [Announcing MCP Support in Azure AI Foundry Agent Service](https://devblogs.microsoft.com/foundry/announcing-model-context-protocol-support-preview-in-azure-ai-foundry-agent-service/)
+ [Announcing the Browser Automation Tool in Azure AI Foundry Agent Service](https://devblogs.microsoft.com/foundry/announcing-the-browser-automation-tool-preview-in-azure-ai-foundry-agent-service/)
---
## 一、前置需求
### 1. 己完成下列本機環境安裝
#### Python環境
+ 本機Python環境 3.10以上版本
+ **驗證安裝**:
```shell
python
```
#### Vistual Studio Code環境
+ 本機Vistual Studio Code
+ 安裝以下Extension
- Azure Tool
- Python
- Jupyter
- Azure AI Foundry
#### Azure CLI
+ 安裝[AZ Cli](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&pivots=msi)
+ **驗證安裝**:
```shell
az login
```
#### Node.js
- **版本**: 建議使用最新的 LTS 版本,如 v20.x.x
- **下載地址**: [nodejs.org](https://nodejs.org/)
- **驗證安裝**:
```bash
node --version
npm --version
```
### 2. Download Code & Create Python venv
#### **Python Sample Code**
- 請下載[Sample Code](https://1drv.ms/u/c/8302862bf709a02b/EQG0QS_-jf5Mk2GCDtl0V-MBlvFXbZLHBUBDD7wbsRkwcg?e=OyxgIV)
#### **Create a Virtual Environment**
切換到Sample Code資料夾
```bash
cd "您的專案資料夾路徑"
```
建立python venv
```bash
python -m venv .venv
```
- **Activate venv**
```bash
# For Windows
.\.venv\Scripts\activate
```
- **Install Dependency**
```bash
# For Windows
pip install -r requirements.txt
```
- **Quick Test**
+ 以VS Code開專案檔 .env填寫 **PROJECT_ENDPOINT**: 由AI Foundry overview頁面取得

+ 存檔後,重新啟動VS Code 重新讀取env資訊
+ 執行 `00-test-ai-agent.ipynb` 確認是否可正常執行無誤

### 3. 部署o3-deep-research Model
+ 登入AI Foundry Portal
+ 點擊 `Models + enpoints`

+ 點擊 `+ Deploy model`
+ 點擊 `Deploy base model`

+ search `o3-deep-research`
+ 選擇後點擊 `Confirm`

+ Deploy

### 4. Vistual Code Language: 請將Language設定為English
+ Windows OS: Press Ctrl+Shift+P to open the Command Palette.
+ Type: `Configure Display Language`

+ 選擇 `English`

---
## 二、Research Agent
### 1. Connect Resource - Grounding with Bing Search
+ Management center

+ `Connected resources` ➜ `+ New connection`

+ Grounding with Bing Search

+ Add connection

+ Close

### 2. 必要env資訊
+ **PROJECT_ENDPOINT**:由AI Foundry overview頁面取得

+ **AZURE_OPENAI_DEPLOYMENT**:`gpt-4.1` 或 `gpt-4o`
+ **BING_RESOURCE_NAME**:您的grouding bign search名稱
+ **DEEP_RESEARCH_MODEL_DEPLOYMENT_NAME**:`o3-deep-research`
+ Save後,請重新啟動 Visual Studio Code,以讓env資訊生效
### 3. Run Research Agent
+ 開啟 **01-research agent.ipynb**

+ 可在**content**罝換任何您想進行的深度學習報告,範例:
```bash
請提供 2025 Gartner Magic Quadrant for Cloud-Native Application Platforms 的研究報告
```

+ Deep Research Agent將結果寫入**research_summary.md**

+ 於Following Question回覆Deep Research Agent的確認需求,例如:
```bash
請專注於具體領導廠商與挑戰者的名單與分析
```
⚠️ 請注意:若回覆內容與問題不符,可能會導致 Research Agent 無法正確執行任務!

+ 於Following Question回覆 Research Agent 的確認問題, 例如:
```bash
只需領導者(Leaders)和挑戰者(Challengers)
```
+ 於Following Question回覆 Research Agent 的確認問題, 例如:
```bash
重點整理並分析各入選廠商的優勢、技術特色、和存在挑戰即可
```
+ 當 Research Agent 回覆 `Starting deep research...`,表示深度研究報告已開始執行,預估所需時間約為 5 至 30 分鐘,視研究內容的複雜度而定

+ 以2025 Gartner Magic Quadrant 研究報告為例,實際執行時間為11分14秒 內容存放至`research_summary.md`

## 三、MCP Inpsector : Test Your Server
### 1. 安裝MCP函式庫
安裝必要的 Python 函式庫:
```bash
pip install mcp[cli]
pip install mcp-server-time
```
### 2. 啟動 MCP Inspector
cmd mode執行npx命令
```bash
npx @modelcontextprotocol/inspector
```

### 3. 測試 MCP-Server-Time
+ Transport Type: **STDIO**
+ Command: 指定本機 Python 絕對路徑。可使用 `where python` 查詢所有已安裝的 Python 路徑
+ Argument: `-m mcp_server_time`
+ Connect

+ Tools ➜ List Tools

+ 測試 **get_current_time**
+ timezone: America/New_York
+ Run Tool

+ Tool Result

### 4. Find More MCP Server - MCP.so
+ 登入 https://mcp.so/

+ Bazi MCP [Server Config](https://github.com/cantian-ai/bazi-mcp)

+ Airbnb MCP Server [Server Config](https://github.com/MCP-Mirror/openbnb-org_mcp-server-airbnb)

### 5. MCP Inpsector : Test Bazi MCP
+ Transport Type: **STDIO**
+ Command: 指定本機 npx 絕對路徑。可使用 `where npx` 查詢所有已安裝的 npx 路徑
+ Argument: `bazi-mcp`
+ Connect

### 6. MCP Inpsector : Test Airbnb MCP
+ Transport Type: **STDIO**
+ Command: 指定本機 npx 絕對路徑。可使用 `where npx` 查詢所有已安裝的 npx 路徑
+ Argument: `@openbnb/mcp-server-airbnb`
+ Connect

---
## 四、MCP Proxy : SSE to STDIO
### 🧩 mcp-proxy 是為了解決什麼問題?
mcp-proxy 是一個 橋接工具,用來在不同的 MCP 傳輸協定(如 stdio、SSE、Streamable HTTP)之間轉換,讓不支援某些協定的客戶端或伺服器也能互通。
- 解決許多 MCP server 只支援本地 stdio、無法直接遠端連線的問題
- 透過 proxy 包裝,使之能以 SSE 形式被遠端 client 使用
### 1. SSE to STDIO 的作法
+ 啟動一個 proxy server
- 外部:對外開放 SSE server (HTTP port),接受遠端請求
- 內部:啟動本地 stdio MCP server,處理實際邏輯
- Proxy 負責將 SSE 請求轉送給 stdio server,再把回應轉回 SSE
### 2. 安裝mcp-proxy函式庫
安裝必要的 Python 函式庫:
```bash
pip install mcp-proxy
```
### 3. 本機mcp proxy 模擬SSE to STDIO
+ 以 @openbnb/mcp-server-airbnb 為例
💡 mcp-proxy does not set CORS headers by default; you need to explicitly specify them using --allow-origin.
```bash
mcp-proxy --port=8080 --host=0.0.0.0 --allow-origin "*" -- npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt
```
+ sse endpoint應為 `http://localhost:8080/sse`

### 4. MCP Inpsector : 測試mcp-proxy sse
+ Transport Type: **SSE**
+ URL: `http://localhost:8080/sse`
+ Connection Type: Direct
+ Authenticaiton: Use the toggle to **disable** headers
+ Connect

+ 成功模擬sse連線

### 5. Multiple Named MCP Server
+ **啟動方式**:透過 **configuration file** 一次啟動多個 MCP Server。
```bash
{
"mcpServers": {
"time": {
"enabled": true,
"timeout": 100,
"command": "python",
"args": [
"-m", "mcp_server_time"
],
"transportType": "stdio"
},
"airbnb": {
"enabled": true,
"timeout": 100,
"command": "npx",
"args": [
"-y",
"@openbnb/mcp-server-airbnb",
"--ignore-robots-txt"
],
"transportType": "stdio"
},
"Bazi": {
"enabled": true,
"timeout": 100,
"command": "npx",
"args": [
"bazi-mcp"
],
"transportType": "stdio"
}
}
}
```
+ **範例指令**
```bash
mcp-proxy --port=8080 --host=0.0.0.0 --allow-origin "*" --named-server-config ./servers.json
```
+ **SSE Endpoint 規則:**
每個 named server 會對應一個獨立的 SSE endpoint,格式如下:
`http://localhost:8080/servers/<server_name>/sse`
---
## 五、Web App Service : Host MCP Server
### 1. Create Web Services
+ Azure Portal search bar 輸入 **App Services**

+ Create **+ Web App**

+ Resource Group: 請選擇您的resource group
+ Name: 輸入可識別的名稱
+ Publish: `Code`
+ Runtime Stack: `Python 3.11`
+ Operation System: `Linux`
+ Region: 選擇同一個Region
+ Pricing Plan: `Free F1` (每個 Azure 訂閱僅能使用一個 Free F1 免費方案。在 workshop 活動期間,建議大家共用同一個 Web App,以節省資源。)
+ Review + Create

+ Create

💡 If you got the quota issue, please file a support request under the category **Service and Subscription Limits (Quotas)** and select **Function or Web App (Windows and Linux)**.
### 2. Deploy to Web Services
+ 下載 [mcp-proxy](https://1drv.ms/u/c/8302862bf709a02b/EVbnFwhREDVBmSdENX4V7BQBofalVMtxANGX-hW7Xs0knQ?e=SSAuzK) web app專案
+ 以Visual Studio Code開啟專案
+ 在 `azure`資料夾按右鍵,點選**Deploy to web app...**

+ 選擇您的subscription名稱

+ 選擇您剛建立的web app

+ Deploy

+ Deploy to web app Succeeded

### 3. 設定Startup Command
+ 在 Azure Portal找到剛建立的Web App
+ 點選 `Settings` ➜ `Configuration`

+ 在Startup command 輸入
```bash
cd /home/site/wwwroot/ && pip install -r requirements.txt && bash startup.sh
```
+ Save ➜ Continue

+ 點選 `Overview` 回到主畫面
+ Restart ➜ Yes
+ 靜候3-5分鐘,web app將安裝requirements.txt並啟動mcp server

+ 點選 `Log stream` 可以看到安裝進度
+ 出現類似字樣,即表示mcp server已啟動
```bash
2025-08-23T08:22:34.8524046Z [I 2025-08-23 08:22:34,851.851 mcp_proxy.mcp_server] Serving MCP Servers via SSE:
2025-08-23T08:22:34.8524103Z [I 2025-08-23 08:22:34,851.851 mcp_proxy.mcp_server] - http://0.0.0.0:8000/servers/time/sse
2025-08-23T08:22:34.8524143Z [I 2025-08-23 08:22:34,851.851 mcp_proxy.mcp_server] - http://0.0.0.0:8000/servers/airbnb/sse
2025-08-23T08:22:34.8524584Z [I 2025-08-23 08:22:34,851.851 mcp_proxy.mcp_server] - http://0.0.0.0:8000/servers/Bazi/sse
2025-08-23T08:22:34.891232Z INFO: Started server process [2000]

```

### 4. Test the Web Services via MCP Inspector
+ 確認 Web App的Default Domain 的url
+ SSE Endpoint
+ Time : `https://<default domain>/servers/time/sse`
+ AirBnb: `https://<default domain>/servers/airbnb/sse`
+ Bazi: `https://<default domain>/servers/Bazi/sse`

+ 以sse測試Time

+ 以sse測試AirBnb

+ 以sse測試Bazi

## 六、Native MCP Agent
### 1. 必要env資訊
將對應web services的sse url輸入下述欄位
+ **TIME_URL**
+ **AIRBNB_URL**
+ **BAZI_URL**
+ Save後,請重新啟動 Visual Studio Code,以讓env資訊生效
### 2. Run Native MCP Agent
+ 開啟 **02-native-mcp.ipynb**
+ 於Creating a User Message Thread可定義user_prompt, 例如:
+
```bash
請確認最近一週({today}-{next_week}) 哪一天適合出遊,並依據當天農民曆的吉方位,推薦一個由台北出發、沿該方位前往的國家中,目前可預訂且預算為 100 美金的最佳旅館,並提供該地目前的當地時間
```

+ **Final Messages**: native-mcp-agent 成功串接 Bazi MCP,取得當日黃曆資訊以判斷是否適合出遊,並獲得最佳方位建議。接著依據方位推薦旅遊國家,並透過 Airbnb MCP 查詢符合預算且可預訂的飯店。最後,使用 Time MCP 取得該國當地時間

## 七、Browser Automation Agent
### 1. Create Playwright workspace resouce
+ 登入Azure Portal
+ search並選擇 `playwright workspaces`

+ Create

+ Resource Group: 選擇你的資源群組
+ workspace Name: 輸入任一名稱
+ Region: 選擇相同的Region
+ Review + Create

+ Create

+ Go to resource

### 2. Generate Playwright Access Token
+ Settings ➜ Access Management ➜ Playwright Service Access Token ➜ Enable

+ Generate Token

+ Access token name: 輸入任一名稱
+ Expired Date: 選擇有效期限
+ Generate Token

+ 請Copy Token並妥善保存,後續場景將使用

### 3. Assign Permission to AI Project
+ 點選 Access Control(IAM) ➜ add role assignment

+ 點選 Privileged administrator roles ➜ `Contributor` ➜ Next

+ 點選 manage identity ➜ select member ➜ 選擇您的Azure AI Foundry ➜ 點擊 **Select** ➜ Next

+ Review + assign

### 4. Connect Playwright to AI Foundry
+ Management center

+ `Connected resources` ➜ `+ New connection`

+ Serverless Model

+ Target URI: 請copy `Browser endpoint`

+ key: 請輸入 Playwright Access Token
+ Connection name: 請輸入任一名稱
+ Add connection

### 5. 必要env資訊
+ **PLAYWRIGHT_RESOURCE_NAME**: 請輸入您的playwright名稱
+ Save後,請重新啟動 Visual Studio Code,以讓env資訊生效
### 6. Run Browser Automation Agent
+ 開啟 **03-simple-browser-automation-agent.ipynb**
+ 於Creating a User Message Thread可定義user_prompt, 例如:
```bash
請造訪 DevDays Asia 2025 官方網站: https://www.digitimes.com.tw/Seminar/DevDaysAsia2025/index_en.html
接著請點選「Agenda」頁面,並參考第一天(9月23日)下午場次,請列出完整議程內容與講者。
```

+ **Final Messages**: browser-automation-agent 成功操作網頁,點選不同日期及Track,找到所有資訊

---