Msgraph sdk

From github/awesome-copilot · View interactive version

Msgraph sdk is an AI agent skill from the GitHub repository github/awesome-copilot. Integrate Microsoft Graph SDK into any project — .NET, TypeScript/JavaScript, or Python. Covers auth patterns (client credentials, OBO, managed identity), SDK setup, calling Graph APIs, batching, delta queries, change notifications, throttling, and permission scopes. Use when accessing Microsoft 365

How to use this skill

Skill file

Microsoft Graph SDK

Use this skill when integrating Microsoft Graph into an application to access Microsoft 365 data and services.

Always ground implementation in the current Microsoft Graph SDK documentation and SDK version for the target language rather than relying on memory alone.

Determine the target language first

  1. Use the .NET workflow when the project contains .cs, .csproj, or .sln files, or when the user asks for C# guidance. Follow references/dotnet.md.
  2. Use the TypeScript / JavaScript workflow when the project contains package.json, .ts, or .js files, or when the user asks for Node.js / browser guidance. Follow references/typescript.md.
  3. Use the Python workflow when the project contains .py, pyproject.toml, or requirements.txt, or when the user asks for Python guidance. Follow references/python.md.
  4. If multiple languages are present, match the language of the files being edited or ask the user.

Always consult live documentation

Authentication — choose the right pattern

Selecting the wrong auth flow is the most common Graph integration mistake. Apply this decision tree before writing any auth code:

| Scenario | Flow to use |

|---|---|

| Background service / daemon with no user | Client credentials (app-only) |

| Agent or API acting on behalf of a signed-in user | On-Behalf-Of (OBO) |

| App running in Azure (Function, Container App, VM) | Managed Identity (preferred over secrets) |

| CLI tool or local dev script | Device code or interactive browser |

| Single-page app (browser only) | Authorization code + PKCE |

Core SDK usage patterns

Building the client

Always construct GraphServiceClient once and reuse it (it manages token caching internally).

Pass a credential from the Azure Identity library — never build raw HTTP clients manually.

Making calls

Pagination

Graph paginates collections. Never assume all items arrive in one response:

Advanced patterns

Batch requests

Combine up to 20 independent Graph calls into a single HTTP request using the $batch endpoint. Use batching when:

Batch responses arrive out of order — match them by the id field you assigned each request.

Delta queries

Use delta queries to sync changes incrementally instead of polling full collections:

Change notifications (webhooks)

Subscribe to resource changes with POST /subscriptions:

Throttling

Graph throttles aggressively. Always handle HTTP 429:

Permissions

Get permissions right before writing auth code — wrong scopes result in 403 errors that are hard to debug later.

Common Graph resources — quick reference

| Goal | Resource path |

|---|---|

| Get signed-in user's profile | GET /me |

| List user's mailbox messages | GET /me/messages |

| Send an email | POST /me/sendMail |

| List calendar events | GET /me/events |

| Get user's OneDrive root | GET /me/drive/root/children |

| List Teams the user is in | GET /me/joinedTeams |

| Post a Teams channel message | POST /teams/{id}/channels/{id}/messages |

| List SharePoint site lists | GET /sites/{siteId}/lists |

| Search across M365 | POST /search/query |

| List all users in tenant (app-only) | GET /users |

| Get group members | GET /groups/{id}/members |

In similar fashion, use the SDK's fluent API to navigate to these resources in code.

Workflow

  1. Determine the target language and read the matching reference file.
  2. Identify the auth scenario and choose the correct flow from the table above.
  3. Fetch current SDK docs and Graph Explorer examples before making implementation choices.
  4. Apply least-privilege permissions — confirm in the Graph permissions reference.
  5. Implement pagination from the start — don't assume single-page responses.
  6. Enable retry middleware for throttling from day one.
  7. For syncing scenarios, prefer delta queries over polling.
  8. Use the language-specific package names, auth provider setup, and code patterns from the chosen reference file.

Completion criteria

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.