|
| 1 | +# **RFC-0014 for Presto** |
| 2 | + |
| 3 | +## Presto Model Context Protocol Support |
| 4 | + |
| 5 | +Proposers |
| 6 | + |
| 7 | +* Reetika Agrawal |
| 8 | + |
| 9 | +## Summary |
| 10 | + |
| 11 | +This proposal introduces support for integrating Model Context Protocol (MCP) with Presto through a separate lightweight process, referred to as the MCP Server. |
| 12 | +The MCP Server acts as a protocol translation layer between AI agents using JSON-RPC and Presto’s existing HTTP-based query protocol. |
| 13 | + |
| 14 | +## Background |
| 15 | + |
| 16 | +Presto exposes a RESTful HTTP API for query submission and result retrieval. Clients submit a query via a POST request and receive a tokenized nextUri chain for incremental result fetching. |
| 17 | +However, AI frameworks like OpenAI MCP operate on a request–response model over JSON-RPC, where clients expect complete results in a single response, not streamed batches. |
| 18 | +Because MCP and Presto differ fundamentally in communication models, a direct integration is impractical. Additionally, direct embedding of MCP into Presto coordinators would disrupt routing and proxy layers that rely on Presto’s native HTTP semantics. |
| 19 | + |
| 20 | +### Goals |
| 21 | + |
| 22 | +- Enable MCP-compatible AI agents (e.g., OpenAI ChatGPT tools) to query Presto seamlessly. |
| 23 | +- Preserve all existing Presto router, proxy, and load-balancing infrastructure without modification. |
| 24 | +- Simplify authentication by reusing existing OAuth/JWT mechanisms. |
| 25 | +- Prevent unbounded queries by applying automatic limits when appropriate. |
| 26 | + |
| 27 | +### Proposed Plan |
| 28 | + |
| 29 | +Introduce a new lightweight service: presto-mcp-server, deployed alongside Presto coordinators and Presto Router. |
| 30 | + |
| 31 | +The MCP server will: |
| 32 | + |
| 33 | +- Expose a JSON-RPC 2.0 HTTP endpoint (`/mcp`, `/v1/mcp`) interface to AI clients. |
| 34 | +- Implement the core MCP primitives: |
| 35 | + - `tools/list` for tool discovery |
| 36 | + - `tools/call` for executing tools |
| 37 | + - Initially provide a single tool: `query.run`, which executes SQL queries against Presto. |
| 38 | +- Internally communicate with Presto coordinators using standard Presto HTTP APIs. |
| 39 | +- Forward OAuth/JWT Bearer tokens transparently from MCP clients to Presto, ensuring that Presto performs all authentication and authorization checks. |
| 40 | +- Translate between the two protocols, aggregating streaming results into a single response. |
| 41 | +- Remain stateless, delegating all query lifecycle management to Presto. |
| 42 | + |
| 43 | +## Proposed Implementation |
| 44 | + |
| 45 | +#### Core Changes |
| 46 | + |
| 47 | +```json |
| 48 | +JsonRpcServlet → McpDispatcher → ToolRegistry → QueryRunTool → PrestoQueryClient → Presto Coordinator |
| 49 | +``` |
| 50 | + |
| 51 | +1. New Module: `presto-mcp-server` |
| 52 | + |
| 53 | + - Implements JSON-RPC 2.0 protocol. |
| 54 | + - Implements core MCP primitive like `tools/list` and `tools/call` |
| 55 | + - Handles methods like query.run. |
| 56 | + |
| 57 | +2. On `query.run`: |
| 58 | + |
| 59 | + - Parses SQL input. |
| 60 | + - Optionally injects a LIMIT clause (if absent) to control data size. |
| 61 | + - Submits the query to Presto coordinator via /v1/statement. |
| 62 | + - Polls the returned nextUri until the query completes. |
| 63 | + - Returns final aggregated results as a single JSON-RPC response. |
| 64 | + |
| 65 | +#### Example Queries |
| 66 | + |
| 67 | +- `tools/list` |
| 68 | +```json |
| 69 | +{ |
| 70 | +"jsonrpc": "2.0", |
| 71 | +"id": 1, |
| 72 | +"method": "tools/list", |
| 73 | +"params": {} |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +- `tools/call → query.run` |
| 78 | +```json |
| 79 | +{ |
| 80 | +"jsonrpc": "2.0", |
| 81 | +"id": 2, |
| 82 | +"method": "tools/call", |
| 83 | +"params": { |
| 84 | + "name": "query.run", |
| 85 | + "arguments": { "sql": "SELECT 1" } |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +### Rationale |
| 91 | + |
| 92 | + - Introduce a new standalone service (presto-mcp-server) to avoid mixing JSON-RPC with Presto’s stateful HTTP protocol. |
| 93 | + - Translate MCP tool calls into Presto HTTP queries, using the existing StatementClient to follow nextUri pages and aggregate results into a single MCP response. |
| 94 | + - Keep the MCP server stateless, with all query lifecycle state remaining on Presto coordinators. |
| 95 | + - Forward OAuth/JWT Bearer tokens directly from MCP clients to Presto, allowing Presto to perform full authentication and authorization without changes. |
| 96 | + - Preserve all existing Presto infrastructure (Router, proxies) by keeping MCP outside the coordinator and communicating using standard Presto HTTP APIs. |
| 97 | + |
| 98 | +## Backward Compatibility Considerations |
| 99 | + |
| 100 | + - MCP server is a new optional component |
| 101 | + - No impact on existing Presto or Router |
| 102 | + - All existing Presto deployments remain unchanged |
| 103 | + |
| 104 | +## Test Plan |
| 105 | + |
| 106 | +- **Unit + Integration Tests:** |
| 107 | +Verify ToolRegistry loading, dispatcher routing, SQL execution via QueryRunTool, and JSON-RPC error handling. |
| 108 | + |
| 109 | +- **End-to-End Validation:** |
| 110 | +Deploy MCP server with Router + Coordinator. Confirm Bearer token forwarding works and MCP clients (Gemini, ChatGPT) successfully execute queries. |
| 111 | + |
| 112 | +## Modules involved |
| 113 | +- `presto-mcp` (new module) |
| 114 | +- `presto-client` |
| 115 | +- `airlift` modules |
| 116 | +- `presto-main` |
| 117 | +- `presto-router` |
| 118 | + |
| 119 | +## Final Thoughts |
| 120 | + |
| 121 | +This proposal cleanly bridges Presto with next-generation agent ecosystems (LLMs, AI workflows, model interaction tools). The MCP server architecture respects Presto’s deployment patterns, is backward-compatible, and provides a robust extension point for future interactive functionality such as: |
| 122 | + |
| 123 | +- Schema browsing tools |
| 124 | +- Table metadata tools |
| 125 | +- Query explanation tools |
| 126 | + |
| 127 | +## WIP - Draft PR Changes |
0 commit comments