Skip to main content
Glama

PostgreSQL MCP Server

by sreedhag
databaseSchema.ts1.27 kB
// src/resources/databaseSchema.ts import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js"; import { pool, SCHEMA_PATH } from "../config/database.js"; export function registerDatabaseSchemaResource(mcpServer: McpServer) { mcpServer.resource( "Database Schema", new ResourceTemplate("database://tables/{tableName}/{schema}", { list: undefined }), async (uri, { tableName, schema }) => { if (schema !== SCHEMA_PATH) { throw new Error("Invalid resource URI"); } const client = await pool.connect(); try { const result = await client.query( "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = $1", [tableName], ); return { contents: [ { uri: uri.href, mimeType: "application/json", text: JSON.stringify(result.rows, null, 2), }, ], }; } finally { client.release(); } } ); }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sreedhag/postgres-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server