Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,51 @@ The following MCP tools are available:
2. **list_jobs()** - List all Databricks jobs in your workspace
3. **get_job_status(job_id: int)** - Get the status of a specific Databricks job by ID
4. **get_job_details(job_id: int)** - Get detailed information about a specific Databricks job
5. **preview_table(table_name: str, limit: int = 10)** - Preview rows from a Delta table
6. **search_workspace(path: str = "/")** - List objects in a Databricks workspace path
7. **list_pipelines()** - List Delta Live Tables pipelines

## Example Usage with LLMs
## Example Prompts for New Functions

You can ask your LLM to use these tools in various ways. Here are some example prompts for each available function:

### 1. `run_sql_query(sql: str)`
- "Run the SQL: `SELECT count(*) FROM users`"
- "What is the total revenue in the `sales` table?"
- "Give me the earliest and latest order dates in the orders table."

### 2. `list_jobs()`
- "List all Databricks jobs in my workspace."
- "What jobs are currently available to run?"

### 3. `get_job_status(job_id: int)`
- "Show me the run status for job 9876."
- "Did job 123 finish successfully?"
- "How many times has job 222 failed?"

### 4. `get_job_details(job_id: int)`
- "What tasks are included in job 1001?"
- "Give me the details for job 345."

### 5. `preview_table(table_name: str, limit: int = 10)`
- "Preview the top 5 rows in the `customers` table."
- "Show 10 records from table `events`."
- "What data is in the `users_activity` table?"

### 6. `search_workspace(path: str = "/")`
- "List all folders in the workspace root."
- "What notebooks are in `/Shared/Analytics`?"
- "Show me all files in `/Users/janedoe`."

### 7. `list_pipelines()`
- "List all Delta Live Tables pipelines."
- "Which DLT pipelines are available in my environment?"

---

Feel free to adapt these prompts to your needs or combine them for more complex workflows!

When used with LLMs that support the MCP protocol, this server enables natural language interaction with your Databricks environment:

- "Show me all tables in the database"
- "Run a query to count records in the customer table"
- "List all my Databricks jobs"
- "Check the status of job #123"
- "Show me details about job #456"

## Troubleshooting

Expand Down
36 changes: 36 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,41 @@ def get_job_details(job_id: int) -> str:
except Exception as e:
return f"Error getting job details: {str(e)}"

@mcp.tool()
def preview_table(table_name: str, limit: int = 10) -> str:
"""Preview rows from a Delta table"""
sql = f"SELECT * FROM {table_name} LIMIT {limit}"
return run_sql_query(sql)

@mcp.tool()
def search_workspace(path: str = "/") -> str:
"""List objects in a Databricks workspace path"""
try:
response = databricks_api_request(f"workspace/list?path={path}")
objects = response.get("objects", [])
if not objects:
return f"No objects found at path: {path}"
table = "| Path | Type |\n| ---- | ---- |\n"
for obj in objects:
table += f"| {obj.get('path')} | {obj.get('object_type')} |\n"
return table
except Exception as e:
return f"Error listing workspace objects: {str(e)}"

@mcp.tool()
def list_pipelines() -> str:
"""List Delta Live Tables pipelines"""
try:
response = databricks_api_request("pipelines")
pipelines = response.get("statuses", [])
if not pipelines:
return "No DLT pipelines found."
table = "| Pipeline ID | Name | State |\n| ------------ | ---- | ------ |\n"
for p in pipelines:
table += f"| {p.get('pipeline_id')} | {p.get('name')} | {p.get('state')} |\n"
return table
except Exception as e:
return f"Error listing DLT pipelines: {str(e)}"

if __name__ == "__main__":
mcp.run()