🤖 Production-ready AI Agent Server | 生產級 AI 代理伺服器
ms-agentframework 是 Microsoft Agent Framework 與 Model Context Protocol (MCP) 的生產級整合,提供 SSE/HTTP 串流傳輸。
ms-agentframework is a production-ready integration of Microsoft Agent Framework with Model Context Protocol (MCP), providing SSE/HTTP streamable transport.
示範內容 | What the demo shows:
- ✅ 工具自動載入與註冊 | Automatic tool loading and registration
- ✅ 即時查詢處理 | Real-time query processing
- ✅ 多工具協同使用 | Multi-tool collaboration
- ✅ 結果即時顯示 | Real-time result display
📸 示範截圖 | Demo Screenshots (點擊展開 | Click to expand)
示範影片展示了:
- ✅ 工具自動載入與註冊 | Automatic tool loading and registration
- ✅ 即時查詢處理 | Real-time query processing
- ✅ 多工具協同使用 | Multi-tool collaboration
- ✅ 結果即時顯示 | Real-time result display
The demo showcases:
- ✅ Automatic tool loading and registration
- ✅ Real-time query processing
- ✅ Multi-tool collaboration
- ✅ Real-time result display
- ✅ Microsoft Agent Framework - 官方 Azure OpenAI 代理框架 | Official Azure OpenAI agent framework
- ✅ MCP 協議 - AI 代理工具的標準協議 | Standard protocol for AI agent tools
- ✅ SSE 傳輸 - Server-Sent Events 即時串流 | Server-Sent Events for real-time streaming
- ✅ Python uv - 現代化 Python 套件管理 | Modern Python package management
- ✅ FastAPI - 高效能異步網頁框架 | High-performance async web framework
- ✅ 生產就緒 - 包含 Docker、測試、監控 | Production ready with Docker, testing, monitoring
# 完整設置並啟動 | Complete setup and start (推薦 | Recommended)
make quickstart# 1. 複製專案 | Clone repository
git clone https://github.com/jimmyliao/ms-agentframework.git
cd ms-agentframework
# 2. 一鍵設置安裝 | One-command setup
make quickstart
# 或手動分步 | Or manual steps:
# make setup # 設置環境 | Setup environment
# make install # 安裝依賴 | Install dependencies
# make run # 啟動伺服器 | Start server# 測試所有工具 | Test all tools
make demo-tools
# 或單獨測試 | Or test individually:
make demo-weather # 天氣工具 | Weather tool
make demo-calc # 計算器 | Calculator
make demo-stock # 股票查詢 | Stock price- SSE 端點 | SSE Endpoint:
http://localhost:8000/sse - 訊息端點 | Messages Endpoint:
http://localhost:8000/messages - 健康檢查 | Health Check:
http://localhost:8000/health - API 文件 | API Docs:
http://localhost:8000/docs
MCP-MAF 實作三層架構 | MCP-MAF implements a three-layer architecture:
- 獨立代理 | Standalone Agent - 直接使用代理進行測試 | Direct agent usage for testing
- 遠端 MCP (SSE) | Remote MCP (SSE) - 生產伺服器模式 ⭐ | Production server mode ⭐
- STDIO MCP - CLI 整合模式(可選)| CLI integration mode (optional)
┌──────────────────────────────────┐
│ Codex CLI / Gemini CLI │
│ (MCP 客戶端 | MCP Client) │
└────────────┬─────────────────────┘
│ HTTP/SSE
↓
┌──────────────────────────────────┐
│ MCP-MAF Server (FastAPI) │
│ - SSE Transport │
│ - JSON-RPC 2.0 Protocol │
└────────────┬─────────────────────┘
│
↓
┌──────────────────────────────────┐
│ Microsoft Agent Framework │
│ - Azure OpenAI GPT-4.1 │
│ - Tool Management │
└────────────┬─────────────────────┘
│
↓
┌──────────────────────────────────┐
│ MCP 工具 | MCP Tools │
│ - Weather Tool │
│ - Calculator Tool │
│ - Stock Price Tool │
└──────────────────────────────────┘
# 安裝開發依賴 | Install dev dependencies
make install-dev
# 執行測試 | Run tests
make test
# 執行測試(含覆蓋率)| Run with coverage
make test-cov
# Lint 程式碼 | Lint code
make lint
# 格式化程式碼 | Format code
make format
# 開發伺服器(熱重載)| Development server (hot reload)
make dev# 建置映像 | Build image
make docker-build
# 執行容器 | Run container
make docker-run
# 或使用 Docker Compose | Or use Docker Compose
make docker-up
make docker-down- 架構概覽 | Architecture Overview
- MCP 協議 | MCP Protocol
- Codex CLI 整合 | Codex CLI Integration
- 部署指南 | Deployment Guide
編輯 Claude Desktop 配置檔 | Edit Claude Desktop config:
路徑 | Path: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"mcp-maf": {
"command": "uv",
"args": [
"--directory",
"/Users/jimmyliao/workspace/mcp-maf",
"run",
"uvicorn",
"mcp_maf.server:app",
"--host",
"0.0.0.0",
"--port",
"8000"
]
}
}
}# 測試連接 | Test connection
# 重啟 Claude Desktop 後工具將自動可用
# Tools will be available automatically after restarting Claude Desktop
# 使用範例 | Usage examples
# 在 Claude Desktop 中:| In Claude Desktop:
# "查詢台北天氣" | "What's the weather in Taipei?"
# "計算 123 * 456" | "Calculate 123 * 456"
# "查詢台積電股價(2330)" | "What's TSMC (2330) stock price?"from mcp_maf import MCPMAFAgent
agent = MCPMAFAgent(
azure_endpoint="your-endpoint",
api_key="your-key",
deployment_name="gpt-4.1"
)
await agent.initialize()
# 繁中範例 | Chinese example
response = await agent.run("台北的天氣如何?")
print(response)
# 英文範例 | English example
response = await agent.run("What's the weather in Taipei?")
print(response)import httpx
import json
async with httpx.AsyncClient() as client:
async with client.stream('GET', 'http://localhost:8000/sse') as response:
async for line in response.aiter_lines():
if line.startswith('data:'):
data = json.loads(line[5:]) # 移除 'data:' 前綴 | Remove 'data:' prefix
print(data)# 執行所有測試 | Run all tests
make test
# 含覆蓋率報告 | With coverage report
make test-cov
# 執行特定測試檔案 | Run specific test file
uv run pytest tests/unit/test_protocol.py -v
# 監視模式 | Watch mode
make test-watch取得任何地點的即時天氣資訊。| Get current weather information for any location.
用法 | Usage: get_weather(location: str)
範例 | Examples:
- 繁中:
"台北的天氣如何?" - English:
"What's the weather in Taipei?"
執行數學運算。| Perform mathematical calculations.
用法 | Usage: calculate(expression: str)
範例 | Examples:
- 繁中:
"計算 123 乘以 456" - English:
"Calculate 123 * 456"
查詢台灣證券交易所股票價格。| Query Taiwan stock prices from TWSE.
用法 | Usage: get_stock_price(stock_code: str)
範例 | Examples:
- 繁中:
"台積電(2330)的股價是多少?" - English:
"What's TSMC (2330) stock price?"
支援的股票 | Supported Stocks:
- 2330 - 台積電 | TSMC
- 2454 - 聯發科 | MediaTek
- 2317 - 鴻海 | Hon Hai (Foxconn)
- 更多... | And more...
環境變數在 .env 中配置 | Environment variables are configured in .env:
# Azure OpenAI(已配置)| Azure OpenAI (already configured)
AZURE_OPENAI_ENDPOINT=https://msfoundry-jimmyliao.openai.azure.com/
AZURE_OPENAI_API_KEY=***
AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4.1
# 伺服器 | Server
SERVER_HOST=0.0.0.0
SERVER_PORT=8000
LOG_LEVEL=INFO- Python 3.11+ - 現代 Python | Modern Python
- uv - 快速套件管理器 | Fast package manager
- FastAPI - 異步網頁框架 | Async web framework
- Uvicorn - ASGI 伺服器 | ASGI server
- Microsoft Agent Framework - Azure AI 代理 | Azure AI agents
- Azure OpenAI - GPT-4.1 部署 | GPT-4.1 deployment
- OpenAI SDK - 後備 SDK | Fallback SDK
- MCP (Model Context Protocol) - 2024-11-05 規範 | 2024-11-05 spec
- JSON-RPC 2.0 - 遠端程序調用 | Remote procedure calls
- SSE (Server-Sent Events) - 即時串流 | Real-time streaming
歡迎貢獻!請閱讀 CONTRIBUTING.md 了解詳情。
Contributions are welcome! Please read CONTRIBUTING.md for details.
MIT 授權 - 詳見 LICENSE 檔案。
MIT License - see LICENSE for details.
- Microsoft Agent Framework - 微軟代理框架 | Microsoft's agent framework
- Model Context Protocol - MCP 協議規範 | MCP protocol specification
- FastAPI - 現代網頁框架 | Modern web framework
- Agent Lucy - 參考實作 | Reference implementation
- 問題回報 | Issues: GitHub Issues
- 討論區 | Discussions: GitHub Discussions
✅ 已完成 | Completed:
- 基礎架構 | Core architecture
- MCP 協議實作 | MCP protocol implementation
- SSE 傳輸層 | SSE transport layer
- 三個範例工具 | Three example tools
- Docker 支援 | Docker support
- 完整測試 | Complete testing
- 文件撰寫 | Documentation
🚧 計劃中 | Planned:
- STDIO 傳輸 | STDIO transport
- 更多工具 | More tools
- CI/CD 管道 | CI/CD pipeline
- 效能優化 | Performance optimization
版本 | Version: 1.0.0 作者 | Author: Jimmy Liao 用 ❤️ 打造 | Built with ❤️ 使用 | using Microsoft Agent Framework and MCP Protocol
Co-Authored-By: Agent-Lucy hi@leapdesign.ai