Skip to main content
Glama
vikramdse

Library Docs MCP Server

get_docs

Search documentation for Langchain, Llama-Index, MCP, and OpenAI libraries to find specific information using queries.

Instructions

Search the docs for a given query and library.
Supports langchain, llama-index, mcp, and openai.

Args:
    query: The query to search for (e.g. "Chroma DB")
    library: The library to search in (e.g. "langchain")

Returns:
    Text from the docs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
libraryYes

Implementation Reference

  • server.py:56-82 (handler)
    The main handler function for the 'get_docs' MCP tool. Decorated with @mcp.tool() for registration. Takes a query and library, constructs a site-specific search query, uses Serper API to find relevant docs pages, fetches their content using BeautifulSoup, and returns the concatenated text.
    @mcp.tool()
    async def get_docs(query: str, library: str):
        """
        Search the docs for a given query and library.
        Supports langchain, llama-index, mcp, and openai.
    
        Args:
            query: The query to search for (e.g. "Chroma DB")
            library: The library to search in (e.g. "langchain")
        
        Returns:
            Text from the docs
        """
        if library not in docs_urls:
            raise ValueError(f"Library {library} not supported by this tool")
    
        query = f"site:{docs_urls[library]} {query}" # Serper search format for searching in specified site
        results = await search_web(query)
    
        if len(results["organic"]) == 0:
            return "No results found"
        
        text = ""
        for result in results["organic"]:
            text += await fetch_url(result["link"])
        
        return text
  • Helper function to perform web search using Serper API for the given query, returning search results or empty on timeout.
    async def search_web(query: str) -> dict | None:
        payload = json.dumps({"q": query, "num": 2})
    
        headers = {
            "X-API-KEY": os.getenv("SERPER_API_KEY"),
            "Content-Type": "application/json"
        }
    
        async with httpx.AsyncClient() as client:
            try:
                response = await client.post(
                    SERPER_URL, headers=headers, data=payload, timeout=30.0
                )
                response.raise_for_status()
                return response.json()
            except httpx.TimeoutException:
                return {"organic": []}
  • Helper function to fetch content from a URL, parse with BeautifulSoup to extract text, handling timeouts.
    async def fetch_url(url: str):
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(url, timeout=30.0)
                soup = BeautifulSoup(response.text, "html.parser")
                text = soup.get_text()
                return text
            except httpx.TimeoutException:
                return "Timeout error"
  • Dictionary mapping supported libraries to their documentation base URLs, used to construct site-specific search queries.
    docs_urls = {
        "langchain": "python.langchain.com/docs",
        "llama-index": "docs.llamaindex.ai/en/stable",
        "mcp": "modelcontextprotocol.io",
        "openai": "platform.openai.com/docs"
    }
  • Tool schema and description provided in the docstring, defining input parameters (query: str, library: str) and output (text from docs).
    """
    Search the docs for a given query and library.
    Supports langchain, llama-index, mcp, and openai.
    
    Args:
        query: The query to search for (e.g. "Chroma DB")
        library: The library to search in (e.g. "langchain")
    
    Returns:
        Text from the docs
    """
Install Server

Other Tools

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/vikramdse/docs-mcp-server'

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