godoc

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2025 License: MIT Imports: 6 Imported by: 0

README

godoc-mcp

Overview

godoc-mcp is a server that provides information about Go project packages, types, functions, constants, and variables via the Multi-Command Protocol (MCP). It allows you to flexibly retrieve and utilize Go code documentation and structure from external tools.

Main Features

  • Retrieve a list of Go packages
  • List exported structs, functions, and methods in a package
  • Get detailed information about structs (fields, methods, comments)
  • Get detailed information about functions and methods (signature, comments, examples)
  • Get detailed information about constants and variables in a package

Installation

Go 1.24.2 or later is required.

make build

Usage

Start the Server
./godoc-mcp -root <root directory of your Go project>
  • Use the -root option to specify the root directory of the Go project to analyze.
  • If omitted, the current directory or the environment variable GODOC_MCP_ROOT_DIR will be used.
Using as an MCP Tool

You can use the following tools from an MCP client:

  • golang_list_packages: Get a list of packages and their comments
  • golang_inspect_package: List structs, functions, and methods in a package
  • golang_get_struct_doc: Get detailed information about a struct
  • golang_get_func_doc: Get detailed information about a function
  • golang_get_method_doc: Get detailed information about a struct method
  • golang_get_const_and_var_doc: Get detailed information about constants and variables
Example: mcp settings for Roo Code
{
  "mcpServers": {
    "godoc-mcp": {
      "type": "stdio",
      "command": "godoc-mcp",
      "env": {
        "GODOC_MCP_ROOT_DIR": "${env:HOME}/go/src/github.com/golang/tools/internal",
        "GOPATH": "${env:HOME}/go",
        "HOME": "${env:HOME}",
        "GOCACHE": "${env:HOME}/Library/Caches/go-build"
      },
    }
  }
}

Test

go test ./...

Dependencies

  • github.com/ktr0731/go-mcp
  • golang.org/x/exp/jsonrpc2
  • golang.org/x/tools

Environment Variables

  • GOPATH: Required by golang.org/x/tools/go/packages
  • GOCACHE: Required by golang.org/x/tools/go/packages
  • GODOC_MCP_ROOT_DIR: Root directory of the Go project to analyze

License

MIT License

Documentation

Overview

Code generated by mcp-codegen. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var (
	ToolGolangListPackagesInputSchema      = json.RawMessage(`{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"additionalProperties":false,"type":"object"}`)
	ToolGolangInspectPackageInputSchema    = json.RawMessage(`{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"package_name":{"type":"string","description":"Package name"},"include_comments":{"type":"boolean","description":"Whether to include comments","default":true}},"additionalProperties":false,"type":"object","required":["package_name"]}`)
	ToolGolangGetStructDocInputSchema      = json.RawMessage(`{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"package_name":{"type":"string","description":"Package name where the struct is defined"},"struct_name":{"type":"string","description":"Name of the struct"}},"additionalProperties":false,"type":"object","required":["package_name","struct_name"]}`)
	ToolGolangGetFuncDocInputSchema        = json.RawMessage(`{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"package_name":{"type":"string","description":"Package name where the function is defined"},"func_name":{"type":"string","description":"Name of the function"}},"additionalProperties":false,"type":"object","required":["package_name","func_name"]}`)
	ToolGolangGetMethodDocInputSchema      = json.RawMessage(`{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"package_name":{"type":"string","description":"Package name where the method is defined"},"struct_name":{"type":"string","description":"Name of the struct that owns the method"},"method_name":{"type":"string","description":"Name of the method"}},"additionalProperties":false,"type":"object","required":["package_name","struct_name","method_name"]}`)
	ToolGolangGetConstAndVarDocInputSchema = json.RawMessage(`{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"package_name":{"type":"string","description":"Package name"}},"additionalProperties":false,"type":"object","required":["package_name"]}`)
)

JSON Schema type definitions generated from inputSchema

View Source
var PromptList = []protocol.Prompt{}

PromptList contains all available prompts.

View Source
var ToolList = []protocol.Tool{
	{
		Name:        "golang_list_packages",
		Description: "Display a list of Go packages and their package comments. You can check the description and purpose of each package.",
		InputSchema: ToolGolangListPackagesInputSchema,
	},
	{
		Name:        "golang_inspect_package",
		Description: "List publicly available structs, methods, and functions in the specified Go package. You can check comments for each element.",
		InputSchema: ToolGolangInspectPackageInputSchema,
	},
	{
		Name:        "golang_get_struct_doc",
		Description: "Display detailed information about the specified Go struct. You can check the struct's comments, fields, methods, and their comments.",
		InputSchema: ToolGolangGetStructDocInputSchema,
	},
	{
		Name:        "golang_get_func_doc",
		Description: "Display detailed information about the specified Go function. You can check the function's signature, comments, and usage examples.",
		InputSchema: ToolGolangGetFuncDocInputSchema,
	},
	{
		Name:        "golang_get_method_doc",
		Description: "Display detailed information about the specified Go struct method. You can check the method's signature, comments, and usage examples.",
		InputSchema: ToolGolangGetMethodDocInputSchema,
	},
	{
		Name:        "golang_get_const_and_var_doc",
		Description: "Display detailed information about constants and variables in the specified Go package. You can check the type, value, and comments for each constant and variable.",
		InputSchema: ToolGolangGetConstAndVarDocInputSchema,
	},
}

ToolList contains all available tools.

Functions

func NewHandler

func NewHandler(toolHandler ServerToolHandler) *mcp.Handler

NewHandler creates a new MCP handler.

Types

type ServerPromptHandler

type ServerPromptHandler interface {
}

ServerPromptHandler is the interface for prompt handlers.

type ServerToolHandler

type ServerToolHandler interface {
	HandleToolGolangListPackages(ctx context.Context, req *ToolGolangListPackagesRequest) (*mcp.CallToolResult, error)
	HandleToolGolangInspectPackage(ctx context.Context, req *ToolGolangInspectPackageRequest) (*mcp.CallToolResult, error)
	HandleToolGolangGetStructDoc(ctx context.Context, req *ToolGolangGetStructDocRequest) (*mcp.CallToolResult, error)
	HandleToolGolangGetFuncDoc(ctx context.Context, req *ToolGolangGetFuncDocRequest) (*mcp.CallToolResult, error)
	HandleToolGolangGetMethodDoc(ctx context.Context, req *ToolGolangGetMethodDocRequest) (*mcp.CallToolResult, error)
	HandleToolGolangGetConstAndVarDoc(ctx context.Context, req *ToolGolangGetConstAndVarDocRequest) (*mcp.CallToolResult, error)
}

ServerToolHandler is the interface for tool handlers.

type ToolGolangGetConstAndVarDocRequest

type ToolGolangGetConstAndVarDocRequest struct {
	PackageName string `json:"package_name"`
}

ToolGolangGetConstAndVarDocRequest contains input parameters for the golang_get_const_and_var_doc tool.

type ToolGolangGetFuncDocRequest

type ToolGolangGetFuncDocRequest struct {
	PackageName string `json:"package_name"`
	FuncName    string `json:"func_name"`
}

ToolGolangGetFuncDocRequest contains input parameters for the golang_get_func_doc tool.

type ToolGolangGetMethodDocRequest

type ToolGolangGetMethodDocRequest struct {
	PackageName string `json:"package_name"`
	StructName  string `json:"struct_name"`
	MethodName  string `json:"method_name"`
}

ToolGolangGetMethodDocRequest contains input parameters for the golang_get_method_doc tool.

type ToolGolangGetStructDocRequest

type ToolGolangGetStructDocRequest struct {
	PackageName string `json:"package_name"`
	StructName  string `json:"struct_name"`
}

ToolGolangGetStructDocRequest contains input parameters for the golang_get_struct_doc tool.

type ToolGolangInspectPackageRequest

type ToolGolangInspectPackageRequest struct {
	PackageName     string `json:"package_name"`
	IncludeComments bool   `json:"include_comments,omitempty"`
}

ToolGolangInspectPackageRequest contains input parameters for the golang_inspect_package tool.

type ToolGolangListPackagesRequest

type ToolGolangListPackagesRequest struct {
}

ToolGolangListPackagesRequest contains input parameters for the golang_list_packages tool.

Directories

Path Synopsis
cmd
mcpgen command
server command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL