slcg

slcg

Provides a read-only PostgreSQL MCP server with schema introspection. Enforces least-privilege database roles to prevent any writes, even from malicious SQL.

Category
访问服务器

README

SLCG — read-only you can actually trust

A read-only PostgreSQL MCP server that gives an AI clean schema context — with a read-only guarantee enforced by the database itself, not by trying to filter the SQL an agent sends.

The popular way to give an AI database access shipped a "read-only" mode that a single COMMIT; DROP SCHEMA can break out of. This is the version where the guarantee holds — and there's a test suite that proves the attacks fail.

The 60-second version

A read-only mode is only real if it survives someone actively trying to leave it. Enforcing it by inspecting the agent's SQL is the same losing game as classic SQL injection, now with an LLM as the untrusted input — anything the agent reads (a row, a ticket, a web page) can carry the payload. So SLCG doesn't filter SQL. It connects as a PostgreSQL role that was never granted the ability to write.

The attack that breaks the naive approach, run against this one:

# The documented breakout:  BEGIN READ ONLY; SELECT ...; COMMIT; DROP TABLE ...
#
# Against a privileged connection (the vulnerable pattern):
DROP TABLE            <- table destroyed

# Against the slcg_readonly role (this project):
ERROR:  cannot execute DROP TABLE in a read-only transaction

# ...and even if the attacker turns the read-only flag OFF first:
SET default_transaction_read_only = off;
INSERT INTO customers ...
ERROR:  permission denied for table customers   <- the privilege layer, not a flag

That last line is the whole point: there is nothing to talk your way around, because the role has no write privilege to begin with.

What it does / what it doesn't

Does Doesn't
Introspects schema: tables, columns, PKs, FKs, indexes Offer a run_sql / arbitrary-query tool
Enforces read-only via a least-privilege DB role RBAC, SSO, control plane
Ships an adversarial test suite + threat model Multi-DB, vector search, dashboards
Speaks MCP (Claude Desktop, Cursor, …) Write access "with safeguards"

Quickstart

1. Create the least-privilege role (this file is the security model — read it):

psql -v db=mydb -f sql/01_setup_readonly_role.sql -d mydb

2. Run the server as that role:

pip install -e .
PGDATABASE=mydb PGUSER=slcg_readonly slcg-server

3. Point an MCP client at it. Example Claude Desktop config:

{
  "mcpServers": {
    "slcg": {
      "command": "slcg-server",
      "env": { "PGDATABASE": "mydb", "PGUSER": "slcg_readonly" }
    }
  }
}

Prove it yourself

pip install -e ".[dev]"
pytest            # 10 adversarial attacks blocked, 6 introspection checks

The attack cases read like a spec: test_commit_breakout_cannot_drop_table, test_disabling_readonly_still_cannot_write, test_copy_to_program_exfil_is_denied, test_injected_row_payload_cannot_trigger_write.

Why the keys come from pg_catalog, not information_schema

A detail worth knowing: information_schema's constraint views are privilege-filtered — a low-privilege read-only role literally cannot see primary and foreign keys through them. SLCG reads keys from pg_catalog, which is world-readable, so introspection stays complete for exactly the least-privilege role the design insists on.

Design decisions

See docs/THREAT_MODEL.md for the threat model mapped to the OWASP LLM / MCP risk categories, and the sql/01_setup_readonly_role.sql comments for the enforcement rationale.

Status

Working and tested: the read-only server, the least-privilege role, and a 10-case adversarial test suite all pass. Planned polish — a recorded terminal demo (asciinema → gif) at the top of this README, and a linked writeup of the transaction-breakout bypass class this design defends against.

License

MIT.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选