Skip to main content

MCP Server

Kvery ships a built-in MCP (Model Context Protocol) server, so AI assistants that speak MCP can discover and run your queries as tools — letting an assistant answer questions straight from your databases through Kvery.

What MCP exposes​

Through the MCP server an assistant can:

  • List queries available to it (kvery_list_queries).
  • List groups (kvery_list_groups).
  • Search queries by description, internal note or SQL (kvery_search; SQL only for queries you can edit, and not with a token that hides the SQL).
  • Get a query's details and parameters (kvery_get_query).
  • Execute a query that reads data (with parameters) and read the result (kvery_execute_query). A query that modifies data is refused with a message that points to kvery_execute_write_query.
  • Execute any query, including one that modifies data (kvery_execute_write_query) — not offered to read-only tokens.

Every tool except kvery_execute_write_query is marked as read-only for MCP clients, so a client can let reads run without asking and ask for confirmation before a query that modifies data. Lists, search results and query details tell whether a query modifies data (isWrite). The SQL, the connection name, the average runtime and the time of the last run are only shown for queries you can edit, as in the web app — and a token can hide the SQL even then (see Hiding the SQL).

Access is scoped by the token you issue (see below) — an assistant only ever sees what its token is allowed to see. Basic Auth with your e-mail address and password is also accepted, but prefer tokens: Basic Auth has the full access of your account, cannot be limited with scope tags, made read-only or set to hide the SQL, sends your password with every request and does not ask for the two-factor code.

Connecting​

The server offers the MCP protocol and a REST API on the same address:

TransportEndpointUse
MCP (Streamable HTTP)POST /mcpJSON-RPC 2.0 calls from MCP clients, answered with plain JSON
RESTGET /mcp/queries, /mcp/groups, /mcp/search, GET /mcp/queries/{id}, POST /mcp/queries/{id}/executedirect integration

GET /mcp only announces the POST /mcp endpoint (in an endpoint event) and then closes the stream. MCP clients that can only use the HTTP+SSE transport of MCP protocol version 2024-11-05, which expects the answers on that event stream, are not supported.

Point your MCP-capable client at the /mcp endpoint and authenticate with a Kvery MCP token. The token dialog in Kvery gives you a ready-to-paste client configuration:

{
"mcpServers": {
"kvery": {
"url": "https://app.kvery.io/mcp",
"headers": {
"Authorization": "Bearer kvery_mcp_..."
}
}
}
}

The same token works on the REST endpoints, for scripts, CI pipelines or any HTTP client — see Using the REST API.

POST /mcp takes one JSON-RPC message or a batch of up to 20 messages and offers the methods initialize, ping, tools/list and tools/call. initialize agrees on the protocol version the client asks for when it is 2025-06-18, 2025-03-26 or 2024-11-05, and on 2025-06-18 otherwise. Notifications and responses sent by the client are not answered: a request that holds only such messages gets 202 with an empty body. A tool that fails answers with a result marked isError: true and the message as its text; a successful tool result carries the data as structuredContent and the same JSON as text. Other problems are answered with a JSON-RPC error:

CodeHTTP statusMeaning
-32700400The body is empty or not valid JSON
-32600400An invalid message, an empty batch or a batch of more than 20 messages; inside a batch only the invalid message gets this error
-32601200Unknown method
-32602200params, or the arguments of tools/call, is not an object
-32001401Missing, invalid or expired token, or wrong Basic Auth credentials
-32029429Rate limit reached, or Basic Auth blocked after failed attempts
-32000403 or 503The browser origin is not allowed (403), or a temporary server problem such as an unavailable rate limiter (503)
-32603500Unexpected server error; the message names a reference to quote to the administrator

A batch that is processed is answered with the status 200, with an error for each of its messages that failed.

MCP tokens​

You manage access with MCP tokens, which you create and revoke from your profile menu → MCP / API Keys:

  • Every token is prefixed with kvery_mcp_, so it's easy to recognise. It is shown only once, when you create it: Kvery stores only its HMAC-SHA256 hash.
  • Tokens expire 90 days after they are created. Expired tokens stay in the list, marked Expired, and are deleted automatically 30 days later.
  • Each token can carry optional scope tags (it then only reaches queries with at least one of those tags), so you can hand different assistants different, least-privilege access. Only tags you may use can be chosen; automatic tags that Kvery adds to queries (such as the names of the tables a query uses) and tags starting with _ cannot be used. Scope tags are case-sensitive: use them exactly as they appear on your queries (a tag written in another letter case is refused with a suggestion).
  • The tags are read at every request: when someone who can edit a query you can access adds one of the token's tags to it, the token reaches that query too. Tick Only tags I added count to keep this in your own hands (see below).
  • A token can be read-only and can hide the SQL of your queries (see below).
  • Revoke a token at any time to immediately cut off access.
  • A token name and a scope tag can each be up to 100 characters long (a token created without a name is called MCP Token), a token can have up to 100 scope tags, and you can create up to 5 tokens per hour.
  • Each row of the token list shows the token's name with its badges (Read-only, SQL hidden, Own tags, Expired) and when it was last used (Never used before its first call), its tags, the number of queries it reaches, its creation and expiry dates, and two buttons: Activity opens the token's calls (see Your activity under Limits and security), Revoke revokes it after the question "Revoke this token? Integrations using it will stop working."
  • The token list is paged and searchable, and can be exported to CSV or Excel with the columns Name (followed by "(Read-only)", "(SQL hidden)", "(Own tags)" or "(Expired)" where they apply), Tags, Created, Last used, Expires and Queries (the number of queries the token reaches), with the times in your local time.
  • The list shows how many queries each token reaches (your access when the list is loaded, narrowed by the token's scope tags). Click the number to see these queries with their description and group, filter them by description, group or query ID with the filter box above the list, execute a query in a new browser tab, or edit it if you can. A query of another group opens for editing in the same window, because the editor switches to the query's group. A token that reaches no query shows a highlighted 0; an expired token reaches none and shows a dash.
  • In a window narrower than 768 pixels the token list, and in a window narrower than 992 pixels the activity list, show each row as a card, with the column names as labels; the column names above the token cards sort the list.
  • Changing or resetting your password revokes all of your tokens — create new ones afterwards. Your profile warns you before the change and tells you if the tokens could not be revoked.
warning

An MCP token grants an assistant the ability to run your queries. Store it like a password, scope it tightly, and revoke tokens you don't use.

Read-only tokens​

Tick Read-only when you create a token, and the token can only run queries that read data:

  • MCP clients using it don't get kvery_execute_write_query, so they can only use kvery_execute_query, which runs queries that read data.
  • On the REST API, executing a query that modifies data answers 403.
  • Listing, searching and query details work as usual.

Read-only is enforced at the database, not only by checking the SQL text. Every read-only run (kvery_execute_query with any token, and any run with a read-only token) executes inside a transaction that is always rolled back:

  • On MySQL / MariaDB and PostgreSQL the transaction is READ ONLY, so the database itself rejects any data change — including one made by a function or procedure called from a SELECT — and nothing is ever committed. A schema change, which MySQL / MariaDB commit implicitly, is stopped by the SQL text check: it counts as a write, so a read-only run never sends it.
  • On SQL Server (no read-only transaction mode) a normal transaction is used and the rollback discards anything the query changed. A COMMIT or ROLLBACK in the query's own SQL ends this transaction early, so whatever runs after it is only covered by the SQL text check.
  • Agent connections can't be enforced this way, so a read-only run of an agent-connection query is refused; use a full-access (non read-only) token with kvery_execute_write_query for those.
  • A value inserted into a statement while the query runs (a query variable, :name = …) can't add another statement to it: a read-only run refuses such a statement.

So on MySQL / MariaDB and PostgreSQL a read-only token can't change the data of your database's tables even if the SQL text check misjudges a query.

Hiding the SQL​

The SQL of a query is only shown to people who can edit it. Tick Hide SQL when you create a token, and the token doesn't reveal the SQL even when you are an editor — as far as the SQL is concerned, it behaves as if you couldn't edit the queries:

  • Query details (kvery_get_query) contain no SQL, and search (kvery_search) doesn't look into the SQL.
  • When a query is refused because it modifies data, only the kind of cause is named, never the keyword that triggered it.
  • When a query fails, the generic error message is returned instead of the database's error text, also on agent connections (a message the query defines with ON ERROR RETURN is still returned, and for database errors the full error stays in the query log).

Everything else works as usual: the token reaches and runs the same queries, and still sees whether a query modifies data, its parameters, connection name and run statistics.

Only tags you added​

Tick Only tags I added count when you create a token with scope tags (the option needs at least one tag). A scope tag then counts on a query only if you added that tag to the query yourself, so tags that others add never widen the token:

  • Listing, search, query details, running queries, the group list and the number of queries the token reaches all follow this rule. The token list shows the option as an Own tags badge.
  • Only editors can add tags. In a group where you can't edit queries you can't add tags either, so there the token reaches only the queries you tagged while you could edit them.
  • A tag is on a query only once. If a colleague already added the same tag to a query, the token doesn't reach that query until you remove the tag and add it again. The tag is then yours, and the query leaves the reach of your colleague's tokens that use this option.
  • When you copy a query (clone it and keep the original), the tags of the copy count as added by you. When you move a query (clone it and delete the original), its tags keep who added them. A copy that someone else made can still name you as the user who added its tags; your token then reaches that copy too (and the copier may have edited its SQL). Click the token's number of queries to see them. When the copier removes such a tag and adds it again, the tag becomes theirs.
  • The option decides which queries the token reaches, not what they do: an editor of a query can still change its SQL.

Read and write queries​

A query counts as reading only if every statement in it is a SELECT, WITH, SHOW, EXPLAIN, DESCRIBE / DESC, VALUES or TABLE statement (or starts with an opening parenthesis) without any data or schema changing command; anything Kvery can't classify safely counts as a write. A query with a webhook directive (such as ON SUCCESS POST '…' TO '…') or an inline HTTP fetch directive (GET('…'), POST('…'), PUT('…'), PATCH('…'), RPOST('…'), RPUT('…'), RPATCH('…'), RDELETE('…')) also counts as a write, because it makes an outbound HTTP request when the query runs. So does a construct whose effect a rollback can't undo: sequence steps (NEXT VALUE FOR, nextval(), setval()), statements sent over another connection or to another server (PostgreSQL dblink…(), SQL Server OPENQUERY(), OPENROWSET(), OPENDATASOURCE()), server-side files (lo_export(), lo_import()) and ending other sessions (pg_terminate_backend(), pg_cancel_backend()). On MySQL / MariaDB an executable comment (/*! … */ or /*M! … */) and on PostgreSQL dollar quoting ($$ … $$ or $tag$ … $tag$) also make a query count as a write, wherever they stand in the text. The check uses the SQL that actually runs (the published version, snippets, form-field SQL and the parameter values).

note

Database functions called from a SELECT are not inspected by the SQL text check, but a read-only run still can't change your tables: it runs in an always-rolled-back transaction, so on MySQL / MariaDB and PostgreSQL the database rejects the change and on SQL Server it is discarded. This does not apply to agent connections (a read-only run of one is refused). A function or extension of your database that changes something outside the transaction (for example on another server or in a file) can't be recognised from the SQL, so for complete protection connect through a database user that only has read permissions.

Running queries​

  • Parameters are passed by name — kvery_get_query lists them with their field type and label (the field's display name). A display name that is SQL or contains {% %} / [% %] blocks or a $variable is never shown: the label is then the parameter name. Parameter names may contain only letters, digits, _ and -, and names the query does not use are ignored. A value can be a string, number, boolean or a list of these (for multi-select fields): true is passed as 1, false as an empty value, a list is joined with commas, and null leaves the parameter out. A parameter name with other characters, an object or a nested list as a value, and a required parameter without a value ("Provide required parameter(s) before executing this query: …") are refused: with 400 on the REST API, as a tool error over MCP. Values are filled in as in the web app (see How values are inserted): a value that contains Kvery's own query syntax is refused.
  • Results come back as the query ID plus column names and rows: {"queryId": "…", "result": {"columns": ["id", "name"], "data": [["1", "Acme Ltd"], ...]}}. For a query that returns no rows the result is {"columns": [], "data": []}: the column names are only known from a row.
  • A query that answers with return() or returnk() gives one column, response, with that value in one row (a JSON object or array as JSON text); a returnk() answer with status 0 is reported as an error. In a batch, the requests after such a run are answered with the error "Not processed: the batch was stopped by an earlier request".
  • HTTP request directives of the query don't pass on the Authorization header of the API call, and the body values they pass on are the parameters the call gives the query.
  • If the query fails (for example, an SQL error), the tool reports an error instead of an empty result. If you can edit the query, the message is the database's error text (also the one an agent connection relays), as in the editor (not with a token that hides the SQL). Otherwise it is a generic message, unless the query sets its own message with ON ERROR RETURN, which everyone gets.
  • Runs are recorded in the query's logs with their real result, so log levels that record only errors or only successes, and webhooks, work as for runs in the app.
  • The MCP server and its REST API always run the published version of a query: an unpublished draft doesn't change what they return until you publish it. Query details and search show the SQL of that version as well. Drafts are kept only while a query is shared, so for a query that is not shared this is its latest saved version.
  • Each request runs at most one query: when an MCP client sends several execute calls in one batch, only the first one that passes its checks runs, and the others get an error asking to send them in separate requests. A call refused by its checks (for example for a missing parameter) does not count; a call refused by the group's IP whitelist, or because the query's group no longer exists, does.
  • Queries run with the settings of their own group (tags, snippets, package limits). The group's IP whitelist always applies to running queries through the API — also for the group you last opened in the web app, because a token can be used from any address; listing, searching and query details are not restricted by it.

Using the REST API​

Send the token in the Authorization header of every request (the word Bearer is not case-sensitive):

Authorization: Bearer kvery_mcp_...

Every response is JSON in the same envelope:

{ "responseCode": "OK", "response": { ... } }
{ "responseCode": "ERROR", "response": "error message" }

The endpoints and the response they give:

EndpointParameters (query string)response
GET /mcp/queriesgroup (the name of a group, in any letter case), limit, offset; without limit every query is listed{queries, total, offset, limit, hasMore}; each query has id, description, connectionName, avgRuntime and lastExecuteAt (only for queries you can edit), isWrite (when it can be determined) and group ({name})
GET /mcp/groups—{groups: [{name}, …]}, sorted by name; a token with scope tags lists only the groups that hold a query it reaches
GET /mcp/searchq (or query, at least 2 characters), group, limit (50 by default, at most 200){query, results}; each result has id, description, group ({name}), matchedIn (description, internal_note, sql), snippets (the text around each match) and isWrite
GET /mcp/queries/{id}—{query: {…}}: the fields of the query list, then parameters (each with name, type, label, required and hidden) and sql (where the SQL may be shown)
POST /mcp/queries/{id}/executethe parameters of the query (see below){queryId, result: {columns, data}}

To run a query, send its parameters in a parameters object to POST /mcp/queries/{id}/execute:

curl -X POST 'https://app.kvery.io/mcp/queries/1727775300aB3dE5fG7hJ9kL1mN3pQ5r/execute' \
-H 'Authorization: Bearer kvery_mcp_...' \
-H 'Content-Type: application/json' \
-d '{"parameters":{"status":"active"}}'
{
"responseCode": "OK",
"response": {
"queryId": "1727775300aB3dE5fG7hJ9kL1mN3pQ5r",
"result": {
"columns": ["id", "name", "status"],
"data": [
["1", "Acme Ltd", "active"],
["2", "Globex Inc", "active"]
]
}
}
}

The parameters can also be sent as form fields or in the query string. The parameters object of a JSON body takes precedence, then the form fields, then the query string; a form field or query-string value whose name is not a valid parameter name is skipped. A body sent as JSON must be a JSON object, and its parameters member an object; otherwise the call is refused with 400.

The main status codes:

StatusMeaning
400Invalid request (for example a missing required parameter), or the query failed
401Missing, invalid or expired token (or wrong Basic Auth credentials)
403The query does not exist or you have no access to it (also when the token's scope tags leave it out), a read-only token tried to run a query that modifies data, a read-only run was attempted on an agent-connection query, the group's IP whitelist refused the call, or the browser origin is not allowed
404The query is hidden from you in its group (also for a short time after its group has been deleted)
429Rate limit reached — retry after the number of seconds in the Retry-After header
500Unexpected server error; the message names a reference to quote to the administrator
503Temporary server problem (for example the rate limiter is unavailable) — try again later

Limits and security​

  • Rate limit: 60 requests per minute per user; every REST request and every tool call counts, also inside a batch. Users behind the same IP address (e.g. an office network; for IPv6 the same /64 network) can send up to 600 requests per minute together. A batch can contain up to 20 messages. The answers carry the headers X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset (the Unix time when the current window ends) of the limit counted last; a 429 answer also has Retry-After. The group and query rate limit applies only to the public query API (/query/api/…): the MCP server and its REST API are not counted by it, and neither are shared links and shared dashboards.
  • Basic Auth: repeated failed attempts temporarily block Basic Auth. Failures are counted for an IP address and account together (10), for an IP address (50, blocking every account from it) and for an account (100, blocking it from every address). While blocked, the API answers 429 with a Retry-After header until 15 minutes have passed since the last failed attempt (tokens are not affected). An IPv6 address counts by its /64 network in these limits. Password checks that are still running count toward these limits too: a call that would go over a limit waits up to 3 seconds for them, and is accepted as soon as a parallel call with the same credentials has succeeded. If nothing frees up in time, it gets 429 with Retry-After: 1. A successful Basic Auth login is remembered for 5 minutes, so calls with the same credentials are not checked again in that time.
  • Sessions: every request is authenticated on its own. The API never creates a web session and does not accept the session cookie of a browser signed in to Kvery. Every JSON answer is sent with Cache-Control: private, no-store, so no browser or proxy cache keeps it.
  • Browser requests: browser apps can send a token in the Authorization header. app.kvery.io accepts requests from every origin. The server configuration can restrict browser origins; then browser requests are accepted only from Kvery itself and the allowed origins (servers, scripts and desktop MCP clients are not affected).
  • Activity log: every tool call and every REST call made with valid credentials is logged, including calls refused by the rate limit, with the token, query, parameters (the values of password fields are stored as ***), result size and IP address. When a run with password field values fails, its entry holds the generic error text "Something went wrong!" instead of the error message. Entries are kept for 90 days: older entries (and tokens that expired more than 30 days ago) are deleted by a cleanup that the server's scheduler runs about once an hour and that also runs with about 1 in 100 authenticated MCP / REST requests. Connection set-up messages (such as listing the tools), token management, failed sign-ins and requests refused before sign-in are not logged.
  • Your activity: MCP / API Keys → Activity lists your own calls, newest first, with times in your local time; calls made with a token that has been revoked or deleted show Deleted token. Each call shows the description of its query (hover over it to see the query ID); a query that has been deleted or that you cannot access is shown by its ID. The list is paged and searchable — the search covers the action, the transport (mcp or rest), the authentication (token or basic), the token (or Basic Auth, or Deleted token), query description and ID, parameters, error message, IP address and the time in UTC (YYYY-MM-DD HH:MM:SS). The caller list next to the search box (All callers by default) shows only the calls of one token, of Basic Auth or of Deleted token; your tokens are listed newest first, and tokens with the same name are told apart by their creation time. The Activity button of a token on the Tokens tab opens the Activity tab with the calls of that token, without a search. The list can be exported to CSV or Excel with the search and the caller applied (up to 10,000 entries, newest first, times in your local time) with the columns Time, Transport, Action, Token, Authentication, Query (the query ID), Parameters, Result (OK or Error), Error, Rows, Duration (ms), IP address and Query description. For Basic Auth calls and calls of deleted tokens the Token column is empty; Authentication shows basic or token. Other users' activity is never shown.
  • Activity endpoints: while you are signed in to Kvery in the browser, your activity can also be read with GET /mcp/audit-log and downloaded with GET /mcp/audit-log/export. These two endpoints accept only the session of the signed-in browser (a call without it gets 401; tokens and Basic Auth are not accepted) and return only your own calls, newest first. Both take search (as the search box) and caller: a token ID, basic (Basic Auth calls) or deleted (calls of deleted tokens); without caller every call is included, and any other value is refused with 400 ("Unsupported caller …"). GET /mcp/audit-log also takes limit (50 by default, at most 200) and offset, and answers {available, enabled, entries, total, totalAll, offset, limit, search, caller, hasMore} (total counts the entries that match the search and the caller, totalAll all of your entries); each entry has id, createdAt (UTC), transport, authMethod, action, tokenName, queryId, queryDescription, parameters, rowCount, success, error, ip and durationMs. The export takes format: csv (the default) downloads a CSV file with the columns of the export above, whose times are in UTC (first column "Time (UTC)"); json answers {available, columns, rows, timeColumns, total, exported, truncated} with the same rows. The export holds at most the newest 10,000 matching entries, and another format is refused with 400.
  • Live activity: while the Activity tab is open, it refreshes itself every 10 seconds and highlights the new calls for a moment; with another search or caller, only the calls that arrive after its first load are highlighted. Switch Auto-refresh off to stop it (your browser remembers the choice), or use the refresh button. The time of the last refresh ("Updated …") is shown next to the switch. The automatic refresh waits while a later page than the first is shown ("paused" then follows the time), while a typed search has not been applied yet, while an export runs, while text is selected in the table and while the browser tab is in the background (it refreshes at once when the tab is shown again and the last refresh was more than 10 seconds ago).

Tips​

  • Publish and name queries clearly so an assistant can find the right one via search.
  • Use tags to group the queries a token should expose.
  • Tick Only tags I added count when others in your groups tag queries too, so their tags can't widen a token.
  • Use read-only tokens for assistants that only need to read data.
  • Tick Hide SQL for assistants that should run your queries without seeing how they are written.