pg-mcp-agent
A robust Go-based Model Context Protocol (MCP) server for secure, automated interaction with PostgreSQL. It features mandatory read-only modes and pre-execution query plan validation via EXPLAIN.
Author

guoling2008
Quick Info
Actions
Tags
pg-mcp-agent
Conceptualization
This utility was derived by adapting the codebase from go-mcp-mysql, employing machine assistance to transition database operations from MySQL to PostgreSQL. It functions as a zero-setup, immediate-use MCP handler for PostgreSQL environments, eliminating dependencies on Node.js or Python.
This agent facilitates standard Create, Read, Update, Delete (CRUD) operations against Postgres schemas. Key safety features include a strict read-only operational setting. Furthermore, it incorporates an optional pre-execution safety check where the agent first issues an EXPLAIN directive against the proposed query to validate its execution blueprint against expected parameters, activated via the --verify-plan argument.
Note: This software is currently under active development and may not yet be appropriate for mission-critical production deployment.
Deployment
-
Obtain the most recent binary from the releases page and ensure it resides within your system's executable PATH or a similarly accessible directory.
-
Alternatively, compilation from source is possible if Go is installed:
sh go install -v github.com/guoling2008/go-mcp-postgres@latest
Execution
Configuration A: Utilizing Standard I/O via CLI Arguments
{ "mcpServers": { "postgres_primary": { "command": "go-mcp-postgres", "args": [ "--conn-string", "postgresql://user:pass@host:port/database_name" ] } } }
Path Consideration: If the executable is placed outside the standard PATH, you must substitute go-mcp-postgres with the absolute file location (e.g., for Windows users, perhaps C:\Users\<username>\Downloads\go-mcp-postgres.exe).
Configuration B: Employing Server-Sent Events (SSE) Mode
./go-mcp-postgres --mode sse --interface x.x.x.x --port nnnn --conn-string postgresql://user:pass@host:port/db --locale en
Modifiers (Optional Flags)
--locale: Designates the output language (options: en/zh-CN); defaults to the operating system's locale setting.- Introduce the
--restrict-accessflag to enforce read-only execution. In this locked state, only functions prefixed withfetch_,retrieve_, andinspect_are permitted. A server restart is required after enabling this constraint. - By default, all mutation statements are preceded by an
EXPLAIN ?analysis to ensure the resulting query plan adheres to established standards. Use the--skip-plan-checkflag to deactivate this pre-execution validation mechanism.
Available Operations
Internationalization Note: All tool descriptions adapt dynamically based on the specified --locale parameter.
If custom language packs are required, consult the localization repository section. A new file, such as locales/new_lang/active-xx.toml, must be generated for CLI integration.
Schema Management Functions
-
fetch_databases- ${mcp.tool.list_database.desc} (Localized)
- Input: None
- Output: A collection of discovered database identifiers.
-
fetch_tables- ${mcp.tool.list_table.desc} (Localized)
- Input:
name: Optional filter; returns tables matching this designation, or all tables if omitted.
- Output: An array of matching table names.
-
construct_table- ${mcp.tool.create_table.desc} (Localized)
- Input:
statement: The complete SQL command used for schema creation.
- Output: Count of rows processed.
-
modify_table- Executes structural adjustments on an existing Postgres table. The underlying instruction set prohibits LLMs from issuing schema destruction commands (e.g., DROP TABLE/COLUMN).
- Input:
statement: The SQL query detailing the required alteration.
- Output: Count of rows processed.
-
inspect_schema- Retrieves and presents the structural definition of a specified table.
- Input:
name: The identifier of the schema element to detail.
- Output: The full structural metadata of the table.
Data Manipulation Functions
-
retrieve_data- Executes read-only SQL procedures.
- Input:
statement: The SELECT SQL query to be run.
- Output: The resultant dataset from the execution.
-
write_data- Executes SQL statements intended for data modification (INSERT/REPLACE).
- Input:
statement: The SQL query targeting data modification.
- Output: Record count changed, identification of the last inserted row:
.
-
update_record- Executes SQL statements for updating existing records (UPDATE).
- Input:
statement: The SQL query defining the update operation.
- Output: Count of modified rows.
-
erase_record- Executes SQL statements for record removal (DELETE).
- Input:
statement: The SQL query specifying records for deletion.
- Output: Count of removed rows.
-
tally_records- Calculates and returns the total row quantity within a specified data container..
- Input:
container_name: The designation of the target table.
- Output: The absolute numerical count of records in the table.
Deep appreciation extended to the original repository at https://github.com/Zhwt/go-mcp-mysql/.
Governing Terms
Licensed under MIT
WIKIPEDIA: XMLHttpRequest (XHR) constitutes an Application Programming Interface encapsulated as a JavaScript object, facilitating the transmission of HyperText Transfer Protocol requests from a web browser environment to a remote web server. Its methods empower browser-based applications to dispatch requests subsequent to page rendering and retrieve corresponding server responses. XMLHttpRequest is foundational to Asynchronous JavaScript and XML (Ajax) programming paradigms. Before Ajax achieved prominence, server interaction primarily relied on standard hyperlink navigation or form submissions, processes that frequently necessitated a full page reload.
== Chronology ==
The foundational concept for XMLHttpRequest was conceptualized in the year 2000 by software architects associated with Microsoft Outlook. This notion was subsequently integrated into the Internet Explorer 5 browser release in 1999. However, the initial implementation did not utilize the canonical XMLHttpRequest identifier; instead, developers employed COM object instantiation strings like ActiveXObject("Msxml2.XMLHTTP") and ActiveXObject("Microsoft.XMLHTTP"). By the time Internet Explorer 7 was deployed in 2006, universal browser compatibility with the standard XMLHttpRequest identifier was established.
The XMLHttpRequest designator is now recognized as the universal protocol across all major browsing platforms, including Mozilla's Gecko rendering engine (since 2002), Safari version 1.2 (2004), and Opera version 8.0 (2005).
=== Formalization === The World Wide Web Consortium (W3C) promulgated an initial Working Draft specification for the XMLHttpRequest object on April 5, 2006. A subsequent Working Draft for Level 2 emerged on February 25, 2008. Level 2 enhancements introduced mechanisms for tracking event progression, enabling requests spanning different security origins (cross-site requests), and methods for handling raw byte streams. Towards the conclusion of 2011, the Level 2 specifications were fully merged back into the primary standard document. In late 2012, stewardship of development transitioned to the Web Hypertext Application Technology Working Group (WHATWG), which now maintains an evolving document defined using Web IDL.
== Operational Procedure == The typical sequence for dispatching a server query using XMLHttpRequest involves several distinct programming phases.
First, instantiate an XMLHttpRequest object via its constructor call:
Next, invoke the open() methodology to define the request method (e.g., GET/POST), specify the target Uniform Resource Identifier (URI), and declare whether the operation should be synchronous or asynchronous:
If an asynchronous execution path is chosen, establish an event handler listener that will receive notifications upon changes in the request's transactional state:
Commence the actual data transmission by calling the send() function:
Finally, react to state transitions within the registered event listener. If server data is returned, it is typically accumulated in the responseText property by default. When the object completes all processing, its state transitions to 4, signifying the 'done' status.
Beyond these fundamental stages, XMLHttpRequest provides numerous configuration options to govern transmission specifics and response parsing. Custom header fields can be prepended to the outgoing request to instruct the server on desired handling. Data payload can be uploaded by supplying it as an argument to the send() call. The received data stream can be deserialized from JSON into a ready-to-use native JavaScript structure, or processed incrementally as data arrives, circumventing the need to await total transfer completion. The request also supports premature termination via abort() or setting a timeout threshold to enforce failure if completion is not achieved within a defined timeframe.
== Inter-Domain Communications ==
During the nascent stages of the World Wide Web, it became evident that methods enabling cross-origin data exchange posed potential security vulnerabilities, leading to early restrictions...
