Documentation/Features/MCP server

MCP server

DBCraft has a built-in Model Context Protocol server. Connect Claude, or any MCP client, and it can explore your schemas, run read-only queries and build dashboards for you, with your permissions and nothing more.

How it works

One endpoint

Your server exposes MCP at <base_url>/mcp over HTTP. Nothing extra to deploy.

OAuth 2.1 with PKCE

Authorization code flow, S256 PKCE only. Clients register themselves at /oauth/register.

Explicit consent

Users sign in to DBCraft and see exactly which permissions a client is asking for before they click Allow.

Isolated tokens

MCP tokens carry their own audience. They are rejected by the web API, and web sessions are rejected by /mcp.

Rotating refresh tokens

Access tokens last 1 hour, refresh tokens 30 days and rotate on every use. Authorization codes are single-use and expire in 60 seconds.

Same rules as the UI

Every tool call runs as the signed-in user, with their data source access and the same PII masking.

Connect a client

  1. 1Make sure DBCRAFT__SERVER__BASE_URL is set to your public HTTPS address. The OAuth discovery documents are built from it.
  2. 2In Claude, add a custom connector with the URL https://your-dbcraft-host/mcp. Other clients take the same URL.
  3. 3The client registers itself and opens DBCraft. Sign in, review the requested permissions, and click Allow.
  4. 4Ask for what you need, for example "build a dashboard of weekly signups by channel".

For clients configured with a file, the equivalent definition looks like this:

{
  "name": "dbcraft",
  "transport": "http",
  "url": "https://your-dbcraft-host/mcp",
  "auth": {
    "type": "oauth2",
    "client_name": "My MCP client",
    "scopes": [
      "dbcraft.datasources.read",
      "dbcraft.schema.read",
      "dbcraft.queries.execute",
      "dbcraft.dashboards.read",
      "dbcraft.dashboards.write",
      "dbcraft.charts.write",
      "dbcraft.dashboards.share"
    ]
  }
}

Request only the scopes you need. Leave out dbcraft.dashboards.share if the client should never publish links.

Scopes

ScopeGrants
dbcraft.datasources.readList data sources and read their schemas (never credentials).
dbcraft.queries.executeRun read-only SQL against data sources the user can reach.
dbcraft.queries.writeCreate, edit and delete saved queries.
dbcraft.dashboards.readList dashboards and read chart configuration and SQL.
dbcraft.dashboards.writeCreate dashboards, edit them, set layout, delete dashboards you own.
dbcraft.charts.writeAdd, update and delete charts on dashboards you own.
dbcraft.dashboards.shareTurn public links on or off, with optional password and expiry.
dbcraft.schema.readRead curated schema notes on tables and columns.
dbcraft.schema.writeAdd and replace schema notes. Admins only.

A tool called without its scope fails with insufficient_scope and names the scope it needed.

Tools

22 tools, covering everything you can do in the dashboard builder.

Data sources and schema

dbcraft_list_datasourcesList the data sources you can see, with connection metadata and no credentials.
dbcraft_get_datasource_schemaLive databases, tables and columns, with curated schema notes inlined.
dbcraft_sample_tableA small, read-only sample of rows to check a table's shape before writing SQL.

Queries

dbcraft_execute_queryRun read-only SQL and get columns and rows back. Writes are rejected.
dbcraft_list_saved_queriesSaved queries, grouped into personal and org-wide templates.
dbcraft_save_querySave a query for reuse, personally or as an org-wide template.
dbcraft_update_saved_queryEdit a saved query you own.
dbcraft_delete_saved_queryDelete a saved query you own.

Dashboards

dbcraft_list_dashboardsDashboards you can see, grouped into personal, global and org-shared.
dbcraft_get_dashboardA dashboard's layout, filters and metadata.
dbcraft_create_dashboardCreate an empty dashboard and get its id back.
dbcraft_update_dashboardChange a dashboard's metadata, filters or full layout.
dbcraft_delete_dashboardDelete a dashboard and its charts. Owner or admin only.

Charts and layout

dbcraft_add_chartAdd a chart to a dashboard. The SQL is stored and re-run on every render.
dbcraft_update_chartUpdate a chart. Fields you leave out stay as they are.
dbcraft_delete_chartRemove a chart from its dashboard.
dbcraft_arrange_layoutSet every chart's position in one call, on a 12-column grid.

Sharing

dbcraft_share_dashboardTurn a public link on or off, with an optional password and expiry.

Schema notes

dbcraft_list_schema_notesActive notes on a data source, filterable by scope, target and severity.
dbcraft_add_schema_noteAdd a curated note to a data source, table or column. Admins only.
dbcraft_supersede_schema_notesReplace a set of notes with new ones in a single transaction. Admins only.
dbcraft_get_active_user_predicateThe canonical WHERE fragment that filters to active users, if one is defined.

Schema notes

Schema notes are short, curated facts about your data: which table holds settled payments, how to filter to active users, which columns hold personal data, which timezone timestamps are stored in. Admins attach them to a data source, database, table or column, with a severity of info, warn or critical.

They are inlined into dbcraft_get_datasource_schema: data source notes at the top, table notes on each table, column notes on each column. An agent reads them at the moment it looks at the table, before it writes any SQL, which is where most wrong answers start.

Security model

  • A data source the user cannot reach in the UI returns "not found" over MCP as well.
  • Query results go through the same PII classification and masking as the UI, so personal data reaches the model masked.
  • Read-only mode, query deadlines and row limits apply to every call.
  • Unknown clients and unregistered redirect URIs get an error page, never a redirect, so the consent flow cannot be used as an open redirect.

Endpoints

PathPurpose
/mcpMCP endpoint (JSON-RPC over HTTP POST)
/.well-known/oauth-protected-resourceProtected resource metadata (RFC 9728)
/.well-known/oauth-authorization-serverAuthorization server metadata (RFC 8414)
/oauth/registerDynamic client registration, public clients only (RFC 7591)
/oauth/authorizeSign-in and consent screen
/oauth/tokenCode exchange and refresh token rotation
/oauth/revokeToken revocation (RFC 7009)
/oauth/introspectToken introspection (RFC 7662)

Related Guides