Skip to main content
Glama
VKneider

Slice.js Documentation MCP

by VKneider

search_docs

Search Slice.js documentation by keyword or phrase to find relevant information quickly. This tool returns specific documentation sections based on your search query.

Instructions

Searches across all docs by keyword/phrase

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
max_resultsNo

Implementation Reference

  • The main search_docs tool implementation including tool definition, schema validation with zod, and the execute handler that searches through all documentation files for matching keywords/phrases and returns results with snippets
    export const searchDocsTool = {
      name: "search_docs",
      description: "Searches across all docs by keyword/phrase",
      parameters: z.object({
        query: z.string(),
        max_results: z.number().optional().default(5),
      }),
      execute: async (args: { query: string; max_results: number }) => {
        if (!isInitialized) await initializeDocsStructure();
        const { query, max_results } = args;
        const results: any[] = [];
    
        for (const doc of DOCS_STRUCTURE) {
          const content = await fetchDocContent(doc.id);
          if (!content) continue;
    
          const lines = content.split('\n');
          for (let i = 0; i < lines.length; i++) {
            const line = lines[i];
            if (line.toLowerCase().includes(query.toLowerCase())) {
              const snippet = line.trim();
              results.push({
                doc_id: doc.id,
                title: doc.title,
                relevance_score: 1, // simple match
                snippet,
                path: doc.path,
              });
              if (results.length >= max_results) break;
            }
          }
          if (results.length >= max_results) break;
        }
    
        return JSON.stringify(results);
      },
    };
  • src/index.ts:1-21 (registration)
    Server initialization and tool registration - imports searchDocsTool and adds it to the FastMCP server on line 15
    #!/usr/bin/env node
    
    import { FastMCP } from "fastmcp";
    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);
    server.addTool(searchDocsTool);
    server.addTool(getDocContentTool);
    server.addTool(getLlmFullContextTool);
    
    server.start({
      transportType: "stdio",
    });
  • Input parameter schema using zod - defines required 'query' string and optional 'max_results' number with default of 5
    parameters: z.object({
      query: z.string(),
      max_results: z.number().optional().default(5),
    }),
  • Helper function fetchDocContent() that retrieves document content from GitHub with caching support, used by search_docs to get document content for searching
    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;
      }
    }
  • Helper function initializeDocsStructure() that builds the DOCS_STRUCTURE from llm.txt on GitHub and manages the isInitialized flag, called by search_docs on first execution
    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