feat(connections): allow database override via "<id>/<database>" syntax#24
Open
rrsela wants to merge 1 commit intosrthkdev:mainfrom
Open
feat(connections): allow database override via "<id>/<database>" syntax#24rrsela wants to merge 1 commit intosrthkdev:mainfrom
rrsela wants to merge 1 commit intosrthkdev:mainfrom
Conversation
DBeaver connections are bound to a single database (the one in the JDBC URL
or workspace config). DBeaver itself opens additional sessions per database
under the hood when browsing the navigator, but the MCP server only builds
one client per logical connection — so a cluster with N databases requires
N separate workspace connections to query them all.
This change lets callers pass `<connectionId>/<database>` as the connectionId
to any tool. The parser splits on the first `/`, looks up the base connection
normally, then returns a clone with `database`, `properties.database`, and
a synthetic `id` (`<original-id>/<database>`) so connection pools stay
keyed per target DB. Without a `/`, behaviour is unchanged.
- src/utils.ts: extend sanitizeConnectionId to allow `/`; add parseConnectionId
helper for the split logic
- src/config-parser.ts: getConnection consumes parseConnectionId and applies
the override without mutating the cached connection
- tests: cover sanitize/parse helpers plus override happy-path, name lookup,
unmatched base, and immutability of the cached connection
Example:
// base connection points at "postgres"
list_tables({ connectionId: "my-conn/analytics" })
// queries "analytics" instead, no extra workspace connection needed
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.
Summary
Adds support for a
<connectionId>/<database>override syntax on every tool that takes aconnectionId, so a single workspace connection can target any database on the same server — no need to create N workspace connections for an N-database cluster.Why
PostgreSQL (and other) connections are bound to a single database (the one in the JDBC URL / workspace config). When you browse a multi-DB server in DBeaver's navigator, DBeaver transparently opens additional sessions per database under the hood. The MCP server doesn't replicate that — it builds one client per logical workspace connection — so to query 8 databases on a cluster, you currently have to define 8 separate workspace connections.
This is impractical when:
What changed
src/utils.ts: extendsanitizeConnectionIdto preserve/; add a smallparseConnectionIdhelper that splits<id>/<database>into{ baseId, databaseOverride }.src/config-parser.ts:getConnectionconsumesparseConnectionId, looks up bybaseIdas before, and when an override is present returns a shallow clone with:id=${match.id}/${databaseOverride}(so per-DB pool caches stay separate)database= overrideproperties.database= overrideBackwards compatibility
When the connection ID does not contain
/, behaviour is byte-for-byte identical to before. No changes to tool schemas, no breaking changes to existing callers.Example
Tests
Added 8 new tests (53 total, all passing):
parseConnectionId: no slash, single slash, empty halves, multiple slashessanitizeConnectionId: preserves/for the override suffixgetConnection: id lookup, name lookup, override applies database to all required fields, cache immutability, unknown base id returns nullnpm run typecheck✓npm run lint✓npm test✓ (53/53)Test plan
postgres) successfully listed tables in 7 sibling databases via<id>/<database>syntax.