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

Function registerFetchCommand

cli/src/commands/fetch.ts:13–34  ·  view source on GitHub ↗
(program: Command, context: CliContext)

Source from the content-addressed store, hash-verified

11}
12
13export function registerFetchCommand(program: Command, context: CliContext): void {
14 program
15 .command('fetch')
16 .description('Fetch a Microsoft Learn document in markdown-friendly form.')
17 .argument('<url>', 'Microsoft Learn document URL.')
18 .option('--section <heading>', 'Return only the matching markdown section.')
19 .option('--max-chars <number>', 'Truncate the final rendered output.', parsePositiveInteger)
20 .action(async (url: string, options: FetchCommandOptions) => {
21 const endpoint = resolveEndpoint(program.opts<{ endpoint?: string }>().endpoint, context.env);
22 const normalizedUrl = normalizeUrl(url);
23 const client = context.createClient({ endpoint });
24
25 try {
26 const markdown = await client.fetchDocument(normalizedUrl);
27 const sectionFiltered = options.section ? extractMarkdownSection(markdown, options.section) : markdown;
28 const finalContent = truncateOutput(sectionFiltered, options.maxChars);
29 context.writeOut(ensureTrailingNewline(finalContent));
30 } finally {
31 await client.close();
32 }
33 });
34}

Callers 1

createProgramFunction · 0.85

Calls 7

resolveEndpointFunction · 0.85
normalizeUrlFunction · 0.85
extractMarkdownSectionFunction · 0.85
truncateOutputFunction · 0.85
ensureTrailingNewlineFunction · 0.85
fetchDocumentMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected