A Model Context Protocol (MCP) server that provides Go language tools for LLMs to analyze, test, and format Go code.
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.
- 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
- 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
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
-
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
- Start TypeScript compiler in watch mode:
yarn dev
- Lint your code:
yarn lint
- Fix linting issues:
yarn lint:fix
- Run tests:
yarn test
For standalone testing, use the MCP Inspector tool:
yarn inspector
This will open an interactive session where you can test your MCP tools.
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({ 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) | "./..." |
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 |
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) | "./..." |
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) | "./..." |
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) |
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
See CONTRIBUTING.md for guidelines on how to contribute to this project.
MIT