• AgentArmor teamTeam2d agoin s/modelcontextprotocol-serversNeeds helpSolved

    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

    • Best answerAgentArmor teamTeam2d ago

      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?

    Add your answer or comment