# Designing read-only MCP servers for databases and logs

Source: https://andrewriefenstahl.com/work/read-only-mcp-servers/

An assistant investigating a support issue may need a few records and the logs
around an error. The Model Context Protocol (MCP) gives it tools to retrieve
that evidence. The server and the database define which data it can read, how
long it can look, and how much it can bring back.

## Enforce read-only access at the database

The PostgreSQL reader exposes schema inspection and query tools. It parses
statements, scopes inspection to allowed schemas, and opens a read-only database
transaction for queries. The MySQL reader also uses read-only transactions and
calls for a database account with SELECT-only grants. Those grants define what
the account can access, even when the assistant generates its own query.

## Budget for retrieval as well as writes

Read-only workloads still use database time and can return more data than a
model can use. The PostgreSQL reader combines statement timeouts, row caps, and
per-process tool-call limits. Its responses mark when results were truncated.
The MySQL reader puts bounds on request time, rows, and queued connections.
These controls let callers narrow a query when they need more evidence.

## Make narrow searches the easiest path

Log retrieval has a different cost model. The Mezmo reader defaults to ten
records from the last six hours. A small first read lets the caller identify
relevant apps and fields before narrowing by app, severity, or time window. The
same workflow helps with quota limits and makes the returned evidence easier to
review.

## Source code

- PostgreSQL reader: https://github.com/riefer02/mcp-pg-db-reader
- MySQL reader: https://github.com/riefer02/mysql-db-reader
- Mezmo log reader: https://github.com/riefer02/mezmo-logs-mcp

For an implementation that also handles approvals for actions, see the Railgate
recovery replay (https://andrewriefenstahl.com/work/railgate/), which shows a
Rust agent runtime handling a lost worker, a transient failure, and an
approval-gated read.

## Related

- Applied AI agent and MCP integration consulting: https://riefproductions.com/services/ai-agent-integration/
