Skip to content

Commit 935ee6b

Browse files
committed
Merge branch 'jahe-addAnnotateCLI' of https://github.com/hejingkan2005/mcp into jahe-addAnnotateCLI
# Conflicts: # cli/src/context.ts
2 parents 04b9eaa + abe8ea1 commit 935ee6b

File tree

12 files changed

+105
-35
lines changed

12 files changed

+105
-35
lines changed

cli/src/commands/code-search.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ export function registerCodeSearchCommand(program: Command, context: CliContext)
1919
.option('--json', 'Output raw JSON instead of formatted text.')
2020
.action(async (query: string, options: CodeSearchCommandOptions) => {
2121
const endpoint = resolveEndpoint(program.opts<{ endpoint?: string }>().endpoint, context.env);
22-
const client = context.createClient({
23-
endpoint,
24-
clientName: 'mslearn',
25-
clientVersion: context.version,
26-
});
22+
const client = context.createClient({ endpoint });
2723

2824
try {
2925
const payload = await client.searchCodeSamples(query, options.language);

cli/src/commands/doctor.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@ export function registerDoctorCommand(program: Command, context: CliContext): vo
3535
async function runDoctorChecks(endpoint: string, context: CliContext): Promise<DoctorReport> {
3636
const runtimeVersion = process.versions.node;
3737
const runtimeSupported = Number.parseInt(runtimeVersion.split('.')[0] ?? '0', 10) >= 22;
38-
const reachability = await probeEndpoint(endpoint, context.fetchImpl);
38+
const reachability = await probeEndpoint(endpoint);
3939
const errors: string[] = [];
4040
const tools: DoctorReport['tools'] = {};
4141
let connected = false;
4242
let discovered = false;
4343

44-
const client = context.createClient({
45-
endpoint,
46-
clientName: 'mslearn',
47-
clientVersion: context.version,
48-
});
44+
const client = context.createClient({ endpoint });
4945

5046
try {
5147
const mapping = await client.getToolMapping(true);

cli/src/commands/fetch.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ export function registerFetchCommand(program: Command, context: CliContext): voi
2020
.action(async (url: string, options: FetchCommandOptions) => {
2121
const endpoint = resolveEndpoint(program.opts<{ endpoint?: string }>().endpoint, context.env);
2222
const normalizedUrl = normalizeUrl(url);
23-
const client = context.createClient({
24-
endpoint,
25-
clientName: 'mslearn',
26-
clientVersion: context.version,
27-
});
23+
const client = context.createClient({ endpoint });
2824

2925
try {
3026
const markdown = await client.fetchDocument(normalizedUrl);

cli/src/commands/search.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ export function registerSearchCommand(program: Command, context: CliContext): vo
1717
.option('--json', 'Output raw JSON instead of formatted text.')
1818
.action(async (query: string, options: SearchCommandOptions) => {
1919
const endpoint = resolveEndpoint(program.opts<{ endpoint?: string }>().endpoint, context.env);
20-
const client = context.createClient({
21-
endpoint,
22-
clientName: 'mslearn',
23-
clientVersion: context.version,
24-
});
20+
const client = context.createClient({ endpoint });
2521

2622
try {
2723
const payload = await client.searchDocs(query);

cli/src/context.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export interface CliContext {
66
version: string;
77
writeOut: (value: string) => void;
88
writeErr: (value: string) => void;
9-
fetchImpl: typeof fetch;
109
createClient: (options: LearnClientOptions) => LearnCliClientLike;
1110
createAnnotationStore: () => AnnotationStore;
1211
}
@@ -22,7 +21,11 @@ export function createDefaultContext(version: string): CliContext {
2221
process.stderr.write(value);
2322
},
2423
fetchImpl: globalThis.fetch.bind(globalThis) as typeof fetch,
25-
createClient: (options) => createLearnCliClient(options),
24+
createClient: (options) =>
25+
createLearnCliClient({
26+
clientVersion: version,
27+
...options,
28+
}),
2629
createAnnotationStore: () => createFileAnnotationStore(),
2730
};
2831
}

cli/src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ export function createProgram(context: CliContext): Command {
2626
.addOption(new Option('--endpoint <url>', 'Override the Learn MCP endpoint for this command.').hideHelp())
2727
.showHelpAfterError()
2828
.configureOutput({
29-
writeOut: (value) => {
30-
context.writeOut(value);
31-
},
32-
writeErr: (value) => {
33-
context.writeErr(value);
34-
},
29+
writeOut: context.writeOut,
30+
writeErr: context.writeErr,
3531
outputError: (value, write) => {
3632
write(value);
3733
},

cli/src/mcp/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { OperationError } from '../utils/errors.js';
77
import { createFileLearnSessionCacheStore, type LearnSessionCacheStore } from './cache.js';
88
import { discoverLearnTools, type DiscoveredLearnTools, type ListedTool } from './tool-discovery.js';
99

10+
const DEFAULT_CLIENT_NAME = 'learn-cli';
11+
1012
export interface LearnClientOptions {
1113
endpoint: string;
1214
clientName?: string;
@@ -43,7 +45,7 @@ interface TransportLike {
4345
close(): Promise<void>;
4446
}
4547

46-
export async function probeEndpoint(endpoint: string, fetchImpl: typeof fetch): Promise<ReachabilityReport> {
48+
export async function probeEndpoint(endpoint: string, fetchImpl: typeof fetch = globalThis.fetch): Promise<ReachabilityReport> {
4749
try {
4850
const response = await fetchImpl(endpoint, {
4951
method: 'GET',
@@ -271,7 +273,7 @@ class LearnCliClient implements LearnCliClientLike {
271273
private createDefaultSdkClient(): SdkClientLike {
272274
return new Client(
273275
{
274-
name: this.options.clientName ?? 'mslearn',
276+
name: this.options.clientName ?? DEFAULT_CLIENT_NAME,
275277
version: this.options.clientVersion ?? '0.1.0',
276278
},
277279
{

cli/test/unit/cli.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function createTestContext(client: LearnCliClientLike): {
4343
writeErr: (value) => {
4444
stderr.push(value);
4545
},
46-
fetchImpl: vi.fn(async () => new Response(null, { status: 405 })) as unknown as typeof fetch,
4746
createClient: () => client,
4847
createAnnotationStore: () => createFileAnnotationStore({ annotationsDir }),
4948
},

skills/microsoft-code-reference/SKILL.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: microsoft-code-reference
33
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.
44
context: fork
5-
compatibility: Requires Microsoft Learn MCP Server (https://learn.microsoft.com/api/mcp)
5+
compatibility: Works best with Microsoft Learn MCP Server (https://learn.microsoft.com/api/mcp). Can also use the mslearn CLI as a fallback.
66
---
77

88
# Microsoft Code Reference
@@ -77,3 +77,24 @@ Before generating code using Microsoft SDKs, verify it's correct:
7777
3. **Find working sample**`microsoft_code_sample_search(query: "[task]", language: "[lang]")`
7878

7979
For simple lookups, step 1 alone may suffice. For complex API usage, complete all three steps.
80+
81+
## CLI Alternative
82+
83+
If the Learn MCP server is not available, use the `mslearn` CLI from the command line instead:
84+
85+
```sh
86+
# Run directly (no install needed)
87+
npx @microsoft/learn-cli search "BlobClient UploadAsync Azure.Storage.Blobs"
88+
89+
# Or install globally, then run
90+
npm install -g @microsoft/learn-cli
91+
mslearn search "BlobClient UploadAsync Azure.Storage.Blobs"
92+
```
93+
94+
| MCP Tool | CLI Command |
95+
|----------|-------------|
96+
| `microsoft_docs_search(query: "...")` | `mslearn search "..."` |
97+
| `microsoft_code_sample_search(query: "...", language: "...")` | `mslearn code-search "..." --language ...` |
98+
| `microsoft_docs_fetch(url: "...")` | `mslearn fetch "..."` |
99+
100+
Pass `--json` to `search` or `code-search` to get raw JSON output for further processing.

skills/microsoft-docs/SKILL.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: microsoft-docs
33
description: Query official Microsoft documentation to understand concepts, find tutorials, and learn how services work. Use for Azure, .NET, Microsoft 365, Windows, Power Platform, and all Microsoft technologies. Get accurate, current information from learn.microsoft.com and other official Microsoft websites—architecture overviews, quickstarts, configuration guides, limits, and best practices.
44
context: fork
5-
compatibility: Requires Microsoft Learn MCP Server (https://learn.microsoft.com/api/mcp)
5+
compatibility: Works best with Microsoft Learn MCP Server (https://learn.microsoft.com/api/mcp). Can also use the mslearn CLI as a fallback.
66
---
77

88
# Microsoft Docs
@@ -55,3 +55,23 @@ Fetch after search when:
5555
- **Accuracy** — live docs, not training data that may be outdated
5656
- **Completeness** — tutorials have all steps, not fragments
5757
- **Authority** — official Microsoft documentation
58+
59+
## CLI Alternative
60+
61+
If the Learn MCP server is not available, use the `mslearn` CLI from the command line instead:
62+
63+
```sh
64+
# Run directly (no install needed)
65+
npx @microsoft/learn-cli search "azure functions timeout"
66+
67+
# Or install globally, then run
68+
npm install -g @microsoft/learn-cli
69+
mslearn search "azure functions timeout"
70+
```
71+
72+
| MCP Tool | CLI Command |
73+
|----------|-------------|
74+
| `microsoft_docs_search(query: "...")` | `mslearn search "..."` |
75+
| `microsoft_docs_fetch(url: "...")` | `mslearn fetch "..."` |
76+
77+
The `fetch` command also supports `--section <heading>` to extract a single section and `--max-chars <number>` to truncate output.

0 commit comments

Comments
 (0)