fetch-peacock-docs
Retrieves Peacock for VS Code documentation from GitHub and provides answers to your questions about the extension.
Instructions
Fetches the Peacock for VS Code extension docs from its GitHub repository and answers questions based on the documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The question to answer based on the Peacock documentation |
Implementation Reference
- src/index.ts:25-46 (registration)The tool 'fetch-peacock-docs' is registered on the MCP server. It accepts a 'query' string (zod-validated) and delegates to handleDocumentationQuery.
server.tool( "fetch-peacock-docs", "Fetches the Peacock for VS Code extension docs from its GitHub repository and answers questions based on the documentation ", { query: z.string().describe("The question to answer based on the Peacock documentation") }, async ({ query }) => { try { const { text } = await handleDocumentationQuery(query); return { content: [{ type: "text", text }], }; } catch (error) { return { content: [ { type: "text", text: `Error searching Peacock documentation: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); - src/utils/peacock-docs.ts:221-251 (handler)handleDocumentationQuery is the core handler: initializes the docs cache if needed, then searches documentation and code files for the query and returns relevant sections.
export async function handleDocumentationQuery(query: string): Promise<{ text: string }> { // Initialize cache if needed if (!isDocsCacheInitialized) { isDocsCacheInitialized = await initializeDocsCache(); if (!isDocsCacheInitialized) { return { text: "Failed to initialize documentation cache. Please try again later." }; } } // Check if cache is empty if (Object.keys(docsCache).length === 0 && Object.keys(codeCache).length === 0) { return { text: "No files were found in the Peacock repository." }; } // Handle listing available files if (query.toLowerCase().includes("available") && query.toLowerCase().includes("files")) { return { text: `Available documentation files:\n${docFilesList.join("\n")}\n\nAvailable code files:\n${codeFilesList.join( "\n" )}`, }; } // Search documentation and code const { results, sources } = searchAll(query); if (!results) { return { text: `No information related to "${query}" was found in the Peacock documentation or code.` }; } return { text: `Information related to "${query}":\n\n${results}\n\nSources: ${sources.join(", ")}` }; } - src/utils/peacock-docs.ts:175-218 (helper)searchAll searches both docsCache and codeCache for query matches, extracting relevant sections via processMatchingMarkdownSection and processMatchingCodeSection.
export function searchAll(query: string): { results: string; sources: string[] } { const queryLower = query.toLowerCase(); const relevantContent: string[] = []; const sources: string[] = []; // Search documentation files for (const [filePath, content] of Object.entries(docsCache)) { if (!content.toLowerCase().includes(queryLower)) continue; const lines = content.split("\n"); for (let i = 0; i < lines.length; i++) { if (lines[i].toLowerCase().includes(queryLower)) { const { content: sectionContent, endIndex } = processMatchingMarkdownSection(lines, i, queryLower); if (sectionContent) { relevantContent.push(sectionContent); sources.push(filePath); } i = endIndex; } } } // Search code files for (const [filePath, content] of Object.entries(codeCache)) { if (!content.toLowerCase().includes(queryLower)) continue; const lines = content.split("\n"); for (let i = 0; i < lines.length; i++) { if (lines[i].toLowerCase().includes(queryLower)) { const { content: sectionContent, endIndex } = processMatchingCodeSection(lines, i, queryLower, filePath); if (sectionContent) { relevantContent.push(sectionContent); sources.push(filePath); } i = endIndex; } } } return { results: relevantContent.join("\n\n---\n\n"), sources: [...new Set(sources)], }; } - src/utils/peacock-docs.ts:91-113 (helper)initializeDocsCache fetches the README.md, docs/ and src/ directories from the Peacock GitHub repo, caching documentation (.md) and code (.ts/.js/.tsx/.jsx) files.
export async function initializeDocsCache(): Promise<boolean> { try { // Process root README await processDocumentationFile("README.md"); // Process docs directory const docsItems = await fetchDirectoryContents("docs"); await processDirectoryItems(docsItems); // Process src directory const srcItems = await fetchDirectoryContents("src"); await processDirectoryItems(srcItems); const totalFiles = docFilesList.length + codeFilesList.length; console.error( `Indexed ${docFilesList.length} documentation files and ${codeFilesList.length} code files from Peacock repository` ); return totalFiles > 0; } catch (error) { console.error(`Error initializing cache: ${error instanceof Error ? error.message : String(error)}`); return false; } } - src/index.ts:28-28 (schema)The input schema for the tool: a single 'query' field of type string, validated via Zod.
{ query: z.string().describe("The question to answer based on the Peacock documentation") },