Skip to main content
Glama
PulkitXChadha

Databricks MCP Server

test_uc_tools.pyβ€’10.2 kB
#!/usr/bin/env python3 """Test script for Unity Catalog tools in the Databricks MCP server. Tests all UC tools including volumes, functions, models, external locations, etc. """ import os import sys from databricks.sdk import WorkspaceClient def test_uc_tools(): """Test all Unity Catalog tools.""" # Get configuration from environment host = os.environ.get('DATABRICKS_HOST') token = os.environ.get('DATABRICKS_TOKEN') if not host or not token: print('❌ Error: DATABRICKS_HOST and DATABRICKS_TOKEN environment variables must be set') print("Please run: export DATABRICKS_HOST='https://your-workspace.cloud.databricks.com'") print("Please run: export DATABRICKS_TOKEN='your-token'") sys.exit(1) print(f'πŸ”§ Testing Unity Catalog tools against workspace: {host}') try: # Test connection w = WorkspaceClient(host=host, token=token) user = w.current_user.me() print(f'βœ… Connected as: {user.user_name}') # Test describing a common catalog print('\nπŸ“ Testing describe_uc_catalog with common catalog...') catalog_names = ['hive_metastore', 'main', 'samples'] catalog_found = False for catalog_name in catalog_names: try: print(f' Trying catalog: {catalog_name}') catalog_details = w.catalogs.get(catalog_name) print(f'βœ… Found catalog: {catalog_details.name}') catalog_found = True # List schemas schemas = list(w.schemas.list(catalog_name)) print(f"βœ… Found {len(schemas)} schema(s) in catalog '{catalog_name}'") if schemas: schema_name = schemas[0].name full_schema = f'{catalog_name}.{schema_name}' print(f'πŸ“ First schema: {full_schema}') # Test describing schema print(f"\nπŸ“‹ Testing describe_uc_schema for '{full_schema}'...") try: schema_details = w.schemas.get(full_schema) print(f'βœ… Got schema details: {schema_details.name}') # List tables tables = list(w.tables.list(catalog_name=catalog_name, schema_name=schema_name)) print(f"βœ… Found {len(tables)} table(s) in schema '{full_schema}'") if tables: table_name = tables[0].name full_table = f'{full_schema}.{table_name}' print(f'πŸ“ First table: {full_table}') # Test describing table print(f"\nπŸ“‹ Testing describe_uc_table for '{full_table}'...") try: table_details = w.tables.get(full_table) print(f'βœ… Got table details: {table_details.name}') if hasattr(table_details, 'columns') and table_details.columns: print(f'βœ… Table has {len(table_details.columns)} columns') else: print('ℹ️ Table has no column information available') except Exception as e: print(f"⚠️ Could not describe table '{full_table}': {e}") else: print('ℹ️ No tables found in schema') # Test listing volumes print(f"\nπŸ“¦ Testing list_uc_volumes for '{full_schema}'...") try: volumes = list(w.volumes.list(catalog_name=catalog_name, schema_name=schema_name)) print(f"βœ… Found {len(volumes)} volume(s) in schema '{full_schema}'") if volumes: volume_name = volumes[0].name full_volume = f'{full_schema}.{volume_name}' print(f'πŸ“¦ First volume: {full_volume}') # Test describing volume print(f"\nπŸ“‹ Testing describe_uc_volume for '{full_volume}'...") try: volume_details = w.volumes.get(full_volume) print(f'βœ… Got volume details: {volume_details.name}') except Exception as e: print(f"⚠️ Could not describe volume '{full_volume}': {e}") except Exception as e: print(f"⚠️ Could not list volumes for schema '{full_schema}': {e}") # Test listing functions print(f"\nπŸ”§ Testing list_uc_functions for '{full_schema}'...") try: functions = list(w.functions.list(catalog_name=catalog_name, schema_name=schema_name)) print(f"βœ… Found {len(functions)} function(s) in schema '{full_schema}'") if functions: function_name = functions[0].name full_function = f'{full_schema}.{function_name}' print(f'πŸ”§ First function: {full_function}') # Test describing function print(f"\nπŸ“‹ Testing describe_uc_function for '{full_function}'...") try: function_details = w.functions.get(full_function) print(f'βœ… Got function details: {function_details.name}') except Exception as e: print(f"⚠️ Could not describe function '{full_function}': {e}") except Exception as e: print(f"⚠️ Could not list functions for schema '{full_schema}': {e}") # Test listing models print(f"\nπŸ€– Testing list_uc_models for '{full_schema}'...") try: models = list(w.models.list(catalog_name=catalog_name, schema_name=schema_name)) print(f"βœ… Found {len(models)} model(s) in schema '{full_schema}'") if models: model_name = models[0].name full_model = f'{full_schema}.{model_name}' print(f'πŸ€– First model: {full_model}') # Test describing model print(f"\nπŸ“‹ Testing describe_uc_model for '{full_model}'...") try: model_details = w.models.get(full_model) print(f'βœ… Got model details: {model_details.name}') except Exception as e: print(f"⚠️ Could not describe model '{full_model}': {e}") except Exception as e: print(f"⚠️ Could not list models for schema '{full_schema}': {e}") except Exception as e: print(f"⚠️ Could not describe schema '{full_schema}': {e}") else: print('ℹ️ No schemas found in catalog') break # Found a working catalog, exit loop except Exception as e: print(f"⚠️ Could not describe catalog '{catalog_name}': {e}") if not catalog_found: print('ℹ️ No accessible catalogs found') # Test external locations print('\n🌐 Testing list_external_locations...') try: locations = list(w.external_locations.list()) print(f'βœ… Found {len(locations)} external location(s)') if locations: location_name = locations[0].name print(f'🌐 First location: {location_name}') # Test describing external location print(f"\nπŸ“‹ Testing describe_external_location for '{location_name}'...") try: location_details = w.external_locations.get(location_name) print(f'βœ… Got location details: {location_details.name}') except Exception as e: print(f"⚠️ Could not describe location '{location_name}': {e}") except Exception as e: print(f'⚠️ Could not list external locations: {e}') # Test storage credentials print('\nπŸ” Testing list_storage_credentials...') try: credentials = list(w.storage_credentials.list()) print(f'βœ… Found {len(credentials)} storage credential(s)') if credentials: credential_name = credentials[0].name print(f'πŸ” First credential: {credential_name}') # Test describing storage credential print(f"\nπŸ“‹ Testing describe_storage_credential for '{credential_name}'...") try: credential_details = w.storage_credentials.get(credential_name) print(f'βœ… Got credential details: {credential_details.name}') except Exception as e: print(f"⚠️ Could not describe credential '{credential_name}': {e}") except Exception as e: print(f'⚠️ Could not list storage credentials: {e}') # Test metastores print('\nπŸ—οΈ Testing list_metastores...') try: metastores = list(w.metastores.list()) print(f'βœ… Found {len(metastores)} metastore(s)') if metastores: metastore_name = metastores[0].name print(f'πŸ—οΈ First metastore: {metastore_name}') # Test describing metastore print(f"\nπŸ“‹ Testing describe_metastore for '{metastore_name}'...") try: metastore_details = w.metastores.get(metastore_name) print(f'βœ… Got metastore details: {metastore_details.name}') except Exception as e: print(f"⚠️ Could not describe metastore '{metastore_name}': {e}") except Exception as e: print(f'⚠️ Could not list metastores: {e}') # Test search functionality print('\nπŸ” Testing search_uc_objects...') try: # Search for objects containing the catalog name search_results = [] for catalog in w.catalogs.list(): if catalog.name.lower() in catalog.name.lower(): search_results.append( {'name': catalog.name, 'type': 'catalog', 'full_name': catalog.name} ) break # Just get one result for testing if search_results: print(f'βœ… Search found {len(search_results)} result(s)') for result in search_results: print(f' - {result["type"]}: {result["full_name"]}') else: print('ℹ️ Search returned no results') except Exception as e: print(f'⚠️ Could not perform search: {e}') print('\nπŸŽ‰ Unity Catalog tools testing completed successfully!') print('βœ… All core UC operations are working') print( 'ℹ️ Some advanced features (tags, data quality) are placeholders for future implementation' ) except Exception as e: print(f'❌ Error during testing: {e}') sys.exit(1) if __name__ == '__main__': test_uc_tools()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PulkitXChadha/awesome-databricks-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server