You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Materialize includes built-in [Model Context Protocol
12
12
(MCP)](https://modelcontextprotocol.io/) endpoints that let AI agents discover
13
13
and query your real-time data products over HTTP. No sidecar process or external
14
-
server is required — the MCP interface is served directly by the database.
14
+
server is required. The MCP interface is served directly by the database.
15
15
16
16
Two endpoints are available:
17
17
18
-
| Endpoint | Path |Purpose|
19
-
|----------|------|---------|
20
-
|**Agents**|`/api/mcp/agents`| Discover and read data products (indexed views with comments). Designed for customer-facing AI agents. |
21
-
|**Observatory**|`/api/mcp/observatory`| Query `mz_*` system catalog tables for troubleshooting and observability. |
18
+
| Endpoint | Path |Description|
19
+
|----------|------|-------------|
20
+
|**Agents**|`/api/mcp/agents`| Discover and read data products (indexed views with comments). Designed for customer-facing AI agents. Available on the HTTP port (default `6876`). |
21
+
|**Observatory**|`/api/mcp/observatory`| Query `mz_*` system catalog tables for troubleshooting and observability. Available on the HTTP port (default `6876`). |
22
22
23
23
Both endpoints speak [JSON-RPC 2.0](https://www.jsonrpc.org/specification) over
24
24
HTTP POST and support the MCP `initialize`, `tools/list`, and `tools/call`
@@ -40,28 +40,23 @@ Use the credentials of a Materialize user or
40
40
***User ID:** Your email address or service account name.
41
41
***Password:** An [app password](/security/cloud/users-service-accounts/create-service-accounts/).
42
42
43
-
```
44
-
https://<region-host>/api/mcp/agents
45
-
```
46
-
47
43
For production use, we recommend creating a dedicated service account and
48
44
granting it a role with [limited privileges](#rbac).
49
45
50
46
{{< /tab >}}
51
47
52
48
{{< tab "Self-Managed" >}}
53
49
54
-
Use the credentials of a Materialize role with `LOGIN`:
50
+
Create a functional role for MCP privileges, then assign it to a login role:
55
51
56
52
```mzsql
57
-
CREATE ROLE mcp_agent LOGIN PASSWORD 'secret';
53
+
CREATE ROLE mcp_agent;
54
+
CREATE ROLE my_agent LOGIN PASSWORD 'secret';
55
+
GRANT mcp_agent TO my_agent;
58
56
```
59
57
60
-
The MCP endpoints are available on the HTTP listener port (default `6876`):
61
-
62
-
```
63
-
http://<host>:6876/api/mcp/agents
64
-
```
58
+
Authenticate using the login role credentials (`my_agent`). You can create
59
+
additional login roles and grant them the same `mcp_agent` role as needed.
65
60
66
61
{{< /tab >}}
67
62
@@ -100,25 +95,25 @@ CREATE MATERIALIZED VIEW mcp_schema.payment_status AS
100
95
FROM orders
101
96
JOIN payments USING (order_id);
102
97
103
-
CREATE INDEX ON mcp_schema.payment_status (order_id);
98
+
CREATE INDEX payment_status_order_id_idx ON mcp_schema.payment_status (order_id);
104
99
```
105
100
106
101
### 3. Add a comment
107
102
108
-
The top-level comment becomes the tool's description. Column comments become
109
-
parameter descriptions. Write comments that help a language model understand
110
-
**when** and **how** to use the tool.
103
+
The comment on the **index**becomes the data product's description. Column
104
+
comments on the underlying view become parameter descriptions. Write comments
105
+
that help a language model understand **when** and **how** to use the tool.
111
106
112
107
```mzsql
113
-
COMMENT ON MATERIALIZED VIEW mcp_schema.payment_status IS
108
+
COMMENT ON INDEX mcp_schema.payment_status_order_id_idx IS
114
109
'Given an order ID, return the current payment status and last update time.
115
110
Use this tool to drive user-facing payment tracking.';
116
111
117
112
COMMENT ON COLUMN mcp_schema.payment_status.order_id IS
118
113
'The unique identifier for the order';
119
114
```
120
115
121
-
### 4. Create a role and permissions for your agent {#rbac}
116
+
## Create a role and permissions for your agent {#rbac}
122
117
123
118
The role used to authenticate with the MCP endpoint must have:
124
119
@@ -190,18 +185,54 @@ following tools:
190
185
191
186
### `get_data_products`
192
187
193
-
Discover all available data products. Returns a list of names and descriptions.
188
+
Discover all available data products. Returns a lightweight list with name,
189
+
cluster, and description for each product.
194
190
195
191
**Parameters:** None.
196
192
193
+
**Example response:**
194
+
195
+
```json
196
+
{
197
+
"jsonrpc": "2.0",
198
+
"id": 1,
199
+
"result": {
200
+
"content": [
201
+
{
202
+
"type": "text",
203
+
"text": "[\n [\n\"\\\"materialize\\\".\\\"mcp_schema\\\".\\\"payment_status\\\"\",\n\"mcp_cluster\",\n\"Given an order ID, return the current payment status.\"\n ]\n]"
204
+
}
205
+
]
206
+
}
207
+
}
208
+
```
209
+
197
210
### `get_data_product_details`
198
211
199
-
Get the full schema (columns, types, index keys) for a specific data product.
212
+
Get the full details for a specific data product, including its JSON schema
213
+
with column names, types, and descriptions.
200
214
201
215
| Parameter | Type | Required | Description |
202
216
|-----------|------|----------|-------------|
203
217
|`name`| string | Yes | Exact name from the `get_data_products` list. |
204
218
219
+
**Example response:**
220
+
221
+
```json
222
+
{
223
+
"jsonrpc": "2.0",
224
+
"id": 1,
225
+
"result": {
226
+
"content": [
227
+
{
228
+
"type": "text",
229
+
"text": "[\n [\n\"\\\"materialize\\\".\\\"mcp_schema\\\".\\\"payment_status\\\"\",\n\"mcp_cluster\",\n\"Given an order ID, return the current payment status.\",\n\"{\\\"order_id\\\": {\\\"type\\\": \\\"integer\\\", \\\"position\\\": 1}, \\\"status\\\": {\\\"type\\\": \\\"text\\\", \\\"position\\\": 3}}\"\n ]\n]"
230
+
}
231
+
]
232
+
}
233
+
}
234
+
```
235
+
205
236
### `read_data_product`
206
237
207
238
Read rows from a data product.
@@ -212,6 +243,23 @@ Read rows from a data product.
212
243
|`limit`| integer | No | Maximum rows to return. Default: 500, max: 1000. |
213
244
|`cluster`| string | No | Cluster override. If omitted, uses the cluster from the catalog. |
0 commit comments