How It Works
This page explains the technical internals of msgraph for those who want to understand or extend it.
Architecture Overview
Section titled “Architecture Overview”The diagram below shows how an AI agent interacts with the skill. The search layer runs entirely locally against pre-built SQLite FTS5 databases — no network calls, no auth. The execution layer is optional and requires authentication.
Agent Workflow
Section titled “Agent Workflow”When an agent receives a user request involving Microsoft 365 data, it follows a progressive lookup strategy — each level adds more detail:
- Own knowledge — try first for well-known endpoints (
/me,/users,/groups). sample-search— curated, hand-verified samples. Highest quality. Best for common tasks and multi-step workflows.api-docs-search— per-endpoint permissions, supported query parameters, required headers, and resource property details with filter operators.openapi-search— full catalog of 27,700 APIs. Use when the endpoint can’t be found any other way.- Reference files — concept docs on paging, batching, throttling, errors, and best practices.
Build Pipeline
Section titled “Build Pipeline”The search indexes are built offline and bundled with the skill. Each release runs the indexer tools to produce fresh databases:
Technical Details
Section titled “Technical Details”Auth Method Detection
Section titled “Auth Method Detection”The auth method is auto-detected from environment variables in priority order:
MSGRAPH_CLIENT_SECRETset → Client secretMSGRAPH_CLIENT_CERTIFICATE_PATHset → CertificateMSGRAPH_FEDERATED_TOKEN_FILE(orAZURE_FEDERATED_TOKEN_FILE/AWS_WEB_IDENTITY_TOKEN_FILE) set → Workload identityMSGRAPH_AUTH_METHOD=managed-identity→ Managed identity- None of the above → Delegated (interactive browser / device code)
Silent Token Acquisition
Section titled “Silent Token Acquisition”After initial sign-in, tokens are cached. Subsequent calls use silent acquisition:
- Check the in-memory/file cache for a valid token
- If expired, MSAL automatically refreshes using the refresh token (delegated) or re-acquires via credentials (app-only)
- Only if refresh fails does it prompt for interactive auth (delegated only)
Incremental Consent (Delegated Only)
Section titled “Incremental Consent (Delegated Only)”When a 403 Forbidden occurs with delegated auth:
- Parse the error message for required scope names (regex:
[A-Z][a-zA-Z]+\.[A-Z][a-zA-Z]+) - Merge new scopes with existing scopes
- Re-authenticate with the combined scope set
- Retry the original request with the new token
Incremental consent is not available for app-only auth — all permissions must be pre-configured and admin-consented in the Entra ID app registration.
Safety Enforcement
Section titled “Safety Enforcement”Safety is enforced at the CLI level before any HTTP request is made:
| Method | Default | With —allow-writes |
|---|---|---|
| GET | Allowed | Allowed |
| HEAD | Allowed | Allowed |
| OPTIONS | Allowed | Allowed |
| POST | Blocked | Allowed |
| PUT | Blocked | Allowed |
| PATCH | Blocked | Allowed |
| DELETE | Blocked | Blocked |
DELETE is blocked unconditionally — there is no flag to enable it.
OpenAPI Index
Section titled “OpenAPI Index”The index is built by tools/openapi-indexer/:
- Downloads the official Graph OpenAPI YAML (~60MB)
- Parses using
gopkg.in/yaml.v3with flexibleinterface{}unmarshaling - Extracts path, method, summary, description, operation IDs, parameters, deprecation info, doc URLs, request/response schema refs, and security scopes
- Outputs a SQLite FTS5 database (
graph-api-index.db, ~27,000 endpoints)
The search algorithm uses SQLite FTS5 full-text search:
- BM25 ranking with weighted columns (path weight 10, summary 5, description 3)
- Porter stemming tokenizer for flexible term matching
- Filters by method (exact match) and resource (path segment match)
- Returns results ranked by relevance
Build System
Section titled “Build System”- Cross-platform: Pre-built for macOS, Linux, and Windows (amd64 and arm64)
- Cross-compilation: 6 platform targets (darwin/linux/windows × amd64/arm64)
- Docs site: Astro + Starlight, deployed to GitHub Pages
- Monorepo: CLI source at root, npm workspace for docs