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.
Install the MCP Database Server globally using npm:
npm install -g mcp-dbs
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
.
Specify a custom port with the --port
option:
npx mcp-dbs --port 8080
For tools that communicate over standard input/output:
npx mcp-dbs --stdio
Integrate mcp-dbs with Claude Desktop by adding it to your configuration file:
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.
Configure your database connections using environment variables:
export MCP_SQLITE_FILENAME="path/to/database.db"
export MCP_SQLITE_CREATE_IF_NOT_EXISTS="true"
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"
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"
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"
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"
}
Use the disconnect-database
tool:
{
"connectionId": "my-postgres-db"
}
Use the execute-query
tool for queries that return results:
{
"connectionId": "my-postgres-db",
"query": "SELECT * FROM users WHERE age > $1",
"params": [21]
}
{
"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}})"
}
Use the execute-update
tool for queries that modify data:
{
"connectionId": "my-postgres-db",
"query": "INSERT INTO users (name, age) VALUES ($1, $2)",
"params": ["John Doe", 30]
}
{
"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})"
}
The server provides these resource endpoints:
URI: database://{connectionId}/schema
Returns complete schema information about the database.
URI: database://{connectionId}/tables/{tableName}
Returns schema information for a specific table.
URI: database://{connectionId}/tables
Returns a list of all tables in the database.
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.
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.
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"
}
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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