Database Connections MCP server

Provides a unified TypeScript-based database server for seamlessly connecting to SQLite, PostgreSQL, SQL Server, and MongoDB, enabling flexible database interactions through server-sent events and standard I/O communication modes.
Back to servers
Setup instructions
Provider
Cuong Le
Release date
Mar 18, 2025
Language
TypeScript
Package
Stats
640 downloads
18 stars

The MCP Database Server provides a Model Context Protocol implementation for connecting to various database systems including SQLite, PostgreSQL, Microsoft SQL Server, and MongoDB. It allows you to interact with databases through a simple API interface.

Installation

Install the MCP Database Server globally using npm:

npm install -g mcp-dbs

Running the Server

SSE Mode (Default)

By default, the server runs in SSE (Server-Sent Events) mode on port 3001:

npx mcp-dbs

This starts an HTTP server with an SSE endpoint at http://localhost:3001/mcp.

Using a Custom Port

Specify a custom port with the --port option:

npx mcp-dbs --port 8080

STDIO Mode

For tools that communicate over standard input/output:

npx mcp-dbs --stdio

Claude Desktop Integration

Integrate mcp-dbs with Claude Desktop by adding it to your configuration file:

  1. Open or create your Claude Desktop configuration file
  2. Add the mcp-dbs configuration to the mcpServers section:
{
  "mcpServers": {
    "mcp-dbs": {
      "command": "node",
      "args": [
        "/path/to/your/mcp-dbs/dist/cli.js",
        "--stdio"
      ],
      "env": {
        "MCP_MONGODB_URI": "mongodb://localhost:27017",
        "MCP_MONGODB_DATABASE": "your-database-name"
      }
    }
  }
}

Replace the environment variables with your database connection details.

Database Configuration

Configure your database connections using environment variables:

SQLite

export MCP_SQLITE_FILENAME="path/to/database.db"
export MCP_SQLITE_CREATE_IF_NOT_EXISTS="true"

PostgreSQL

export MCP_POSTGRES_HOST="your-postgres-host"
export MCP_POSTGRES_PORT="5432"
export MCP_POSTGRES_DATABASE="your-database-name"
export MCP_POSTGRES_USER="your-username"
export MCP_POSTGRES_PASSWORD="your-password"
export MCP_POSTGRES_SSL="false"

SQL Server

export MCP_MSSQL_SERVER="your-server-address"
export MCP_MSSQL_PORT="1433"
export MCP_MSSQL_DATABASE="your-database-name"
export MCP_MSSQL_USER="your-username"
export MCP_MSSQL_PASSWORD="your-password"
export MCP_MSSQL_ENCRYPT="true"
export MCP_MSSQL_TRUST_SERVER_CERTIFICATE="true"

MongoDB

export MCP_MONGODB_URI="mongodb://localhost:27017"
export MCP_MONGODB_DATABASE="your-database-name"
export MCP_MONGODB_MAX_POOL_SIZE="10"
export MCP_MONGODB_USE_UNIFIED_TOPOLOGY="true"

Using MCP Tools

Connecting to a Database

Use the connect-database tool to establish a connection:

{
  "connectionId": "my-sqlite-db",
  "type": "sqlite"
}
{
  "connectionId": "my-postgres-db",
  "type": "postgres"
}
{
  "connectionId": "my-mssql-db",
  "type": "mssql"
}
{
  "connectionId": "my-mongodb-db",
  "type": "mongodb"
}

Disconnecting from a Database

Use the disconnect-database tool:

{
  "connectionId": "my-postgres-db"
}

Executing Queries

Use the execute-query tool for queries that return results:

SQL Databases

{
  "connectionId": "my-postgres-db",
  "query": "SELECT * FROM users WHERE age > $1",
  "params": [21]
}

MongoDB

{
  "connectionId": "my-mongodb-db",
  "query": "[{\"$match\": {\"age\": {\"$gt\": 21}}}, {\"$sort\": {\"name\": 1}}]",
  "params": ["users"]
}

Or with embedded collection:

{
  "connectionId": "my-mongodb-db",
  "query": "{\"collection\": \"users\", \"pipeline\": [{\"$match\": {\"age\": {\"$gt\": 21}}}, {\"$sort\": {\"name\": 1}}]}"
}

Using shell syntax:

{
  "connectionId": "my-mongodb-db",
  "query": "db.users.find({\"age\": {\"$gt\": 21}})"
}

Executing Updates

Use the execute-update tool for queries that modify data:

SQL Databases

{
  "connectionId": "my-postgres-db",
  "query": "INSERT INTO users (name, age) VALUES ($1, $2)",
  "params": ["John Doe", 30]
}

MongoDB

{
  "connectionId": "my-mongodb-db",
  "query": "{\"insertOne\": {\"name\": \"John Doe\", \"age\": 30}}",
  "params": ["users"]
}

Or with embedded collection:

{
  "connectionId": "my-mongodb-db",
  "query": "{\"collection\": \"users\", \"operation\": {\"insertOne\": {\"name\": \"John Doe\", \"age\": 30}}}"
}

Using shell syntax:

{
  "connectionId": "my-mongodb-db",
  "query": "db.users.insertOne({\"name\": \"John Doe\", \"age\": 30})"
}

MCP Resources

The server provides these resource endpoints:

Database Schema

URI: database://{connectionId}/schema

Returns complete schema information about the database.

Table Schema

URI: database://{connectionId}/tables/{tableName}

Returns schema information for a specific table.

Tables List

URI: database://{connectionId}/tables

Returns a list of all tables in the database.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mcp-dbs" '{"command":"node","args":["/path/to/your/mcp-dbs/dist/cli.js","--stdio"],"env":{"MCP_MONGODB_URI":"mongodb://localhost:27017","MCP_MONGODB_DATABASE":"your-database-name"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mcp-dbs": {
            "command": "node",
            "args": [
                "/path/to/your/mcp-dbs/dist/cli.js",
                "--stdio"
            ],
            "env": {
                "MCP_MONGODB_URI": "mongodb://localhost:27017",
                "MCP_MONGODB_DATABASE": "your-database-name"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

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

2. Add this to your configuration file:

{
    "mcpServers": {
        "mcp-dbs": {
            "command": "node",
            "args": [
                "/path/to/your/mcp-dbs/dist/cli.js",
                "--stdio"
            ],
            "env": {
                "MCP_MONGODB_URI": "mongodb://localhost:27017",
                "MCP_MONGODB_DATABASE": "your-database-name"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later