MCP Server Setup
Sonar exposes an MCP (Model Context Protocol) server that lets any compatible AI agent — Cursor, Claude Desktop, LangChain, or custom builds — discover, query, and manage your data lake with zero integration code.
Quick start
The MCP server runs on each regional Sonar API host. Select every region your agent should reach — the generated .cursor/mcp.json includes one endpoint per region. You need an API key per organization region from Organization > API Keys.
Each region is a separate MCP server entry (sonar-{region}). Cursor namespaces tools by server name so agents can call sonar-us-east-1 vs sonar-ap-south-1 without ambiguity. API keys are region-scoped — use the key created for each org/region.
1. Create API keys
Create one key per region your org uses (switch region in the sidebar before creating the key). MCP clients authenticate with API keys only — not browser cookies. Select the permissions your agent needs (see Permissions). Copy each key — it is only shown once.
2. Configure your client
Copy the JSON below into .cursor/mcp.json. Replace each region-specific placeholder (e.g. <your-api-key-us-east-1>) with the matching regional key.
Client configuration
Single-region setup. Enable all listed servers under Cursor Settings → MCP.
Cursor
Add to .cursor/mcp.json in your project root:
{
"mcpServers": {
"sonar-us-east-1": {
"url": "https://api.lakeops.dev/mcp",
"headers": {
"Authorization": "Bearer <your-api-key-us-east-1>"
}
}
}
}Claude Desktop
Add the same block to your Claude Desktop claude_desktop_config.json:
{
"mcpServers": {
"sonar-us-east-1": {
"url": "https://api.lakeops.dev/mcp",
"headers": {
"Authorization": "Bearer <your-api-key-us-east-1>"
}
}
}
}Custom / future regions
To add a region not listed above, append another entry under mcpServers with a unique name and the regional https://…/mcp URL. Contact Sonar for new region hostnames.
Permissions & scopes
API keys carry scopes that control which MCP tools the agent can call. Each tool requires a minimum scope — calls without it return a scope '...' required error naming the missing scope. A key can hold a global wildcard, one or more domain scopes, or both — pick domain scopes in the dashboard's API Keys panel to issue a key narrower than full read/write access.
Global wildcards
| Scope | Grants |
|---|---|
read | Read access to every domain, including cross-domain tools like get_lake_health and get_table_events |
write | Write access to every domain |
Domain scopes
Narrower alternative to the wildcards above — grant just what an integration needs, e.g. a key that can only execute_policy without touching catalogs or tables.
| Domain | Scopes | Grants |
|---|---|---|
| Policies | policies:read policies:write | List, create, update, enable/disable, and execute governance policies |
| Catalogs | catalogs:read catalogs:write | List catalogs; register, configure, and refresh catalogs |
| Tables | tables:read tables:write | Browse, search, and inspect tables (schema, metadata, insights, partitions); compact, roll back, rename, or delete tables |
| Query | query:read | Run ad-hoc SQL queries. Read-only — there is no query:write |
Read and write are independent per domain: a policies:write-only key can call create_policy and also list_policies (write implies read within the same domain), but nothing in the catalogs, tables, or query domains, and none of the cross-domain tools that require the bare read wildcard. The same independence applies to the global wildcards themselves — a write-only key does not gain read access unless read is also granted.
Response formats
Discovery tools
Return structured JSON (catalog lists, table maps, policy objects, dashboard metrics).
Analysis tools (analyze_*)
Return { title, instructions }. The instructions field contains preloaded data and a structured report format for the agent to follow. These are read-only — they do not execute maintenance.
Errors
Failed tool calls return { "error": "..." }. Common messages: scope 'policies:write' required, no tenant context, Table not found.
Available tools
The MCP server exposes 27 tools across discovery, analysis, and governance. Agents auto-discover them via the standard MCP tool listing.
Discovery & read
| Tool | Scope | Description |
|---|---|---|
list_catalogs | catalogs:read | List all Iceberg catalogs with stats (table count, total size, status). Start here. |
list_namespaces | tables:read | List namespaces in a catalog. Optional query filter on namespace path. |
search_tables | tables:read | Search and filter tables by name, catalog, namespace, or health status. The query argument is optional — omit it to list/filter by catalog, status, and sort order only. |
get_table_details | tables:read | Stats for one table: size, record count, delete files, status, location. |
get_schema | tables:read | Current table schema: columns, identifier_columns, partition_by, sort_by, schema_id. Prefer over get_table_metadata when you only need layout. |
get_table_metadata | tables:read | Full Iceberg metadata plus ai_context (schema, partition_by, sort_by, snapshot stats). Use for schema/layout questions. |
get_table_insights | tables:read | Health insights explaining why a table is WARNING or CRITICAL, with recommendations. |
get_maintenance_signals | tables:read | Adaptive maintenance signals: needs_compaction, needs_expire_snapshots, needs_rewrite_manifests, scores, and projected trigger times. |
get_table_profile | tables:read | Combined maintenance profile: stats, insights, signals, health_signals[], and maintenance_decisions in one call. |
get_partition_distribution | tables:read | Partition-level file distribution: counts, sizes, delete ratios, and histograms per partition. Supports pagination and partition-path search. |
get_hot_partitions | tables:read | Top partitions by file count and record count to detect skew, with a skew_signal when the hottest partition exceeds 10× the average. |
get_table_scan_cost_hints | tables:read | Full-scan cost signals from table stats: file counts, bytes, delete files, snapshot/manifest counts, and cost_signals[] warnings. |
get_table_events | read | Operation history (compaction, expiry, orphan cleanup, etc.) with per-event details. Supports time range and filters. Spans policies and tables, so it requires the broader read wildcard rather than one domain scope. |
get_lake_health | read | Org-wide lake health for the last 30 days: catalogs, tables, storage reclaimed, health breakdown. Spans every domain, so it requires the broader read wildcard. |
list_policies | policies:read | List governance policies. Filter by type, catalog, or scopeKind (GOVERNANCE / TABLE_ATTACHED for effective policies on a table). |
Analysis workflows
| Tool | Scope | Description |
|---|---|---|
analyze_table_health | read | Quick health check: preload table stats, insights, and recent events. Returns {title, instructions}. |
analyze_storage_reclaim | read | Preload largest tables and snapshot-bloat insights. Returns storage reclaim analysis instructions. |
analyze_compaction | read | Preload small-file, high-delete, and CRITICAL tables. Returns compaction planning instructions. |
analyze_lake_health | read | Preload 30-day dashboard and CRITICAL tables. Returns executive summary instructions. Pairs with get_lake_health. |
analyze_critical_triage | read | Preload CRITICAL/WARNING tables and top insights. Returns on-call triage instructions. |
analyze_policy_gaps | read | Preload maintenance insights and existing policies. Returns governance gap analysis instructions. |
analyze_table_maintenance | read | Full maintenance decision: profile, policies, and last 20 events. Returns actionable recommendations including do-nothing. |
Governance
| Tool | Scope | Description |
|---|---|---|
create_policy | policies:write | Create a governance policy. REMOVE_ORPHAN_FILES requires an enabled EXPIRE_SNAPSHOTS or ADAPTIVE_MAINTENANCE policy in the same or broader scope first. |
update_policy | policies:write | Update an existing policy by ID. |
enable_policy | policies:write | Enable a previously disabled policy. |
disable_policy | policies:write | Disable a policy without deleting it. |
execute_policy | policies:write | Trigger immediate execution of a SCHEDULED or MANUAL policy. Marked destructive — clients may prompt for confirmation. |
Read tools carry readOnlyHint. Only execute_policy carries destructiveHint — other write tools create or update policy definitions but do not run maintenance directly.
Built-in prompts
The same analysis workflows are registered as both MCP prompts and analyze_* tools. Claude Desktop can invoke prompts directly; Cursor and most agents should call the matching analyze_* tool and follow the returned instructions field.
analyze_table_healthcatalog, namespace, tableQuick health check: load table stats, insights, and recent events, then summarize health status. For full maintenance decisions with policies and signals, use analyze_table_maintenance.
analyze_storage_reclaimcatalog (optional)Load the top tables by reclaimable storage (snapshot bloat, orphan files) into context, then recommend a prioritized cleanup plan.
analyze_compactioncatalog (optional)Load tables with poor file distribution, high delete ratios, or small-file insights into context, then recommend a compaction plan.
analyze_lake_healthcatalog (optional)Load org-wide lake health for the last 30 days (metrics, optimization backlog, maintenance wins) and produce an executive summary.
analyze_critical_triagecatalog (optional), limit (optional)Load CRITICAL and WARNING tables with top insights into context, then rank what to fix first for on-call triage.
analyze_policy_gapscatalog (optional)Load tables with maintenance insights alongside existing policies, then recommend missing or misconfigured governance policies.
analyze_table_maintenancecatalog, namespace, tableFull maintenance decision: load table profile (stats + signals + insights), effective policies, and last 20 events. Produces actionable recommendations including do-nothing when appropriate.
Maintenance decisions
Sonar adaptive maintenance continuously samples each table and stores a maintenance sample with the logic for why compaction, snapshot expiry, or manifest rewrite should run. Fetch them via get_maintenance_signals: needs_compaction, needs_expire_snapshots, needs_rewrite_manifests, per-action scores, accumulation rates, and projected trigger times.
For table-level optimization, prefer get_table_profile or call analyze_table_maintenance for a full decision workflow. In Cursor, use analyze_policy_gaps, analyze_table_health, etc. — call the tool and follow the returned instructions field.
Policy safety: REMOVE_ORPHAN_FILES policies require an enabled EXPIRE_SNAPSHOTS or ADAPTIVE_MAINTENANCE policy in the same or broader scope — snapshot expiry must run before orphan cleanup.
Autocompletion & discovery
Sonar supports two complementary ways to resolve catalog, namespace, and table names:
- •Prompt autocomplete — when a client fills MCP prompt arguments (e.g.
analyze_table_health), the server responds tocompletion/completewith live suggestions. Namespace and table completions use already-selected values fromcontext.arguments(catalog → namespace → table). - •Agent discovery tools — Cursor Agent does not autocomplete tool arguments. Agents should call
list_catalogs,list_namespaces, orsearch_tablesbefore table-scoped reads andanalyze_*workflows.
Completions are registered for all built-in prompts. Up to 20 tenant-scoped suggestions per request.
Authentication & tenant isolation
Every MCP request passes through the same authentication layer as the REST API. Use an organization API key in the Authorization: Bearer header. The key is bound to your organization and data region — agents can only see and act on your tenant's data.
- •Unauthenticated requests — rejected with 401
- •Invalid or expired keys — rejected with 401
- •Insufficient scope — tool returns an error result (does not execute)
- •Cross-tenant access — not possible; tenant context is derived from the key, not from agent input
Troubleshooting
| Symptom | Fix |
|---|---|
| 401 Unauthorized | Check the API key is valid for that region's endpoint and the Authorization header uses Bearer prefix |
scope required error | The key is missing the scope for that tool. Create a new key with the required permissions. |
no tenant context error | The key is not associated with an organization. Ensure the key was created from an org context. |
| Tools not appearing in client | Enable each server in Cursor Settings → MCP. URLs must end in /mcp and support Streamable HTTP. |
| Agent calls wrong region | With multiple servers, tell the agent which MCP server to use (e.g. sonar-us-east-1) or disable regions you don't need in mcp.json. |
| Empty catalogs or no tables | Likely a region mismatch. Keys for US East (N. Virginia) orgs must use api.lakeops.dev, not api-in.lakeops.dev. Update the matching server entry to https://api.lakeops.dev/mcp. |
Read tools fail with scope required | The key has write scope only. Write does not include read — add the read scope when creating the key. |
| 403 Forbidden (HTTP) | The key lacks the scope required for the HTTP route, or the key is not associated with an organization. Tool-level scope errors return 200 with an error payload instead. |
