An MCP (Model Context Protocol) server specialized for Go codebases. It provides structural code search capabilities for AI agents by combining:
- Local AST Analysis: Parses local Go files to find function, struct, and interface definitions.
- Gopls Integration: Queries the Go Language Server (
gopls) to search across your dependencies and the Go standard library. - Hybrid Ranking: Intelligently ranks results, prioritizing your business logic over library code.
- On non Go code it is performing fuzzy filename search.
- Go 1.22+
gopls(for dependency search):go install golang.org/x/tools/gopls@latest
go install github.com/akhenakh/codemcp@latest
# Be sure your GOPATH/bin is in your PATHYou can run codemcp directly in your terminal to find code.
# Search for "auth" in the current directory, it will look for auth in the code and in the dependencies (if it's a Go module)
codemcp "auth"You can point it to a different path.
codemcp -path ../myrepo "authorize"
Output Example:
🔎 Searching 'json unmarshal' in /home/user/myproject
🚀 Gopls enabled (searching dependencies)
⏱️ Found 5 files in 45ms
SCORE | REASON | FILE
----------------------------------------------------------------------------------------------------
105 | func:Unmarshal | encoding.go
80 | gopls:Unmarshal | [DEP] /usr/lib/go/src/encoding/json/decode.go
65 | func:Decode | [DEP] /usr/lib/go/src/encoding/json/stream.go
When run without arguments, it starts the MCP server over stdio. It should work with any agents.
Add the following to your agent configuration (e.g., .vibe/config.toml):
enabled_tools = ["bash", "grep", "read_file", "write_file", "todo", "search_replace", "codemcp_*"]
[[mcp_servers]]
name = "codemcp"
transport = "stdio"
command = "codemcp"
prompt = """
Use codemcp whenever the user asks to search for specific code patterns, definitions, or symbols.
It is much smarter than grep because it understands Go structure and can search dependencies.
"""The server exposes the following tools:
-
search_files:- Arguments:
query(string). - Description: "Search codebase and dependencies. Uses AST for local files and Gopls for dependencies/symbols. Always use this before read_file."
- Arguments:
-
read_file:- Arguments:
path(string). - Description: "Read the full content of a file. This tool is restricted to files within the project root, the Go Module Cache, or the Go Standard Library. Use this to read files found via search_files."
- Arguments:
- Tokenization: Splits CamelCase queries (e.g., "UserLogin" -> "user", "login").
- Local Scan:
- Uses
git ls-filesfor speed. - Parses
.gofiles usinggo/parser(AST). - Boosts score if query matches a
func,type, orinterfacename.
- Uses
- Dependency Scan:
- Spawns
goplsin the background. - Sends LSP
workspace/symbolrequests. - Filters out noise (test files, internal vendor folders).
- Applies a small penalty to dependencies so your local code ranks higher.
- Spawns