Rethunk-Tech/mcp-golang
If you are the rightful owner of mcp-golang and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server that provides Go language tools for LLMs to analyze, test, and format Go code.
MCP Golang
A Model Context Protocol (MCP) server that provides Go language tools for LLMs to analyze, test, and format Go code.
What is MCP?
The Model Context Protocol (MCP) is a standardized way for applications to provide context to Large Language Models (LLMs). Learn more at the Model Context Protocol Website.
Features
- TypeScript implementation with strict type checking
- Full set of Go code analysis tools:
go_find_dead_code
: Find unused code in Go projectsgo_vet
: Run Go's static analyzergo_format
: Format Go codego_lint
: Run Go lintinggo_test
: Run Go testsgo_mod_tidy
: Clean up Go module dependencies
- Comprehensive error handling and validation
- Passes tool output directly to the LLM
Prerequisites
- Node.js 18 or later
- npm or yarn
- Go 1.18 or later
- The following Go tools installed:
golint
:go install golang.org/x/lint/golint@latest
deadcode
:go install github.com/remyoudompheng/go-misc/deadcode@latest
Project Structure
mcp-golang/
āāā build/ # Compiled JavaScript files
āāā cmd/ # Example Go code for testing
ā āāā example/ # Simple Go application
āāā src/
ā āāā __tests__/ # Integration tests and test utilities
ā āāā errors/ # Custom error classes
ā āāā tools/ # MCP tool implementations
ā ā āāā goTools.ts # Go tools for LLM
ā ā āāā noteTools.ts # Example note tools
ā āāā types/ # TypeScript type definitions
ā āāā index.ts # Main server entry point
āāā package.json # Project configuration
āāā tsconfig.json # TypeScript configuration
āāā README.md # Project documentation
Getting Started
-
Clone the repository:
git clone https://github.com/Rethunk-Tech/mcp-golang.git cd mcp-golang
-
Install dependencies:
yarn install
-
Build and run the server:
yarn build yarn start
Development
- Start TypeScript compiler in watch mode:
yarn dev
- Lint your code:
yarn lint
- Fix linting issues:
yarn lint:fix
- Run tests:
yarn test
Testing with MCP Inspector
For standalone testing, use the MCP Inspector tool:
yarn inspector
This will open an interactive session where you can test your MCP tools.
Available Go Tools
Find Dead Code
go_find_dead_code({
wd: "/path/to/go/project",
path: "./..."
})
Finds unused code in Go projects.
Parameter | Type | Description | Default |
---|---|---|---|
wd | string | Working directory where the command will be executed | (required) |
path | string | Path pattern to analyze (e.g., "./...", "./pkg/...", specific file) | "./..." |
Go Vet
go_vet({
wd: "/path/to/go/project",
path: "./..."
})
Runs Go's built-in static analyzer to find potential issues.
Parameter | Type | Description | Default |
---|---|---|---|
wd | string | Working directory where the command will be executed | (required) |
path | string | Path pattern to analyze (e.g., "./...", "./pkg/...", specific file) | "./..." |
Format Go Code
go_format({
wd: "/path/to/go/project",
path: "./...",
write: true
})
Formats Go code. Set write
to true to modify files directly.
Parameter | Type | Description | Default |
---|---|---|---|
wd | string | Working directory where the command will be executed | (required) |
path | string | Path pattern of files to format (e.g., "./...", "./pkg/...", specific file) | "./..." |
write | boolean | Whether to write changes directly to the source files (true) or just output the diff (false) | false |
Lint Go Code
go_lint({
wd: "/path/to/go/project",
path: "./..."
})
Runs the Go linter to check for style and potential issues.
Parameter | Type | Description | Default |
---|---|---|---|
wd | string | Working directory where the command will be executed | (required) |
path | string | Path pattern to lint (e.g., "./...", "./pkg/...", specific file) | "./..." |
Run Go Tests
go_test({
wd: "/path/to/go/project",
path: "./..."
})
Runs Go tests with verbose output.
Parameter | Type | Description | Default |
---|---|---|---|
wd | string | Working directory where the command will be executed | (required) |
path | string | Path pattern for tests to run (e.g., "./...", "./pkg/...", specific package) | "./..." |
Tidy Go Module Dependencies
go_mod_tidy({
wd: "/path/to/go/project"
})
Cleans up Go module dependencies.
Parameter | Type | Description | Default |
---|---|---|---|
wd | string | Working directory where the command will be executed (should contain go.mod file) | (required) |
Using with Cursor or Claude Desktop
To integrate this MCP server with Cursor or Claude Desktop, add the following configuration to your mcp.json
file:
{
"mcpServers": {
"mcp-golang": {
"command": "cmd",
"args": [
"/c",
"node C:\\path\\to\\mcp-golang\\build\\index.js"
],
"enabled": true
}
}
}
Make sure to replace C:\\path\\to\\mcp-golang
with the actual path to your installation, using double backslashes for Windows paths.
You can then access the tools in Cursor or Claude Desktop with the following names:
mcp_go_find_dead_code
mcp_go_vet
mcp_go_format
mcp_go_lint
mcp_go_test
mcp_go_mod_tidy
Contributing
See for guidelines on how to contribute to this project.
License
MIT