Add Learn CLI option to microsoft-docs skills (#1003)

* Add Learn CLI option to microsoft-docs skills

* avoid context fork

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Tianqi Zhang
2026-03-16 08:53:03 +08:00
committed by GitHub
parent 39a1a0ce04
commit 822d0407de
4 changed files with 89 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
---
name: microsoft-code-reference
description: Look up Microsoft API references, find working code samples, and verify SDK code is correct. Use when working with Azure SDKs, .NET libraries, or Microsoft APIs—to find the right method, check parameters, get working examples, or troubleshoot errors. Catches hallucinated methods, wrong signatures, and deprecated patterns by querying official docs.
compatibility: Requires Microsoft Learn MCP Server (https://learn.microsoft.com/api/mcp)
compatibility: Works best with Microsoft Learn MCP Server (https://learn.microsoft.com/api/mcp). Can also use the mslearn CLI as a fallback.
---
# Microsoft Code Reference
@@ -76,3 +76,24 @@ Before generating code using Microsoft SDKs, verify it's correct:
3. **Find working sample**`microsoft_code_sample_search(query: "[task]", language: "[lang]")`
For simple lookups, step 1 alone may suffice. For complex API usage, complete all three steps.
## CLI Alternative
If the Learn MCP server is not available, use the `mslearn` CLI from a terminal or shell (for example, Bash, PowerShell, or cmd) instead:
```sh
# Run directly (no install needed)
npx @microsoft/learn-cli search "BlobClient UploadAsync Azure.Storage.Blobs"
# Or install globally, then run
npm install -g @microsoft/learn-cli
mslearn search "BlobClient UploadAsync Azure.Storage.Blobs"
```
| MCP Tool | CLI Command |
|----------|-------------|
| `microsoft_docs_search(query: "...")` | `mslearn search "..."` |
| `microsoft_code_sample_search(query: "...", language: "...")` | `mslearn code-search "..." --language ...` |
| `microsoft_docs_fetch(url: "...")` | `mslearn fetch "..."` |
Pass `--json` to `search` or `code-search` to get raw JSON output for further processing.