模块 2:使用 AI Toolkit 的 MCP 基础知识 [Duration]() [Difficulty]() [Prerequisites]() 学习目标 完成本模块后,您将能够: ✅ 理解 Model Context Protocol (MCP) 的架构及其优势 ✅ 探索微软的 MCP 服务器生态系统 ✅ 将 MCP 服务器集成到 AI Toolkit Agent Builder 中 ✅ 使用 Playwright MCP 构建功能齐全的浏览器自动化代理 ✅ 配置并测试代理中的 MCP 工具 ✅ 导出并部署基于 MCP 的代理以供生产使用 基于模块 1 的进阶 在模块 1 中,我们掌握了 AI Toolkit 的基础知识,并创建了第一个 Python 代理。
完成本模块后,您将能够:
在模块 1 中,我们掌握了 AI Toolkit 的基础知识,并创建了第一个 Python 代理。现在,我们将通过革命性的 Model Context Protocol (MCP),将您的代理连接到外部工具和服务,实现升级强化。
可以把这比作从普通计算器升级到完整计算机——您的 AI 代理将具备以下能力:
Model Context Protocol (MCP) 是 AI 应用的 “USB-C” —— 一个革命性的开放标准,将大型语言模型(LLM)连接到外部工具、数据源和服务。正如 USB-C 通过统一接口解决了线缆混乱,MCP 通过统一协议简化了 AI 的集成复杂性。
MCP 之前:
使用 MCP 后:
MCP 采用客户端-服务器架构,构建了一个安全且可扩展的生态系统:
** 核心组件:**
| 组件 | 角色 | 示例 |
|---|---|---|
| MCP Hosts | 使用 MCP 服务的应用 | Claude Desktop、VS Code、AI Toolkit |
| MCP Clients | 协议处理器(与服务器一一对应) | 内置于主机应用 |
| MCP Servers | 通过标准协议提供能力 | Playwright、Files、Azure、GitHub |
| 传输层 | 通信方式 | stdio、HTTP、WebSockets |
微软引领 MCP 生态,提供一套全面的企业级服务器,满足真实业务需求。
** 仓库**:azure/azure-mcp
** 目标**:集成 AI 的全面 Azure 资源管理
✨ 主要功能:
** 使用场景:**
** 文档**:Microsoft Dataverse 集成
** 目标**:面向业务数据的自然语言接口
✨ 主要功能:
** 使用场景:**
** 仓库**:microsoft/playwright-mcp
** 目标**:浏览器自动化与网页交互能力
✨ 主要功能:
** 使用场景:**
** 仓库**:microsoft/files-mcp-server
** 目标**:智能文件系统操作
✨ 主要功能:
** 使用场景:**
** 仓库**:microsoft/markitdown
** 目标**:高级 Markdown 处理与操作
✨ 主要功能:
** 使用场景:**
** 包**:@microsoft/clarity-mcp-server
** 目标**:网页分析与用户行为洞察
✨ 主要功能:
** 使用场景:**
除了微软的服务器,MCP 生态还包括:
** 项目目标**:使用 Playwright MCP 服务器创建一个智能浏览器自动化代理,能够浏览网站、提取信息并执行复杂网页交互。
BrowserAgent%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/BrowserAgent.webp)
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/AddMCP.webp)
** Understanding Tool Types:**
Choose "MCP Server" option to proceed%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/AddMCPServer.webp)
Browse MCP Catalog to explore available integrations%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/MCPCatalog.webp)
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/MCPID.webp)
** Critical Step**: Select ALL available Playwright methods for maximum functionality
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/Tools.webp)
️ Essential Playwright Tools:
goto, goBack, goForward, reloadclick, fill, press, hover, dragtextContent, innerHTML, getAttributeisVisible, isEnabled, waitForSelectorscreenshot, pdf, videosetExtraHTTPHeaders, route, waitForResponse✅ 成功标志:
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/AgentTools.webp)
** 常见问题排查:**
创建利用 Playwright 全功能的复杂提示:
# Web Automation Expert System Prompt ## Core Identity You are an advanced web automation specialist with deep expertise in browser automation, web scraping, and user experience analysis. You have access to Playwright tools for comprehensive browser control. ## Capabilities & Approach ### Navigation Strategy - Always start with screenshots to understand page layout - Use semantic selectors (text content, labels) when possible - Implement wait strategies for dynamic content - Handle single-page applications (SPAs) effectively ### Error Handling - Retry failed operations with exponential backoff - Provide clear error descriptions and solutions - Suggest alternative approaches when primary methods fail - Always capture diagnostic screenshots on errors ### Data Extraction - Extract structured data in JSON format when possible - Provide confidence scores for extracted information - Validate data completeness and accuracy - Handle pagination and infinite scroll scenarios ### Reporting - Include step-by-step execution logs - Provide before/after screenshots for verification - Suggest optimizations and alternative approaches - Document any limitations or edge cases encountered ## Ethical Guidelines - Respect robots.txt and rate limiting - Avoid overloading target servers - Only extract publicly available information - Follow website terms of service
设计展示多种能力的用户提示:
** 网页分析示例:**
Navigate to github.com/kinfey and provide a comprehensive analysis including: 1. Repository structure and organization 2. Recent activity and contribution patterns 3. Documentation quality assessment 4. Technology stack identification 5. Community engagement metrics 6. Notable projects and their purposes Include screenshots at key steps and provide actionable insights.
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/Prompt.webp)
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/Browser.webp)
在 Agent Builder 界面查看全面分析报告:
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/Result2.webp)
Agent Builder 支持多种部署方式:
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/Code.webp)
✅ 掌握技能:
** 恭喜!** 您已成功掌握 MCP 集成,现可构建具备外部工具能力的生产级 AI 代理!
准备好提升您的 MCP 技能了吗?前往 模块 3:使用 AI Toolkit 的高级 MCP 开发,学习如何:
免责声明:
本文件由 AI 翻译服务 Co-op Translator 进行翻译。虽然我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。原始文件的母语版本应被视为权威来源。对于重要信息,建议采用专业人工翻译。对于因使用本翻译而产生的任何误解或误释,我们不承担任何责任。