MCP HubMCP Hub
mrjoshuak

godoc-mcp

by: mrjoshuak

go doc mcp server

42created 05/12/2024
Visit
Go
documentation

📌Overview

Purpose: godoc-mcp aims to enhance the efficiency of accessing Go documentation for large language models (LLMs), enabling better comprehension of Go projects.

Overview: godoc-mcp is a Model Context Protocol server designed to streamline the way LLMs access Go documentation. By providing targeted documentation retrieval, it eliminates the need for LLMs to read extensive source files, significantly improving performance and reducing token usage during Go development.

Key Features:

  • Efficient Documentation Access: Facilitates rapid retrieval of official Go documentation while minimizing token usage.

  • Smart Package Discovery: Automatically identifies Go packages in directories lacking source files, aiding in project navigation.

  • Flexible Path Support: Supports both local file paths and import paths, enabling versatile access to documentation.

  • Automatic Module Context: Seamlessly creates temporary Go projects and manages module context without manual setup.

  • Module-Aware: Capable of documenting third-party packages based on the current working directory context.

  • Performance Optimized: Utilizes built-in caching and focused token usage to enhance response efficiency and minimize payload sizes.


godoc-mcp

Overview

godoc-mcp is a Model Context Protocol (MCP) server that provides efficient access to Go documentation. It helps LLMs understand Go projects by providing direct access to package documentation without needing to read entire source files. godoc-mcp can vastly improve the performance of using LLMs to develop in Go by substantially reducing the number of tokens needed to understand and make use of Go packages.

Getting Started

go install github.com/mrjoshuak/godoc-mcp@latest

Why Use godoc-mcp?

In a sentence: godoc-mcp provides a more token efficient way for LLMs to understand Go projects.

Traditional file-reading approaches require LLMs to process entire source files, often many files, to understand a single package. godoc-mcp provides several advantages:

  1. Token Efficiency: Returns only the essential documentation, reducing token usage significantly
  2. Structured Information: Provides official package documentation in a consistent, well-structured format
  3. Project Navigation: Smart handling of project structures helps LLMs understand multi-package projects
  4. Integration Ready: Works alongside other MCP servers, enabling both high-level and detailed code analysis
  5. Performance: Caching and optimized token usage make godoc-mcp a fast and efficient tool for Go development
  6. Local: Does not require an internet connection to access documentation

Levels of detail available to an LLM:

  • Documentation for one exported symbol
  • The complete source for one symbol
  • A list of all exported symbols (concise documentation)
  • A list of all symbols including unexported symbols
  • The full documentation for a package
  • The entire source for a package

This makes godoc-mcp an essential tool for Go developers using LLMs by enabling them to understand significantly more, and in more detail, about the context than previously possible.

Features

  • Returns package documentation for directories containing Go files
  • Lists available Go packages in subdirectories for directories without Go files
  • Returns standard library or third-party package documentation for import paths
  • Efficient documentation access with minimal token usage
  • Smart package discovery for directories without Go files
  • Supports local file paths and import paths
  • Creates temporary Go projects and sets up module context automatically for external packages
  • No manual module setup required; handles cleanup of temporary projects
  • Supports third-party package documentation by running go doc from the working directory
  • Performance optimized with response caching and efficient token usage
  • Provides metadata about response sizes
  • Smart handling of standard library vs external packages

Examples

Project Understanding

"I'm looking at a Go project at /path/to/some/project. What packages does it contain and what do they do?"

Package Interface Understanding

"What interfaces does the io package provide? I'm particularly interested in anything related to reading."

Implementation Guidance

"I need to implement the io.Reader interface. Show me its documentation and any related types I should know about."

API Usage

"Show me the documentation for the Resource type in the /path/to/some/project. I need to understand how to create and use it."

Library Exploration

"I'm in /path/to/some/project which uses github.com/gorilla/mux. Show me the documentation for the Router type."

Method Discovery

"What methods are available on the http.Request type? I'm working with standard library HTTP handlers."

Focused Learning

"Explain how to configure the Server type in the /path/to/project/server package."

Package Browsing

"I'm in a new Go project directory and see multiple packages. Can you show me what each one does?"

Usage

To add to the Claude desktop app:

{
  "mcpServers": {
    # other MCP servers ...
    "godoc": {
      "command": "/path/to/godoc-mcp",
      "args": [],
      "env": {
        "GOPATH": "/path/to/go",
        "GOMODCACHE": "/path/to/go/pkg/mod"
      }
    }
  }
}

When connected to an MCP-capable LLM (like Claude), godoc-mcp provides the get_doc tool with the following parameters:

  • path: Path to the Go package or file (import path or file path)
  • target (optional): Specific symbol to document (function, type, etc.)
  • cmd_flags (optional): Additional go doc command flags
  • working_dir (optional): Working directory for module-aware documentation (if not provided, a temporary project will be created automatically)

Advanced cmd_flags values an LLM can leverage:

  • -all: Show all documentation for package, excluding unexported symbols
  • -u: Show unexported symbols
  • -src: Show the source code instead of documentation

Troubleshooting

  • For local paths, ensure they contain Go source files or point to directories containing Go packages
  • If you see module-related errors, ensure GOPATH and GOMODCACHE environment variables are set correctly in your MCP server configuration
  • The server automatically handles module context for external packages, but you can still provide a specific working_dir if needed for special cases

License

This project is licensed under the MIT License.