msgraph
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMicrosoft Graph Agent Skill
Microsoft Graph Agent Skill
You can query and manage Microsoft 365 data through the Microsoft Graph API using the binary.
msgraph-skill你可以通过二进制工具使用Microsoft Graph API查询和管理Microsoft 365数据。
msgraph-skillQuick Start
快速开始
-
Check auth status before making any Graph call:
msgraph-skill auth status -
Sign in if not authenticated:
msgraph-skill auth signin -
Make Graph API calls:
msgraph-skill graph-call GET /me
-
在发起任何Graph调用前先检查认证状态:
msgraph-skill auth status -
如果未认证请登录:
msgraph-skill auth signin -
发起Graph API调用:
msgraph-skill graph-call GET /me
Authentication
身份验证
The tool handles authentication automatically using Microsoft's identity platform (MSAL).
- Interactive browser auth is the default — a browser window opens for sign-in
- Device code flow is used automatically when no browser is detected (SSH sessions, containers) or can be forced with
--device-code - Incremental consent is handled automatically — if a 403 Forbidden is returned, the tool re-authenticates with the required scopes and retries
- Session-scoped cache — tokens are cached in a temp file for the session only; no persistent credential storage
该工具使用微软身份平台(MSAL)自动处理身份验证。
- 默认采用交互式浏览器认证——会打开浏览器窗口供登录
- 当未检测到浏览器时(SSH会话、容器环境)会自动使用设备码流,也可以通过参数强制启用
--device-code - 自动处理增量同意——如果返回403 Forbidden错误,工具会使用所需权限范围重新认证并重试
- 会话级缓存——令牌仅临时缓存到会话的临时文件中,不会持久化存储凭证
Auth Commands
认证命令
| Command | Description |
|---|---|
| Sign in to Microsoft 365 |
| Sign in using device code flow |
| Sign in requesting specific scopes |
| Clear the current session |
| Check if signed in and show account info |
| Switch to a different M365 tenant |
| 命令 | 描述 |
|---|---|
| 登录Microsoft 365 |
| 使用设备码流登录 |
| 登录时请求指定权限范围 |
| 清除当前会话 |
| 检查登录状态并展示账户信息 |
| 切换到其他M365租户 |
Making Graph API Calls
发起Graph API调用
Use to execute REST calls against the Graph API.
msgraph-skill graph-call <METHOD> <URL>使用向Graph API发起REST调用。
msgraph-skill graph-call <METHOD> <URL>Read Operations (default)
读操作(默认)
bash
undefinedbash
undefinedGet current user profile
获取当前用户资料
msgraph-skill graph-call GET /me
msgraph-skill graph-call GET /me
List users with selected fields
列出用户的指定字段
msgraph-skill graph-call GET /users --select "displayName,mail,userPrincipalName" --top 10
msgraph-skill graph-call GET /users --select "displayName,mail,userPrincipalName" --top 10
Get user's mail with filtering
筛选获取用户邮件
msgraph-skill graph-call GET /me/messages --filter "isRead eq false" --top 5 --select "subject,from,receivedDateTime"
msgraph-skill graph-call GET /me/messages --filter "isRead eq false" --top 5 --select "subject,from,receivedDateTime"
List groups
列出组
msgraph-skill graph-call GET /groups --select "displayName,description" --top 25
msgraph-skill graph-call GET /groups --select "displayName,description" --top 25
Get team channels
获取团队频道
msgraph-skill graph-call GET /teams/{team-id}/channels
msgraph-skill graph-call GET /teams/{team-id}/channels
Search users
搜索用户
msgraph-skill graph-call GET /users --filter "startsWith(displayName,'John')"
undefinedmsgraph-skill graph-call GET /users --filter "startsWith(displayName,'John')"
undefinedWrite Operations (requires --allow-writes)
写操作(需要--allow-writes参数)
IMPORTANT: Before making any write operation (POST, PUT, PATCH), you MUST ask the user for confirmation. Write operations require the flag.
--allow-writesbash
undefined重要提示: 在发起任何写操作(POST、PUT、PATCH)之前,你必须向用户请求确认。写操作需要携带标识。
--allow-writesbash
undefinedSend a message (ask user first!)
发送消息(请先询问用户!)
msgraph-skill graph-call POST /me/sendMail --body '{"message":{"subject":"Hello","body":{"content":"Hi there"},"toRecipients":[{"emailAddress":{"address":"user@example.com"}}]}}' --allow-writes
msgraph-skill graph-call POST /me/sendMail --body '{"message":{"subject":"Hello","body":{"content":"Hi there"},"toRecipients":[{"emailAddress":{"address":"user@example.com"}}]}}' --allow-writes
Update user properties (ask user first!)
更新用户属性(请先询问用户!)
msgraph-skill graph-call PATCH /me --body '{"jobTitle":"Engineer"}' --allow-writes
**DELETE operations are always blocked** for safety regardless of flags.msgraph-skill graph-call PATCH /me --body '{"jobTitle":"Engineer"}' --allow-writes
**出于安全考虑,DELETE操作始终被禁止**,无论是否携带对应标识。Query Parameters
查询参数
| Flag | Description | Example |
|---|---|---|
| OData $select | |
| OData $filter | |
| OData $top (limit results) | |
| OData $expand | |
| OData $orderby | |
| API version (v1.0 or beta) | |
| Request additional scopes | |
| Custom HTTP headers | |
| Output format (json or raw) | |
| 标识 | 描述 | 示例 |
|---|---|---|
| OData $select | |
| OData $filter | |
| OData $top(限制结果数量) | |
| OData $expand | |
| OData $orderby | |
| API版本(v1.0或beta) | |
| 请求额外权限范围 | |
| 自定义HTTP头 | |
| 输出格式(json或raw) | |
Finding the Right Endpoint
查找合适的端点
Strategy
查找策略
-
First: Try constructing the Graph API call from your training knowledge. The Microsoft Graph API follows consistent patterns:
- — current user
/me - — all users
/users - — specific user
/users/{id} - — current user's mail
/me/messages - — all groups
/groups - — team channels
/teams/{id}/channels
-
If unsure: Use the OpenAPI search command to find endpoints:
msgraph-skill openapi-search --query "send mail" msgraph-skill openapi-search --resource users --method GET msgraph-skill openapi-search --query "calendar events" --method POST -
Check the reference for detailed API documentation: See references/REFERENCE.md for common Graph API patterns and endpoint details.
-
首先: 根据你的训练知识尝试构造Graph API调用。Microsoft Graph API遵循统一的模式:
- — 当前用户
/me - — 所有用户
/users - — 指定用户
/users/{id} - — 当前用户的邮件
/me/messages - — 所有组
/groups - — 团队频道
/teams/{id}/channels
-
如果不确定: 使用OpenAPI搜索命令查找端点:
msgraph-skill openapi-search --query "send mail" msgraph-skill openapi-search --resource users --method GET msgraph-skill openapi-search --query "calendar events" --method POST -
查阅参考文档获取详细API说明: 查看 references/REFERENCE.md 了解常见Graph API模式和端点详情。
OpenAPI Search Command
OpenAPI搜索命令
bash
undefinedbash
undefinedSearch by keyword
按关键词搜索
msgraph-skill openapi-search --query "list users"
msgraph-skill openapi-search --query "list users"
Search by resource and method
按资源和请求方法搜索
msgraph-skill openapi-search --resource messages --method GET
msgraph-skill openapi-search --resource messages --method GET
Combined search
组合搜索
msgraph-skill openapi-search --query "create" --resource groups --method POST
undefinedmsgraph-skill openapi-search --query "create" --resource groups --method POST
undefinedImportant Rules
重要规则
- Always check auth status before the first Graph call in a session
- GET requests are the default — no special flags needed
- Write operations require — always confirm with the user first
--allow-writes - DELETE is always blocked — inform the user this is not supported
- The default API version is beta — use for production-stable endpoints
--api-version v1.0 - 403 errors trigger automatic re-auth — the tool will request additional scopes and retry
- All output is JSON — parse the and
statusCodefields from the responsebody
- 会话中第一次调用Graph前始终检查认证状态
- 默认支持GET请求——无需特殊标识
- 写操作需要参数——使用前必须获得用户确认
--allow-writes - DELETE操作始终被禁止——告知用户该操作不支持
- 默认API版本为beta——生产环境稳定端点请使用
--api-version v1.0 - 403错误会触发自动重认证——工具会请求额外权限并重试
- 所有输出为JSON格式——请从响应中解析和
statusCode字段body
Error Handling
错误处理
- 401 Unauthorized: Token expired. Run again.
msgraph-skill auth signin - 403 Forbidden: Insufficient permissions. The tool automatically attempts incremental consent. If it still fails, the user may need admin consent for those permissions.
- 404 Not Found: The resource doesn't exist or the URL is incorrect. Verify the endpoint path.
- 429 Too Many Requests: Rate limited. Wait and retry.
- 401 Unauthorized: 令牌过期,请重新运行
msgraph-skill auth signin - 403 Forbidden: 权限不足,工具会自动尝试增量同意。如果仍然失败,用户可能需要管理员同意对应权限
- 404 Not Found: 资源不存在或URL错误,请校验端点路径
- 429 Too Many Requests: 请求频率超限,请等待后重试
Environment Variables
环境变量
| Variable | Description | Default |
|---|---|---|
| Custom Azure AD app registration client ID | Microsoft Graph CLI Tools app |
| Target tenant ID | |
| Default API version | |
| Path to OpenAPI index JSON | Auto-detected |
| 变量 | 描述 | 默认值 |
|---|---|---|
| 自定义Azure AD应用注册客户端ID | Microsoft Graph CLI Tools应用 |
| 目标租户ID | |
| 默认API版本 | |
| OpenAPI索引JSON路径 | 自动检测 |