gopls version

0.0.0

go env

N/A

What did you do?

Run gopls mcp -listen ADDRESS or gopls mcp

What did you see happen?

N/A

What did you expect to see?

Some MCP client surface the error from STDERR to the user, this may seems confusing. Instead, in non-go workspace, the gopls mcp server should be quiet.

The error is reported from Go see source

In addition, when launching gopls mcp server in non-go workspace, it takes a few seconds for the server to start serving mcp request either for stdio or sse.

Editor and settings

No response

Logs

2025/07/11 14:31:48 Error:2025/07/11 14:31:48 go/packages.Load #1: err: exit status 2: stderr: panic: LoadImport called with empty package path [recovered, repanicked]

goroutine 1 [running]:
cmd/go/internal/load.(*preload).flush(0x140002582b0)
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:1122 +0x80
panic({0x100727640?, 0x10080dd90?})
        /GOPATH/go/src/runtime/panic.go:783 +0x120
cmd/go/internal/load.loadImport({0x100817070, 0x100c408e0}, {0x0, 0x1, 0x0, 0x1, 0x1, 0x0}, 0x0, {0x107ba69a9, ...}, ...)
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:711 +0x100c
cmd/go/internal/load.(*Package).load(0x140006b0608, {0x100817070, 0x100c408e0}, {0x0, 0x1, 0x0, 0x1, 0x1, 0x0}, {0x140000c1460, ...}, ...)
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:2029 +0x1d50
cmd/go/internal/load.loadImport({0x100817070, 0x100c408e0}, {0x0, 0x1, 0x0, 0x1, 0x1, 0x0}, 0x140002582b0, {0x140000c1460, ...}, ...)
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:774 +0x3d8
cmd/go/internal/load.PackagesAndErrors({0x100817070?, 0x100c408e0?}, {0x0, 0x1, 0x0, 0x1, 0x1, 0x0}, {0x140001343f0, 0x2, ...})
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:2955 +0x714
cmd/go/internal/list.runList({0x100817070, 0x100c408e0}, 0x14000132858?, {0x140001343f0, 0x2, 0x2})
        /GOPATH/go/src/cmd/go/internal/list/list.go:616 +0xbdc
main.invoke(0x100c09b80, {0x14000134350, 0xc, 0xc})
        /GOPATH/go/src/cmd/go/main.go:341 +0x63c
main.main()
        /GOPATH/go/src/cmd/go/main.go:220 +0xd58

        view_id="1"
        snapshot=0
        directory=/GOPATH/python-workspace
        query=[/Users/hxjiang/... builtin]
        packages=0
        duration=36.535622333s
2025/07/11 14:31:48 Error:2025/07/11 14:31:48 initial workspace load failed: packages.Load error: err: exit status 2: stderr: panic: LoadImport called with empty package path [recovered, repanicked]

goroutine 1 [running]:
cmd/go/internal/load.(*preload).flush(0x140002582b0)
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:1122 +0x80
panic({0x100727640?, 0x10080dd90?})
        /GOPATH/go/src/runtime/panic.go:783 +0x120
cmd/go/internal/load.loadImport({0x100817070, 0x100c408e0}, {0x0, 0x1, 0x0, 0x1, 0x1, 0x0}, 0x0, {0x107ba69a9, ...}, ...)
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:711 +0x100c
cmd/go/internal/load.(*Package).load(0x140006b0608, {0x100817070, 0x100c408e0}, {0x0, 0x1, 0x0, 0x1, 0x1, 0x0}, {0x140000c1460, ...}, ...)
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:2029 +0x1d50
cmd/go/internal/load.loadImport({0x100817070, 0x100c408e0}, {0x0, 0x1, 0x0, 0x1, 0x1, 0x0}, 0x140002582b0, {0x140000c1460, ...}, ...)
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:774 +0x3d8
cmd/go/internal/load.PackagesAndErrors({0x100817070?, 0x100c408e0?}, {0x0, 0x1, 0x0, 0x1, 0x1, 0x0}, {0x140001343f0, 0x2, ...})
        /GOPATH/go/src/cmd/go/internal/load/pkg.go:2955 +0x714
cmd/go/internal/list.runList({0x100817070, 0x100c408e0}, 0x14000132858?, {0x140001343f0, 0x2, 0x2})
        /GOPATH/go/src/cmd/go/internal/list/list.go:616 +0xbdc
main.invoke(0x100c09b80, {0x14000134350, 0xc, 0xc})
        /GOPATH/go/src/cmd/go/main.go:341 +0x63c
main.main()
        /GOPATH/go/src/cmd/go/main.go:220 +0xd58

2025/07/11 14:31:48 Listening for MCP messages on stdin...

Comment From: h9jiang

Sorry for the noisy. This is not a problem with gopls. Instead is a problem with my local setup.

I have a go.mod, go.sum in the parent dir of the python workspace. And gopls find that module and think that is the root of the module. :D

Instead, this may be an issue with Go command. I will keep looking and find the exact command being executed.

cc @findleyr sorry for the confusion, it's not a problem for gopls.

Comment From: findleyr

@h9jiang it does seem like an issue with gopls, which generally should not crash!

However, given the setup, it's probably a lot less likely than we originally thought.