Sign In

@marcelo-ochoa/server-postgres

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@marcelo-ochoa/server-postgres - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+21
LICENSE
MIT License
Copyright (c) 2025
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+41
-7

@@ -1,2 +0,2 @@

import { withConnection, getResourceBaseUrl } from "./db.js";
import { withConnection } from "./db.js";
import { queryHandler } from "./tools/query.js";

@@ -23,10 +23,9 @@ import { statsHandler } from "./tools/stats.js";

export const listResourcesHandler = async (request) => {
const resourceBaseUrl = getResourceBaseUrl();
return await withConnection(async (client) => {
const result = await client.query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'");
const result = await client.query("SELECT table_name, table_schema FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog')");
return {
resources: result.rows.map((row) => ({
uri: new URL(`${row.table_name}/${SCHEMA_PATH}`, resourceBaseUrl).href,
uri: `postgres://${row.table_schema}/${row.table_name}/${SCHEMA_PATH}`,
mimeType: "application/json",
name: `"${row.table_name}" database schema`,
name: `"${row.table_schema}"."${row.table_name}" database schema`,
})),

@@ -41,2 +40,3 @@ };

const tableName = pathComponents.pop();
const schemaName = resourceUrl.hostname;
if (schema !== SCHEMA_PATH) {

@@ -46,3 +46,34 @@ throw new Error("Invalid resource URI");

return await withConnection(async (client) => {
const result = await client.query("SELECT column_name, data_type FROM information_schema.columns WHERE table_name = $1", [tableName]);
const columnsResult = await client.query(`SELECT
column_name,
data_type,
is_nullable,
column_default,
character_maximum_length,
numeric_precision,
numeric_scale
FROM information_schema.columns
WHERE table_name = $1 AND table_schema = $2
ORDER BY ordinal_position`, [tableName, schemaName]);
const indexesResult = await client.query(`SELECT
ix.relname as index_name,
i.indisunique as is_unique,
a.attname as column_name
FROM
pg_class t,
pg_class ix,
pg_index i,
pg_attribute a,
pg_namespace n
WHERE
t.oid = i.indrelid
AND ix.oid = i.indexrelid
AND a.attrelid = t.oid
AND a.attnum = ANY(i.indkey)
AND t.relkind = 'r'
AND t.relname = $1
AND n.oid = t.relnamespace
AND n.nspname = $2
ORDER BY
ix.relname`, [tableName, schemaName]);
return {

@@ -53,3 +84,6 @@ contents: [

mimeType: "application/json",
text: JSON.stringify(result.rows, null, 2),
text: JSON.stringify({
columns: columnsResult.rows,
indexes: indexesResult.rows
}, null, 2),
},

@@ -56,0 +90,0 @@ ],

+2
-2

@@ -10,3 +10,3 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";

name: "postgres-server",
version: "1.0.1",
version: "1.0.2",
}, {

@@ -39,3 +39,3 @@ capabilities: {

{
uriTemplate: "postgres://{database}/{table_name}/schema",
uriTemplate: "postgres://{schema}/{table_name}/schema",
name: "Table Schema",

@@ -42,0 +42,0 @@ description: "Schema information for a PostgreSQL database table including column names and data types",

import { withConnection } from "../db.js";
export const statsHandler = async (request) => {
const tableName = request.params.arguments?.name;
let schema = 'public';
let tableName = request.params.arguments?.name;
if (tableName.includes('.')) {
const parts = tableName.split('.');
schema = parts[0];
tableName = parts[1];
}
return await withConnection(async (client) => {

@@ -18,3 +24,3 @@ const result = await client.query(`

LEFT JOIN pg_stat_user_tables s ON s.relid = c.oid
WHERE c.relname = $1 AND n.nspname = 'public'
WHERE c.relname = $1 AND n.nspname = $2
),

@@ -34,3 +40,3 @@ 'index_stats', (

JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = $1 AND n.nspname = 'public'
WHERE c.relname = $1 AND n.nspname = $2
),

@@ -47,6 +53,6 @@ 'column_stats', (

FROM pg_stats
WHERE tablename = $1 AND schemaname = 'public'
WHERE tablename = $1 AND schemaname = $2
)
) as stats_json
`, [tableName]);
`, [tableName, schema]);
return {

@@ -53,0 +59,0 @@ content: [{ type: "text", text: JSON.stringify(result.rows[0].stats_json, null, 2), mimeType: "application/json" }],

{
"name": "@marcelo-ochoa/server-postgres",
"mcpName": "io.github.marcelo-ochoa/postgres",
"version": "1.0.1",
"version": "1.0.2",
"description": "MCP server for interacting with PostgreSQL databases",

@@ -6,0 +6,0 @@ "keywords": [

@@ -232,2 +232,2 @@ # PostgreSQL

This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
This MCP server is licensed under the [MIT License](https://github.com/marcelo-ochoa/servers/blob/main/src/postgres/LICENSE). This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.