Datalevin MCP Server
Runs a local Datalevin MCP server over stdio, exposing read-only or read-write database tools to any MCP-compliant client.
What this file does
Runs a local Datalevin MCP server over stdio, exposing read-only or read-write database tools to any MCP-compliant client.
When to use it
- You want to expose a Datalevin database as MCP tools for an AI agent
- You need a local MCP server that can also reach remote dtlv:// databases
- You are building a custom AI app that needs a stable Datalevin tool surface
- You want to control write access separately from read-only queries
Assumes this stack
Datalevin MCP Server
dtlv mcp runs a Datalevin MCP server over stdio.
The MCP server is a local process adapter over Datalevin APIs:
- local MCP clients talk to
dtlv mcpoverstdio - the MCP server opens local Datalevin databases directly
- the MCP server can also open remote
dtlv://...targets behind the same localstdioprocess
The intended integration target is generic:
- any MCP-compliant client that can launch a local
stdioserver - custom AI-powered applications that want a stable Datalevin tool surface
It is not designed around any specific branded host or coding-agent workflow.
Starting the Server
Read-only mode is the default:
dtlv mcp
Enable write tools explicitly when needed:
dtlv --allow-writes mcp
Session Lifecycle
The server follows MCP 2025-06-18 session sequencing:
- the first request in a session must be
initialize initializemust includeprotocolVersion,capabilities, andclientInfo- request methods such as
initialize,ping,tools/list, andtools/callmust include a JSON-RPC requestid - normal requests such as
tools/listandtools/callare only accepted after the client sendsnotifications/initialized - JSON-RPC batch requests are rejected
Tool Result Shape
tools/call replies follow the normal MCP JSON-RPC envelope and return both a
machine-readable payload and a text payload:
{
"jsonrpc": "2.0",
"id": 7,
"result": {
"content": [
{
"type": "text",
"text": "{\"database\":\"database-...\",\"result\":[[\":name\",\"Alice\"]]}"
}
],
"structuredContent": {
"database": "database-...",
"result": [[":name", "Alice"]]
}
}
}
Use structuredContent as the authoritative payload. content[0].text is a
compact text rendering for MCP clients that expect a text block.
When a tool fails, MCP returns result.isError = true and the
structuredContent value contains the machine-readable error payload.
Large Responses
The MCP server applies its own response shaping on top of Datalevin's JSON API limits.
Current defaults:
- max result items:
200 - max serialized response bytes:
524288
The byte limit is enforced against the full MCP JSON-RPC reply, not just
structuredContent.
When a result is truncated, structuredContent includes:
{
"meta": {
"truncated": true,
"truncations": [
{
"kind": "items",
"path": "result",
"limit": 200,
"returned": 200,
"original": 684
}
]
}
}
Truncation Records
meta.truncations is an array. Each element describes one truncation step.
Item truncation:
{
"kind": "items",
"path": "result",
"limit": 200,
"returned": 200,
"original": 684
}
kind = "items"means the top-levelresultcollection was shortenedpath = "result"identifies the truncated fieldlimitis the applied MCP item capreturnedis the number of items still presentoriginalis the original top-level item count before truncation
Byte truncation with preview:
{
"kind": "bytes",
"path": "result",
"limit": 524288,
"mode": "preview"
}
Byte truncation with omission:
{
"kind": "bytes",
"path": "result",
"limit": 524288,
"mode": "omitted"
}
kind = "bytes"means the serialized response would have exceeded the MCP byte budgetmode = "preview"meansstructuredContent.resultstill contains a shortened previewmode = "omitted"meansstructuredContent.resultwas set tonullbecause even the preview form would still be too large
When truncation happens, content[0].text is no longer a full duplicate of the
structured payload. It becomes a small summary instead:
Result truncated.
When an untruncated structuredContent payload is still too large to duplicate
in content[0].text, the text block becomes See structuredContent. instead.
This avoids paying the full payload cost twice.
Pagination Guidance
For naturally paged tools, pass explicit limits instead of relying on MCP truncation:
datalevin_datomsdatalevin_kv_rangedatalevin_search_datoms
For Datalog queries, include query-level limiting when possible. MCP still enforces its own caps even if the query itself does not.
Remote Access
The MCP server itself remains a local stdio process. Remote Datalevin access
uses Datalevin's existing client/server support behind that process.
Examples:
- local Datalog DB:
{"dir":"/data/app-db"} - remote Datalog DB:
{"uri":"dtlv://user:pass@dbhost/app-db"} - local KV store:
{"dir":"/data/app-kv"} - remote KV store:
{"uri":"dtlv://user:pass@dbhost/app-kv"}
Current Notes
- write tools are disabled unless
--allow-writesis passed at startup - MCP ids such as
database,kv,searchIndex, andvectorIndexare session-scoped - the MCP transport is
stdioonly in v1
What's inside
6 sections covering startup, session lifecycle, tool result shape, large responses, pagination, and remote access
Change this for your project
- Replace
dtlvwith your Datalevin binary path if not on PATH - Replace
dtlv://user:pass@dbhost/app-dbwith your own remote database URIs - Replace
/data/app-dband/data/app-kvwith your own local database directories
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Return both a machine-readable structuredContent and a text fallback in tool results
- Apply response truncation with detailed meta records instead of silent clipping
- Use a startup flag (--allow-writes) to gate destructive operations
Related Documents
GitHub MCP Server
Exposes 20+ GitHub API operations as MCP tools so AI assistants can manage repos, issues, PRs, releases, and files.
GitHub MCP Server
Documents setup and configuration for both a remote and local GitHub MCP server, enabling AI tools to interact with GitHub via natural language.
Heti AI Ökoszisztéma Figyelő
Summarises 23 signals from GitHub and external sources into a weekly AI ecosystem watch with recommendations for the Brunella project.