Skip to main content
Glama
aserper

RTFD (Read The F*****g Docs)

by aserper

fetch_npm_docs

Retrieve npm package documentation directly from registry README files to access installation instructions, usage examples, and API references for JavaScript/Node.js packages.

Instructions

        Fetch actual npm package documentation from npm registry README.

        USE THIS WHEN: You need installation instructions, usage examples, API reference, or quickstart guides.

        BEST FOR: Getting complete, formatted documentation for JavaScript/Node.js packages.
        Better than using curl or WebFetch because it:
        - Automatically extracts relevant sections (Installation, Usage, Examples, API)
        - Prioritizes most useful content sections
        - Already in Markdown format (npm requires Markdown READMEs)

        NOT SUITABLE FOR: External documentation sites (use docs_url from npm_metadata + WebFetch)

        Args:
            package: npm package name (e.g., "express", "react", "axios")
            max_bytes: Maximum content size, default 20KB (increase for large packages)

        Returns:
            JSON with actual documentation content, size, truncation status, version

        Example: fetch_npm_docs("express") → Returns formatted README with installation and usage
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageYes
max_bytesNo

Implementation Reference

  • The main handler function for the 'fetch_npm_docs' MCP tool. It invokes the internal helper and serializes the result into CallToolResult format.
    async def fetch_npm_docs(package: str, max_bytes: int = 20480) -> CallToolResult:
        """
        Fetch actual npm package documentation from npm registry README.
    
        USE THIS WHEN: You need installation instructions, usage examples, API reference, or quickstart guides.
    
        BEST FOR: Getting complete, formatted documentation for JavaScript/Node.js packages.
        Better than using curl or WebFetch because it:
        - Automatically extracts relevant sections (Installation, Usage, Examples, API)
        - Prioritizes most useful content sections
        - Already in Markdown format (npm requires Markdown READMEs)
    
        NOT SUITABLE FOR: External documentation sites (use docs_url from npm_metadata + WebFetch)
    
        Args:
            package: npm package name (e.g., "express", "react", "axios")
            max_bytes: Maximum content size, default 20KB (increase for large packages)
    
        Returns:
            JSON with actual documentation content, size, truncation status, version
    
        Example: fetch_npm_docs("express") → Returns formatted README with installation and usage
        """
        result = await self._fetch_npm_docs(package, max_bytes)
        return serialize_response_with_meta(result)
  • Internal helper method containing the core logic to fetch npm registry data, process README content, extract/prioritize sections, truncate if necessary, and handle errors.
    async def _fetch_npm_docs(self, package: str, max_bytes: int = 20480) -> dict[str, Any]:
        """
        Fetch documentation content for npm package.
    
        Args:
            package: Package name
            max_bytes: Maximum content size in bytes
    
        Returns:
            Dict with content, size, source info
        """
        try:
            url = f"https://registry.npmjs.org/{package}"
    
            async with await self._http_client() as client:
                resp = await client.get(url)
                resp.raise_for_status()
                data = resp.json()
    
            # npm registry includes README in "readme" field (already Markdown)
            content = data.get("readme", "")
    
            # If no README or very short, note it
            source = "npm"
            if not content or len(content.strip()) < 100:
                content = (
                    f"# {package}\n\n{data.get('description', 'No description available.')}\n\n"
                )
                source = "npm_minimal"
    
            # Extract and prioritize sections
            sections = extract_sections(content)
            if sections:
                final_content = prioritize_sections(sections, max_bytes)
            # Fallback: simple truncation
            elif len(content.encode("utf-8")) > max_bytes:
                encoded = content.encode("utf-8")[:max_bytes]
                # Handle multi-byte characters
                while len(encoded) > 0:
                    try:
                        final_content = encoded.decode("utf-8")
                        break
                    except UnicodeDecodeError:
                        encoded = encoded[:-1]
            else:
                final_content = content
    
            return {
                "package": package,
                "content": final_content,
                "size_bytes": len(final_content.encode("utf-8")),
                "source": source,
                "truncated": len(content.encode("utf-8")) > max_bytes,
                "version": data.get("version"),
            }
    
        except httpx.HTTPStatusError as exc:
            return {
                "package": package,
                "content": "",
                "error": f"npm registry returned {exc.response.status_code}",
                "size_bytes": 0,
                "source": None,
            }
        except Exception as exc:
            return {
                "package": package,
                "content": "",
                "error": f"Failed to fetch docs: {exc!s}",
                "size_bytes": 0,
                "source": None,
            }
  • Provider metadata declaration that conditionally includes 'fetch_npm_docs' in the list of available tools.
    def get_metadata(self) -> ProviderMetadata:
        tool_names = ["npm_metadata"]
        if is_fetch_enabled():
            tool_names.append("fetch_npm_docs")
    
        return ProviderMetadata(
            name="npm",
            description="npm package registry metadata and documentation",
            expose_as_tool=True,
            tool_names=tool_names,
            supports_library_search=True,
            required_env_vars=[],
            optional_env_vars=[],
        )
  • Registration of the 'fetch_npm_docs' function in the tools dictionary returned by get_tools() method for MCP integration.
    tools = {"npm_metadata": npm_metadata}
    if is_fetch_enabled():
        tools["fetch_npm_docs"] = fetch_npm_docs
    
    return 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/aserper/RTFD'

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