Labsco
cuongtl1992 logo

MCP Database Server

โ˜… 21

from cuongtl1992

Connects to and interacts with various database systems like SQLite, PostgreSQL, SQL Server, and MongoDB.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

MseeP.ai Security Assessment Badge

MCP Database Server

A Model Context Protocol (MCP) implementation for connecting to and working with various database systems.

Supported Databases

  • SQLite
  • PostgreSQL
  • Microsoft SQL Server
  • MongoDB

Claude Desktop Integration

You can integrate mcp-dbs with Claude Desktop by adding it to your Claude configuration file.

Configuration Steps

  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 own database connection details.

Notes

  • The command should be node
  • In args, provide the absolute path to the cli.js file in your mcp-dbs installation
  • Configure the appropriate environment variables for your database type (see the environment variables section below)
  • You can use environment variables for any of the supported databases (SQLite, PostgreSQL, SQL Server, or MongoDB)

Using with Claude

Once configured, Claude will be able to access your database using the MCP tools described below. You can ask Claude to:

  • Connect to your database
  • Execute queries and get results
  • Explore your database schema
  • Work with tables and data

Tools

  • connect-database: Connect to a database
  • disconnect-database: Disconnect from a database
  • execute-query: Execute a query and return results
  • execute-update: Execute a query without returning results

Resources

  • database-schema: Get the full database schema
  • table-schema: Get the schema for a specific table
  • tables-list: Get a list of all tables

MCP Tools

The server exposes the following MCP tools:

connect-database

Connect to a database.

Parameters:

  • connectionId: A unique identifier for the connection
  • type: Database type (sqlite, postgres, mssql, or mongodb)

Example for SQLite:

{
  "connectionId": "my-sqlite-db",
  "type": "sqlite"
}

Example for PostgreSQL:

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

Example for SQL Server:

{
  "connectionId": "my-mssql-db",
  "type": "mssql"
}

Example for MongoDB:

{
  "connectionId": "my-mongodb-db",
  "type": "mongodb"
}

disconnect-database

Disconnect from a database.

Parameters:

  • connectionId: The connection ID to disconnect

execute-query

Execute a query that returns results.

Parameters:

  • connectionId: The connection ID
  • query: SQL query or MongoDB aggregation pipeline (as JSON string)
  • params: (Optional) Array of parameters for the query. For MongoDB, the first parameter is the collection name.

Example for SQL:

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

Example for MongoDB:

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

Example for MongoDB (new format with embedded collection):

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

Example for MongoDB (shell syntax):

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

Example for MongoDB (direct collection reference shell syntax):

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

Example for MongoDB (raw command):

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

execute-update

Execute a query that doesn't return results (INSERT, UPDATE, DELETE).

Parameters:

  • connectionId: The connection ID
  • query: SQL query or MongoDB command (as JSON string)
  • params: (Optional) Array of parameters for the query. For MongoDB, the first parameter is the collection name.

Example for SQL:

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

Example for MongoDB:

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

Example for MongoDB (new format with embedded collection):

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

Example for MongoDB (shell syntax):

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

Example for MongoDB (direct collection reference shell syntax):

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

Example for MongoDB (raw command):

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

MCP Resources

The server exposes the following MCP resources:

Database Schema

URI: database://{connectionId}/schema

Returns schema information about the database, including all tables and their columns.

Table Schema

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

Returns schema information about a specific table, including its columns.

Tables List

URI: database://{connectionId}/tables

Returns a list of all tables in the database.

Development

Testing

Run the tests:

npm test