Secure read-only PostgreSQL multi-schema server with schema isolation and cross-schema discovery
The PostgreSQL Multi-Schema Model Context Protocol (MCP) Server is a specialized server designed to provide read-only access to PostgreSQL databases while enhancing multi-schema support. This MCP server plays a pivotal role in enabling AI applications, such as Claude Desktop, Continue, and Cursor, to inspect database schemas across multiple namespaces and execute read-only queries without breaching schema isolation boundaries.
The PostgreSQL Multi-Schema MCP Server introduces several key features that cater to the needs of advanced data access in AI workflows. These include explicit multi-schema support for enhanced flexibility, strict schema isolation through command-line configuration, cross-schemata discovery with a unified view while maintaining schema boundaries, and metadata security measures such as filtering system catalogs to expose user-defined tables.
One of the core capabilities of this MCP server is its ability to selectively expose specific database schemas. Administrators can define which schemas are accessible in the configuration stage, ensuring that sensitive data remains protected within unlisted schema domains. This selective exposure enhances security by limiting potential access points for unauthorized users or applications.
Schema isolation ensures that each query operates within a predefined and managed environment. By leveraging command-line parameters in the server’s startup configuration, administrators can configure read-only transactions to respect the search_path
settings and execute queries from authorized schemas only, thereby maintaining strict data integrity and security standards.
The server offers a unified view of tables across multiple schemas without necessitating developers to manually identify associated schema boundaries. This feature simplifies query execution by abstracting schema-related complexities away from end-users, allowing for seamless navigation through interconnected data systems.
Metadata exposure is managed through robust security filters that prevent system catalogs from being accessible outside explicitly defined user-defined tables within specified schemas. This measure ensures that critical information remains protected from unintended access, thus preserving the integrity of operational databases.
The architecture and protocol implementation underlying this MCP server are carefully designed to integrate seamlessly with AI applications while maintaining robust security measures. The server architecture is composed of key components such as query
tools that execute read-only SQL queries within a READ ONLY transaction context, ensuring that schema isolation and security are preserved.
query
tool provides functionality to run read-only SQL queries against the database.search_path
setting ensures that only authorized schemas are queried.The server resource layer exposes detailed metadata for tables across supported schemas, providing JSON schema definitions that include critical information such as column names and data types. This metadata is automatically discovered from the underlying database schema, ensuring a consistent and accurate representation of table structures.
To deploy the PostgreSQL Multi-Schema MCP Server, you'll need to follow these steps:
npx -y mcp-server-postgres-multi-schema <database-url> [schemas]
<database-url>
with your PostgreSQL database connection string, and provide a comma-separated list of schemas to expose.public
, analytics
, and staging
, use:
npx -y mcp-server-postgres-multi-schema postgresql://localhost/mydb [schemas]
These steps provide a streamlined setup process for developers wishing to integrate this server into their data access workflows.
Imagine an AI application that requires cross-database queries. By configuring the PostgreSQL Multi-Schema MCP Server with multiple schemas, such as public
, analytics
, and staging
, this setup enables seamless interoperability among these databases without compromising security.
In a real-time analytics scenario, where data needs to be fetched from various internal database schemas for anomaly detection or reporting purposes, the PostgreSQL Multi-Schema MCP Server provides the required flexibility. Developers can script queries that run against designated schemas, ensuring only pre-approved data is accessed.
This MCP server is compatible with major AI application clients such as:
The following compatibility matrix outlines the MCP server's current status across different MCP clients:
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ✅ |
Cursor | ❌ | ✅ | ❌ |
This matrix highlights the seamless integration provided by this server for various AI applications, ensuring that developers can leverage these tools without encountering compatibility issues.
graph TD
A[AI Application] -->|MCP Client| B[MCP Server]
B --> C[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
Here's an example JSON configuration snippet for integrating the TCP MCP server into your application:
{
"mcpServers": {
"postgresMultiSchemaServer": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres-multi-schema"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
The server enforces strict schema isolation by limiting queries to only those specified in the command-line configuration. This ensures that unauthorized schemas cannot be accessed.
Yes, the server can be configured with a specific list of schemas during startup using command-line parameters, providing fine-grained control over data access.
query
tool support?The query
tool supports standard SQL read-only operations. Users must ensure that only SELECT statements are used to avoid accidental data modifications.
Metadata is filtered through a secure schema system, ensuring that only user-defined tables within specific schemas are exposed while system catalogs remain off-limits.
No, at present, this particular implementation is tailored specifically for PostgreSQL. However, similar approaches can be adopted for other database systems depending on the use case requirements.
Contributions to improve security and usability are welcome. Developers interested in contributing should follow these guidelines:
For more information, explore additional resources and documentation available at the MCP Community Portal.
This comprehensive documentation positions the PostgreSQL Multi-Schema MCP Server as a robust solution for AI applications, emphasizing its capabilities in securing data access while enhancing integration with various AI tools.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration