purview-dlm-mcp
CLAUDE.md9 starsChanged 8 months agoMITView on GitHub
This is an MCP (Model Context Protocol) server that enables AI assistants to diagnose Microsoft Purview Data Lifecycle Management (DLM) issues in Exchange Online. It provides five tools—run_powershell, get_execution_log, ask_learn, create_issue, and submit_feedback—that let an AI run read-only PowerShell commands against Exchange Online and Security & Compliance sessions, review the diagnostic trail, look up Microsoft Learn documentation, report issues with the MCP server to GitHub, and collect structured diagnostic session feedback. Built with TypeScript and the official MCP SDK (@modelcontextprotocol/sdk).…
- Reads credentials
- Installs packages
In this repository7 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- asklearnSkill
- dlm-diagnosticsSkill
- skill-creatorSkill
- asklearnSkill
- dlm-diagnosticsSkill
- skill-creatorSkill
The file
We split this CLAUDE.md into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 99
Copyright headers: Every .ts file starts with:
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md — Purview DLM Diagnostics MCP Server
Project Purpose
This is an MCP (Model Context Protocol) server that enables AI assistants to diagnose Microsoft Purview Data Lifecycle Management (DLM) issues in Exchange Online. It provides five tools—run_powershell, get_execution_log, ask_learn, create_issue, and submit_feedback—that let an AI run read-only PowerShell commands against Exchange Online and Security & Compliance sessions, review the diagnostic trail, look up Microsoft Learn documentation, report issues with the MCP server to GitHub, and collect structured diagnostic session feedback.
Architecture
Built with TypeScript and the official MCP SDK (@modelcontextprotocol/sdk). Distributed via npm as @microsoft/purview-dlm-mcp, installable via npx.
src/
├── index.ts # Entry point: main(), MCP server, stdio transport, inline tool registration
├── config.ts # Exports COMMAND_TIMEOUT_MS, COLLECT_TELEMETRY, COLLECT_TELEMETRY_MICROSOFT
├── powershell/
│ ├── allowlist.ts # Regex-based command validation (Set<string>)
│ └── executor.ts # PsExecutor: child_process.spawn('pwsh'), MSAL auth via subprocess, marker-based polling
├── tsg-diagnostics.ts # All diagnostics: Severity enum, parsers, 10 evaluators (~1700 lines), report renderer
├── asklearn.ts # Topic map (11 topics) + keyword lookup + markdown formatting
├── github/
│ ├── auth.ts # GitHubAuth: DLM_GITHUB_TOKEN env var → gh CLI fallback, in-memory token cache
│ └── issues.ts # buildIssueBody, categoryToLabels, createGitHubIssue via REST API
├── telemetry.ts # Telemetry singleton: Application Insights wrapper (1P, no PII, opt-out)
├── logger.ts # In-memory LogEntry[] + toMarkdown()
└── utils.ts # escapeForPs, tryParseJson, truncate
tests/
├── unit/
│ ├── cmdletAllowlist.test.ts # ~23 tests
│ ├── outputParsers.test.ts # ~29 tests
│ ├── askLearn.test.ts # ~10 tests
│ ├── executionLog.test.ts # ~5 tests
│ ├── executorHardening.test.ts # ~3 tests (requires pwsh)
│ ├── githubAuth.test.ts # ~8 tests
│ ├── githubIssues.test.ts # ~10 tests
│ └── telemetry.test.ts # ~17 tests
└── e2e/
├── endToEnd.test.ts # ~30 tests (requires EXO)
├── tsgEvaluators.test.ts # ~14 tests (requires EXO)
└── fixtures/
└── mcpServerFixture.ts # Spawns server, polls readiness, provides MCP clientKey Components
index.ts—main()wrapper with.catch(). Creates singletons (ExecutionLog, PsExecutor), registers MCP tools inline, connects stdio transport BEFORE background PS init.executor.ts— Spawns a single long-livedpwshprocess viachild_process.spawn. Acquires MSAL access token by spawning a separate short-lived pwsh process that uses the MSAL DLL bundled with ExchangeOnlineManagement. IncludesexecuteJson<T>()convenience method.allowlist.ts— Defines the explicit set of allowed cmdlets (Get-*,Test-*,Export-*) and blocked verb prefixes. Every command is validated before execution.tsg-diagnostics.ts— Combined module: types/enums, output parsers, 10 pure evaluator functions, and markdown report renderer. No external imports.github/auth.ts—GitHubAuthclass: resolves a GitHub token fromDLM_GITHUB_TOKENenv var orgh auth tokenCLI, caches in-memory.github/issues.ts— Builds structured issue bodies with session diagnostic context (no PII), maps categories to labels, creates issues via GitHub REST API.telemetry.ts—Telemetryclass: wrapsapplicationinsightsTelemetryClient. No-op when disabled. Tracks tool invocations, session lifecycle, and errors. 1P only, no PII.
Skills
Skills are self-contained diagnostic guides used by AI assistants:
- Location:
.github/skills/(for GitHub Copilot) and.claude/skills/(for Claude Code) - Current skills:
dlm-diagnostics— 11 troubleshooting guides for DLM issues (retention policies, archive, inactive mailboxes, etc.)asklearn— Fallback skill that surfaces Microsoft Learn documentation for Purview topicsskill-creator— Meta-skill for authoring new skills following project conventions
Security Model
- Read-only allowlist — Only
Get-*,Test-*,Export-*cmdlets may be executed. AllSet-*,New-*,Remove-*,Enable-*,Start-*,Invoke-*are blocked at the validation layer (allowlist.ts).buildValidatedCommandre-parses every command with the PowerShell AST inside the session and rejects anything outside the allowlist: unmapped aliases, native binaries, dynamic invocation, redirection, the-asoperator, and file-writing parameters.hardenRunspacealso clearsSessionState.Applications/Scripts(native executables and scripts can't be resolved by name or path) and removes every alias outsideguardAliases. This is defense in depth, not a boundary: code running in the session can still reach .NET, COM, modules, and jobs, so the AST guard is the security boundary. - No stored credentials — Authentication uses MSAL interactive browser flow via a subprocess that loads the MSAL DLL from ExchangeOnlineManagement; tokens are in-memory only.
- Session isolation — Each MCP server instance runs its own PowerShell process with its own session.
- Audit trail — Every command and result is logged via
ExecutionLogand retrievable throughget_execution_log. - GitHub authentication —
create_issueauthenticates viaDLM_GITHUB_TOKENenv var orgh auth tokenCLI; no credentials are stored. - Telemetry — 1P Application Insights only, no PII collected. Opt-out via
DLM_COLLECT_TELEMETRY=falseorDLM_COLLECT_TELEMETRY_MICROSOFT=false.
Development Commands
npm install # Install dependencies
npm run build # Build TypeScript
npm test # Run unit tests (Vitest, no EXO needed)
npm run test:e2e # Run E2E + TSG tests (requires EXO)
npm run lint # Run ESLint
npm run format # Check Prettier formatting
node dist/index.js # Start the MCP serverTesting
- Test runner: Vitest
- Unit tests (no EXO):
cmdletAllowlist.test.ts,outputParsers.test.ts,askLearn.test.ts,executionLog.test.ts,githubAuth.test.ts,githubIssues.test.ts,telemetry.test.ts— 107 tests - E2E tests (live EXO):
endToEnd.test.ts— 30 tests - TSG integration tests (live EXO):
tsgEvaluators.test.ts— ~14 tests - Environment variables: Tests require
DLM_UPNandDLM_ORGANIZATIONfor Exchange Online connectivity.DLM_COMMAND_TIMEOUT_MSoptionally overrides the default command timeout (180 000 ms).DLM_COLLECT_TELEMETRYandDLM_COLLECT_TELEMETRY_MICROSOFTcontrol telemetry (default:true). - Known gotchas:
- E2E and TSG tests require a live PowerShell 7 (
pwsh) installation and Exchange Online access. - Unit tests (allowlist, parser, ask-learn, execution-log) run without external dependencies.
- The
mcpServerFixturestarts a single MCP server process shared across E2E/TSG tests. - The build must succeed (
npm run build) before E2E tests can run.
- E2E and TSG tests require a live PowerShell 7 (
Coding Conventions
- Copyright headers: Every
.tsfile starts with:// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - Language: TypeScript 5 / Node.js 18+, strict mode enabled
- Module system: ESM (
"type": "module"in package.json),NodeNextmodule resolution - MCP tools: Zod schemas for parameter validation, registered inline in
index.tsviaserver.tool() - DI: Manual singletons (no framework — only 2 services: PsExecutor, ExecutionLog)
- Pure evaluators: Diagnostic evaluation functions in
tsg-diagnostics.tsare pure (no I/O, no side effects) — they take parsed data and return structured results - Naming: camelCase for files/functions/variables, PascalCase for types/classes/enums
Key File Paths
| Purpose | Path |
| MCP server entry point | src/index.ts |
| Runtime configuration | src/config.ts |
| PowerShell executor | src/powershell/executor.ts |
| Cmdlet allowlist | src/powershell/allowlist.ts |
| TSG diagnostics (types + parsers + evaluators + renderer) | src/tsg-diagnostics.ts |
| Ask Learn topic lookup | src/asklearn.ts |
| Execution logger | src/logger.ts |
| Utility functions | src/utils.ts |
| GitHub authentication | src/github/auth.ts |
| GitHub issue creation | src/github/issues.ts |
| Telemetry (App Insights) | src/telemetry.ts |
| DLM diagnostics skill | .github/skills/dlm-diagnostics/SKILL.md |
| Skill creator guide | .github/skills/skill-creator/SKILL.md |
| CI/CD pipeline | azure-pipelines.yml |
| Unit tests | tests/unit/ |
| E2E tests | tests/e2e/ |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

