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.

Regions in mcp.json

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

ScopeGrants
readRead access to every domain, including cross-domain tools like get_lake_health and get_table_events
writeWrite 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.

DomainScopesGrants
Policiespolicies:read policies:writeList, create, update, enable/disable, and execute governance policies
Catalogscatalogs:read catalogs:writeList catalogs; register, configure, and refresh catalogs
Tablestables:read tables:writeBrowse, search, and inspect tables (schema, metadata, insights, partitions); compact, roll back, rename, or delete tables
Queryquery:readRun 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

ToolScope
list_catalogscatalogs:read
list_namespacestables:read
search_tablestables:read
get_table_detailstables:read
get_schematables:read
get_table_metadatatables:read
get_table_insightstables:read
get_maintenance_signalstables:read
get_table_profiletables:read
get_partition_distributiontables:read
get_hot_partitionstables:read
get_table_scan_cost_hintstables:read
get_table_eventsread
get_lake_healthread
list_policiespolicies:read

Analysis workflows

ToolScope
analyze_table_healthread
analyze_storage_reclaimread
analyze_compactionread
analyze_lake_healthread
analyze_critical_triageread
analyze_policy_gapsread
analyze_table_maintenanceread

Governance

ToolScope
create_policypolicies:write
update_policypolicies:write
enable_policypolicies:write
disable_policypolicies:write
execute_policypolicies:write

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, table

Quick 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, table

Full 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 to completion/complete with live suggestions. Namespace and table completions use already-selected values from context.arguments (catalog → namespace → table).
  • Agent discovery tools — Cursor Agent does not autocomplete tool arguments. Agents should call list_catalogs, list_namespaces, or search_tables before table-scoped reads and analyze_* 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

SymptomFix
401 UnauthorizedCheck the API key is valid for that region's endpoint and the Authorization header uses Bearer prefix
scope required errorThe key is missing the scope for that tool. Create a new key with the required permissions.
no tenant context errorThe key is not associated with an organization. Ensure the key was created from an org context.
Tools not appearing in clientEnable each server in Cursor Settings → MCP. URLs must end in /mcp and support Streamable HTTP.
Agent calls wrong regionWith 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 tablesLikely 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 requiredThe 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.