Lakebase Connect
A small VS Code extension for connecting to Databricks Lakebase (managed Postgres) without fighting
with tokens. It signs in to Databricks (as a service principal or as yourself), fetches the short-lived
Lakebase database credential, refreshes it before it expires, and connects with the Node pg driver, so
the length of the token never matters. Write SQL in a normal .sql editor and run it with
Ctrl+Enter (Cmd+Enter on macOS). Results appear in the Lakebase output channel.
It can also let GitHub Copilot (agent mode) and other MCP clients query Lakebase through the same
saved connections: read-only by default, and the AI never sees a secret or token.
Unofficial. This is a community project. It is not made, supported or endorsed by Databricks.
"Databricks" and "Lakebase" are trademarks of Databricks, Inc.
Status: early release (0.x). The Postgres, TLS and AI-tool paths are covered by automated tests
against a real Postgres server; the Databricks and Microsoft sign-in calls are tested against mock
servers. Please open an issue if something
does not work with your workspace.
Install
- VS Code Marketplace: search for Lakebase Connect in the Extensions view, or run
code --install-extension notsujansharma.lakebase-connect.
- From a .vsix file: download
lakebase-connect-<version>.vsix from the
GitHub releases, then in the Extensions view
click … (top right) → Install from VSIX…, or run code --install-extension lakebase-connect-<version>.vsix.
Needs VS Code 1.95 or later. The MCP integration for Copilot needs VS Code 1.101 or later; older
versions get the same tools as Copilot "language model tools" instead.

Quick start
- Click the Lakebase icon in the activity bar, then Add Connection. The form shows only the fields
your sign-in mode needs. Use Browse… to pick a Lakebase project → branch → endpoint from your
workspace, and Test Connection to check sign-in, credential and Postgres in one go.
- Click Save & Connect. The connection opens in the sidebar: databases → schemas → tables → columns.
- Click New SQL File (or right-click a table → New Query for This Table), write SQL and press
Ctrl+Enter (Cmd+Enter on macOS) to run the statement under the cursor, or
Ctrl+Shift+Enter (Cmd+Shift+Enter) to run the whole file. Results appear in the
Lakebase Results panel.
On a company network that inspects TLS (you need a corporate .crt file for your scripts), run
Lakebase: Set Up Corporate Certificate first. See Corporate networks.
The status bar shows the connection and database of the SQL file you are in. Click it for Choose
Connection for This File, Select Database, Disconnect, Diagnostics and more. Hover it, or a connection
in the sidebar, to see who you are signed in as.
Writing SQL

- Run the statement under the cursor with Ctrl+Enter (Cmd+Enter), or click ▶ Run above any
statement. Select text to run exactly that; Ctrl+Shift+Enter (Cmd+Shift+Enter) or the
Run All button runs the whole file. The statement that ran is highlighted briefly, and if Postgres
reports an error position, the word is underlined in the editor and listed in Problems. (To get the
old "run the whole file" behaviour on Ctrl+Enter, set
lakebaseConnect.runWithoutSelection to file.)
- Each SQL file remembers its connection and database. The first line shows it (for example
dev-spn / databricks_postgres); click it, or use Choose Connection for This File, to change it. Open
one file on dev and another on prod side by side: each runs on its own session. A new file, or one
that has never run, uses the connection you used last. New SQL File and New Query for This Table
from the sidebar start on that connection and database.
- Autocomplete and hover from the live schema of the file's connection: tables and views after
FROM/JOIN, columns after alias. or table., tables after schema., and the columns of the
tables in the statement anywhere else. Hover a table to see its columns, or a column to see its
type, key and default. This only works while the connection is open (typing never signs you in),
and names are quoted when they need to be.
- Query history: every query you run from the editor is listed under Query History in the
sidebar, with its connection, result and time. Open it in a new editor, run it again, copy it or
search it. History is kept only on this computer, never includes results, and passwords in SQL
(for example
PASSWORD '...') are masked. Set lakebaseConnect.history.maxEntries to 0 to turn
it off.
- Connections: each saved connection with its sign-in mode. The connected one shows its databases
(the one the editor uses is marked current), then schemas, tables and views, and columns with their
types and primary keys. Everything loads when you expand it.
- Buttons on each item: Connect, Disconnect and New SQL File on connections; Use This
Database on databases; Preview Rows on tables (the first 100 rows, read-only). Right-click for
Edit, Delete, Show Diagnostics, Copy Fresh Token, New Query for This Table and
Copy Name (quoted when needed).
- Lakebase Results (bottom panel): one tab per statement, sortable columns (click a header), NULLs shown
clearly, the row count and time, Copy as CSV, a Cancel button while a query runs, and Postgres
errors with the position marked. The Lakebase output channel keeps a text log of every run; set
lakebaseConnect.resultsView to outputChannel if you prefer text tables only.

Sign-in modes
Every mode ends at the same place: a Databricks access token, which is exchanged for a Lakebase
database credential. Secrets are kept only in VS Code's SecretStorage (the OS credential store); the
Lakebase token is kept only in memory.
| Mode |
What you need |
Postgres user name |
| A. Azure service principal (client secret) |
Workspace URL, tenant ID, client ID, client secret value from the Azure portal |
the SPN's client (application) ID |
| B. Databricks service principal (OAuth secret) |
Workspace URL, client ID, an OAuth secret generated in Databricks |
the SPN's application ID |
| C. Sign in as myself (Microsoft account in VS Code) |
Workspace URL, optional tenant ID |
your email / UPN |
| D. My Azure CLI login |
az login done in a terminal, workspace URL, optional tenant ID |
your email / UPN |
| E. Databricks CLI profile |
A profile in ~/.databrickscfg (%USERPROFILE%\.databrickscfg on Windows) |
from the profile's identity |
Notes per mode:
- A works only with Azure Databricks (
*.azuredatabricks.net). It requests a token for the Azure
Databricks resource (2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default) with @azure/identity. No app
approval needed.
- B calls
POST <workspace>/oidc/v1/token with grant_type=client_credentials, scope=all-apis.
Works on Azure, AWS and GCP. No app approval needed.
- C uses VS Code's built-in Microsoft sign-in. Some tenants require an admin to consent to VS Code
accessing Azure Databricks. If you see a consent or "admin approval" error, use D instead.
- D uses
az account get-access-token under the hood. If you have several tenants, set the tenant
ID on the connection or run az login --tenant <tenant-id>.
- E reads profiles from
~/.databrickscfg and, if set, the file in DATABRICKS_CONFIG_FILE.
- Profiles created by
databricks auth login are signed in by running
databricks auth token -p <profile> (set lakebaseConnect.databricksCliPath if databricks is not on
your PATH).
- Profiles that contain a service principal secret (
azure_client_id/azure_client_secret/azure_tenant_id
or client_id/client_secret), a PAT (token) or auth_type = azure-cli are signed in directly
with those values. This avoids a profile meant for an SPN quietly falling back to your personal
azure-cli login.
- Environment variables such as
DATABRICKS_TOKEN, DATABRICKS_HOST and DATABRICKS_AUTH_TYPE can
override a profile. The connection form warns about them and Show Diagnostics lists them (names only).
After every sign-in the extension calls the Databricks SCIM Me API and shows who you are really
signed in as. If a service-principal connection turns out to be signed in as a person (or the other
way round), you get a warning.
Commands
| Command |
What it does |
| Lakebase: Add / Edit / Delete Connection |
Open the connection form, or delete a connection (and its secret). |
| Lakebase: Connect / Disconnect |
Open or close the editor's Postgres session. |
| Lakebase: Choose Connection for This File |
Pick the connection and database the current SQL file runs on. |
| Lakebase: Select Database |
Switch the current file (or the default) to another database. |
| Lakebase: New SQL File |
Open an untitled SQL editor on the current connection. |
| Lakebase: Run Statement or Selection (Ctrl/Cmd+Enter) |
Run the selection, or the statement under the cursor. |
| Lakebase: Run All (Ctrl/Cmd+Shift+Enter) |
Run the whole file. |
| Lakebase: Search / Clear Query History |
Find a past query, or forget them all. |
| Lakebase: Cancel Query |
pg_cancel_backend, or close the connection if that fails. |
| Lakebase: Show Diagnostics |
Step-by-step check of a connection (see below). |
| Lakebase: Set Up Corporate Certificate |
Trust your company's root certificate file, or the certificates installed on this computer. |
| Lakebase: Copy Last Result as CSV |
Copy the rows shown for the last query. |
| Lakebase: Copy Fresh Token |
Copy a current Lakebase token, for other tools. |
| Lakebase: Write pgpass Entry |
Optional. Writes the token to your pgpass file and keeps it fresh. Writes a token to disk. |
| Lakebase: Manage AI Access to Connections |
Choose which connections Copilot may use. |
| Lakebase: Show MCP Status |
How the AI tools are exposed and with which limits. |
How queries run:
- Each connection and database has its own Postgres session, kept open, so
BEGIN, SET and temporary
tables carry over between runs, as in psql.
- A single statement is read through a cursor, so only
lakebaseConnect.maxRows rows (default 500) are
ever fetched. Several statements are sent together and each result is shown.
lakebaseConnect.queryTimeoutSeconds (default 300) sets statement_timeout.
- Postgres errors are shown psql-style with the line, a caret at the position, DETAIL and HINT.
Settings
| Setting |
Default |
|
lakebaseConnect.maxRows |
500 |
Rows shown per result. |
lakebaseConnect.queryTimeoutSeconds |
300 |
statement_timeout for editor queries (0 = none). |
lakebaseConnect.resultsView |
grid |
grid (Lakebase Results panel) or outputChannel (text only). |
lakebaseConnect.runWithoutSelection |
statement |
What Ctrl/Cmd+Enter runs with nothing selected: statement or file. |
lakebaseConnect.codeLens |
true |
▶ Run above each statement and the connection on the first line. |
lakebaseConnect.autocomplete |
true |
Suggestions and hover from the connected database. |
lakebaseConnect.history.maxEntries |
500 |
Queries kept in the history (0 = off). |
lakebaseConnect.databricksCliPath |
databricks |
For mode E. Machine setting. |
lakebaseConnect.tls.caFile |
|
Your company's root certificate (.crt/.pem/.cer, PEM or DER). Used for Databricks, Microsoft sign-in and Postgres. Machine setting. |
lakebaseConnect.tls.useSystemCertificates |
true |
Also trust the certificates installed on this computer (needs VS Code with Node 22.15+). |
lakebaseConnect.tls.allowInvalidCertificates |
false |
Last resort, Postgres only: skip certificate checks. |
lakebaseConnect.mcp.enabled |
true |
Offer the AI tools to Copilot. |
lakebaseConnect.mcp.allowWrites |
false |
Let AI run writes/DDL, each confirmed in a dialog. |
lakebaseConnect.mcp.allowedConnections |
[] |
Connection names AI may use (* = all). Empty = none. |
lakebaseConnect.mcp.maxRows |
200 |
Row limit for AI queries. |
lakebaseConnect.mcp.queryTimeoutSeconds |
30 |
statement_timeout for AI queries. |
lakebaseConnect.mcp.maxResultChars |
60000 |
Size cap for one AI tool result. |
The security-related settings (mcp.*, tls.allowInvalidCertificates) can only be set in your user
settings, and the path settings (databricksCliPath, tls.caFile) only per machine, so a repository's
.vscode/settings.json cannot turn on AI writes or point the extension at another executable.
Corporate networks (TLS inspection)
Many company networks inspect TLS traffic and re-sign it with the company's own root certificate.
Everything then fails with errors like unable to get local issuer certificate or
self-signed certificate in certificate chain until that root certificate is trusted.
Run Lakebase: Set Up Corporate Certificate and pick one of:
- Use my company's certificate file: the
.crt, .pem or .cer file you already use with your
scripts. PEM (Base-64) and DER (binary, as Windows exports it) both work, and so does a bundle with
several certificates. You see who issued it and when it expires before it is saved.
- Certificates installed on this computer: the Windows certificate store, macOS keychain or Linux
system store, where IT usually installs corporate roots. This is on by default. The command lists the
installed certificates that are not in Node's built-in list, which are usually the company's.
The certificate is used for every connection the extension makes itself: Databricks API calls,
Microsoft sign-in for the Azure service principal mode, and Postgres. HTTPS calls still go through VS
Code's proxy settings (http.proxy). The command's Check the certificates for a connection (and
Show Diagnostics) connect to the workspace, Microsoft sign-in and the Postgres host and show the
certificate chain each one presents, for example
adb-123.azuredatabricks.net ← Zscaler Intermediate (top issued by "Zscaler Root CA").
The Azure CLI (mode D) and the Databricks CLI (mode E, for databricks auth login profiles) make their
own HTTPS calls, so they use their own certificate settings: REQUESTS_CA_BUNDLE for the Azure CLI, and
the OS certificate store (or SSL_CERT_FILE on Linux) for the Databricks CLI. If az or databricks
works in your terminal but not here, VS Code was probably started without those environment variables.
Fixing common errors
Run Lakebase: Show Diagnostics first. It prints the sign-in mode, the identity the token belongs to,
the Databricks/Azure environment variables that are set (names only), the host, endpoint and Postgres
host, when the Lakebase token expires, the TLS setup, and the result of SELECT current_user, version().
| You see |
What it usually means |
invalid_client, AADSTS7000215 |
Wrong secret, or an Azure secret used in mode B (or a Databricks dose… secret in mode A). Switch between A and B. |
AADSTS7000222 |
The Azure client secret has expired. Create a new one and edit the connection. |
| Consent / "admin approval" (mode C) |
Your tenant needs admin consent. Use mode D (az login). |
Please run 'az login' |
Run az login (with --tenant if needed). |
password authentication failed |
The identity has no Postgres role on the Lakebase project. Add the SPN (by application ID) or user on the project's Roles page. |
self-signed certificate, unable to get local issuer certificate, endpoints_resolution_error |
Your network inspects TLS. Run Lakebase: Set Up Corporate Certificate (see above). |
| Signed in as the wrong identity |
Check the diagnostics for environment variables like DATABRICKS_TOKEN or ARM_CLIENT_ID, and for profile fallbacks. |
ENOTFOUND, timeouts |
Check the host names, VPN, and that outbound port 5432 is allowed. |
Secrets and tokens are never written to settings or logs. Everything printed to the output channel
goes through a redaction filter.
Copilot and other AI agents (MCP)
On VS Code 1.101+ the extension registers an MCP server with VS Code itself, so Copilot finds it with no
mcp.json editing. The server runs inside the extension on 127.0.0.1, on a random port, protected by
a random per-session bearer token that only VS Code receives. On older VS Code the same tools are offered
as language model tools.
Tools: list_connections, get_active_connection, list_databases, list_schemas, list_tables,
describe_table, run_query, explain_query.
Safety rules:
- AI can use only the connections in
lakebaseConnect.mcp.allowedConnections (empty by default). The Add
Connection form has a checkbox for it, and when Copilot asks for a connection that is not allowed you get a prompt.
Keep production connections out unless you really need them.
- Every AI query runs in
BEGIN READ ONLY with statement_timeout, one statement per call, with a row
limit and a result size cap. Transaction control and SET are refused.
- Writes need
lakebaseConnect.mcp.allowWrites and your confirmation in a dialog that shows the full
SQL, every time. EXPLAIN ANALYZE is only allowed when writes are on. Functions that have side effects
even in a read-only transaction (for example pg_terminate_backend, dblink, advisory locks) are
treated as writes.
- Every AI query is logged in the Lakebase output channel, marked
[MCP].
- Tool results never contain tokens, secrets or connection strings.
Contributing
Issues and pull requests are welcome.
npm install
npm run build # bundle to dist/extension.js (esbuild)
npm test # type-check tests and run unit tests
npm run package # type-check, bundle and create the .vsix
Press F5 in VS Code with this folder open to run the extension in a development host.
To release a new version: update version in package.json and add a ## <version> section to
CHANGELOG.md, commit, then push a matching tag. The
Publish workflow runs the tests, publishes to the Marketplace with Trusted
Publishing (no token stored anywhere) and creates the GitHub release with the same .vsix.
git tag v0.3.0
git push origin v0.3.0
Integration tests run against a real Postgres with TLS (a self-signed CA and a 1,800-character
token-like password) and are skipped unless the LBC_IT_* variables are set. On Linux or macOS with
Postgres server binaries and openssl installed:
scripts/test-postgres.sh /tmp/lbc-pg > /tmp/lbc-pg.env
source /tmp/lbc-pg.env && npm test
scripts/test-postgres.sh /tmp/lbc-pg stop
Code map: src/extension.ts (activation), src/commands.ts (commands), src/views/ (sidebar tree, results
grid, connection form; their browser code is in media/), src/formModel.ts (form rules), src/pickers.ts
(Browse and connection pickers), src/auth/ (one file per sign-in mode), src/databricksApi.ts (REST
calls), src/lakebase.ts (credential cache and refresh), src/service.ts (ties sign-in, credentials and
pools together), src/session.ts and src/db.ts (Postgres), src/catalog.ts (schema queries),
src/results.ts (output), src/diagnostics.ts, src/errors.ts (plain-language errors), src/ai/ (MCP
server and tools).
API details this build relies on, and where they were checked:
- Autoscaling credential:
POST /api/2.0/postgres/credentials with {"endpoint": "projects/…/endpoints/…"},
response {token, expire_time}. Endpoint host: GET /api/2.0/postgres/<endpoint> → status.hosts.host.
Projects, branches and endpoints are listed under /api/2.0/postgres/… with page_token paging.
(Databricks Python SDK 0.171, service/postgres.py.)
- Provisioned credential:
POST /api/2.0/database/credentials with {instance_names, request_id}, response
{token, expiration_time}. Instance host: GET /api/2.0/database/instances/<name> → read_write_dns.
(Same SDK, service/database.py.)
- M2M OAuth:
<host>/oidc/v1/token, Basic auth, scope=all-apis (same SDK, oauth_service_principal).
databricks auth token -p <profile> prints {"access_token", "token_type", "expiry"} (same SDK, CLI
token source). Not verified: whether auth token works for profiles that are not databricks auth login
profiles, which is why those are signed in directly.
- VS Code Microsoft sign-in understands the
VSCODE_TENANT:<id> scope (VS Code 1.143's built-in
microsoft-authentication extension).
- Inside VS Code (checked on 1.143 with and without a proxy), the built-in
fetch ignores custom CA
certificates, even after tls.setDefaultCACertificates, while https.request with ca and the Azure SDK
with tlsOptions honor them and still use VS Code's proxy. That is why REST calls use https (src/net.ts).
vscode.lm.registerMcpServerDefinitionProvider + contributes.mcpServerDefinitionProviders, with
McpHttpServerDefinition(label, uri, headers, version), stable since VS Code 1.101. Both the MCP
provider and language model tools get implicit activation events, so the extension still starts only
when needed. The fallback tools have a when clause so Copilot does not see them twice.
Not yet covered by automated tests: each sign-in mode against a real Databricks workspace, Windows, a
token refresh during a session longer than an hour, and Copilot agent mode end to end. Reports from real
workspaces are very welcome.
License
MIT
| |