MCPcopy Create free account
hub / github.com/MicrosoftDocs/mcp / registerCodeSearchCommand

Function registerCodeSearchCommand

cli/src/commands/code-search.ts:13–32  ·  view source on GitHub ↗
(program: Command, context: CliContext)

Source from the content-addressed store, hash-verified

11}
12
13export function registerCodeSearchCommand(program: Command, context: CliContext): void {
14 program
15 .command('code-search')
16 .description('Search Microsoft Learn code samples through the Learn MCP server.')
17 .argument('<query>', 'Search query.')
18 .option('--language <name>', 'Preferred language filter to pass to Learn.')
19 .option('--json', 'Output raw JSON instead of formatted text.')
20 .action(async (query: string, options: CodeSearchCommandOptions) => {
21 const endpoint = resolveEndpoint(program.opts<{ endpoint?: string }>().endpoint, context.env);
22 const client = context.createClient({ endpoint });
23
24 try {
25 const payload = await client.searchCodeSamples(query, options.language);
26 const output = options.json ? payload : formatCodeSearchResults(payload);
27 context.writeOut(ensureTrailingNewline(output));
28 } finally {
29 await client.close();
30 }
31 });
32}

Callers 1

createProgramFunction · 0.85

Calls 5

resolveEndpointFunction · 0.85
formatCodeSearchResultsFunction · 0.85
ensureTrailingNewlineFunction · 0.85
searchCodeSamplesMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected