Postgres SQL
The Postgres Connector can be utilized to connect to any Postgres Database using the TCP socket. UNIX sockets are currently not supported.
Setup Configuration
Section titled “Setup Configuration”| Parameter | Definition |
|---|---|
| Host | The hostname or IP Address of the Server |
| Port | The TCP port where the PSQL can be connected to. |
| Database | The database within the PSQL instance to connect to. |
| User | The username for the connection. |
| Password | The password for the connection. |
| SSL | Require: Encrypted but certificate is not checked Verify Full: Encrypted and the certificate is validated Disable: Not encrypted. (Not recommended) |
UI Reference
Section titled “UI Reference”Use this as a guide when configuring tools on the MCP Express User Interface.
This defines the actual SQL command to execute when the tool is called. You can utilize Placeholders using parameters. Example:
select id, status, total from orderswhere customer_id={{customer_id}}order by created_at desclimit {{limit}};Tips:
- Values should be sent as parameters and never direcltyplaced into the SQL
- Use Placeholders for values only; not for table or column names.
- Use
'%' || {{q}} || '%'for this special case to use the parameter q as a pattern for use withlikeorilikestatements.
Developer Reference
Section titled “Developer Reference”Code Sample
Section titled “Code Sample”import { z } from "zod";import { defineTool, postgres, sql } from "@mcpexpress/core";
export const recentOrders = defineTool({ // Other declarations ... // "shop_database" is the connector's name on the Connectors page; `shop` is yours. connectors: { shop: postgres("shop_database") }, // Tool function with connectors provided during runtime execute: async ({ customerId }, { connectors }) => { const { rows } = await connectors.shop.query( sql`select id, status, total from orders where customer_id = ${customerId} order by created_at desc limit 10`, ); return { orders: rows }; },});Available Methods
Section titled “Available Methods”query(text, values?, options?)
Section titled “query(text, values?, options?)”This method can be used to query the database. Args:
- text (string): The query to execute. Placeholders can be marked using
$neg.select * from orders where customer=$1 - values (list): An ordered list of values which will be used to fill in the placeholders within the text.
- options : The list of options
query(sql`...`, options?)
Section titled “query(sql`...`, options?)”This is an alternate method to query the database. Refer query(text, values?, options?) for further details. This is simply a convenience method to enable easier formatting of the sql query (see Code Sample).