Add support for multiple database connections with descriptions#114
Open
andre-c-andersen wants to merge 8 commits intocrystaldba:mainfrom
Open
Add support for multiple database connections with descriptions#114andre-c-andersen wants to merge 8 commits intocrystaldba:mainfrom
andre-c-andersen wants to merge 8 commits intocrystaldba:mainfrom
Conversation
- Add DATABASE_URI_* env vars for multiple connections (e.g., DATABASE_URI_APP → "app") - Add DATABASE_DESC_* env vars for connection descriptions visible to AI - Update all tools to accept required conn_name parameter - Add ConnectionRegistry to manage multiple connection pools - Display available connections in server context - Update tests for new connection architecture
The psycopg AsyncConnectionPool automatically handles connection recovery by discarding broken connections and creating new ones. Manual invalidation during query execution is redundant and can cause misleading error messages for SQL errors (missing columns, tables, etc.). The _is_valid flag should only be managed during pool lifecycle events (creation in pool_connect() and closure in close()), not during normal query execution.
This avoids sneaking the instructions via private variables. (It was even done incorrectly, in my earlier implementation.)
Enables the application to connect to multiple databases using the `--db` command-line argument. Validates the database connection names and URLs. Supports setting database connections via environment variables, with environment variables taking precedence over command-line arguments. For backwards compatibility, continues to support a default `DATABASE_URI` from a positional argument.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When adding multiple database connections, I noticed the
postgres-mcpcontext tokens were duplicated:To limit token usage for multi-connection scenarios, I added support for multiple connections:
Additional fixes:
Future work:
Reflections: