DB Query MCP server

Connects AI models to multiple database systems for executing queries and retrieving results across PostgreSQL, MySQL, and SQLite.
Back to servers
Provider
ALX99
Release date
Feb 13, 2025
Language
Go
Stats
1 star

This utility allows AI assistants supporting the Model Context Protocol (MCP) to interact with databases. The db-mcp server provides a simple interface for connecting to and querying various database systems, making it easier for AI tools to work with structured data.

Installation

You can install db-mcp using Go's package manager:

go install github.com/alx99/db-mcp/cmd/db-mcp@latest

Usage

Starting the Server

To start the db-mcp server with default settings:

db-mcp

Configuration Options

When starting the server, you can specify the following flags:

  • -default-dsn: Sets the Data Source Name to use for the default database connection

Example with a default PostgreSQL connection:

db-mcp -default-dsn="postgres://username:password@localhost:5432/mydatabase"

Supported Databases

The server works with multiple database systems:

  • PostgreSQL
  • MySQL
  • SQLite

Available Tools

db-mcp provides three main tools that can be used through the MCP interface:

Connect Tool

Establishes a connection to a database using a DSN (Data Source Name).

Query Tool

Executes SQL queries on a connected database and returns results in CSV format.

Flavor Tool

Retrieves information about the type of database currently connected.

Connection Strings (DSN)

To connect to different database systems, you'll need to construct the appropriate DSN:

PostgreSQL

postgres://username:password@localhost:5432/database

MySQL

mysql://username:password@localhost:3306/database

SQLite

sqlite:///path/to/database.db

For more detailed information on constructing DSNs:

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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