dj-postgres-mcp
Version:
Model Context Protocol (MCP) server for PostgreSQL database operations with centralized configuration via dj-config-mcp
53 lines (52 loc) • 2.64 kB
JavaScript
/**
* Consistent message formatting utilities for user-facing messages
*/
export const MessageFormatter = {
// Success messages with consistent emoji and format
success: {
connection: (details) => `✅ Connection successful\n${details}`,
configuration: (details) => `✅ Configuration saved\n${details}`,
query: (rowCount, time) => `✅ Query executed successfully\n- Rows affected: ${rowCount}\n- Execution time: ${time}ms`,
tableCreated: (tableName) => `✅ Table "${tableName}" created successfully`,
general: (message) => `✅ ${message}`
},
// Error messages with consistent format
error: {
connection: (error) => `❌ Connection failed\n${error}`,
configuration: (error) => `❌ Configuration failed\n${error}`,
query: (error) => `❌ Query execution failed\n${error}`,
validation: (field, issue) => `❌ Invalid ${field}: ${issue}`,
notFound: (resource, identifier) => `❌ ${resource} "${identifier}" not found`,
general: (error) => `❌ Error: ${error}`
},
// Info messages with consistent format
info: {
configuration: (host, port, database, user, ssl) => `📋 Configuration Details:\n- Host: ${host}:${port}\n- Database: ${database}\n- User: ${user}\n- SSL: ${ssl ? 'enabled' : 'disabled'}`,
tableCount: (count) => `📊 Found ${count} table${count !== 1 ? 's' : ''}`,
queryPlan: (plan) => `📊 Query Plan:\n${plan}`,
general: (message) => `ℹ️ ${message}`
},
// Warning messages
warning: {
deprecation: (feature, alternative) => `⚠️ Warning: ${feature} is deprecated. Use ${alternative} instead.`,
performance: (issue) => `⚠️ Performance warning: ${issue}`,
security: (issue) => `⚠️ Security warning: ${issue}`,
general: (message) => `⚠️ ${message}`
},
// Headers for different sections
headers: {
tables: () => '📊 Database Tables',
tableStructure: (schema, table) => `📋 Table Structure: ${schema}.${table}`,
queryResults: () => '📊 Query Results',
configuration: () => '🔧 PostgreSQL Configuration'
},
// Format lists consistently
list: (items, indent = ' ') => items.map(item => `${indent}• ${item}`).join('\n'),
// Format key-value pairs consistently
keyValue: (key, value, indent = ' ') => `${indent}${key}: ${value}`,
// Sanitize sensitive information
sanitize: {
password: (password) => password ? '********' : 'not set',
connectionString: (connStr) => connStr.replace(/:[^@]+@/, ':********@')
}
};