# πŸ”§ λͺ¨λ“ˆ 3: Microsoft Foundry Toolkitλ₯Ό ν™œμš©ν•œ κ³ κΈ‰ MCP 개발 ![Duration](https://img.shields.io/badge/Duration-20_minutes-blue?style=flat-square) ![Microsoft Foundry Toolkit](https://img.shields.io/badge/Microsoft_Foundry_Toolkit-Required-orange?style=flat-square) ![Python](https://img.shields.io/badge/Python-3.10+-green?style=flat-square) ![MCP SDK](https://img.shields.io/badge/MCP_SDK-1.9.3-purple?style=flat-square) ![Inspector](https://img.shields.io/badge/MCP_Inspector-0.14.0-blue?style=flat-square) ## 🎯 ν•™μŠ΅ λͺ©ν‘œ 이 μ‹€μŠ΅μ„ μ™„λ£Œν•˜λ©΄ λ‹€μŒμ„ ν•  수 μžˆμŠ΅λ‹ˆλ‹€: - βœ… Microsoft Foundry Toolkit을 μ‚¬μš©ν•΄ μ»€μŠ€ν…€ MCP μ„œλ²„ 생성 - βœ… μ΅œμ‹  MCP Python SDK(v1.9.3) ꡬ성 및 μ‚¬μš© - βœ… 디버깅을 μœ„ν•œ MCP Inspector μ„€μ • 및 ν™œμš© - βœ… Agent Builder와 Inspector ν™˜κ²½μ—μ„œ MCP μ„œλ²„ 디버깅 - βœ… κ³ κΈ‰ MCP μ„œλ²„ 개발 μ›Œν¬ν”Œλ‘œμš° 이해 ## πŸ“‹ 사전 μ€€λΉ„ 사항 - 랩 2 (MCP 기초) μ™„λ£Œ - Microsoft Foundry Toolkit ν™•μž₯ ν”„λ‘œκ·Έλž¨μ΄ μ„€μΉ˜λœ VS Code - Python 3.10+ ν™˜κ²½ - Inspector 섀정을 μœ„ν•œ Node.js 및 npm ## πŸ—οΈ λ§Œλ“€κ²Œ 될 ν”„λ‘œμ νŠΈ 이 μ‹€μŠ΅μ—μ„œλŠ” Weather MCP Serverλ₯Ό λ§Œλ“€μ–΄ λ‹€μŒμ„ λ³΄μ—¬μ€λ‹ˆλ‹€: - μ»€μŠ€ν…€ MCP μ„œλ²„ κ΅¬ν˜„ - Microsoft Foundry Toolkit Agent Builder와 톡합 - 전문적인 디버깅 μ›Œν¬ν”Œλ‘œμš° - μ΅œμ‹  MCP SDK ν™œμš© νŒ¨ν„΄ --- ## πŸ”§ 핡심 ꡬ성 μš”μ†Œ κ°œμš” ### 🐍 MCP Python SDK Model Context Protocol Python SDKλŠ” μ»€μŠ€ν…€ MCP μ„œλ²„λ₯Ό κ΅¬μΆ•ν•˜λŠ” κΈ°λ°˜μ„ μ œκ³΅ν•©λ‹ˆλ‹€. 버전 1.9.3을 μ‚¬μš©ν•˜λ©° ν–₯μƒλœ 디버깅 κΈ°λŠ₯이 ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. ### πŸ” MCP Inspector κ°•λ ₯ν•œ 디버깅 λ„κ΅¬λ‘œ λ‹€μŒ κΈ°λŠ₯을 μ œκ³΅ν•©λ‹ˆλ‹€: - μ‹€μ‹œκ°„ μ„œλ²„ λͺ¨λ‹ˆν„°λ§ - 도ꡬ μ‹€ν–‰ μ‹œκ°ν™” - λ„€νŠΈμ›Œν¬ μš”μ²­/응닡 검사 - μΈν„°λž™ν‹°λΈŒ ν…ŒμŠ€νŠΈ ν™˜κ²½ --- ## πŸ“– 단계별 κ΅¬ν˜„ ### 1단계: Agent Builderμ—μ„œ WeatherAgent 생성 1. VS Codeμ—μ„œ Microsoft Foundry Toolkit ν™•μž₯ ν”„λ‘œκ·Έλž¨μ„ 톡해 **Agent Builder μ‹€ν–‰** 2. λ‹€μŒ κ΅¬μ„±μœΌλ‘œ **μƒˆ μ—μ΄μ „νŠΈ 생성**: - μ—μ΄μ „νŠΈ 이름: `WeatherAgent` ![Agent Creation](../../../../translated_images/ko/Agent.c9c33f6a412b4cde.webp) ### 2단계: MCP μ„œλ²„ ν”„λ‘œμ νŠΈ μ΄ˆκΈ°ν™” 1. Agent Builderμ—μ„œ **Tools** β†’ **Add Tool** 이동 2. μ‚¬μš© κ°€λŠ₯ν•œ μ˜΅μ…˜ 쀑 **"MCP Server" 선택** 3. **"Create A new MCP Server" 선택** 4. **`python-weather` ν…œν”Œλ¦Ώ 선택** 5. μ„œλ²„ 이름 μ§€μ •: `weather_mcp` ![Python Template Selection](../../../../translated_images/ko/Pythontemplate.9d0a2913c6491500.webp) ### 3단계: ν”„λ‘œμ νŠΈ μ—΄κΈ° 및 κ²€ν†  1. VS Codeμ—μ„œ μƒμ„±λœ ν”„λ‘œμ νŠΈ μ—΄κΈ° 2. ν”„λ‘œμ νŠΈ ꡬ쑰 κ²€ν† : ``` weather_mcp/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ __init__.py β”‚ └── server.py β”œβ”€β”€ inspector/ β”‚ β”œβ”€β”€ package.json β”‚ └── package-lock.json β”œβ”€β”€ .vscode/ β”‚ β”œβ”€β”€ launch.json β”‚ └── tasks.json β”œβ”€β”€ pyproject.toml └── README.md ``` ### 4단계: μ΅œμ‹  MCP SDK둜 μ—…κ·Έλ ˆμ΄λ“œ > **πŸ” μ—…κ·Έλ ˆμ΄λ“œ 이유?** μ΅œμ‹  MCP SDK (v1.9.3)와 Inspector μ„œλΉ„μŠ€ (0.14.0)λ₯Ό μ‚¬μš©ν•˜μ—¬ ν–₯μƒλœ κΈ°λŠ₯κ³Ό 더 λ‚˜μ€ 디버깅 ν™˜κ²½μ„ κ΅¬ν˜„ν•©λ‹ˆλ‹€. #### 4a. Python 쒅속성 μ—…λ°μ΄νŠΈ **`pyproject.toml` νŽΈμ§‘:** [./code/weather_mcp/pyproject.toml](../../../../10-StreamliningAIWorkflowsBuildingAnMCPServerWithAIToolkit/lab3/code/weather_mcp/pyproject.toml) μ—…λ°μ΄νŠΈ #### 4b. Inspector ꡬ성 μ—…λ°μ΄νŠΈ **`inspector/package.json` νŽΈμ§‘:** [./code/weather_mcp/inspector/package.json](../../../../10-StreamliningAIWorkflowsBuildingAnMCPServerWithAIToolkit/lab3/code/weather_mcp/inspector/package.json) μ—…λ°μ΄νŠΈ #### 4c. Inspector 쒅속성 μ—…λ°μ΄νŠΈ **`inspector/package-lock.json` νŽΈμ§‘:** [./code/weather_mcp/inspector/package-lock.json](../../../../10-StreamliningAIWorkflowsBuildingAnMCPServerWithAIToolkit/lab3/code/weather_mcp/inspector/package-lock.json) μ—…λ°μ΄νŠΈ > **πŸ“ μ°Έκ³ :** 이 νŒŒμΌμ—λŠ” λ°©λŒ€ν•œ 쒅속성 μ •μ˜κ°€ ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. μ•„λž˜λŠ” 핡심 ꡬ쑰이며, 전체 λ‚΄μš©μ„ μ‚¬μš©ν•΄μ•Ό μ •μƒμ μœΌλ‘œ 쒅속성 해결이 κ°€λŠ₯ν•©λ‹ˆλ‹€. > **⚑ 전체 νŒ¨ν‚€μ§€ Lock:** package-lock.json은 μ•½ 3000μ€„μ˜ 쒅속성 μ •μ˜λ₯Ό ν¬ν•¨ν•©λ‹ˆλ‹€. μœ„λŠ” μ£Όμš” ꡬ쑰만 보여주며 전체 νŒŒμΌμ„ μ‚¬μš©ν•˜μ„Έμš”. ### 5단계: VS Code 디버깅 ꡬ성 μ„€μ • *μ°Έκ³ : μ§€μ •λœ 경둜의 νŒŒμΌμ„ λ³΅μ‚¬ν•˜μ—¬ 둜컬 파일과 κ΅μ²΄ν•˜μ„Έμš”.* #### 5a. μ‹€ν–‰ ꡬ성 μ—…λ°μ΄νŠΈ **`.vscode/launch.json` νŽΈμ§‘:** ```json { "version": "0.2.0", "configurations": [ { "name": "Attach to Local MCP", "type": "debugpy", "request": "attach", "connect": { "host": "localhost", "port": 5678 }, "presentation": { "hidden": true }, "internalConsoleOptions": "neverOpen", "postDebugTask": "Terminate All Tasks" }, { "name": "Launch Inspector (Edge)", "type": "msedge", "request": "launch", "url": "http://localhost:6274?timeout=60000&serverUrl=http://localhost:3001/sse#tools", "cascadeTerminateToConfigurations": [ "Attach to Local MCP" ], "presentation": { "hidden": true }, "internalConsoleOptions": "neverOpen" }, { "name": "Launch Inspector (Chrome)", "type": "chrome", "request": "launch", "url": "http://localhost:6274?timeout=60000&serverUrl=http://localhost:3001/sse#tools", "cascadeTerminateToConfigurations": [ "Attach to Local MCP" ], "presentation": { "hidden": true }, "internalConsoleOptions": "neverOpen" } ], "compounds": [ { "name": "Debug in Agent Builder", "configurations": [ "Attach to Local MCP" ], "preLaunchTask": "Open Agent Builder", }, { "name": "Debug in Inspector (Edge)", "configurations": [ "Launch Inspector (Edge)", "Attach to Local MCP" ], "preLaunchTask": "Start MCP Inspector", "stopAll": true }, { "name": "Debug in Inspector (Chrome)", "configurations": [ "Launch Inspector (Chrome)", "Attach to Local MCP" ], "preLaunchTask": "Start MCP Inspector", "stopAll": true } ] } ``` **`.vscode/tasks.json` νŽΈμ§‘:** ``` { "version": "2.0.0", "tasks": [ { "label": "Start MCP Server", "type": "shell", "command": "python -m debugpy --listen 127.0.0.1:5678 src/__init__.py sse", "isBackground": true, "options": { "cwd": "${workspaceFolder}", "env": { "PORT": "3001" } }, "problemMatcher": { "pattern": [ { "regexp": "^.*$", "file": 0, "location": 1, "message": 2 } ], "background": { "activeOnStart": true, "beginsPattern": ".*", "endsPattern": "Application startup complete|running" } } }, { "label": "Start MCP Inspector", "type": "shell", "command": "npm run dev:inspector", "isBackground": true, "options": { "cwd": "${workspaceFolder}/inspector", "env": { "CLIENT_PORT": "6274", "SERVER_PORT": "6277", } }, "problemMatcher": { "pattern": [ { "regexp": "^.*$", "file": 0, "location": 1, "message": 2 } ], "background": { "activeOnStart": true, "beginsPattern": "Starting MCP inspector", "endsPattern": "Proxy server listening on port" } }, "dependsOn": [ "Start MCP Server" ] }, { "label": "Open Agent Builder", "type": "shell", "command": "echo ${input:openAgentBuilder}", "presentation": { "reveal": "never" }, "dependsOn": [ "Start MCP Server" ], }, { "label": "Terminate All Tasks", "command": "echo ${input:terminate}", "type": "shell", "problemMatcher": [] } ], "inputs": [ { "id": "openAgentBuilder", "type": "command", "command": "ai-mlstudio.agentBuilder", "args": { "initialMCPs": [ "local-server-weather_mcp" ], "triggeredFrom": "vsc-tasks" } }, { "id": "terminate", "type": "command", "command": "workbench.action.tasks.terminate", "args": "terminateAll" } ] } ``` --- ## πŸš€ MCP μ„œλ²„ μ‹€ν–‰ 및 ν…ŒμŠ€νŠΈ ### 6단계: 쒅속성 μ„€μΉ˜ ꡬ성 λ³€κ²½ ν›„ λ‹€μŒ λͺ…λ Ήμ–΄ μ‹€ν–‰: **Python 쒅속성 μ„€μΉ˜:** ```bash uv sync ``` **Inspector 쒅속성 μ„€μΉ˜:** ```bash cd inspector npm install ``` ### 7단계: Agent Builder둜 디버깅 1. **F5 ν‚€λ₯Ό λˆ„λ₯΄κ±°λ‚˜** **"Debug in Agent Builder"** ꡬ성 μ‹€ν–‰ 2. 디버그 νŒ¨λ„μ—μ„œ 볡합 ꡬ성 선택 3. μ„œλ²„κ°€ μ‹œμž‘λ˜κ³  Agent Builderκ°€ 열릴 λ•ŒκΉŒμ§€ λŒ€κΈ° 4. μžμ—°μ–΄ 쿼리둜 날씨 MCP μ„œλ²„ ν…ŒμŠ€νŠΈ μ•„λž˜μ™€ 같은 μž…λ ₯ ν”„λ‘¬ν”„νŠΈ μ‚¬μš© SYSTEM_PROMPT ``` You are my weather assistant ``` USER_PROMPT ``` How's the weather like in Seattle ``` ![Agent Builder Debug Result](../../../../translated_images/ko/Result.6ac570f7d2b1d538.webp) ### 8단계: MCP Inspector둜 디버깅 1. **"Debug in Inspector"** ꡬ성 μ‚¬μš© (Edge λ˜λŠ” Chrome) 2. `http://localhost:6274` μ—μ„œ Inspector μΈν„°νŽ˜μ΄μŠ€ μ—΄κΈ° 3. μΈν„°λž™ν‹°λΈŒ ν…ŒμŠ€νŠΈ ν™˜κ²½ 탐색: - μ‚¬μš© κ°€λŠ₯ν•œ 도ꡬ 보기 - 도ꡬ μ‹€ν–‰ ν…ŒμŠ€νŠΈ - λ„€νŠΈμ›Œν¬ μš”μ²­ λͺ¨λ‹ˆν„°λ§ - μ„œλ²„ 응닡 디버깅 ![MCP Inspector Interface](../../../../translated_images/ko/Inspector.5672415cd02fe873.webp) --- ## 🎯 핡심 ν•™μŠ΅ μ„±κ³Ό 이 μ‹€μŠ΅μ„ μ™„λ£Œν•˜λ©΄ λ‹€μŒμ„ ν•  수 μžˆμŠ΅λ‹ˆλ‹€: - [x] Microsoft Foundry Toolkit ν…œν”Œλ¦ΏμœΌλ‘œ **μ»€μŠ€ν…€ MCP μ„œλ²„ 생성** - [x] ν–₯μƒλœ κΈ°λŠ₯을 μœ„ν•œ μ΅œμ‹  MCP SDK (v1.9.3)둜 μ—…κ·Έλ ˆμ΄λ“œ - [x] Agent Builder 및 Inspector λͺ¨λ‘μ— λŒ€ν•œ **μ „λ¬Έ 디버깅 μ›Œν¬ν”Œλ‘œμš° ꡬ성** - [x] μΈν„°λž™ν‹°λΈŒ μ„œλ²„ ν…ŒμŠ€νŠΈλ₯Ό μœ„ν•œ **MCP Inspector μ„€μ •** - [x] MCP κ°œλ°œμ„ μœ„ν•œ **VS Code 디버깅 ꡬ성 λ§ˆμŠ€ν„°** ## πŸ”§ νƒμƒ‰ν•œ κ³ κΈ‰ κΈ°λŠ₯ | κΈ°λŠ₯ | μ„€λͺ… | μ‚¬μš© 사둀 | |---------|-------------|----------| | **MCP Python SDK v1.9.3** | μ΅œμ‹  ν”„λ‘œν† μ½œ κ΅¬ν˜„ | μ΅œμ‹  μ„œλ²„ 개발 | | **MCP Inspector 0.14.0** | μΈν„°λž™ν‹°λΈŒ 디버깅 도ꡬ | μ‹€μ‹œκ°„ μ„œλ²„ ν…ŒμŠ€νŠΈ | | **VS Code 디버깅** | 톡합 개발 ν™˜κ²½ | μ „λ¬Έ 디버깅 μ›Œν¬ν”Œλ‘œμš° | | **Agent Builder 톡합** | Microsoft Foundry Toolkit 직접 μ—°κ²° | μ—”λ“œνˆ¬μ—”λ“œ μ—μ΄μ „νŠΈ ν…ŒμŠ€νŠΈ | ## πŸ“š μΆ”κ°€ 자료 - [MCP Python SDK λ¬Έμ„œ](https://modelcontextprotocol.io/docs/sdk/python) - [Microsoft Foundry Toolkit ν™•μž₯ κ°€μ΄λ“œ](https://code.visualstudio.com/docs/ai/ai-toolkit) - [VS Code 디버깅 λ¬Έμ„œ](https://code.visualstudio.com/docs/editor/debugging) - [Model Context Protocol 사양](https://modelcontextprotocol.io/docs/concepts/architecture) --- **πŸŽ‰ μΆ•ν•˜ν•©λ‹ˆλ‹€!** λͺ¨λ“ˆ 3 μ‹€μŠ΅μ„ μ„±κ³΅μ μœΌλ‘œ μ™„λ£Œν–ˆμŠ΅λ‹ˆλ‹€. 이제 μ „λ¬Έ 개발 μ›Œν¬ν”Œλ‘œμš°λ₯Ό μ‚¬μš©ν•˜μ—¬ μ»€μŠ€ν…€ MCP μ„œλ²„λ₯Ό 생성, 디버깅, 배포할 수 μžˆμŠ΅λ‹ˆλ‹€. ### πŸ”œ λ‹€μŒ λͺ¨λ“ˆλ‘œ 계속 μ§„ν–‰ ν˜„μ‹€ 세계 개발 μ›Œν¬ν”Œλ‘œμš°μ— MCP κΈ°μˆ μ„ μ μš©ν•  μ€€λΉ„κ°€ λ˜μ…¨λ‚˜μš”? λ‹€μŒ **[λͺ¨λ“ˆ 4: μ‹€μš©μ μΈ MCP 개발 - μ»€μŠ€ν…€ GitHub 클둠 μ„œλ²„](../lab4/README.md)** μ—μ„œ: - GitHub μ €μž₯μ†Œ μž‘μ—…μ„ μžλ™ν™”ν•˜λŠ” ν”„λ‘œλ•μ…˜ μ€€λΉ„ MCP μ„œλ²„ ꡬ좕 - MCPλ₯Ό ν†΅ν•œ GitHub μ €μž₯μ†Œ ν΄λ‘œλ‹ κΈ°λŠ₯ κ΅¬ν˜„ - VS Code 및 GitHub Copilot Agent Mode와 μ»€μŠ€ν…€ MCP μ„œλ²„ 톡합 - ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œ μ»€μŠ€ν…€ MCP μ„œλ²„ ν…ŒμŠ€νŠΈ 및 배포 - 개발자λ₯Ό μœ„ν•œ μ‹€μš©μ μΈ μ›Œν¬ν”Œλ‘œμš° μžλ™ν™” ν•™μŠ΅ --- **λ©΄μ±… μ‘°ν•­**: 이 λ¬Έμ„œλŠ” AI λ²ˆμ—­ μ„œλΉ„μŠ€ [Co-op Translator](https://github.com/Azure/co-op-translator)λ₯Ό μ‚¬μš©ν•˜μ—¬ λ²ˆμ—­λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 정확성을 κΈ°ν•˜κΈ° μœ„ν•΄ λ…Έλ ₯ν•˜κ³  μžˆμœΌλ‚˜, μžλ™ λ²ˆμ—­μ€ 였λ₯˜λ‚˜ λΆ€μ •ν™•ν•œ 뢀뢄이 μžˆμ„ 수 μžˆμŒμ„ μœ μ˜ν•˜μ‹œκΈ° λ°”λžλ‹ˆλ‹€. 원본 λ¬Έμ„œμ˜ 원어본이 κΆŒμœ„ μžˆλŠ” 자료둜 κ°„μ£Όλ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€. μ€‘μš”ν•œ μ •λ³΄μ˜ 경우, μ „λ¬Έκ°€μ˜ 인간 λ²ˆμ—­μ„ ꢌμž₯ν•©λ‹ˆλ‹€. 이 λ²ˆμ—­ μ‚¬μš©μœΌλ‘œ 인해 λ°œμƒν•˜λŠ” μ˜€ν•΄λ‚˜ 잘λͺ»λœ 해석에 λŒ€ν•΄ λ‹Ήμ‚¬λŠ” μ±…μž„μ„ μ§€μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.