list_docs
Retrieve available documentation sections and categories from the Slice.js GitHub repository to navigate and access specific documentation content.
Instructions
Returns available documentation sections/categories
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/list-docs.ts:8-15 (handler)The execute function for list_docs tool that initializes the docs structure if needed and returns a JSON string of available documentation sections with id, title, and path fields
execute: async () => { if (!isInitialized) await initializeDocsStructure(); return JSON.stringify(DOCS_STRUCTURE.map(doc => ({ id: doc.id, title: doc.title, path: doc.path, }))); }, - src/tools/list-docs.ts:4-16 (schema)Tool definition including name, description, and Zod schema for parameters (empty object), along with the execute handler
export const listDocsTool = { name: "list_docs", description: "Returns available documentation sections/categories", parameters: z.object({}), execute: async () => { if (!isInitialized) await initializeDocsStructure(); return JSON.stringify(DOCS_STRUCTURE.map(doc => ({ id: doc.id, title: doc.title, path: doc.path, }))); }, }; - src/index.ts:4-14 (registration)Import of listDocsTool from tools/list-docs.js and registration with the FastMCP server using server.addTool()
import { listDocsTool } from "./tools/list-docs.js"; import { searchDocsTool } from "./tools/search-docs.js"; 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); - src/utils.ts:100-123 (helper)initializeDocsStructure function that fetches and parses llm.txt to build the DOCS_STRUCTURE array, called by the list_docs handler if not already initialized
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 = []; } } - src/utils.ts:126-157 (helper)parseDocsFromLlmTxt function that parses the llm.txt content to extract document metadata (id, path, title) for each documentation section
export function parseDocsFromLlmTxt(content: string): DocItem[] { const items: DocItem[] = []; const sections = content.split(/\n=== /).slice(1); console.error(`[MCP] Parsing ${sections.length} sections from llm.txt`); for (const section of sections) { const lines = section.split('\n'); const filePath = lines[0].replace(' ===', ''); const docContent = lines.slice(1).join('\n').trim(); if (filePath && docContent) { // Extract title from first # line const titleMatch = docContent.split('\n').find(line => line.startsWith('# ')); const title = titleMatch ? titleMatch.replace('# ', '') : filePath.split('/').pop()?.replace('.md', '') || 'Untitled'; const relativePath = filePath.replace(/^markdown\//, ''); const id = relativePath.replace(/\.md$/, ''); items.push({ id, path: filePath, title, }); } else { console.error(`[MCP] Skipped section from llm.txt: ${lines[0]}, has filePath: ${!!filePath}, docContent length: ${docContent.length}`); } } console.error(`[MCP] Parsed docs from llm.txt: ${items.map(i => i.path).join(', ')}`); return items; }