Allows execution of queries against MongoDB databases with support for connection management and secure credential handling
Provides secure query execution against MySQL databases with connection configuration and management
Enables secure interaction with PostgreSQL databases including connection management and query execution
Uses SQLite as the configuration database to store and manage connection details for other database systems
MCP Database Server
This project provides a Middleware/Control Plane (MCP) server that allows code agents (like Gemini, Claude Desktop, and Claude Code) to securely execute queries against various databases (PostgreSQL, MySQL, MongoDB, Oracle) without directly exposing credentials. Database connection configurations are managed within an SQLite database (mcp_config.sqlite3
).
1. Installation
To set up the project, follow these steps:
- Clone the repository (if you haven't already):
- Install dependencies:
This project uses a
venv
(virtual environment) to manage dependencies. Run the following command to create the virtual environment and install the required Python packages:This will create avenv/
directory and install everything listed inrequirements.txt
.
2. Running the MCP Server
To start the MCP server, use the make run
command:
The server will start and listen for incoming requests from your code agents.
3. Database Configuration
Database connections are stored in mcp_config.sqlite3
. You can manage these connections using the global mcp-db
command (recommended) or the local main.py
script.
Adding a Database Connection
Use the add-db
command. The required parameters vary by database type.
General Syntax (Global Command - Recommended):
Alternative (Local Command):
Examples (Global Command):
- PostgreSQL:
- MySQL:
- Oracle:
- MongoDB:
Removing a Database Connection
Use the remove-db
command with the alias of the connection you want to remove:
Global Command:
Local Command:
Example:
Getting Help
For detailed help and examples:
4. Integration with Code Agents
Gemini
Once the MCP server is running (make run
), Gemini will automatically discover and make the following tools available for interacting with your configured databases:
list_aliases()
: Lists all configured database aliases.add_database(...)
: Adds a new database connection.remove_database(...)
: Removes a database connection.execute_query(database_alias, query, params, schema)
: Executes a query against a configured database.
Gemini Usage Examples:
- List aliases:
- Execute a SQL query (PostgreSQL/MySQL/Oracle):
- Execute a MongoDB query:
Claude Desktop
To integrate with Claude Desktop, you need to configure its claude_desktop_config.json
file to point to your MCP server. Create or modify this file (usually located in your Claude Desktop configuration directory) with an entry similar to this:
Important: Replace /your-path-to/custom-mcp-database
with the actual absolute path to your custom-mcp-database
directory.
After configuring, restart Claude Desktop. The MCP tools will then be available for use within Claude Desktop.
Tool Configuration for AI Agents
To enable AI agents like Claude Code and Gemini to automatically discover and utilize the MCP server's tools, you need to configure them to launch or connect to the MCP server. This typically involves providing the path to the main.py
script and specifying the working directory.
Here are examples of how you might configure your AI agent's mcpServers
section:
For Claude Code
For Gemini
Important: Replace /your-path-to/custom-mcp-database
with the actual absolute path to your custom-mcp-database
directory.
Refer to your specific AI agent's official documentation for the most accurate and up-to-date instructions on configuring external MCP servers.
This server cannot be installed
A Middleware/Control Plane server that allows AI code agents to securely execute queries against various databases (PostgreSQL, MySQL, MongoDB, Oracle) without directly exposing credentials.
Related MCP Servers
- -securityAlicense-qualityA server that enables AI models to interact with MySQL databases through a Model Control Protocol, providing tools for table creation, schema inspection, query execution, and data retrieval.Last updated -26PythonMIT License
- -securityFlicense-qualityA powerful server that enables AI agents to interact with MySQL databases, execute SQL queries, and manage database content through a simple interface.Last updated -425JavaScript
- -securityAlicense-qualityA Model Context Protocol server that provides AI assistants with comprehensive access to SQL databases, enabling schema inspection, query execution, and database operations with enterprise-grade security.Last updated -42TypeScriptMIT License
- -securityFlicense-qualityA middleware server that intelligently routes AI model queries to appropriate data sources, providing contextual information to enhance AI responses.Last updated -Python