Godoctor MCP
No description available
Ask AI about Godoctor MCP
Powered by Claude · Grounded in docs
I know everything about Godoctor MCP. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
godoctor
godoctor is a command-line tool that provides information about Go source code. It is implemented as a Model Context Protocol (MCP) server, and it can be used with any MCP-compatible client.
Features
hello_world: A simple tool to check if the server is running.read_docs: A tool to retrieve documentation for Go packages and symbols, using thego doccommand.
For Users
Prerequisites
- Go 1.26.1 or later.
- An MCP-compatible client. This project includes a simple client that can be used to interact with the server.
Building
To build the server and the client, run the following commands from the root of the project:
go build -o ./bin/godoctor ./cmd/godoctor
go build -o ./bin/client ./cmd/client
This will create two executables in the bin directory: godoctor (the server) and client (the client).
Usage
The godoctor server is started automatically by the client.
To list the available tools:
./bin/client --list-tools
To call a tool:
./bin/client --call-tool <tool_name> [arguments...]
Examples:
-
Check if the server is running:
./bin/client --call-tool "hello_world" -
Get documentation for the
fmtpackage:./bin/client --call-tool "read_docs" "fmt" -
Get documentation for the
fmt.Printlnfunction:./bin/client --call-tool "read_docs" "fmt" "Println" -
Get documentation for a third-party package:
./bin/client --call-tool "read_docs" "github.com/modelcontextprotocol/go-sdk/mcp"
For Developers
Project Structure
cmd/godoctor: The main package for thegodoctorserver.cmd/client: The main package for the client.internal/tools/docs: A package that contains the implementation of theread_docstool.bin: The directory where the binaries are created.
MCP Server
The server is implemented using the github.com/modelcontextprotocol/go-sdk/mcp library. It uses the stdio transport to communicate with the client.
The server registers two tools: hello_world and read_docs. The read_docs tool is implemented in the internal/tools/docs package and uses the os/exec package to run the go doc command.
The server uses the generic mcp.AddTool function to register the tools. This function automatically generates the input and output schemas for the tools from Go structs.
Client
The client is also implemented using the github.com/modelcontextprotocol/go-sdk/mcp library. It uses the CommandTransport to start the godoctor server as a subprocess and communicates with it over stdio.
The client uses command-line flags to determine which action to perform: --list-tools or --call-tool.
When calling a tool, the client constructs a map[string]any to pass the arguments to the server. The server then automatically unmarshals the arguments into the corresponding Go struct for the tool.
The client parses the JSON output from the server to display the result of the tool call.
