file-mcp

#Filesystem MCP Server Node.js server implementing Model Context Protocol (MCP) for filesystem operations.

Features Read/write files Create/list/delete directories Move files/directories Search files Get file metadata Note: The server will only allow operations within directories specified via args.

PostgreSQL MCP Server

A Model Context Protocol (MCP) server that provides read-only access to PostgreSQL databases for AI assistants and other MCP clients.

Features

Installation

```bash npm install -g postgresql-mcp-server ```

From source

```bash git clone cd postgresql-mcp-server npm install npm run build npm link \`\`\`

Configuration

The server requires a PostgreSQL connection string via the DATABASE_URL environment variable:

```bash export DATABASE_URL=”postgresql://username:password@hostname:port/database” ```

Supported connection string formats:

Supported database providers:

Usage

With Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

```json { “mcpServers”: { “postgresql”: { “command”: “postgresql-mcp-server”, “env”: { “DATABASE_URL”: “postgresql://username:password@hostname:port/database” } } } } ```

With other MCP clients

The server implements the standard MCP protocol and can be used with any compatible client.

API Reference

Resources

postgresql://database-schema

Complete database schema with all tables and columns in JSON format.

postgresql://table-list

Simple list of all tables in the database.

Tools

execute_sql

Execute read-only SQL queries against the database.

Parameters:

Example: ```sql SELECT * FROM users WHERE created_at > ‘2024-01-01’ ```

get_table_info

Get detailed information about a specific table.

Parameters:

Returns:

analyze_data

Generate common data analysis queries for a table.

Parameters:

search_tables

Search for tables and columns matching a pattern.

Parameters:

Security

This server implements several security measures:

Development

Setup

```bash git clone cd postgresql-mcp-server npm install \`\`\`

Running in development

```bash npm run dev ```

Building

```bash npm run build ```

Testing

```bash

Run tests

npm test

Run tests with coverage

npm run test:coverage

Run linting

npm run lint ```

Project Structure

``` src/ ├── index.ts # Main server entry point ├── database.ts # Database connection and query management ├── validation.ts # Environment validation ├── logging.ts # Logging utility ├── tools/ │ ├── index.ts # Tools handler │ ├── execute-sql.ts # SQL execution tool │ ├── get-table-info.ts # Table information tool │ ├── analyze-data.ts # Data analysis tool │ └── search-tables.ts # Search tool └── resources/ ├── index.ts # Resources handler ├── database-schema.ts # Schema resource └── table-list.ts # Table list resource

tests/ # Test files ├── database.test.ts ├── tools/ └── resources/ ```

Examples

Basic Queries

```sql – Get recent users SELECT * FROM users WHERE created_at > ‘2024-01-01’ LIMIT 10;

– Count records by status SELECT status, COUNT(*) FROM orders GROUP BY status;

– Find top products SELECT product_name, SUM(quantity) as total_sold FROM order_items GROUP BY product_name ORDER BY total_sold DESC LIMIT 5; ```

Data Analysis

Search & Discovery

Troubleshooting

Connection Issues

  1. “Failed to connect to database”
    • Verify your DATABASE_URL is correct
    • Check that the database server is running and accessible
    • Ensure your credentials are valid
  2. SSL/TLS errors
    • For cloud databases, try adding ?sslmode=require to your connection string
    • For local development, you may need ?sslmode=disable

Query Issues

  1. “Only read-only queries are allowed”
    • The server only accepts SELECT, WITH, EXPLAIN, SHOW, and DESCRIBE statements
    • Modify your query to use only these statement types
  2. “Query contains potentially dangerous operations”
    • Your query contains keywords that could modify data
    • Review your query for INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, or TRUNCATE statements

Performance Issues

  1. Slow queries
    • Use the limit parameter to reduce result set size
    • Add appropriate indexes to your database
    • Consider using the analysis tools instead of raw queries for large datasets

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

License

MIT License - see LICENSE file for details. ```

```plaintext file=”.env.example”

PostgreSQL Database Connection

Replace with your actual database connection string

DATABASE_URL=postgresql://username:password@hostname:port/database

Optional: Enable debug logging

DEBUG=true

Example connection strings:

Local PostgreSQL:

DATABASE_URL=postgresql://postgres:password@localhost:5432/mydb

Cloud PostgreSQL (with SSL):

DATABASE_URL=postgresql://user:pass@host.com:5432/dbname?sslmode=require

Neon (serverless PostgreSQL):

DATABASE_URL=postgresql://user:pass@ep-xxx.us-east-1.aws.neon.tech/dbname?sslmode=require

Supabase:

DATABASE_URL=postgresql://postgres:[password]@db.[project-ref].supabase.co:5432/postgres

Railway:

DATABASE_URL=postgresql://postgres:pass@containers-us-west-xxx.railway.app:port/railway

Render:

DATABASE_URL=postgresql://user:pass@dpg-xxx-a.oregon-postgres.render.com/dbname