Check for empty host and port #79
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See Slack thread for background.
There was an issue reported where the
db_execute_queryMCP tool failed with the following error:Given that the part in backticks doesn't include a hostname or database name, and the port appears to be 5432 (the fallback value), I believe this likely indicates that the service host came back from the API as the empty/zero value (
"") and the port came back asnil, and we therefore built a connection string that looked something likepostgresql://tsdbadmin@:5432/tsdb?sslmode=require. As a result,pgxtried to connect to a local unix domain socket, and failed.This is similar to the error returned by
psqlwhen you try to use that same connection string:This PR updates the logic in
GetConnectionDetailsto check not just for anilhost, but also for an empty host (""), and return an error rather than trying to connect with the empty host. It also removes the fallback port logic, and instead validates that a non-zero port was provided. I don't believe there's realistically a case where we would fail to return a port in the "get service" response, and 5432 would just so happen to be the correct value to fall back to (but please correct me if I'm wrong about that).This doesn't resolve or explain the underlying error (an empty host/port coming back from the backend), but it should at least make the source of the error much clearer if/when it happens again in the future, which should give us a better footing to investigate deeper.