Description of the bug
When the OpenCode server is deployed on a remote server protected by HTTP basic authentication, the MCP server fails to connect to it. The isServerRunning() function makes an unauthenticated GET request to the /global/health endpoint, which returns a 401 Unauthorized status. This causes the function to incorrectly report the server as unhealthy or not running, even when it is operational.
To Reproduce
Steps to reproduce the behavior:
- Run an OpenCode server on a remote host with HTTP basic authentication enabled.
OPENCODE_SERVER_PASSWORD=secret opencode serve --hostname 0.0.0.0 --port 4096
- run opencode-mcp from another host
OPENCODE_BASE_URL="http://X.X.X.X:4096" \
OPENCODE_SERVER_USERNAME="opencode" \
OPENCODE_SERVER_PASSWORD="secret" \
OPENCODE_AUTO_SERVE="false" \
opencode-mcp
- It is not connecting to opencode and print message:
Warning: OpenCode server is not running at http://X.X.X.X:4096 and OPENCODE_AUTO_SERVE=false.
Start it manually: opencode serve
opencode-mcp v1.9.0 started (OpenCode server at http://X.X.X.X:4096)
Expected behavior
The OpenCode client should successfully connect to a remote OpenCode server protected by basic authentication. The health check should include the appropriate Authorization: Basic <credentials> header when credentials are provided via environment variables.
Additional context
The issue affects the entire connection flow:
- Initial health check in
ensureServer()
- Server status polling in
waitForHealthy()
- Client reconnection logic in
OpenCodeClient.request()
The fix has been implemented in Pull Request #3 . Changes include:
- Modifying
isServerRunning() to accept optional username and password parameters
- Adding authorization headers to health check requests when credentials are provided
- Propagating auth parameters through
ensureServer(), waitForHealthy(), and client reconnection logic
- Maintaining backward compatibility for servers without authentication
Linked Pull Request: #3
Description of the bug
When the OpenCode server is deployed on a remote server protected by HTTP basic authentication, the MCP server fails to connect to it. The
isServerRunning()function makes an unauthenticated GET request to the/global/healthendpoint, which returns a 401 Unauthorized status. This causes the function to incorrectly report the server as unhealthy or not running, even when it is operational.To Reproduce
Steps to reproduce the behavior:
Expected behavior
The OpenCode client should successfully connect to a remote OpenCode server protected by basic authentication. The health check should include the appropriate
Authorization: Basic <credentials>header when credentials are provided via environment variables.Additional context
The issue affects the entire connection flow:
ensureServer()waitForHealthy()OpenCodeClient.request()The fix has been implemented in Pull Request #3 . Changes include:
isServerRunning()to accept optionalusernameandpasswordparametersensureServer(),waitForHealthy(), and client reconnection logicLinked Pull Request: #3