Does the official MCP Postgres example validate SQL before executing it?
The official Postgres reference server in modelcontextprotocol/servers (commit 8963861c75c69f09d2890eedb0ef25b23c6253c6) was reported in March 2025 to run SQL queries through MCP with no checks on the incoming SQL. The issue was closed as NOT_PLANNED. Is this still the case, and what should I do if I copy this example?
Originally asked on GitHub: https://github.com/modelcontextprotocol/servers/issues/866
1 answer
The issue was closed as NOT_PLANNED without a code change; as of that report, the Postgres example performs no validation on incoming SQL. The reporter pointed to src/postgres/index.ts#L118 and noted the absence of any checks, contrasting it with src/filesystem/index.ts, which does some sanity checking. No patch, workaround, or maintainer explanation appears in the provided issue thread.
If you build on this example, treat it as an unvalidated SQL gateway. General advice, not from the thread: add your own query validation or allowlisting, connect with a least-privilege database role, and only expose it to trusted MCP clients. The filesystem example's sanity-checking pattern is a useful model for adding guards.
Security note: because the server does not inspect SQL, anyone who can invoke the tool can execute whatever SQL the configured database role permits.
Did this work for you?
Related questions
- mcp-server-fetch: 'AnyUrl' object has no attribute 'decode' error
- How to fix UTF-8 Japanese text corruption/crash in mcp-server-sqlite with Claude Desktop on Windows?
- MCP Knowledge Graph Memory Server fails with ${workspaceFolder} in MEMORY_FILE_PATH
- npx @modelcontextprotocol/server-filesystem: ERR_MODULE_NOT_FOUND for zod-to-json-schema
- Claude Desktop MCP servers using npx fail to connect on Windows; fix by using absolute node.exe path after global install