Skip to main content
Glama
VKneider

Slice.js Documentation MCP

by VKneider

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

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYes
include_metadataNo

Implementation Reference

  • 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);
      },
    };
  • 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);
  • 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;
      }
    }
  • 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 = [];
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/VKneider/slicejs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server