Skip to main content
Glama
aserper

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

by aserper

fetch_godocs_docs

Retrieve Go package documentation from godocs.io to access function signatures, type definitions, and API references for development tasks.

Instructions

        Fetch actual Go package documentation from godocs.io.

        USE THIS WHEN: You need package overview, function signatures, type definitions, or API reference.

        BEST FOR: Getting complete documentation for Go packages.
        Better than using curl or WebFetch because it:
        - Extracts package overview and descriptions
        - Includes function and type documentation
        - Formats content in readable text format
        - Limits output to avoid overwhelming context

        NOT SUITABLE FOR: Source code (use GitHub provider for that)

        Args:
            package: Go package path (e.g., "github.com/gin-gonic/gin", "golang.org/x/sync")
            max_bytes: Maximum content size, default 20KB (increase for large packages)

        Returns:
            JSON with documentation content, size, truncation status, and source info

        Example: fetch_godocs_docs("github.com/gin-gonic/gin") → Returns overview and API docs
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageYes
max_bytesNo

Implementation Reference

  • The primary MCP tool handler for 'fetch_godocs_docs'. It invokes the internal scraper and serializes the result into CallToolResult format.
    async def fetch_godocs_docs(package: str, max_bytes: int = 20480) -> CallToolResult:
        """
        Fetch actual Go package documentation from godocs.io.
    
        USE THIS WHEN: You need package overview, function signatures, type definitions, or API reference.
    
        BEST FOR: Getting complete documentation for Go packages.
        Better than using curl or WebFetch because it:
        - Extracts package overview and descriptions
        - Includes function and type documentation
        - Formats content in readable text format
        - Limits output to avoid overwhelming context
    
        NOT SUITABLE FOR: Source code (use GitHub provider for that)
    
        Args:
            package: Go package path (e.g., "github.com/gin-gonic/gin", "golang.org/x/sync")
            max_bytes: Maximum content size, default 20KB (increase for large packages)
    
        Returns:
            JSON with documentation content, size, truncation status, and source info
    
        Example: fetch_godocs_docs("github.com/gin-gonic/gin") → Returns overview and API docs
        """
        result = await self._fetch_godocs_docs(package, max_bytes)
        return serialize_response_with_meta(result)
  • Core implementation logic for fetching, parsing, extracting, and truncating Go package documentation from godocs.io.
    async def _fetch_godocs_docs(self, package: str, max_bytes: int = 20480) -> dict[str, Any]:
        """
        Fetch full documentation content for a Go package from godocs.io.
    
        Args:
            package: Package name (e.g., 'github.com/user/repo')
            max_bytes: Maximum content size in bytes
    
        Returns:
            Dict with content, size, source, etc.
        """
        try:
            # Handle full URLs or just package paths
            if package.startswith("https://godocs.io/"):
                package = package.replace("https://godocs.io/", "")
    
            url = f"https://godocs.io/{package}"
            headers = {"User-Agent": "curl/7.68.0"}
    
            async with await self._http_client() as client:
                resp = await client.get(url, headers=headers)
                resp.raise_for_status()
                soup = BeautifulSoup(resp.text, "html.parser")
    
            # Extract comprehensive documentation content
            content_parts = []
    
            # 1. Get package overview/description
            overview_header = soup.find(["h2", "h3"], {"id": "pkg-overview"})
            if overview_header:
                for sibling in overview_header.find_next_siblings():
                    if sibling.name in ("h2", "h3"):
                        break
                    if sibling.name in ("p", "pre"):
                        text = sibling.get_text(strip=True)
                        if text and not text.startswith('import "'):
                            content_parts.append(text)
    
            # 2. Get function/type documentation (first few entries)
            # Look for main content section
            main_content = soup.find("div", class_=["container", "main"])
            if not main_content:
                main_content = soup.find("div", id="main")
    
            if main_content:
                # Extract text content, limit to avoid huge outputs
                text_content = main_content.get_text(separator="\n", strip=True)
                # Clean up excessive whitespace
                lines = [line.strip() for line in text_content.split("\n") if line.strip()]
                content_parts.extend(lines[:50])  # Limit to 50 lines of main content
    
            # Combine and truncate
            full_content = "\n".join(content_parts)
    
            # Encode and truncate if necessary
            content_bytes = full_content.encode("utf-8")
            if len(content_bytes) > max_bytes:
                full_content = full_content[:max_bytes]
                truncated = True
            else:
                truncated = False
    
            return {
                "package": package,
                "content": full_content,
                "size_bytes": len(full_content.encode("utf-8")),
                "source": "godocs",
                "truncated": truncated,
            }
    
        except httpx.HTTPStatusError as exc:
            if exc.response.status_code == 404:
                return {
                    "package": package,
                    "content": "",
                    "error": "Package not found on GoDocs",
                    "size_bytes": 0,
                    "source": None,
                }
            return {
                "package": package,
                "content": "",
                "error": f"GoDocs returned {exc.response.status_code}",
                "size_bytes": 0,
                "source": None,
            }
        except httpx.HTTPError as exc:
            return {
                "package": package,
                "content": "",
                "error": f"GoDocs request failed: {exc}",
                "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,
            }
  • The get_tools method registers the fetch_godocs_docs tool conditionally in the tools dictionary for MCP.
    def get_tools(self) -> dict[str, Callable]:
        """Return MCP tool functions."""
    
        async def godocs_metadata(package: str) -> CallToolResult:
            """
            Get Go package metadata from godocs.io (name, summary, URLs).
    
            USE THIS WHEN: You need basic package info or links to documentation sites.
    
            RETURNS: Package metadata ONLY - does NOT include actual documentation content.
            For full documentation, use fetch_godocs_docs instead.
    
            The response includes:
            - Package name and summary/description
            - godocs.io URL
            - pkg.go.dev source URL
    
            Args:
                package: Go package path (e.g., "github.com/gin-gonic/gin", "golang.org/x/tools")
    
            Example: godocs_metadata("github.com/gin-gonic/gin") → Returns metadata with summary
            """
            result = await self._fetch_metadata(package)
            return serialize_response_with_meta(result)
    
        async def fetch_godocs_docs(package: str, max_bytes: int = 20480) -> CallToolResult:
            """
            Fetch actual Go package documentation from godocs.io.
    
            USE THIS WHEN: You need package overview, function signatures, type definitions, or API reference.
    
            BEST FOR: Getting complete documentation for Go packages.
            Better than using curl or WebFetch because it:
            - Extracts package overview and descriptions
            - Includes function and type documentation
            - Formats content in readable text format
            - Limits output to avoid overwhelming context
    
            NOT SUITABLE FOR: Source code (use GitHub provider for that)
    
            Args:
                package: Go package path (e.g., "github.com/gin-gonic/gin", "golang.org/x/sync")
                max_bytes: Maximum content size, default 20KB (increase for large packages)
    
            Returns:
                JSON with documentation content, size, truncation status, and source info
    
            Example: fetch_godocs_docs("github.com/gin-gonic/gin") → Returns overview and API docs
            """
            result = await self._fetch_godocs_docs(package, max_bytes)
            return serialize_response_with_meta(result)
    
        tools = {"godocs_metadata": godocs_metadata}
        if is_fetch_enabled():
            tools["fetch_godocs_docs"] = fetch_godocs_docs
    
        return tools
  • The get_metadata method conditionally includes 'fetch_godocs_docs' in the provider's tool_names list.
    def get_metadata(self) -> ProviderMetadata:
        tool_names = ["godocs_metadata"]
        if is_fetch_enabled():
            tool_names.append("fetch_godocs_docs")
    
        return ProviderMetadata(
            name="godocs",
            description="GoDocs package documentation metadata",
            expose_as_tool=True,
            tool_names=tool_names,
            supports_library_search=True,
            required_env_vars=[],
            optional_env_vars=[],
        )

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