Skip to content

Commit 8ad5a33

Browse files
authored
feat: MCP server — drop-in Genie MCP replacement (#11)
* feat: MCP server — drop-in replacement for Databricks managed Genie MCP Adds a Streamable HTTP MCP endpoint at /api/2.0/mcp/genie/{gateway_id} that mirrors the official Databricks managed MCP. Clients swap the host and space_id for a gateway_id — same protocol, same tools, same agent code. Semantic cache and rate-limit queue work transparently underneath. - backend: mcp_routes.py with JSON-RPC handler (initialize, tools/list, tools/call) - frontend: MCP reference page with connect info, tools, and code example - test notebook: OpenAI Agents SDK agent comparing managed vs clone MCP Closes #5 Co-authored-by: Isaac * fix: review fixes — race condition lock, parameterize notebook - Add asyncio.Lock per message_id to prevent concurrent polls from double-executing SQL against the warehouse - Replace hardcoded IDs/URLs in test notebook with dbutils.widgets - Rename secret key from "pat" to "oauth_token" for clarity Co-authored-by: Isaac --------- Co-authored-by: lucas-rampimdesouza <lucas.rampim@outlook.com>
1 parent 86f4da7 commit 8ad5a33

File tree

7 files changed

+1158
-3
lines changed

7 files changed

+1158
-3
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Each **gateway** is a named configuration that maps to one Genie Space and SQL W
1616
Caller (OAuth)
1717
|
1818
v
19-
App (/api/2.0/genie/* or /api/v1/ or /api/gateways/)
19+
App (/api/2.0/genie/* or /api/2.0/mcp/* or /api/v1/ or /api/gateways/)
2020
|
2121
+-- Gateway Config (DB) <-- name, space_id, warehouse_id, settings
2222
+-- Embedding Service <-- caller's OAuth (semantic similarity)
@@ -213,6 +213,40 @@ For local development (outside Databricks Apps), configure the **Lakebase Servic
213213

214214
---
215215

216+
## MCP Server (Model Context Protocol)
217+
218+
Drop-in replacement for the [Databricks managed Genie MCP](https://docs.databricks.com/aws/en/generative-ai/mcp/managed-mcp). Any MCP client that supports Streamable HTTP can connect — just provide the URL and auth header.
219+
220+
```
221+
Before: https://<workspace>.cloud.databricks.com/api/2.0/mcp/genie/{space_id}
222+
After: https://<app-name>.aws.databricksapps.com/api/2.0/mcp/genie/{gateway_id}
223+
```
224+
225+
The server exposes two tools per gateway (identical to the managed MCP):
226+
227+
| Tool | Description |
228+
|------|-------------|
229+
| `query_space_{gateway_id}` | Ask a natural language question. Instant on cache hit. |
230+
| `poll_response_{gateway_id}` | Poll for the result of a pending query. |
231+
232+
**Example — OpenAI Agents SDK:**
233+
234+
```python
235+
from agents import Agent, Runner
236+
from agents.mcp import MCPServerStreamableHttp
237+
238+
async with MCPServerStreamableHttp(params={
239+
"url": f"{APP_HOST}/api/2.0/mcp/genie/{GATEWAY_ID}",
240+
"headers": {"Authorization": f"Bearer {TOKEN}"},
241+
}) as mcp:
242+
agent = Agent(name="analyst", model=model, mcp_servers=[mcp])
243+
result = await Runner.run(agent, "Top 3 nations by revenue?")
244+
```
245+
246+
> **Tip:** Enable **Question Normalization** on the gateway when using MCP. LLM agents are non-deterministic — the same user intent can produce different phrasings on each call, reducing cache hit rates. Normalization maps variations to a canonical form before embedding.
247+
248+
---
249+
216250
## API Reference
217251

218252
Three API families are available. Full documentation is built into the app:

0 commit comments

Comments
 (0)