From 933d26a1cca13a8b068dbafd56942584c3531e89 Mon Sep 17 00:00:00 2001 From: code-qtzl Date: Tue, 5 May 2026 23:38:01 -0500 Subject: [PATCH] Add '/mcp' endpoint and fix spacing --- mcp-server-hello-world/README.md | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/mcp-server-hello-world/README.md b/mcp-server-hello-world/README.md index 01e0b68c..2169f8d4 100644 --- a/mcp-server-hello-world/README.md +++ b/mcp-server-hello-world/README.md @@ -37,7 +37,7 @@ mcp-server-hello-world/ ├── requirements.txt # Python dependencies (for pip) ├── app.yaml # Databricks Apps configuration ├── Claude.md # AI assistant context and documentation -└── README.md +└── README.md ``` ## Prerequisites @@ -89,9 +89,9 @@ The server will start on `http://localhost:8000` by default (or your specified p ### Accessing the Server - **MCP Endpoints**: `http://localhost:8000/mcp` -- **Available Tools**: - - `health`: Check server status - - `get_current_user`: Get authenticated user information +- **Available Tools**: + - `health`: Check server status + - `get_current_user`: Get authenticated user information ## Testing the MCP Server @@ -107,6 +107,7 @@ uv run pytest tests/ ``` **What the tests do:** + - Automatically start the MCP server - Test that `list_tools()` works correctly - Test that all registered tools can be called without errors by invoking the `call_tools()` @@ -123,7 +124,7 @@ uv run pytest tests/ ```python from databricks_mcp import DatabricksMCPClient mcp_client = DatabricksMCPClient( - server_url="http://localhost:8000" + server_url="http://localhost:8000/mcp" ) # List available MCP tools print(mcp_client.list_tools()) @@ -141,6 +142,7 @@ chmod +x scripts/dev/query_remote.sh ``` The script will guide you through: + 1. **Profile selection**: Choose your Databricks CLI profile 2. **App name**: Enter your deployed app name 3. **Automatic configuration**: Extracts app scopes and URLs automatically @@ -148,6 +150,7 @@ The script will guide you through: 5. **End-to-end test**: Tests `list_tools()`, and invokes each tool returned in list_tools **What it does:** + - Retrieves app configuration using `databricks apps get` - Extracts user authorization scopes from `effective_user_api_scopes` - Gets workspace host from your Databricks profile @@ -180,11 +183,11 @@ To add a new tool to your MCP server: def calculate_sum(a: int, b: int) -> dict: """ Calculate the sum of two numbers. - + Args: a: First number b: Second number - + Returns: dict: Contains the sum result """ @@ -206,13 +209,16 @@ def calculate_sum(a: int, b: int) -> dict: The `utils.py` module provides two helper methods for interacting with Databricks resources via the Databricks SDK Workspace Client: **When deployed as a Databricks App:** + - `get_workspace_client()` - Returns a client authenticated as the service principal associated with the app. See [App Authorization](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/auth#app-authorization) for more details. - `get_user_authenticated_workspace_client()` - Returns a client authenticated as the end user with scopes specified by the app creator. See [User Authorization](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/auth#user-authorization) for more details. **When running locally:** + - Both methods return a client authenticated as the current developer, since no service principal identity exists in the local environment. **Example usage in tools:** + ```python from server import utils @@ -237,6 +243,7 @@ python scripts/dev/generate_oauth_token.py \ ``` **Parameters:** + - `--host`: Databricks workspace URL (required) - `--scopes`: Space-separated OAuth scopes (default: `all-apis offline_access`) - `--redirect-uri`: Callback URI (default: `http://localhost:8020`) @@ -244,6 +251,7 @@ python scripts/dev/generate_oauth_token.py \ **Note:** The script uses the `databricks-cli` OAuth client ID by default. **The script will:** + 1. Generate a PKCE code verifier and challenge 2. Open your browser for authorization 3. Capture the authorization code via local HTTP server @@ -251,6 +259,7 @@ python scripts/dev/generate_oauth_token.py \ 5. Display the token response as JSON (token is valid for 1 hour) **Example with custom scopes:** + ```bash python scripts/dev/generate_oauth_token.py \ --host https://your-workspace.cloud.databricks.com \ @@ -272,6 +281,7 @@ uv run custom-mcp-server --help ``` The default configuration: + - **Host**: `0.0.0.0` (listens on all network interfaces) - **Port**: `8000` (configurable via `--port` argument) @@ -338,11 +348,13 @@ Change the port in `server/main.py` or set the `PORT` environment variable. ### Import Errors Ensure all dependencies are installed: + ```bash uv sync # or pip install -r requirements.txt ``` ## Resources + - [Databricks MCP Documentation](https://docs.databricks.com/aws/en/generative-ai/mcp/custom-mcp) - [Databricks Apps](https://www.databricks.com/product/databricks-apps) - [FastMCP Documentation](https://github.com/jlowin/fastmcp) @@ -353,5 +365,3 @@ uv sync # or pip install -r requirements.txt ## AI Assistant Context See [`Claude.md`](./Claude.md) for detailed project context specifically designed for AI assistants working with this codebase. - -