Skip to content

Commit 41105f3

Browse files
committed
fix: update Databricks permission checking for Unity Catalog
1 parent b9a40e2 commit 41105f3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

.changeset/green-dingos-find.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ansible-database-mcp": patch
3+
---
4+
5+
update Databricks permission checking for Unity Catalog

src/services/databricks-permission-checker.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,23 @@ export async function isDatabricksReadOnlySession(adapter: DatabricksAdapter): P
2525
const userResult = await adapter.raw('SELECT current_user() as user');
2626
const currentUser = userResult.rows[0]?.user || 'unknown';
2727

28+
// Get current catalog for Unity Catalog
29+
const catalogResult = await adapter.raw('SELECT current_catalog() as catalog');
30+
const currentCatalog = catalogResult.rows[0]?.catalog;
31+
2832
// Check if user can create tables (write permission indicator)
2933
try {
30-
// Try to get create table permissions - this will fail if no write access
31-
await adapter.raw(`SHOW GRANT ON CATALOG`);
34+
// For Unity Catalog, we need to specify the catalog name
35+
if (currentCatalog) {
36+
await adapter.raw(`SHOW GRANTS ON CATALOG ${currentCatalog}`);
37+
} else {
38+
// If no catalog is set, try to check schema permissions
39+
const schemaResult = await adapter.raw('SELECT current_schema() as schema');
40+
const currentSchema = schemaResult.rows[0]?.schema;
41+
if (currentSchema) {
42+
await adapter.raw(`SHOW GRANTS ON SCHEMA ${currentSchema}`);
43+
}
44+
}
3245

3346
// If we can show grants, parse them to check for write permissions
3447
// In Databricks, write permissions include: CREATE, MODIFY, DELETE, etc.

0 commit comments

Comments
 (0)