MCP server
Goni's Model Context Protocol server on /mcp/v1: reads execute directly against the semantic + operational surface; writes propose (never apply) via the Proposal review loop.
MCP server
A short reference for connecting external agents to Goni over the Model Context Protocol.
Endpoints on this page
POST /mcp/v1- JSON-RPC 2.0 dispatcherGET /mcp/v1/health- liveness probe
Goni ships an MCP server co-located on the Goni API. It gives an MCP-compatible client (Claude Desktop, Cursor, VS Code, a future CLI) a window into the same git-native semantic layer and operational surface that powers the Goni web app. The surface groups into three intents: read the semantic catalog, read operational state (connections, pipelines, warehouse tables, models), and propose new pipelines / metrics / models for human review.
Reads execute; writes propose
Every read tool (list_metrics, query_metric, list_connections, describe_source_table, list_models, and their siblings) executes directly and returns live data with the caller’s RBAC applied at the same call site REST uses.
Every write tool (create_pipeline, create_metric, create_model) does the opposite: it validates the payload against live state and stores a pending Proposal instead of applying. A human reviewer at POST /api/ai/proposals/{id}/apply commits it. Validation runs twice:
- At propose time, the server introspects the source (columns exist, target table not already in use), runs the metric parser contract (per-type required fields, model resolvable, name unique in the tenant’s semantic project), and checks model materialization and
ref()/source()resolution. - At apply time, the review handler re-runs the same preview and only then invokes the same pipeline, metric, and model write paths a REST caller takes. RBAC, validation, and audit are identical between AI-proposed and human-created artifacts.
Chart, dashboard, alert, and embed writes are still absent from MCP. Those flows stay in the SPA where team collaboration and workspace ACL live. The Proposal pattern is opt-in for the three surfaces (pipelines + metrics + models) where autonomous MCP hosts have legitimate write intent and where the git-native semantic layer already handles diffed review well.
Endpoints
| Method | Path | Auth | Permission | Body | Response | Errors |
|---|---|---|---|---|---|---|
| POST | /mcp/v1 | JWT or PAT | per-tool RBAC | JSON-RPC 2.0 request | JSON-RPC 2.0 response | -32700, -32600, -32601, -32602, -32603, -32002, -32003 |
| GET | /mcp/v1/health | none | none | - | {"ok":true,"server":"goni-mcp","version":"1.0.0"} | - |
MCP routes are served alongside the REST surface.
Auth
MCP uses the same middleware chain as REST. A request must carry either a bearer JWT or a personal access token, and the middleware resolves the caller’s EffectivePermissions. Every tool call re-checks that permission set. The server short-circuits with -32003 authentication required if the resolved user is empty.
Tenant scoping is not opt-in: query_metric extracts tenant_id from the auth context, applies the caller’s RowFilters at SQL compile time, and then applies ColumnMasks to the result rows. The operational read tools resolve tenant_id the same way and refuse when it is empty. The same call path REST uses, no separate MCP privilege.
Methods
The dispatcher supports the five JSON-RPC methods MCP clients need.
{"jsonrpc":"2.0","id":1,"method":"initialize"}
initializereturnsprotocolVersion: "2024-11-05",serverInfo, and thetoolsandresourcescapability keys.tools/listreturns the tool inventory (see below).tools/callinvokes one tool bynamewith typedarguments.resources/listreturns the availablegoni://URIs.resources/readfetches one URI.
Tools
Three groups. Every row’s _persona argument is described in the _persona attribution section below.
Read (semantic)
| Tool | Arguments | Returns | RBAC gate | Audit action |
|---|---|---|---|---|
list_metrics | _persona? | every metric visible to the caller under AllowMetrics | AllowMetrics per-metric filter | mcp.list_metrics |
describe_metric | name, _persona? | label, dimensions, and the metric’s declared grain | AllowMetrics[name] | mcp.describe_metric |
list_dimensions | metric, _persona? | dimension entities for a metric | AllowMetrics[metric] | mcp.list_dimensions |
query_metric | metric, optional dimensions, time_grain (day, week, month, quarter, year), filters, limit (default 100, hard-capped at 1000), _persona? | columns, rows, stats | AllowMetrics[metric] + RowFilters in SQL + ColumnMasks on rows | mcp.query_metric |
list_playbooks | _persona? | persona metadata and goni://playbooks/<id> URIs | loaded registry | mcp.list_playbooks |
Read (operational)
| Tool | Arguments | Returns | RBAC gate | Audit action |
|---|---|---|---|---|
list_connections | _persona? | id, name, kind, status per connection (secrets redacted) | AllowSave + per-connection filter | mcp.list_connections |
list_pipelines | optional connection_id, _persona? | pipeline metadata for the tenant, optionally filtered to one connection | AllowSave + per-pipeline filter | mcp.list_pipelines |
list_warehouse_tables | optional database, _persona? | ClickHouse system.tables for tenant-visible databases (excludes system / INFORMATION_SCHEMA / leading-underscore); capped at 10,000 rows, returns truncated flag | AllowSave + warehouse role | mcp.list_warehouse_tables |
describe_source_table | connection_id, table, optional database, _persona? | column names, types, nullability read live from the source connection | AllowSave + per-connection filter | mcp.describe_source_table |
list_models | _persona? | every semantic-layer model (built-in + tenant-authored): name, schema, materialization, description, source | AllowSave | mcp.list_models |
describe_model | name, _persona? | one model’s config + qualified name | AllowSave | mcp.describe_model |
Write (proposal-first)
Every write returns {proposal_id, status:"pending", preview, review_url, apply_url, reject_url, next_step} - the tool itself never mutates state.
| Tool | Arguments | Returns | RBAC gate | Audit action |
|---|---|---|---|---|
create_pipeline | connection_id, target_table, mode (full or incremental), optional source / source_table / name / inc_column / inc_start_value / schedule / enabled / add_audit_columns, _persona? | proposal envelope after the server validates against live source introspection | AllowSave + per-connection filter | mcp.create_pipeline |
create_metric | name, label, type (simple / ratio / derived / cumulative) plus per-type fields (measure + model for simple/cumulative, numerator + denominator for ratio, expression for derived, window + time for cumulative), optional filter / entities / grain_boundary, _persona? | proposal envelope after the metric parser contract runs | AllowSave | mcp.create_metric |
create_model | name, description, config (materialized in view / table / materialized_view + schema + optional tags), sql, primary_entity (string or array), optional foreign_entities, _persona? | proposal envelope after refs and materialization are validated | AllowSave | mcp.create_model |
Apply is separately gated on the artifact-specific allow-list at review time: per-pipeline for pipelines, AllowSave for the metric + model paths. A caller cleared to propose is not automatically cleared to apply - the two events audit separately.
_persona attribution
Every tool (read AND write) accepts an optional _persona argument. When set to a known playbook id (data-analyst / data-engineer / data-architect / diagnostic), the server tags the audit-log origin column as ai:<persona>. Empty or missing _persona falls back to system:mcp so unattributed MCP activity is still traceable.
The persona is a client-provided hint - the server does not verify that the persona matches a real playbook, and an unknown id still gets ai:<id> provenance rather than a silent user fallback.
Why the split: the /audit UI can filter MCP activity separately from human REST activity, and separately from web-app AI dispatch (which uses ai:<persona> too but arrives through /api/ai/chat, not /mcp/v1). Grepping the audit log for origin='ai:data-engineer' returns every mutation initiated by that persona regardless of transport.
Proposal apply / reject surface
MCP hosts do not need to implement the review UI themselves. Every write tool returns a review_url, apply_url, and reject_url in its response envelope. Point the human reviewer at review_url for a UI, or POST directly to apply_url / reject_url once approval is captured elsewhere.
The REST surface backing the loop:
| Method | Path | Purpose |
|---|---|---|
GET | /api/ai/proposals | list pending proposals for the tenant |
GET | /api/ai/proposals/{id} | fetch one proposal with its stored payload + preview |
POST | /api/ai/proposals/{id}/apply | re-run preview, invoke the same PutPipeline / PutMetric / PutModel path REST uses, mark applied |
POST | /api/ai/proposals/{id}/reject | mark rejected with an optional reason |
Apply re-runs the full preview against live state at apply time, so a proposal that stored a valid payload against an intact source schema will refuse cleanly if the source drifted (column dropped, target table already exists) between propose and apply. See Proposals: AI writes with a review gate for the full contract.
Example tools/call
Query a metric (read, executes directly):
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "query_metric",
"arguments": {
"metric": "active_arr",
"dimensions": ["country"],
"time_grain": "month",
"limit": 50,
"_persona": "data-analyst"
}
}
}
Propose an incremental pipeline (write, returns a pending proposal):
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "create_pipeline",
"arguments": {
"connection_id": "conn-postgres-prod",
"source_table": "public.orders",
"target_table": "raw_orders.orders",
"mode": "incremental",
"inc_column": "updated_at",
"schedule": "15m",
"add_audit_columns": true,
"_persona": "data-engineer"
}
}
}
The result text payload for the write example is a JSON string of shape:
{
"proposal_id": "p-9f3c4a2b7d18",
"status": "pending",
"preview": {
"canonical_pipeline": { "id": "...", "mode": "incremental", "schedule": "15m" },
"target_ddl": "CREATE TABLE raw_orders.orders ...",
"warnings": []
},
"review_url": "/proposals/p-9f3c4a2b7d18",
"apply_url": "/api/ai/proposals/p-9f3c4a2b7d18/apply",
"reject_url": "/api/ai/proposals/p-9f3c4a2b7d18/reject",
"next_step": "Human reviewer visits the review_url to inspect the preview, then POSTs to apply_url or reject_url. This tool does not apply the pipeline directly."
}
Chat clients render that string; agent frameworks parse it back and drive the review URL themselves.
Resources
Two goni:// URI schemes are exposed by resources/list and resources/read:
goni://catalogreturns the semantic catalog filtered to the caller’sAllowMetrics. A viewer with a restricted allow-list sees only their subset, not the full metric surface.goni://playbooks/<id>returns persona metadata only. The playbook body is confidential; the actual system prompt is applied server-side by/api/ai/chatwhen the tenant’s BYOK key dispatches. MCP clients receivemetaplus anoticefield explaining the split.
RBAC on MCP responses
MCP is not a bypass. Enumeration is filtered before the response is written, and mutation is gated at propose AND apply time:
list_metricswalks the catalog and skips any metric that fails the caller’sAllowMetricscheck.describe_metricandlist_dimensionsreturn-32003 metric not allowed for this user/tenantwhen the allow-list rejects the name, and the deny is recorded in the audit log.query_metricrefuses the same names and, on allowed metrics, injects the caller’s row filter into the compiled SQL and masks columns on the way out.list_connectionsanddescribe_source_tablerequireAllowSaveand re-check the per-connection filter for the target connection - same gate as the REST/api/connectionsand/api/connections/{id}/tablessurface. Connection secrets are redacted before serialisation.list_pipelinesrequiresAllowSaveand filters each pipeline through the per-pipeline allow-list.list_warehouse_tablesrequiresAllowSave+ the warehouse role; system databases and leading-underscore databases are excluded regardless of role.list_modelsanddescribe_modelrequireAllowSavebecause the model list leaks tenant schema shape.create_pipelinerequiresAllowSave+ the per-connection filter on the source. Apply is separately gated on the per-pipeline allow-list.create_metricandcreate_modelrequireAllowSave. Apply re-runs the same preview and writes through the same semantic-layer path REST would use.goni://catalogreads through the sameAllowMetricsgate.
All calls append to the audit log with actions prefixed mcp.. The full set:
mcp.list_metrics
mcp.describe_metric
mcp.list_dimensions
mcp.query_metric
mcp.list_playbooks
mcp.list_connections
mcp.list_pipelines
mcp.list_warehouse_tables
mcp.describe_source_table
mcp.list_models
mcp.describe_model
mcp.create_pipeline
mcp.create_metric
mcp.create_model
mcp.read_catalog
mcp.read_playbook
mcp.resources_list
MCP activity shows up in Audit and lineage next to REST activity, filterable by the origin column (see _persona attribution above). Default-deny Access control rules apply verbatim.
Connecting Claude Desktop
Claude Desktop reads mcp.json and spawns servers over stdio. Goni’s server speaks JSON-RPC over HTTP, so you point Claude at the mcp-remote stdio-to-HTTP bridge and pass your PAT through an env block the bridge forwards as a header.
{
"mcpServers": {
"goni": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://your-goni-host/mcp/v1",
"--header",
"Authorization: Bearer ${GONI_PAT}"
],
"env": {
"GONI_PAT": "paste-your-token-here"
}
}
}
}
Issue the PAT from Settings -> Personal access tokens in the Goni app and paste it into the env block. The PAT inherits the issuing user’s EffectivePermissions. Prefer the env block over hardcoding the token directly in args; Claude Desktop passes env values to the child process, and mcp-remote expands the shell-style ${GONI_PAT} reference before sending the header.
Connecting Cursor
Cursor’s MCP client uses the same shape under ~/.cursor/mcp.json. Point the url at /mcp/v1 on your Goni host and pass the same bearer header. Cursor calls initialize on connect and populates its tool picker from the tools/list response.
Verifying the connection
A quick health check from the host running the client:
curl -s https://your-goni-host/mcp/v1/health
# {"ok":true,"server":"goni-mcp","version":"1.0.0"}
And a signed initialize round-trip:
curl -sX POST https://your-goni-host/mcp/v1 \
-H "Authorization: Bearer $GONI_PAT" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize"}'
Related
Last updated