In short.
Database over MCP is a tutorial for developers connecting Grok to SQLite, but its local setup requires a public tunnel and shares query results with the API provider. It explains database discovery, generated SQL, temporary bearer tokens and server-enforced limits, including read-only access, restricted statements, capped results and a five-second query timeout. Its synthetic coffee-store example makes the tool interactions visible. Runtime behavior, answer accuracy and production suitability are unverified; the quoted timing and costs are the page author's observations.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage is limited to the complete selected page at [https://docs.x.ai/cookbook/examples/database-over-mcp.md], captured on 23 November 2026. Linked documentation, repository implementation files and external terms are excluded. The selected page contains no licence notice. No code was executed; setup success, guard enforcement, cancellation, answer accuracy, performance, costs and production suitability were not independently verified.
The overview
Identity
Database over MCP is a cookbook tutorial published at [https://docs.x.ai/cookbook/examples/database-over-mcp.md]. It connects the Grok API to a local SQLite database through a small server implementing Model Context Protocol, or MCP, which lets an AI service discover and call external tools.
The tutorial describes a TypeScript example with browser and terminal interfaces. Its Grok request names grok-4.7; the selected page does not specify an SDK package version.
Assessment
The tutorial's main educational value is making the boundary between model-generated SQL and database enforcement concrete. Readers can follow how the model discovers data, requests queries and receives errors while the server controls what can execute.
The page provides substantial implementation explanations, but the underlying source files are not included in the supplied evidence. Guard correctness, SQL accuracy and suitability for production use remain unverified.
Users
This resource suits developers learning remote MCP tools, natural-language database access or Grok integration. Familiarity with Node.js, environment variables, HTTP and basic SQL will help readers understand and adapt the example.
Beginners get a visible sequence of questions, tool calls, SQL and results. Experienced developers get details about JSON-RPC handling, process isolation, authentication and streaming events. Connecting an existing business database requires additional implementation work.
Capabilities
The server exposes list_tables for table names and row counts, describe_table for schema definitions and three sample rows, and run_query for model-written SQL. Schema comments explain details such as order statuses and prices expressed in cents.
The browser interface is described as showing reasoning output, tool calls, SQL, returned rows, an answer, a chart of the last result and reported cost. The terminal interface prints calls and results and saves the answer with its queries to output/<question>.md. The browser supports cancellation through Stop or closing the page.
Using it
Requirements
The documented prerequisites are Node.js 22.13 or later, cloudflared, a Grok API key supplied through XAI_API_KEY or a root .env file, and the example project's dependencies. The page says Cloudflare quick tunnels work without an account.
The API provider must be able to reach the MCP server through a public URL. The default setup uses port 3000 for the local browser interface and port 3001 for MCP. The selected page does not provide a repository acquisition command or establish exact dependency versions.
Mechanism
The server uses node:http and implements initialize, ping, tools/list and tools/call. Its Streamable HTTP endpoint accepts POST requests at /mcp, returns JSON for requests and an empty 202 response for notifications, and returns 405 for GET. The page explains that plain JSON responses accommodate Cloudflare quick tunnels, which do not support server-sent events.
Each query runs in a child process that opens SQLite with readOnly: true. The server accepts SQL beginning with SELECT or WITH, rejects additional statements, returns at most 100 rows with a smaller allowance for long results, and kills the process after five seconds. Query failures return isError: true so the model can respond to the error. The readOnlyHint annotation is advisory.
The SDK's mcp() tool gives the provider the endpoint, an explicit allowed_tools list and a bearer token unique to the answer in progress. The server forgets that token when the answer finishes. The provider performs tool calls remotely; stream events expose their start and completion. The browser receives a separate event stream from the local application.
Setup
The documented sequence is to enter examples/database-over-mcp/typescript, install dependencies with npm install, configure the API key and start the browser example with npm run web. The application builds the sample database, starts MCP and opens a tunnel. The page directs readers to [http://localhost:3000].
For terminal use, the page gives npm start -- "Who are our best customers?". MCP_PUBLIC_URL supports another tunnel pointed at the MCP port, while PORT and MCP_PORT change the listeners. These are documented instructions; no installation or execution was performed.
Example
The example builds a synthetic coffee store with 160 customers, 18 products and about 1,350 orders spanning six months. A fixed random seed preserves the generated store's structure while dates shift to end on the current day. A coffee introduced 40 days earlier changes the expected recent bestseller.
One sample question asks which products sold best last month. The described sequence lets Grok inspect tables and schemas, generate SQL and answer from returned rows. Guard demonstrations request an UPDATE, multiple statements, an expensive query and excessive rows. Their actual behavior and the correctness of the resulting answers were not assessed.
Assessment & evidence
Limitations
The implementation described here targets SQLite. Adapting the pattern to another database requires database-specific access controls and query execution logic. Its minimal MCP server offers tools only and does not demonstrate broader protocol features.
The row cap can truncate results, and the timeout can stop expensive queries. Read-only enforcement does not establish that generated SQL answers the business question correctly. Query results travel to the API provider; field-level permissions and redaction are not documented.
The page describes temporary authentication and separate browser and MCP ports, but it does not establish production deployment security, concurrent workload behavior or performance on large databases.
Design reasoning
The layered restrictions address different problems: SQLite's read-only connection blocks writes, statement restrictions narrow permitted operations, result limits constrain data returned to the model, and a separate process permits termination of slow queries. The page notes that a read-only connection alone still permits ATTACH, motivating additional restrictions.
The example uses low reasoning effort because the author reports that default effort produced the same sample answers while sometimes taking twice as long and issuing extra checking queries. That observation is limited to the documented samples; it does not establish the best setting for other questions.
Alternatives
The page identifies the MCP TypeScript SDK at [https://github.com/modelcontextprotocol/typescript-sdk] as an alternative to writing the protocol handler manually. Its own small handler is intended to expose the messages exchanged over HTTP.
It also names ngrok as another tunnel option, configured through MCP_PUBLIC_URL. The linked SDK and tunnel documentation are outside the supplied evidence, so their compatibility, terms and costs are not assessed.
Evidence
The evidence consists of the complete Database over MCP documentation page at [https://docs.x.ai/cookbook/examples/database-over-mcp.md]. It includes setup commands, an SDK configuration excerpt, descriptions of implementation files and author-reported observations.
Linked pages, repository files, dependency manifests and runtime outputs are outside this evidence. Statements about enforcement, cancellation, timing and cost therefore remain documentation claims rather than independently verified results.
Access & freshness
Costs
The page reports that its example questions took about ten seconds, made roughly five MCP calls and cost $0.008 to $0.012 each during the author's runs. These observations do not establish a general benchmark or a current price guarantee.
According to the page, remote MCP calls have no separate provider charge; token billing includes tool results read by Grok. The example displays usage.cost_usd from the API response. Current token rates, costs for other workloads and any infrastructure expenses are unknown.
Rights
The selected page does not state a licence or redistribution terms for the tutorial or accompanying implementation. Permission to copy, modify or redistribute those materials is unknown.
API data-handling terms, retention rules and dependency licences are not established by this page.
Freshness
The page was captured on 23 November 2026 at 15:56:04 UTC. It specifies Node.js 22.13 or later and names grok-4.7, but supplies no publication date, last-updated date or exact SDK version.
Present model availability, API compatibility, tunnel behavior and pricing beyond that captured text are unknown.
Next steps
Begin with the synthetic store and compare answers against SQL results you can verify. Inspect the implementation and confirm the documented rejection, timeout, row-limit and cancellation behavior before adapting it to other data.
For an existing database, define which tables and fields may reach the API provider, supply clear schema context and assess database-specific permissions. Confirm current model support, dependency versions, pricing and reuse terms before committing to an integration.
