get_doc_content
Retrieve full documentation content from Slice.js GitHub repository to access specific pages or complete bundles for AI assistant context.
Instructions
Fetches full content of specific doc page(s)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes | ||
| include_metadata | No |
Implementation Reference
- src/tools/get-doc-content.ts:4-42 (handler)Main tool definition with the execute function that fetches doc content by doc_id(s). Handles initialization, iterates through doc IDs, retrieves content, and optionally includes metadata.
export const getDocContentTool = { name: "get_doc_content", description: "Fetches full content of specific doc page(s)", parameters: z.object({ doc_id: z.union([z.string(), z.array(z.string())]), include_metadata: z.boolean().optional().default(false), }), execute: async (args: { doc_id: string | string[]; include_metadata: boolean }) => { if (!isInitialized) await initializeDocsStructure(); const { doc_id, include_metadata } = args; const ids = Array.isArray(doc_id) ? doc_id : [doc_id]; const results: any[] = []; for (const id of ids) { const doc = DOCS_STRUCTURE.find(d => d.id === id); if (!doc) continue; const content = await fetchDocContent(id); if (!content) continue; const result: any = { doc_id: id, title: doc.title, content, }; if (include_metadata) { result.metadata = { path: doc.path, fetched_at: new Date().toISOString(), }; } results.push(result); } return JSON.stringify(results.length === 1 ? results[0] : results); }, }; - src/tools/get-doc-content.ts:7-10 (schema)Zod schema defining tool parameters: doc_id (string or array of strings) and optional include_metadata boolean flag.
parameters: z.object({ doc_id: z.union([z.string(), z.array(z.string())]), include_metadata: z.boolean().optional().default(false), }), - src/index.ts:6-16 (registration)Tool import and registration with the FastMCP server. The getDocContentTool is added to the server to make it available as an MCP tool.
import { getDocContentTool } from "./tools/get-doc-content.js"; import { getLlmFullContextTool } from "./tools/get-llm-full-context.js"; const server = new FastMCP({ name: "Slice.js Documentation MCP", version: "1.0.0", }); server.addTool(listDocsTool); server.addTool(searchDocsTool); server.addTool(getDocContentTool); - src/utils.ts:160-183 (helper)Core helper function that fetches document content from GitHub using the doc_id. Implements caching to avoid redundant requests and handles errors gracefully.
export async function fetchDocContent(docId: string): Promise<string | null> { const cached = getCached(docId); if (cached) { console.error(`[MCP] Cache hit for doc: ${docId}`); return cached; } console.error(`[MCP] Cache miss for doc: ${docId}, fetching from GitHub`); const doc = DOCS_STRUCTURE.find(d => d.id === docId); if (!doc) return null; const url = `${BASE_URL}${doc.path}`; try { const response = await fetch(url); if (!response.ok) throw new Error(`HTTP ${response.status}`); const content = await response.text(); setCache(docId, content); console.error(`[MCP] Fetched and cached doc: ${docId}`); return content; } catch (error) { console.error(`[MCP] Error fetching ${url}:`, error); return null; } } - src/utils.ts:100-123 (helper)Initialization function that populates DOCS_STRUCTURE from the llm.txt file. Uses caching and handles initialization state to avoid redundant setup.
export async function initializeDocsStructure(): Promise<void> { if (isInitialized) return; try { let llmContent = getCached('llm.txt'); if (!llmContent) { console.error('[MCP] Fetching llm.txt to build docs structure'); const url = `${BASE_URL}llm.txt`; const response = await fetch(url); if (!response.ok) throw new Error(`HTTP ${response.status}`); llmContent = await response.text(); setCache('llm.txt', llmContent); } else { console.error('[MCP] Using cached llm.txt to build docs structure'); } // Parse DOCS_STRUCTURE from llm.txt DOCS_STRUCTURE = parseDocsFromLlmTxt(llmContent); isInitialized = true; console.error(`[MCP] Initialized docs structure with ${DOCS_STRUCTURE.length} documents`); } catch (error) { console.error('[MCP] Failed to initialize docs structure:', error); DOCS_STRUCTURE = []; } }