MCP server for data analytics: what to expose, safely

What the Model Context Protocol is, why an analytics MCP server should expose metrics instead of a raw SQL tool, and the security and governance controls that make AI agents safe on a warehouse.

An MCP server for data analytics is a service that lets AI agents such as Claude, ChatGPT or Cursor discover and query your data through the Model Context Protocol, and the safe design exposes governed metrics rather than a tool that runs any SQL. The reason is accuracy as much as security. A raw execute_sql tool hands the model the hardest job in analytics, writing correct SQL against tables whose business rules it cannot see, and on enterprise-style benchmarks even the best agents still fail a large share of tasks. A metric tool shrinks the job to picking a defined metric, dimensions and filters, so the number matches the dashboard. Security follows the same logic. The MCP specification says servers MUST validate tool inputs, implement access controls, rate limit invocations and sanitize outputs, and that there SHOULD be a human able to deny tool calls. Below: what MCP is, what an analytics server should expose, and the controls, with ClickHouse SQL tested on a real server, that make it safe.

What is an MCP server?

The Model Context Protocol is an open standard for connecting AI applications to external data and tools. Anthropic introduced it in November 2024 and in December 2025 donated it to the Agentic AI Foundation, a directed fund under the Linux Foundation. The current specification revision is dated 2026-07-28.

The protocol has three roles. A host is the AI application the user talks to (a desktop chat app, an IDE, an agent framework). Inside it, a client holds the connection to one server, which is the service that exposes your capabilities. Messages are JSON-RPC 2.0. A server can offer three kinds of features:

FeatureWho controls itAnalytics example
ToolsThe model decides when to call themquery_metric, list_metrics, describe_metric
ResourcesThe application decides how to include them as contextA metric catalog, a data dictionary, a glossary
PromptsThe user invokes them as templates“Weekly revenue review”, “Explain this anomaly”

Tools are where the risk lives. The specification calls them model-controlled: the model reads each tool’s name, description and input schema, then decides on its own to call it. Whatever a tool can do, the model can do, prompted by the user or by anything else that ends up in its context.

An MCP server can run locally over stdio (the host starts it as a child process) or remotely over HTTP. For a shared warehouse, a remote server is usually the better shape, because identity, limits and audit then live in one place you operate rather than on every laptop.

Why a raw SQL tool is the wrong default for analytics

The quickest analytics MCP server is three tools: list tables, describe a table, run a query. Many open-source servers look like this, and for an engineer exploring a dev database it is genuinely useful. As the default way for a company to ask its warehouse questions, it has two problems.

Accuracy. A model with only a schema has to guess business logic: which orders count as revenue, which joins multiply rows, which time zone defines a month, how the engine treats nulls. The result is SQL that runs and returns a plausible, wrong number. We reproduced five of these failure patterns with runnable SQL in text-to-SQL accuracy. An MCP server does not change any of them. It only makes them reachable from more places.

Blast radius. A tool that accepts arbitrary SQL can do whatever the database user behind it can do. If that user can read the PII schema, so can the agent. If it can run a full scan of a ten-billion-row table, the agent can do that too, as often as it likes. And if anything in the conversation can steer the model, that steering reaches the warehouse.

A metric layer fixes both. When the tool is query_metric(metric, dimensions, time_grain, filters), the business logic lives in definitions a human reviewed, and the set of possible queries is bounded by what the layer defines. That is the argument for a semantic layer in general, and it applies with more force when the caller is an autonomous agent.

What should an analytics MCP server expose?

Design the surface in tiers, from safest to riskiest, and turn on only what each audience needs.

TierToolsGood forMain risk
1. Metricslist_metrics, describe_metric, list_dimensions, get_dimension_values, query_metric, get_compiled_sqlBusiness users, executives, most AI Q&AQuestions outside the defined metrics get refused
2. Curated modelslist_models, describe_model, read-only queries limited to modelled tablesAnalysts who need ad hoc slicesModel can still misuse joins and filters
3. Raw SQLlist_tables, describe_table, execute_sqlData engineers on dev or sandbox dataEverything above, plus access to whatever the user can read

Tier 1 is the default for anyone who is not writing SQL themselves. Vendors converge on similar shapes: the dbt MCP server has semantic layer tools named list_metrics, get_dimensions, get_dimension_values, query_metrics and get_metrics_compiled_sql, alongside a separate execute_sql tool. The split between metric tools and SQL tools is the useful pattern to copy.

Write tool definitions that constrain the model

A tool definition is a contract. The tighter its input schema, the fewer ways the model can go wrong. Use enums for anything with a closed set of values, cap limits in the schema, and reject unknown arguments:

{
  "name": "query_metric",
  "title": "Query a governed metric",
  "description": "Returns values for one defined business metric, grouped by up to three dimensions. Use list_metrics first. Do not use for questions about metrics that list_metrics does not return; say the metric is not defined instead.",
  "inputSchema": {
    "type": "object",
    "properties": {
      "metric": { "type": "string", "description": "A name returned by list_metrics" },
      "dimensions": { "type": "array", "items": { "type": "string" }, "maxItems": 3 },
      "time_grain": { "type": "string", "enum": ["day", "week", "month", "quarter", "year"] },
      "filters": { "type": "array", "items": { "type": "string" }, "maxItems": 5 },
      "limit": { "type": "integer", "minimum": 1, "maximum": 1000, "default": 100 }
    },
    "required": ["metric"],
    "additionalProperties": false
  },
  "annotations": { "readOnlyHint": true, "openWorldHint": false }
}

Three details matter. First, the description tells the model when not to call the tool, which reduces guessed answers. Second, the server must still validate every argument: a schema is advice to the model, not a guarantee, and the specification makes input validation a server MUST. Check metric against the catalog the caller may see, and parse filters into a structured form rather than pasting them into SQL. Third, annotations such as readOnlyHint are hints for the host’s UI. The specification says clients MUST treat them as untrusted unless the server is trusted, so they never replace a read-only database user.

Return structured results with provenance

Return rows as structuredContent with an outputSchema, plus the same data serialized as text for older clients. Include the compiled SQL, the metric definition version and the row count, so a human can check where a number came from. When a query is refused or fails validation, return a tool execution error (isError: true) with a message the model can act on, such as “Metric net_arr is not defined. Defined revenue metrics: mrr, active_arr.” That turns a guessed answer into a clarifying one.

Security and governance controls for an analytics MCP server

The controls below are layered on purpose. Each one assumes the layer above it can fail.

1. Authenticate every request as the real user

An agent acting for a user should see what that user sees, no more. That means each request carries the user’s identity, and the server resolves their permissions on every call. Avoid a single shared service account behind the MCP server: it makes every caller equally privileged and turns the audit log into one name.

If the server delegates to another API, follow the MCP security best practices: “MCP servers MUST NOT accept any tokens that were not explicitly issued for the MCP server.” Forwarding a client’s token downstream unchanged (token passthrough) bypasses the server’s own limits and breaks the audit trail. For remote servers, the specification’s authorization chapter is built on OAuth. Request narrow scopes first and step up for privileged tools, rather than granting everything on connect.

2. Enforce least privilege in the warehouse, not only in the server

Application checks have bugs. The database should refuse what the agent must never do, even if the server is compromised or misconfigured. The official ClickHouse MCP server makes the same point in its README: its drop guard is “not a security boundary”; the boundary is the ClickHouse user’s grants. Here is a dedicated agent user in ClickHouse SQL, tested on ClickHouse 26.11:

-- Hard limits that apply to every query this user runs
CREATE SETTINGS PROFILE mcp_agent_profile SETTINGS
    readonly = 1,
    max_execution_time = 30,
    max_result_rows = 10000,
    result_overflow_mode = 'throw',
    max_memory_usage = 4000000000;

-- Read access to modelled tables only, never raw or PII schemas
CREATE ROLE mcp_reader;
GRANT SELECT ON marts.* TO mcp_reader;

CREATE USER mcp_agent IDENTIFIED WITH sha256_password BY 'from-your-secret-manager'
    SETTINGS PROFILE 'mcp_agent_profile';
GRANT mcp_reader TO mcp_agent;

-- Row-level security: this role only ever sees EU rows
CREATE ROW POLICY eu_only ON marts.fct_orders
    FOR SELECT USING region = 'EU' TO mcp_reader;

-- Cap total consumption per hour
CREATE QUOTA mcp_agent_quota
    FOR INTERVAL 1 hour MAX queries = 500, read_rows = 1000000000
    TO mcp_agent;

What happened when we connected as mcp_agent against 50,000 test orders, half EU and half US:

AttemptResult
SELECT region, count() FROM marts.fct_orders GROUP BY regionOne row: EU 25000. The row policy removed US rows silently.
SELECT * FROM raw.customers_piiACCESS_DENIED: needs SELECT ON raw.customers_pii
INSERT INTO marts.fct_orders ... or DROP TABLEACCESS_DENIED
SELECT * FROM marts.fct_orders (25,000 rows)TOO_MANY_ROWS_OR_BYTES: max rows 10 thousand
... SETTINGS max_result_rows = 0 to lift the capREADONLY: cannot modify the setting in readonly mode

The last row is why readonly = 1 matters. Under readonly = 2 a user may change settings with SET, which, unless you add settings constraints, would let a query lift its own limits. The ClickHouse permissions documentation lists what each level allows. For one agent user serving many people, keep per-user row filters in the MCP server or semantic layer too, because a warehouse row policy only knows the warehouse user. Our guide to row-level security in ClickHouse covers the multi-tenant patterns.

3. Mask sensitive columns and filter the catalog

Do not let discovery tools leak what query tools would refuse. If a user may not query a metric, list_metrics should not return it, and a catalog resource should be filtered the same way. Apply column masking (hashing emails, truncating IDs) before rows leave the server, because anything you return goes into the model’s context and possibly the host’s logs.

4. Make writes proposals, not actions

Read-only covers most analytics use. When agents legitimately need to create things (a new metric, a pipeline, a model), do not let the tool apply the change. Have it validate the payload and store a pending proposal that a human reviews and applies, ideally through the same code path a human edit takes. The specification’s guidance supports this: tools should have a human in the loop able to deny invocations, and clients should prompt for confirmation on sensitive operations. A proposal queue makes that review durable rather than a click in a chat window.

5. Plan for prompt injection

An analytics agent often reads untrusted text: support ticket bodies, product reviews, free-text CRM notes. Any of it can contain instructions. Simon Willison’s “lethal trifecta” names the dangerous combination: access to private data, exposure to untrusted content, and the ability to communicate externally. An analytics MCP server supplies the first, your data supplies the second, and other tools in the same host (web fetch, email, a code runner) can supply the third.

You cannot filter injection out of text reliably, so cut the chain instead. Keep the analytics server free of tools that send data anywhere. Return free-text columns only when a question needs them. Treat tool results as data, and expect host-side confirmation before an agent chains a data read into an outbound action.

6. Audit every call

Log each tool call with the user, the tool, the arguments, the compiled SQL, the row count and whether it was allowed or denied, and tag it as agent-initiated so you can separate it from human activity. Denials are the interesting rows: a burst of refused metric names is how you notice an agent probing, or a gap in your semantic layer that users keep hitting.

7. Treat local servers as code you run

A local MCP server is a program running with your privileges. The specification’s best practices warn that one-click setups can run arbitrary startup commands. Pin versions, install from the vendor’s official repository, and do not paste production warehouse credentials into a community server you have not read.

How to roll out an analytics MCP server

  1. Start with tier 1 on a handful of metrics that already have one agreed definition. If definitions conflict across dashboards, fix that first; a metric drift audit shows where.
  2. Create a dedicated, read-only warehouse identity with grants on modelled schemas only, query limits, and a quota, as above.
  3. Wire user identity end to end so permissions, row filters and audit rows name the human, not the server.
  4. Build an evaluation set of 30 to 50 real questions with known answers, including questions that must be refused, and rerun it whenever you change models, prompts or definitions.
  5. Review the audit log weekly for denials and refusals. Each recurring refusal is a candidate metric to define.
  6. Add tiers 2 and 3 only for named groups who need them, ideally against sandbox or dev data first.

Where Goni fits

If your warehouse is ClickHouse, Goni is one option that ships an analytics MCP server built on this model. Full disclosure: this is our product. Its read tools cover the semantic catalog (list_metrics, describe_metric, query_metric and others) and operational state, with the caller’s permissions checked on every call, and row filters and column masks applied to metric queries. There is no tool that runs free-form SQL. Write tools for metrics, models and pipelines return a pending proposal that a human reviews and applies, and every call lands in the audit log tagged as MCP activity. Clients authenticate with personal access tokens that inherit the issuing user’s permissions. The drawbacks are real: ClickHouse is the only warehouse Goni queries, it is not open source, and it is younger than the alternatives. You can try it on your own metrics with the 14-day free trial.

FAQ

What is an MCP server in data analytics?

It is a service that exposes your data to AI applications through the Model Context Protocol, so an assistant like Claude or Cursor can discover metrics or tables and run queries as tools. A well-designed one exposes governed metrics and enforces the calling user’s permissions, rather than handing the model unrestricted SQL access.

Is it safe to connect an AI agent to a production database with MCP?

It can be, if safety does not depend on the model behaving. Use a dedicated read-only database user with grants on modelled tables only, query time and row limits, row-level security, per-user identity, and an audit log. Avoid tools that send data externally in the same agent, and require human approval for any write.

Should an MCP server expose SQL or metrics?

Metrics, for most users. A metric tool returns numbers that match your dashboards because the business logic is predefined, and it bounds what the agent can query. A raw SQL tool is useful for engineers exploring sandbox data, but on production it inherits every text-to-SQL accuracy problem and gives the model the full reach of its database user.

Does MCP handle authentication and permissions?

Partly. The specification defines an OAuth-based authorization flow for remote servers and security best practices such as never accepting tokens issued for another service. It does not decide what each user may see. Row-level security, column masking, metric allow-lists and query limits are your server’s and your warehouse’s job.

What is the difference between MCP tools and resources?

Tools are functions the model decides to call, such as querying a metric. Resources are pieces of context, addressed by URI, that the application or user chooses to include, such as a metric catalog or data dictionary. For analytics, put actions in tools and read-only reference material in resources.