---
title: "AI Agent Access Control: Read-Only Search with Manticore"
description: "A runnable MCP server security example for Manticore, showing how to give an AI agent read-only database access, test denied writes, and spot a tenant-isolation gap."
date: 2026-11-19
author: "Dmitrii Kuzmenkov"
image: https://manticoresearch.com/images/blog/agent-read-only-search.png
lang: en
url: https://manticoresearch.com/blog/agent-read-only-search/
translations:
  ru: https://manticoresearch.com/ru/blog/agent-read-only-search/
  zh: https://manticoresearch.com/zh/blog/agent-read-only-search/
---

# AI Agent Access Control: Read-Only Search with Manticore

A runnable MCP server security example for Manticore, showing how to give an AI agent read-only database access, test denied writes, and spot a tenant-isolation gap.

An agent answering questions from documentation needs search access, not permission to edit data. This example connects the official Manticore MCP server with a database account that can read one table, then tests what that account can and cannot do.

We run reads and attempted writes through MCP and direct HTTP, compare the data and schema before and after, and repeat the checks after a restart. The read grant also exposes other tenants' rows in the same table.

A small test client sends the MCP requests. You don't need a live LLM or model credentials to reproduce the results.

## The Access Boundary

If you've followed our [MCP introduction](/blog/mcp-manticore-server/) or [authentication guide](/blog/how-to-secure-manticore-search-with-authentication-authorization/), this lab shows how to use them together with a restricted account.

The lab uses two tables:

- `agent_docs`: three documentation records, one belonging to a second tenant.
- `private_docs`: an internal runbook that the agent cannot read.

The MCP server connects with a user that has one grant:

```sql
CREATE USER 'agent_docs' IDENTIFIED BY 'DemoReader05!';
GRANT read ON 'agent_docs' TO 'agent_docs';
```

The administrator creates the tables and the read-only user. Only the restricted credentials reach the MCP process; the password shown here is for this disposable lab. Manticore's [authentication and authorization reference](https://manual.manticoresearch.com/Security/Authentication_and_authorization) explains its action and target permissions.

![The tested path from MCP tool calls to a restricted database identity, with a separate administrator path for setup and verification.](./agent-read-only-search/access-boundary.png)

AI agent access control here has three layers worth keeping separate:

| Control | What It Does | Limit |
|---|---|---|
| MCP query guard | Blocks the tested INSERT, UPDATE, DELETE, DROP and TRUNCATE requests | Does not enforce read-only SQL |
| Database grant | Allows reads on `agent_docs`; denies the tested writes and access to `private_docs` | Does not isolate tenants within `agent_docs` |
| Tool selection in an agent host | Limits which tools the agent sees | Does not change database permissions |

This lab tests the MCP guard and the database grant, not the agent host's tool allowlist.

## A Reproducible Lab

[Download the runnable example](https://manticoresearch.com/downloads/agent-read-only-search.tar.gz). It contains Compose files, the unmodified official MCP source and license, pinned Python packages, a protocol test client (`check.py`), and checksums.

The example uses [Manticore 29.9.0](https://github.com/manticoresoftware/manticoresearch/releases/tag/release-29.9.0), pinned to this image digest:

```text
manticoresearch/manticore:29.9.0@sha256:461b419739a2bbbffb4be0b32db26c41d7b435bf7fd1fce95b414ca5ccbb3775
```

The engine reported `29.9.0 58e88d5ab@26091108`. We used official MCP [commit c835b5c](https://github.com/manticoresoftware/mcp-manticore/tree/c835b5c5bd8d50f6ee76969d5c277967660501aa) (package version `0.1.2`), FastMCP `4.1.4`, and `manticoresearch` `11.2.0`. Retest if you upgrade any of them.

The tested platform is Linux amd64. You'll also need Docker Engine with Compose v2, Bash, Python 3, [uv](https://docs.astral.sh/uv/), `tar`, and `sha256sum`. The first run may download an image, Python 3.12, and packages. No embedding model or API key is needed.

The Compose project is `manticore-article05`. The runner checks for existing project resources and a free port. The database binds to `127.0.0.1:39508` and has a one-CPU, 1-GiB limit; Python and downloads use additional host resources. Run only one copy at a time.

Download the archive and its [checksum file](https://manticoresearch.com/downloads/agent-read-only-search.tar.gz.sha256), then run:

```bash
sha256sum -c agent-read-only-search.tar.gz.sha256
mkdir agent-search-lab
tar -xzf agent-read-only-search.tar.gz -C agent-search-lab
cd agent-search-lab
sha256sum -c SHA256SUMS
./run.sh > run.log 2>&1
tail -1 run.log
```

The last line should be:

```text
PASS: reads allowed; mutations denied; data and schema unchanged
```

We verified the archive from a fresh extraction and a new database volume. The runner refuses to reuse a lab volume. The checksums cover downloaded files, not external package repositories.

## Retrieval Through the Official MCP Server

The runner sets `auth = 1` and starts a standalone RT node. It bootstraps the administrator as the container's `manticore` OS user so the daemon can read its private auth store. The administrator then loads the fixtures and creates the restricted user.

Next, the MCP process starts over stdio with:

```text
MANTICORE_HOST=127.0.0.1
MANTICORE_PORT=39508
MANTICORE_USER=agent_docs
MANTICORE_PASSWORD=DemoReader05!
MANTICORE_ALLOW_WRITE_ACCESS=false
MANTICORE_ALLOW_DROP=false
MANTICORE_MCP_TRANSPORT=stdio
```

In your agent host, launch `mcp-manticore` with these settings. Stdio does not open an MCP listening port. Remote MCP connections need separate transport and authentication controls; HTTP/SSE transport is not tested here.

The `tools/list` response contains five tools:

```text
run_query
list_tables
describe_table
list_documentation
get_documentation
```

This version calls the SQL tool `run_query`, not the `execute_query` name used in our introductory post. The tests use the database tools, not the documentation tools.

Start by listing tables, inspecting a schema, and running a query. Here, `list_tables` showed `agent_docs` but not `private_docs`. `describe_table` returned the `agent_docs` schema and denied access to `private_docs`. It builds `DESCRIBE <table_name>` without going through the `run_query` guard, so database permissions matter here too.

We also tried crafted table names outside `check.py`, with the MCP write flags both on and off. Names such as `agent_docs; DROP TABLE agent_docs` and `private_docs; DESCRIBE agent_docs` produced `P01: syntax error` (HTTP 500), without changing the database. An unterminated comment in `agent_docs /* ; DROP TABLE agent_docs` was treated as `DESCRIBE agent_docs`; `private_docs` alone returned 403. The syntax errors came from Manticore's parser, not from MCP name validation: `describe_table` does not validate that argument.

Here is the retrieval request:

```json
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "run_query",
    "arguments": {
      "query": "SELECT id,title,body FROM agent_docs WHERE MATCH('retry') AND tenant_id=1 LIMIT 3"
    }
  }
}
```

The response contained record `1`, titled `Timeouts`, with this body:

```text
Set a request timeout and retry transient failures.
```

The test checks the embedded SQL response for exactly that record. In this fixture, `retry` does not also match `retries`. This is a retrieval example, not a relevance benchmark.

Watch the response format: this MCP version wraps SQL data in `columns`/`rows`. Its outer `total` is `1` for the response envelope, not necessarily the number of matching documents. The raw response is in `results.jsonl`; read the embedded SQL `data` for the actual matches.

## Mutation Tests That Reach the Database

An MCP error alone doesn't tell you whether the guard or the database stopped a write. The runner tries three paths:

1. Default MCP, with both write flags `false`.
2. A new MCP process with both flags `true`, still using `agent_docs`.
3. Direct HTTP SQL with the same restricted credentials, bypassing MCP.

Each path tries these statements:

```sql
INSERT INTO agent_docs(id,title,body,tenant_id) VALUES (99,'bad','bad',1);
UPDATE agent_docs SET tenant_id=99 WHERE id=1;
DELETE FROM agent_docs WHERE id=1;
CREATE TABLE forbidden_table(body text);
ALTER TABLE agent_docs ADD COLUMN injected integer;
DROP TABLE agent_docs;
TRUNCATE TABLE agent_docs;
CREATE USER 'intruder' IDENTIFIED BY 'demo';
```

The table shows which layer blocked each request. `DB 403` means Manticore denied it. A dash means that combination was not tested:

| Request | Default MCP | Flags On | HTTP |
|---|---|---|---|
| INSERT, UPDATE, DELETE | Guard rejects | DB 403 | DB 403 |
| DROP, TRUNCATE | Guard rejects | DB 403 | DB 403 |
| CREATE TABLE, ALTER TABLE | DB 403 | DB 403 | DB 403 |
| CREATE USER | DB 403 | DB 403 | DB 403 |
| SELECT from `private_docs` | DB 403 | — | DB 403 |
| Request without credentials | — | — | HTTP 401 |

For example, the write-enabled MCP call returned `isError: true` and this database response (headers omitted):

```text
(403)
Reason: Forbidden
HTTP response body: {"error":"Permission denied for user 'agent_docs'"}
```

The MCP guard is not complete SQL authorization. We proved this with a separate administrator-only control: with both write flags `false`, `run_query` successfully executed `CREATE TABLE guard_probe(body text)`. An independent administrator query confirmed the table, which we then removed. The pinned [guard code](https://github.com/manticoresoftware/mcp-manticore/blob/c835b5c5bd8d50f6ee76969d5c277967660501aa/mcp_manticore/mcp_server.py) blocks some mutation patterns, not every schema operation.

The guard can also reject harmless reads. In a separate check outside `check.py`, the restricted MCP account got a write-operation error for `SELECT id,title FROM agent_docs WHERE MATCH('update')`, for a `MATCH('"delete from"')` search, and for a query containing `/* update */`. None writes data, but the guard scans the whole SQL text for mutation words. The database grant is what prevents writes when the guard misses them.

**Never give an agent administrator credentials and rely on MCP write flags alone.** The normal MCP process uses the restricted account; the same `CREATE TABLE` request was denied under that account.

## Verification Beyond Error Messages

Before and after the attempted writes, a separate administrator connection compares:

- the full table list;
- the `agent_docs` schema;
- every field in both tables, ordered by ID;
- the user list.

Nothing changed: record `99`, the injected column, forbidden table, and `intruder` user were absent, and the original data remained intact. The temporary administrator-only test table was removed too.

After restarting Manticore with the data volume intact, the snapshots still matched, direct writes were still denied, and MCP retrieval and denial checks passed again. This verifies the standalone setup, not a distributed cluster; see the [authentication rollout checklist](/blog/manticore-auth-migration-hardening-checklist/) for that.

## Read-Only Access Still Exposes Data

The retrieval query uses `tenant_id=1`, but the agent controls the SQL. Remove that filter:

```sql
SELECT id,tenant_id,title FROM agent_docs ORDER BY id ASC;
```

The query returns tenant two's record. The read grant covers the whole table, and a prompt saying 'only query tenant one' cannot change that.

If the agent must not see another tenant's rows, don't give it arbitrary SQL access to a shared table. Use a separate table with a narrow grant, or an application-owned tool that takes tenant identity from trusted caller context and fixes the query scope. Both approaches need isolation tests. This example implements neither row-level authorization nor such an adapter; the `private_docs` test checks only the separate-table boundary.

Read-only access still leaves other AI agent security risks:

- **Resource use:** costly reads can consume CPU or return large amounts of permitted data. The example has a query limit and container resource caps, but no per-agent rate limit or load test.
- **Host privileges:** an agent with Docker access, the administrator password, or database-volume access can bypass these restrictions. Keep all three out of its runtime.
- **Untrusted content:** a document may contain instructions that steer an agent toward other tools or disclosing readable data. Database permissions do not stop prompt injection.

This lab uses HTTP on loopback. For networked deployments, protect credentials in transit and control access to the MCP server. The lab password is not meant for production.

## Cleanup

Check `results.jsonl`, `run.log`, and `mcp-*.log` for the requests and responses, then remove the lab's containers, network, data volume, and auth store:

```bash
./cleanup.sh
```

Images, Python caches, the virtual environment, and logs remain. Unpack the archive again for a clean rerun.

The official MCP server could read the documentation, and Manticore denied all eight tested mutations under the restricted account. The lesson is in the boundary: MCP's guard helps, but the database grant stops writes. And a read grant on a shared table still exposes other tenants' rows.
