From 98484da65000070317786b1c7ae4bff5cf0a30a8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 14:24:17 -0500 Subject: [PATCH 1/2] Release 0.2.0: PyPI packaging, MCP SDK 2.x, current Databricks APIs, tests - Package as databricks-mcp-toolkit with a databricks-mcp command (src/databricks_mcp layout) - Port to MCP SDK 2.x (MCPServer); 0.1.x imported FastMCP and broke on fresh installs - Typed tool arguments, tool annotations, read-only mode, toolset filtering - Jobs 2.2, Clusters 2.1, Unity Catalog 2.1, Files API for volumes, SQL warehouses - Auth through databricks-sdk unified auth (PAT, OAuth M2M/U2M, profiles, Azure) - Retry policy: 429 always, 5xx/timeouts only for idempotent methods - Response size cap, slimmed list output, multi-task run output fan-out - respx-mocked test suite, CI on 3.10-3.13, trusted-publishing release workflow - Fix license metadata (AGPL-3.0-only, matching LICENSE) - Rewrite README, CONTRIBUTING, ARCHITECTURE; add CHANGELOG and RELEASING Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FzyNsyRMzULCtA6hxabfVj --- .env.example | 25 +- .github/workflows/ci.yml | 43 ++ .github/workflows/publish.yml | 50 ++ ARCHITECTURE.md | 411 ++----------- CHANGELOG.md | 42 ++ CONTRIBUTING.md | 559 +---------------- README.md | 447 ++++++-------- RELEASING.md | 33 + docs/phase1.md | 86 --- examples/README.md | 127 ---- examples/command_execution_example.py | 319 ---------- examples/direct_usage.py | 299 --------- examples/explore_catalog.py | 30 + examples/mcp_client_usage.py | 301 --------- examples/submit_notebook_run_example.py | 320 ---------- pyproject.toml | 79 ++- scripts/gen_tools_table.py | 51 ++ scripts/run_client_test.ps1 | 76 --- scripts/run_direct_test.ps1 | 33 - scripts/run_direct_test.sh | 31 - scripts/run_list_tools.ps1 | 77 --- scripts/run_list_tools.sh | 47 -- scripts/run_mcp_client_test.ps1 | 78 --- scripts/run_mcp_client_test.sh | 47 -- scripts/run_mcp_test.ps1 | 56 -- scripts/run_tests.ps1 | 45 -- scripts/show_clusters.py | 28 - scripts/show_notebooks.py | 28 - scripts/start_mcp_server.ps1 | 56 -- scripts/start_mcp_server.sh | 37 -- scripts/test_mcp_server.ps1 | 41 -- src/__init__.py | 4 - src/__main__.py | 15 - src/api/__init__.py | 22 - src/api/clusters.py | 239 -------- src/api/command_execution.py | 265 -------- src/api/dbfs.py | 258 -------- src/api/jobs.py | 268 -------- src/api/notebooks.py | 167 ----- src/api/sql.py | 180 ------ src/cli/__init__.py | 4 - src/cli/commands.py | 91 --- src/core/__init__.py | 4 - src/core/auth.py | 76 --- src/core/config.py | 303 --------- src/core/utils.py | 310 ---------- src/databricks_mcp/__init__.py | 10 + src/databricks_mcp/__main__.py | 10 + src/databricks_mcp/api/__init__.py | 30 + src/databricks_mcp/api/clusters.py | 73 +++ src/databricks_mcp/api/command_execution.py | 92 +++ src/databricks_mcp/api/dbfs.py | 37 ++ src/databricks_mcp/api/files.py | 94 +++ src/databricks_mcp/api/jobs.py | 144 +++++ src/databricks_mcp/api/sql.py | 99 +++ src/databricks_mcp/api/unity_catalog.py | 76 +++ src/databricks_mcp/api/warehouses.py | 32 + src/databricks_mcp/api/workspace.py | 67 ++ src/databricks_mcp/cli.py | 100 +++ src/databricks_mcp/client.py | 208 +++++++ src/databricks_mcp/config.py | 56 ++ src/databricks_mcp/server.py | 642 ++++++++++++++++++++ src/main.py | 123 ---- src/server/__init__.py | 4 - src/server/__main__.py | 15 - src/server/app.py | 78 --- src/server/databricks_mcp_server.py | 442 -------------- start_mcp_server.ps1 | 25 - start_mcp_server.sh | 16 - tests/README.md | 68 --- tests/__init__.py | 4 - tests/conftest.py | 23 + tests/test_api.py | 303 +++++++++ tests/test_client.py | 108 ++++ tests/test_clusters.py | 182 ------ tests/test_command_execution.py | 446 -------------- tests/test_direct.py | 102 ---- tests/test_mcp_client.py | 174 ------ tests/test_mcp_server.py | 181 ------ tests/test_server.py | 137 +++++ tests/test_submit_notebook_run.py | 328 ---------- tests/test_tools.py | 164 ----- 82 files changed, 2927 insertions(+), 7874 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yml create mode 100644 CHANGELOG.md create mode 100644 RELEASING.md delete mode 100644 docs/phase1.md delete mode 100644 examples/README.md delete mode 100644 examples/command_execution_example.py delete mode 100644 examples/direct_usage.py create mode 100644 examples/explore_catalog.py delete mode 100644 examples/mcp_client_usage.py delete mode 100644 examples/submit_notebook_run_example.py create mode 100644 scripts/gen_tools_table.py delete mode 100644 scripts/run_client_test.ps1 delete mode 100644 scripts/run_direct_test.ps1 delete mode 100644 scripts/run_direct_test.sh delete mode 100644 scripts/run_list_tools.ps1 delete mode 100644 scripts/run_list_tools.sh delete mode 100644 scripts/run_mcp_client_test.ps1 delete mode 100644 scripts/run_mcp_client_test.sh delete mode 100644 scripts/run_mcp_test.ps1 delete mode 100644 scripts/run_tests.ps1 delete mode 100644 scripts/show_clusters.py delete mode 100644 scripts/show_notebooks.py delete mode 100644 scripts/start_mcp_server.ps1 delete mode 100644 scripts/start_mcp_server.sh delete mode 100644 scripts/test_mcp_server.ps1 delete mode 100644 src/__init__.py delete mode 100644 src/__main__.py delete mode 100644 src/api/__init__.py delete mode 100644 src/api/clusters.py delete mode 100644 src/api/command_execution.py delete mode 100644 src/api/dbfs.py delete mode 100644 src/api/jobs.py delete mode 100644 src/api/notebooks.py delete mode 100644 src/api/sql.py delete mode 100644 src/cli/__init__.py delete mode 100644 src/cli/commands.py delete mode 100644 src/core/__init__.py delete mode 100644 src/core/auth.py delete mode 100644 src/core/config.py delete mode 100644 src/core/utils.py create mode 100644 src/databricks_mcp/__init__.py create mode 100644 src/databricks_mcp/__main__.py create mode 100644 src/databricks_mcp/api/__init__.py create mode 100644 src/databricks_mcp/api/clusters.py create mode 100644 src/databricks_mcp/api/command_execution.py create mode 100644 src/databricks_mcp/api/dbfs.py create mode 100644 src/databricks_mcp/api/files.py create mode 100644 src/databricks_mcp/api/jobs.py create mode 100644 src/databricks_mcp/api/sql.py create mode 100644 src/databricks_mcp/api/unity_catalog.py create mode 100644 src/databricks_mcp/api/warehouses.py create mode 100644 src/databricks_mcp/api/workspace.py create mode 100644 src/databricks_mcp/cli.py create mode 100644 src/databricks_mcp/client.py create mode 100644 src/databricks_mcp/config.py create mode 100644 src/databricks_mcp/server.py delete mode 100644 src/main.py delete mode 100644 src/server/__init__.py delete mode 100644 src/server/__main__.py delete mode 100644 src/server/app.py delete mode 100644 src/server/databricks_mcp_server.py delete mode 100644 start_mcp_server.ps1 delete mode 100644 start_mcp_server.sh delete mode 100644 tests/README.md create mode 100644 tests/conftest.py create mode 100644 tests/test_api.py create mode 100644 tests/test_client.py delete mode 100644 tests/test_clusters.py delete mode 100644 tests/test_command_execution.py delete mode 100644 tests/test_direct.py delete mode 100644 tests/test_mcp_client.py delete mode 100644 tests/test_mcp_server.py create mode 100644 tests/test_server.py delete mode 100644 tests/test_submit_notebook_run.py delete mode 100644 tests/test_tools.py diff --git a/.env.example b/.env.example index c226f29..a41689f 100644 --- a/.env.example +++ b/.env.example @@ -1,15 +1,16 @@ -# Databricks API configuration (REQUIRED) -DATABRICKS_HOST=https://your-databricks-instance.azuredatabricks.net +# Auth (pick one; see README "Authentication") +DATABRICKS_HOST=https://your-workspace.cloud.databricks.com DATABRICKS_TOKEN=your_personal_access_token +# DATABRICKS_CLIENT_ID=... # OAuth service principal instead of a token +# DATABRICKS_CLIENT_SECRET=... +# DATABRICKS_CONFIG_PROFILE=DEFAULT # or use a ~/.databrickscfg profile -# SQL Warehouse configuration (OPTIONAL - for SQL functionality) -# Get this from your Databricks workspace SQL Warehouses section -DATABRICKS_WAREHOUSE_ID=your_warehouse_id_here +# Optional +DATABRICKS_WAREHOUSE_ID= +DATABRICKS_MCP_READ_ONLY=false +# DATABRICKS_MCP_TOOLSETS=unity_catalog,sql,volumes +# DATABRICKS_MCP_MAX_RESPONSE_CHARS=50000 +# DATABRICKS_MCP_LOG_LEVEL=WARNING -# Server configuration (OPTIONAL - for development) -SERVER_HOST=0.0.0.0 -SERVER_PORT=8000 -DEBUG=False - -# Logging (OPTIONAL) -LOG_LEVEL=INFO +# MCP clients pass env vars in their own config. This file is only read if you +# export it yourself, e.g.: set -a; source .env; set +a diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..aa57816 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11", "3.12", "3.13"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: pip install -e ".[dev]" + - run: ruff check src tests scripts + - run: ruff format --check src tests scripts + - run: pytest -q + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - run: pip install build twine + - run: python -m build + - run: twine check --strict dist/* + # Install the wheel by itself (no source tree) and make sure the entry point works. + - run: | + python -m venv /tmp/wheel-env + /tmp/wheel-env/bin/pip install dist/*.whl + /tmp/wheel-env/bin/databricks-mcp --version + /tmp/wheel-env/bin/databricks-mcp list-tools > /dev/null diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..8dd2f48 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,50 @@ +name: Publish to PyPI + +# Runs when you publish a GitHub release tagged vX.Y.Z. +# Uses PyPI trusted publishing, so no API token is stored in the repo. +# One-time setup: https://docs.pypi.org/trusted-publishers/ (see RELEASING.md). + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Check the tag matches the package version + run: | + version=$(python -c "import re;print(re.search(r'__version__ = \"(.+?)\"', open('src/databricks_mcp/__init__.py').read()).group(1))") + if [ "v${version}" != "${GITHUB_REF_NAME}" ]; then + echo "Tag ${GITHUB_REF_NAME} does not match package version ${version}" >&2 + exit 1 + fi + - run: pip install build twine + - run: python -m build + - run: twine check --strict dist/* + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + + publish: + needs: build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/databricks-mcp-toolkit/ + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 9d05d62..edf41e3 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -1,367 +1,44 @@ -# Architecture Documentation - -## System Overview - -The Databricks MCP Toolkit is designed as a multi-layered architecture that provides a robust, scalable interface between AI agents and Databricks services through the Model Context Protocol (MCP). - -## Architectural Layers - -### 1. MCP Protocol Interface Layer -**Location**: `src/server/databricks_mcp_server.py` - -This layer implements the MCP specification and exposes Databricks functionality as standardized MCP tools. - -**Responsibilities**: -- MCP protocol compliance -- Tool registration and discovery -- Request/response marshaling -- Error handling and standardization - -**Key Components**: -- `DatabricksMCPServer`: Main server class implementing MCP handlers -- Tool definitions with JSON schemas -- Protocol-level error handling - -### 2. API Client Abstraction Layer -**Location**: `src/api/` - -Provides high-level abstractions over Databricks REST APIs with consistent error handling and async support. - -**Modules**: -``` -src/api/ -├── clusters.py # Cluster lifecycle management -├── jobs.py # Job and run operations -├── notebooks.py # Notebook management -├── sql.py # SQL execution -├── command_execution.py # Command execution contexts -└── dbfs.py # File system operations -``` - -**Design Patterns**: -- Async/await for non-blocking I/O -- Consistent error handling with custom exceptions -- Type hints for better IDE support -- Retry logic for transient failures - -### 3. Core Services Layer -**Location**: `src/core/` - -Provides foundational services used across the application. - -**Components**: -- `auth.py`: Authentication and token management -- `config.py`: Configuration management with Pydantic -- `utils.py`: HTTP client, logging, and utilities - -**Features**: -- Environment-based configuration -- Connection pooling for HTTP requests -- Structured logging -- Token validation and refresh - -### 4. CLI Interface Layer -**Location**: `src/cli/` - -Optional command-line interface for direct server interaction. - -**Capabilities**: -- Server startup and shutdown -- Configuration validation -- Health checks -- Tool invocation - -## Data Flow - -### Tool Invocation Flow - -``` -AI Agent Request - ↓ -MCP Protocol Handler - ↓ -Parameter Validation - ↓ -API Client Method - ↓ -HTTP Request (with retry) - ↓ -Databricks REST API - ↓ -Response Processing - ↓ -Result Marshaling - ↓ -MCP Response to Agent -``` - -### Execution Context Flow - -``` -Create Context - ↓ -Initialize on Cluster - ↓ -Execute Command(s) ←─┐ - ↓ │ -Get Status (polling) │ - ↓ │ -More Commands? ──────┘ - ↓ -Destroy Context -``` - -## Key Design Decisions - -### 1. Async-First Architecture - -**Rationale**: Databricks operations are I/O-bound, making async operations ideal for performance. - -**Implementation**: -```python -async def execute_sql(params: Dict[str, Any]) -> Dict[str, Any]: - async with httpx.AsyncClient() as client: - response = await client.post(...) - return await process_response(response) -``` - -### 2. Layered Error Handling - -**Approach**: Each layer has specific error handling responsibilities. - -**Layers**: -1. **MCP Layer**: Protocol-level errors (malformed requests) -2. **API Layer**: Service-level errors (authentication, permissions) -3. **HTTP Layer**: Network-level errors (timeouts, retries) - -### 3. Configuration Management - -**Strategy**: Environment-based with validation. - -```python -class DatabricksConfig(BaseSettings): - host: str - token: SecretStr - warehouse_id: Optional[str] = None - - class Config: - env_prefix = "DATABRICKS_" - case_sensitive = False -``` - -### 4. Type Safety - -**Approach**: Comprehensive type hints throughout codebase. - -**Benefits**: -- Compile-time error detection -- Better IDE support -- Self-documenting code - -## Scalability Considerations - -### Connection Pooling - -HTTP client maintains persistent connections: -```python -client = httpx.AsyncClient( - limits=httpx.Limits(max_keepalive_connections=20), - timeout=httpx.Timeout(60.0) -) -``` - -### Async Concurrency - -Multiple tools can execute concurrently: -```python -results = await asyncio.gather( - server.call_tool('list_clusters', ...), - server.call_tool('list_jobs', ...), - server.call_tool('execute_sql', ...) -) -``` - -### Resource Management - -Context managers ensure proper cleanup: -```python -async with create_execution_context(...) as context: - await execute_commands(context) - # Context automatically destroyed on exit -``` - -## Security Architecture - -### Authentication Flow - -``` -Environment Variables - ↓ -Configuration Loader - ↓ -Token Validator - ↓ -Request Authenticator - ↓ -Databricks API -``` - -### Credential Handling - -1. **Storage**: Environment variables only, never in code -2. **Transmission**: HTTPS only, token in Authorization header -3. **Validation**: Token format and expiration checks -4. **Scope**: Minimum required permissions - -## Extension Points - -### Adding New Tools - -1. **Define tool schema** in `DatabricksMCPServer` -2. **Implement API method** in appropriate `src/api/` module -3. **Register tool handler** in server -4. **Add tests** in `tests/` - -Example: -```python -# In src/api/new_feature.py -async def new_operation(params: Dict[str, Any]) -> Dict[str, Any]: - """Implement new Databricks operation.""" - pass - -# In src/server/databricks_mcp_server.py -@server.list_tools() -async def handle_list_tools(): - return [{ - "name": "new_operation", - "description": "Description of operation", - "inputSchema": {...} - }] -``` - -### Adding New API Clients - -Create new module in `src/api/`: -```python -# src/api/new_service.py -from src.core.utils import get_http_client -from src.core.config import get_config - -async def service_operation(**kwargs): - """Implement service-specific logic.""" - config = get_config() - client = get_http_client() - # Implementation -``` - -## Testing Architecture - -### Test Organization - -``` -tests/ -├── test_mcp_server.py # MCP protocol compliance -├── test_clusters.py # Cluster API tests -├── test_jobs.py # Job API tests -├── test_sql.py # SQL execution tests -└── conftest.py # Shared fixtures -``` - -### Mocking Strategy - -Mock external dependencies: -```python -@pytest.fixture -def mock_databricks_api(mocker): - return mocker.patch('httpx.AsyncClient.post') - -async def test_list_clusters(mock_databricks_api): - mock_databricks_api.return_value.json.return_value = {...} - result = await list_clusters() - assert result is not None -``` - -## Performance Metrics - -### Key Performance Indicators - -- **Tool Invocation Latency**: Time from MCP request to response -- **API Call Duration**: Time for Databricks API calls -- **Connection Pool Utilization**: Active vs. idle connections -- **Error Rate**: Failed requests per total requests - -### Monitoring Points - -1. MCP tool execution time -2. HTTP request/response time -3. Retry attempts and success rate -4. Memory usage for large result sets - -## Future Enhancements - -### Planned Improvements - -1. **Caching Layer**: Cache frequently accessed data (cluster lists, job definitions) -2. **Batch Operations**: Support for bulk operations where applicable -3. **Webhook Integration**: Event-driven notifications for long-running operations -4. **Metrics Export**: Prometheus-compatible metrics endpoint -5. **Rate Limit Management**: Intelligent request throttling - -### API Evolution - -Following semantic versioning: -- **Patch**: Bug fixes, no API changes -- **Minor**: New tools, backward compatible -- **Major**: Breaking changes to existing tools - -## Dependencies - -### Core Dependencies - -- **mcp**: MCP protocol implementation -- **httpx**: Async HTTP client -- **pydantic**: Data validation and settings -- **databricks-sdk**: Official Databricks SDK (for reference) - -### Development Dependencies - -- **pytest**: Testing framework -- **pytest-asyncio**: Async test support -- **black**: Code formatting -- **pylint**: Static analysis -- **mypy**: Type checking - -## Deployment Patterns - -### Standalone Server - -```bash -python -m src.main -``` - -### Docker Container - -```dockerfile -FROM python:3.10-slim -WORKDIR /app -COPY . . -RUN pip install -e . -CMD ["python", "-m", "src.main"] -``` - -### Service Integration - -Embed in larger applications: -```python -from src.server.databricks_mcp_server import DatabricksMCPServer - -async def main(): - server = DatabricksMCPServer() - # Use server in application -``` - ---- - -**Document Version**: 1.0 -**Last Updated**: January 2025 -**Maintainer**: Kush Patel +# Architecture + +``` +MCP client (Claude, Cursor, ...) + │ stdio or streamable HTTP + ▼ +cli.py ──► server.py build_server(): one MCPServer, one tool per operation, + toolset / read-only filtering, error + size handling + │ + ▼ + api/*.py thin functions per Databricks REST area + │ + ▼ + client.py DatabricksClient: httpx, auth, retries, error parsing + │ + ▼ + Databricks REST API (auth via databricks-sdk unified auth) +``` + +## Modules + +| File | Responsibility | +|---|---| +| `cli.py` | Implements the `databricks-mcp` command (`run`, `list-tools`, `--version`). Sends logs to stderr. | +| `config.py` | Holds `Settings` read from `DATABRICKS_MCP_*` env vars. Auth is not configured here. | +| `client.py` | `DatabricksClient` and `DatabricksAPIError`. Gets auth headers per request from `databricks-sdk` (`Config().authenticate()`), so OAuth tokens refresh automatically. | +| `server.py` | `build_server()` registers the tools, sets their MCP annotations, filters by toolset and read-only mode, turns errors into `ToolError`, and truncates large responses. | +| `api/clusters.py` | Clusters API 2.1 | +| `api/jobs.py` | Jobs API 2.2, run polling and per-task output fan-out | +| `api/sql.py` | SQL Statement Execution. Waits up to 50s on the server, then polls client-side, and flattens the results into columns and rows. | +| `api/warehouses.py` | SQL Warehouses API | +| `api/unity_catalog.py` | Unity Catalog 2.1 catalogs, schemas, tables and volumes | +| `api/files.py` | Files API 2.0 for `/Volumes/...` paths. Uses Range reads. | +| `api/workspace.py` | Workspace API: list, export (decoded), import (encoded), mkdirs | +| `api/dbfs.py` | DBFS, read-only (legacy) | +| `api/command_execution.py` | Command Execution 1.2, including `run_once`, which always destroys its context | + +## Design decisions + +- **Retries.** The client always retries 429s, honoring `Retry-After`. It retries connection failures that never reached the server. It retries 5xx responses and timeouts only for GET, HEAD, PUT and DELETE. A POST like `clusters/create` is not safe to resend. +- **Errors.** Expected failures (`DatabricksAPIError`, `ValueError`) become `ToolError`, so the model sees the real message, such as `HTTP 400 INVALID_PARAMETER_VALUE: ...`. Anything else is a crash: the SDK hides its text from the model and logs the traceback. +- **Context budget.** List tools return slimmed records plus pagination tokens. Every response is capped at `DATABRICKS_MCP_MAX_RESPONSE_CHARS`. +- **Read-only mode.** It relies on each tool's `read_only` flag. SQL and code execution count as writes because their effects can't be checked ahead of time. +- **Testing.** All HTTP is mocked with `respx`. Server tests go through a real in-process MCP `Client`, so schema validation and error conversion are exercised end to end. diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d82386b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,42 @@ +# Changelog + +## 0.2.0 (first PyPI release) + +A rewrite of the 0.1 code. + +### Added +- Published to PyPI as `databricks-mcp-toolkit`, with a `databricks-mcp` command and `python -m databricks_mcp`. +- Unity Catalog tools: `list_catalogs`, `list_schemas`, `list_tables`, `get_table`, `list_volumes`. +- Volume file tools on the Files API: `list_volume_directory`, `read_volume_file`, `write_volume_file`, `delete_volume_file`, `create_volume_directory`. +- SQL warehouse tools: `list_sql_warehouses`, `get_sql_warehouse`, `start_sql_warehouse`, `stop_sql_warehouse`, plus `get_sql_statement` and `cancel_sql_statement`. +- Cluster tools: `restart_cluster`, `resize_cluster`, `list_spark_versions`, `list_node_types`. +- Job tools: `list_job_runs`, `cancel_run`, `run_job` with `job_parameters`. `get_run_output` now handles multi-task runs. +- Workspace tools: `import_notebook`, `create_workspace_directory`, `get_workspace_object`. +- Read-only mode (`--read-only` / `DATABRICKS_MCP_READ_ONLY`) and toolset filtering (`--toolsets`). +- MCP tool annotations (read-only, destructive and idempotent hints) on every tool. +- All Databricks auth methods, through `databricks-sdk` unified auth (OAuth M2M/U2M, profiles, Azure). +- Streamable HTTP transport. +- A unit test suite, plus CI on Python 3.10–3.13 and trusted-publishing release workflow. + +### Changed +- Moved to current endpoints: Jobs `2.0` → `2.2`, Clusters `2.0` → `2.1`. Unity Catalog uses `2.1`. +- Tools take typed, named arguments instead of a single opaque `params` object. +- `execute_sql` waits for the result (polling past the API's 50-second limit) and returns flat columns and rows. +- Large responses are truncated with a hint instead of flooding the model's context. +- POST requests are no longer retried on 5xx or timeouts, which could have duplicated resources. 429s are retried with `Retry-After`. +- Renamed tools: + - `list_notebooks` → `list_workspace` + - `list_files` → `list_dbfs` + - `submit_single_run` → `submit_run` + - `wait_for_run_completion` → `wait_for_run` + - `execute_command_simple` → `run_command` +- Requires `mcp>=2.3`. + +### Fixed +- The server failed to start on a fresh install: it imported `FastMCP`, which was removed in MCP SDK 2.x, and the dependency wasn't pinned. +- `pyproject.toml` said MIT while `LICENSE` is AGPL-3.0. The metadata now matches the license. +- The wheel installed a top-level package named `src`. + +### Removed +- The unused FastAPI app, the placeholder API-key auth, and the PowerShell/bash launcher scripts. +- `get_context_status`, and DBFS write helpers (use volumes instead). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f82b3cf..9be8826 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,547 +1,48 @@ -# Contributing to Databricks MCP Toolkit +# Contributing -Thank you for your interest in contributing to the Databricks MCP Toolkit! This document provides guidelines and instructions for contributing to the project. +Issues and pull requests are welcome. For anything bigger than a small fix, open an issue first so we can agree on the approach. -## Table of Contents - -- [Code of Conduct](#code-of-conduct) -- [Getting Started](#getting-started) -- [Development Setup](#development-setup) -- [Development Workflow](#development-workflow) -- [Coding Standards](#coding-standards) -- [Testing Guidelines](#testing-guidelines) -- [Documentation](#documentation) -- [Submitting Changes](#submitting-changes) -- [Review Process](#review-process) - -## Code of Conduct - -### Our Standards - -- Be respectful and inclusive -- Welcome newcomers and help them get started -- Focus on constructive feedback -- Accept criticism gracefully -- Prioritize the community's best interests - -### Unacceptable Behavior - -- Harassment or discriminatory language -- Personal attacks -- Publishing private information -- Unprofessional conduct - -## Getting Started - -### Prerequisites - -- Python 3.10 or higher -- Git -- uv package manager (recommended) -- Databricks workspace access for testing -- Familiarity with async Python and MCP protocol - -### Find an Issue - -1. Browse [open issues](https://github.com/kshptl/databricks-mcp-toolkit/issues) -2. Look for issues labeled `good first issue` for beginner-friendly tasks -3. Check for issues labeled `help wanted` for more complex contributions -4. Comment on the issue to indicate you're working on it - -### Ask Questions - -- Use [GitHub Discussions](https://github.com/kshptl/databricks-mcp-toolkit/discussions) for questions -- Open an issue for bug reports or feature requests -- Be specific and provide context - -## Development Setup - -### 1. Fork and Clone - -```bash -# Fork the repository on GitHub, then: -git clone https://github.com/YOUR_USERNAME/databricks-mcp-toolkit.git -cd databricks-mcp-toolkit -``` - -### 2. Set Up Development Environment +## Setup ```bash -# Create virtual environment -python -m venv .venv -source .venv/bin/activate # Unix/Linux/macOS -.venv\Scripts\activate # Windows - -# Install with development dependencies -uv pip install -e ".[dev]" - -# Or with pip +git clone https://github.com/kshptl/Databricks-MCP-Server +cd Databricks-MCP-Server +python -m venv .venv && source .venv/bin/activate pip install -e ".[dev]" ``` -### 3. Configure Environment - -```bash -# Copy example environment file -cp .env.example .env - -# Edit .env with your Databricks credentials -# DATABRICKS_HOST=https://your-workspace.azuredatabricks.net -# DATABRICKS_TOKEN=your_token -# DATABRICKS_WAREHOUSE_ID=your_warehouse_id -``` - -### 4. Verify Setup - -```bash -# Run tests to verify setup -pytest tests/ -v - -# Check code formatting -black --check src/ tests/ - -# Run linter -pylint src/ - -# Type checking -mypy src/ -``` - -## Development Workflow - -### 1. Create a Branch - -```bash -# Update main branch -git checkout main -git pull upstream main - -# Create feature branch -git checkout -b feature/your-feature-name -# OR -git checkout -b fix/bug-description -``` - -### Branch Naming Conventions - -- `feature/` - New features or enhancements -- `fix/` - Bug fixes -- `docs/` - Documentation updates -- `refactor/` - Code refactoring -- `test/` - Test additions or modifications - -### 2. Make Changes - -- Write clean, readable code -- Follow the coding standards below -- Add tests for new functionality -- Update documentation as needed -- Keep commits focused and atomic - -### 3. Commit Changes - -```bash -# Stage changes -git add . - -# Commit with descriptive message -git commit -m "Add feature: brief description" -``` - -### Commit Message Guidelines - -Format: -``` -: - - - -