mcp-create-declarative-agent by github/awesome-copilot
npx skills add https://github.com/github/awesome-copilot --skill mcp-create-declarative-agentmode: 'agent'
tools: ['changes', 'search/codebase', 'edit/editFiles', 'problems']
description: '通过集成具有身份验证、工具选择和配置功能的 MCP 服务器,为 Microsoft 365 Copilot 创建一个声明式智能体'
model: 'gpt-4.1'
tags: [mcp, m365-copilot, declarative-agent, model-context-protocol, api-plugin]
---
# 为 Microsoft 365 Copilot 创建基于 MCP 的声明式智能体
创建一个完整的 Microsoft 365 Copilot 声明式智能体,该智能体与模型上下文协议(MCP)服务器集成,以访问外部系统和数据。
## 要求
使用 Microsoft 365 Agents Toolkit 生成以下项目结构:
### 项目设置
1. 通过 Agents Toolkit **搭建声明式智能体** 脚手架
2. **添加指向 MCP 服务器的 MCP 操作**
3. **选择要从 MCP 服务器导入的工具**
4. **配置身份验证**(OAuth 2.0 或 SSO)
5. **审查生成的文件**(manifest.json, ai-plugin.json, declarativeAgent.json)
### 生成的关键文件
**appPackage/manifest.json** - 包含插件引用的 Teams 应用清单:
```json
{
"$schema": "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.schema.json",
"manifestVersion": "devPreview",
"version": "1.0.0",
"id": "...",
"developer": {
"name": "...",
"websiteUrl": "...",
"privacyUrl": "...",
"termsOfUseUrl": "..."
},
"name": {
"short": "Agent Name",
"full": "Full Agent Name"
},
"description": {
"short": "Short description",
"full": "Full description"
},
"copilotAgents": {
"declarativeAgents": [
{
"id": "declarativeAgent",
"file": "declarativeAgent.json"
}
]
}
}
```
**appPackage/declarativeAgent.json** - 智能体定义:
```json
{
"$schema": "https://aka.ms/json-schemas/copilot/declarative-agent/v1.0/schema.json",
"version": "v1.0",
"name": "Agent Name",
"description": "Agent description",
"instructions": "You are an assistant that helps with [specific domain]. Use the available tools to [capabilities].",
"capabilities": [
{
"name": "WebSearch",
"websites": [
{
"url": "https://learn.microsoft.com"
}
]
},
{
"name": "MCP",
"file": "ai-plugin.json"
}
]
}
```
**appPackage/ai-plugin.json** - MCP 插件清单:
```json
{
"schema_version": "v2.1",
"name_for_human": "Service Name",
"description_for_human": "Description for users",
"description_for_model": "Description for AI model",
"contact_email": "support@company.com",
"namespace": "serviceName",
"capabilities": {
"conversation_starters": [
{
"text": "Example query 1"
}
]
},
"functions": [
{
"name": "functionName",
"description": "Function description",
"capabilities": {
"response_semantics": {
"data_path": "$",
"properties": {
"title": "$.title",
"subtitle": "$.description"
}
}
}
}
],
"runtimes": [
{
"type": "MCP",
"spec": {
"url": "https://api.service.com/mcp/"
},
"run_for_functions": ["functionName"],
"auth": {
"type": "OAuthPluginVault",
"reference_id": "${{OAUTH_REFERENCE_ID}}"
}
}
]
}
```
**/.vscode/mcp.json** - MCP 服务器配置:
```json
{
"serverUrl": "https://api.service.com/mcp/",
"pluginFilePath": "appPackage/ai-plugin.json"
}
```
## MCP 服务器集成
### 支持的 MCP 端点
MCP 服务器必须提供:
- **服务器元数据** 端点
- **工具列表** 端点(公开可用函数)
- **工具执行** 端点(处理函数调用)
### 工具选择
从 MCP 导入时:
1. 从服务器获取可用工具
2. 选择要包含的特定工具(出于安全/简化考虑)
3. 工具定义会自动在 ai-plugin.json 中生成
### 身份验证类型
**OAuth 2.0(静态注册)**
```json
"auth": {
"type": "OAuthPluginVault",
"reference_id": "${{OAUTH_REFERENCE_ID}}",
"authorization_url": "https://auth.service.com/authorize",
"client_id": "${{CLIENT_ID}}",
"client_secret": "${{CLIENT_SECRET}}",
"scope": "read write"
}
```
**单点登录(SSO)**
```json
"auth": {
"type": "SSO"
}
```
## 响应语义
### 定义数据映射
使用 `response_semantics` 从 API 响应中提取相关字段:
```json
"capabilities": {
"response_semantics": {
"data_path": "$.results",
"properties": {
"title": "$.name",
"subtitle": "$.description",
"url": "$.link"
}
}
}
```
### 添加自适应卡片(可选)
有关添加可视化卡片模板,请参阅 `mcp-create-adaptive-cards` 提示。
## 环境配置
为凭据创建 `.env.local` 或 `.env.dev`:
```env
OAUTH_REFERENCE_ID=your-oauth-reference-id
CLIENT_ID=your-client-id
CLIENT_SECRET=your-client-secret
```
## 测试与部署
### 本地测试
1. 在 Agents Toolkit 中 **预配** 智能体
2. **开始调试** 以在 Teams 中旁加载
3. 在 https://m365.cloud.microsoft/chat 的 Microsoft 365 Copilot 中进行测试
4. 出现提示时进行身份验证
5. 使用自然语言查询智能体
### 验证
- 验证 ai-plugin.json 中的工具导入
- 检查身份验证配置
- 测试每个公开的函数
- 验证响应数据映射
## 最佳实践
### 工具设计
- **功能聚焦**:每个工具应专注于做好一件事
- **描述清晰**:帮助模型理解何时使用每个工具
- **最小化范围**:仅导入智能体所需的工具
- **命名具有描述性**:使用面向操作的函数名称
### 安全性
- **使用 OAuth 2.0** 用于生产场景
- **将密钥存储在环境变量中**
- **在 MCP 服务器端验证输入**
- **将权限范围限制在所需的最小范围**
- **使用引用 ID** 进行 OAuth 注册
### 指令
- **明确说明** 智能体的目的和能力
- **定义** 成功和错误场景下的行为
- 在适用时,**在指令中明确引用工具**
- **为用户设定期望**,说明智能体能做什么和不能做什么
### 性能
- 在 MCP 服务器上 **适当缓存响应**
- **尽可能批处理操作**
- **为长时间运行的操作设置超时**
- **对大型数据集的结果进行分页**
## 常见 MCP 服务器示例
### GitHub MCP 服务器
```
URL: https://api.githubcopilot.com/mcp/
Tools: search_repositories, search_users, get_repository
Auth: OAuth 2.0
```
### Jira MCP 服务器
```
URL: https://your-domain.atlassian.net/mcp/
Tools: search_issues, create_issue, update_issue
Auth: OAuth 2.0
```
### 自定义服务
```
URL: https://api.your-service.com/mcp/
Tools: Custom tools exposed by your service
Auth: OAuth 2.0 or SSO
```
## 工作流程
询问用户:
1. 您要集成哪个 MCP 服务器(URL)?
2. 应向 Copilot 公开哪些工具?
3. 服务器支持哪种身份验证方法?
4. 智能体的主要用途是什么?
5. 您是否需要响应语义或自适应卡片?
然后生成:
- 完整的 appPackage/ 结构(manifest.json, declarativeAgent.json, ai-plugin.json)
- mcp.json 配置
- .env.local 模板
- 预配和测试说明
## 故障排除
### MCP 服务器无响应
- 验证服务器 URL 是否正确
- 检查网络连接
- 验证 MCP 服务器是否实现了所需的端点
### 身份验证失败
- 验证 OAuth 凭据是否正确
- 检查引用 ID 是否与注册信息匹配
- 确认请求的范围是否正确
- 独立测试 OAuth 流程
### 工具未显示
- 确保 mcp.json 指向正确的服务器
- 验证导入过程中是否选择了工具
- 检查 ai-plugin.json 中的函数定义是否正确
- 如果服务器发生更改,请重新从 MCP 获取操作
### 智能体不理解查询
- 检查 declarativeAgent.json 中的指令
- 检查函数描述是否清晰
- 验证 response_semantics 是否提取了正确的数据
- 使用更具体的查询进行测试
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
每周安装量
7.3K
代码仓库
GitHub 星标数
26.9K
首次出现
2026年2月25日
安全审计
安装于
codex7.2K
gemini-cli7.2K
opencode7.2K
cursor7.2K
github-copilot7.2K
kimi-cli7.2K
mode: 'agent'
tools: ['changes', 'search/codebase', 'edit/editFiles', 'problems']
description: 'Create a declarative agent for Microsoft 365 Copilot by integrating an MCP server with authentication, tool selection, and configuration'
model: 'gpt-4.1'
tags: [mcp, m365-copilot, declarative-agent, model-context-protocol, api-plugin]
---
# Create MCP-based Declarative Agent for Microsoft 365 Copilot
Create a complete declarative agent for Microsoft 365 Copilot that integrates with a Model Context Protocol (MCP) server to access external systems and data.
## Requirements
Generate the following project structure using Microsoft 365 Agents Toolkit:
### Project Setup
1. **Scaffold declarative agent** via Agents Toolkit
2. **Add MCP action** pointing to MCP server
3. **Select tools** to import from MCP server
4. **Configure authentication** (OAuth 2.0 or SSO)
5. **Review generated files** (manifest.json, ai-plugin.json, declarativeAgent.json)
### Key Files Generated
**appPackage/manifest.json** - Teams app manifest with plugin reference:
```json
{
"$schema": "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.schema.json",
"manifestVersion": "devPreview",
"version": "1.0.0",
"id": "...",
"developer": {
"name": "...",
"websiteUrl": "...",
"privacyUrl": "...",
"termsOfUseUrl": "..."
},
"name": {
"short": "Agent Name",
"full": "Full Agent Name"
},
"description": {
"short": "Short description",
"full": "Full description"
},
"copilotAgents": {
"declarativeAgents": [
{
"id": "declarativeAgent",
"file": "declarativeAgent.json"
}
]
}
}
```
**appPackage/declarativeAgent.json** - Agent definition:
```json
{
"$schema": "https://aka.ms/json-schemas/copilot/declarative-agent/v1.0/schema.json",
"version": "v1.0",
"name": "Agent Name",
"description": "Agent description",
"instructions": "You are an assistant that helps with [specific domain]. Use the available tools to [capabilities].",
"capabilities": [
{
"name": "WebSearch",
"websites": [
{
"url": "https://learn.microsoft.com"
}
]
},
{
"name": "MCP",
"file": "ai-plugin.json"
}
]
}
```
**appPackage/ai-plugin.json** - MCP plugin manifest:
```json
{
"schema_version": "v2.1",
"name_for_human": "Service Name",
"description_for_human": "Description for users",
"description_for_model": "Description for AI model",
"contact_email": "support@company.com",
"namespace": "serviceName",
"capabilities": {
"conversation_starters": [
{
"text": "Example query 1"
}
]
},
"functions": [
{
"name": "functionName",
"description": "Function description",
"capabilities": {
"response_semantics": {
"data_path": "$",
"properties": {
"title": "$.title",
"subtitle": "$.description"
}
}
}
}
],
"runtimes": [
{
"type": "MCP",
"spec": {
"url": "https://api.service.com/mcp/"
},
"run_for_functions": ["functionName"],
"auth": {
"type": "OAuthPluginVault",
"reference_id": "${{OAUTH_REFERENCE_ID}}"
}
}
]
}
```
**/.vscode/mcp.json** - MCP server configuration:
```json
{
"serverUrl": "https://api.service.com/mcp/",
"pluginFilePath": "appPackage/ai-plugin.json"
}
```
## MCP Server Integration
### Supported MCP Endpoints
The MCP server must provide:
- **Server metadata** endpoint
- **Tools listing** endpoint (exposes available functions)
- **Tool execution** endpoint (handles function calls)
### Tool Selection
When importing from MCP:
1. Fetch available tools from server
2. Select specific tools to include (for security/simplicity)
3. Tool definitions are auto-generated in ai-plugin.json
### Authentication Types
**OAuth 2.0 (Static Registration)**
```json
"auth": {
"type": "OAuthPluginVault",
"reference_id": "${{OAUTH_REFERENCE_ID}}",
"authorization_url": "https://auth.service.com/authorize",
"client_id": "${{CLIENT_ID}}",
"client_secret": "${{CLIENT_SECRET}}",
"scope": "read write"
}
```
**Single Sign-On (SSO)**
```json
"auth": {
"type": "SSO"
}
```
## Response Semantics
### Define Data Mapping
Use `response_semantics` to extract relevant fields from API responses:
```json
"capabilities": {
"response_semantics": {
"data_path": "$.results",
"properties": {
"title": "$.name",
"subtitle": "$.description",
"url": "$.link"
}
}
}
```
### Add Adaptive Cards (Optional)
See the `mcp-create-adaptive-cards` prompt for adding visual card templates.
## Environment Configuration
Create `.env.local` or `.env.dev` for credentials:
```env
OAUTH_REFERENCE_ID=your-oauth-reference-id
CLIENT_ID=your-client-id
CLIENT_SECRET=your-client-secret
```
## Testing & Deployment
### Local Testing
1. **Provision** agent in Agents Toolkit
2. **Start debugging** to sideload in Teams
3. Test in Microsoft 365 Copilot at https://m365.cloud.microsoft/chat
4. Authenticate when prompted
5. Query the agent using natural language
### Validation
- Verify tool imports in ai-plugin.json
- Check authentication configuration
- Test each exposed function
- Validate response data mapping
## Best Practices
### Tool Design
- **Focused functions**: Each tool should do one thing well
- **Clear descriptions**: Help the model understand when to use each tool
- **Minimal scoping**: Only import tools the agent needs
- **Descriptive names**: Use action-oriented function names
### Security
- **Use OAuth 2.0** for production scenarios
- **Store secrets** in environment variables
- **Validate inputs** on the MCP server side
- **Limit scopes** to minimum required permissions
- **Use reference IDs** for OAuth registration
### Instructions
- **Be specific** about the agent's purpose and capabilities
- **Define behavior** for both successful and error scenarios
- **Reference tools** explicitly in instructions when applicable
- **Set expectations** for users about what the agent can/cannot do
### Performance
- **Cache responses** when appropriate on MCP server
- **Batch operations** where possible
- **Set timeouts** for long-running operations
- **Paginate results** for large datasets
## Common MCP Server Examples
### GitHub MCP Server
```
URL: https://api.githubcopilot.com/mcp/
Tools: search_repositories, search_users, get_repository
Auth: OAuth 2.0
```
### Jira MCP Server
```
URL: https://your-domain.atlassian.net/mcp/
Tools: search_issues, create_issue, update_issue
Auth: OAuth 2.0
```
### Custom Service
```
URL: https://api.your-service.com/mcp/
Tools: Custom tools exposed by your service
Auth: OAuth 2.0 or SSO
```
## Workflow
Ask the user:
1. What MCP server are you integrating with (URL)?
2. What tools should be exposed to Copilot?
3. What authentication method does the server support?
4. What should the agent's primary purpose be?
5. Do you need response semantics or Adaptive Cards?
Then generate:
- Complete appPackage/ structure (manifest.json, declarativeAgent.json, ai-plugin.json)
- mcp.json configuration
- .env.local template
- Provisioning and testing instructions
## Troubleshooting
### MCP Server Not Responding
- Verify server URL is correct
- Check network connectivity
- Validate MCP server implements required endpoints
### Authentication Fails
- Verify OAuth credentials are correct
- Check reference ID matches registration
- Confirm scopes are requested properly
- Test OAuth flow independently
### Tools Not Appearing
- Ensure mcp.json points to correct server
- Verify tools were selected during import
- Check ai-plugin.json has correct function definitions
- Re-fetch actions from MCP if server changed
### Agent Not Understanding Queries
- Review instructions in declarativeAgent.json
- Check function descriptions are clear
- Verify response_semantics extract correct data
- Test with more specific queries
Weekly Installs
7.3K
Repository
GitHub Stars
26.9K
First Seen
Feb 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex7.2K
gemini-cli7.2K
opencode7.2K
cursor7.2K
github-copilot7.2K
kimi-cli7.2K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装