SQL Query MCP Server
Provides read-only SELECT query execution and schema discovery for MySQL databases, including listing tables and discovering foreign-key relationships.
Provides read-only SELECT query execution and schema discovery for PostgreSQL databases, including listing tables and discovering foreign-key relationships.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SQL Query MCP Server show me the Orders table schema and its foreign keys"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
SQL Query MCP Server
A Model Context Protocol (MCP) server that provides safe, read-only access to SQL databases through SELECT queries. This server runs in a Docker container and can be integrated with VS Code and other MCP-compatible clients.
Features
Security First: Only SELECT queries are allowed - all data-modifying operations are blocked
Multi-Database Support: Works with SQL Server (MSSQL), MySQL, and PostgreSQL
Containerized: Runs in Docker for isolation and easy deployment
Schema Discovery: Built-in tools to explore database structure and relationships
Foreign Key Detection: Automatically discover table relationships for complex queries
VS Code Integration: Ready to use as a tool in VS Code with GitHub Copilot
Related MCP server: Generic Database MCP Server
Available Tools
1. execute_select_query
Execute a SELECT query on the database.
Parameters:
query(string): The SELECT SQL query to execute
Example:
SELECT * FROM Users WHERE age > 182. get_database_schema
Get the complete database schema including all tables and columns with their data types.
3. list_tables
List all tables in the database.
4. get_table_relationships
Get foreign key relationships between tables. Shows which columns reference other tables, essential for understanding how to join tables in complex queries.
Returns:
constraint_name: Name of the foreign key constrainttable_name: The table that contains the foreign keycolumn_name: The column that is a foreign keyreferenced_table: The table being referencedreferenced_column: The column being referenced
Example use case:
Q: "Check the relationship between Orders, Customers and Products.
Which foreign keys should I use to create a complex query?"
A: The tool returns:
- Orders.CustomerID → Customers.CustomerID
- Orders.ProductID → Products.ProductIDSetup
Prerequisites
Docker and Docker Compose
Node.js 20+ (for local development)
Access to a SQL database (MSSQL, MySQL, or PostgreSQL)
Configuration
Copy the environment example file:
cp .env.example .envEdit
.envwith your database credentials:DB_TYPE=mssql # Options: mssql, mysql, postgres DB_HOST=host.docker.internal # For Docker to access host machine DB_PORT=1433 DB_USER=your_user DB_PASSWORD=your_password DB_NAME=your_database DB_ENCRYPT=false # Set to true for Azure SQL
Building and Running
Option 1: Using Docker Compose (Recommended)
docker-compose up --buildOption 2: Using Docker directly
# Build the image
docker build -t mcp-sql-query-server .
# Run the container
docker run -i \
-e DB_TYPE=mssql \
-e DB_HOST=host.docker.internal \
-e DB_PORT=1433 \
-e DB_USER=sa \
-e DB_PASSWORD=YourPassword \
-e DB_NAME=master \
mcp-sql-query-serverOption 3: Local Development (without Docker)
# Install dependencies
npm install
# Build TypeScript
npm run build
# Set environment variables and run
export DB_TYPE=mssql
export DB_HOST=localhost
export DB_PORT=1433
export DB_USER=sa
export DB_PASSWORD=YourPassword
export DB_NAME=master
npm startVS Code Integration
To use this MCP server with VS Code and GitHub Copilot:
1. Configure MCP in VS Code
Create or edit your MCP settings file. The location depends on your OS:
Windows:
%APPDATA%\Code\User\globalStorage\github.copilot-chat\mcp.jsonmacOS:
~/Library/Application Support/Code/User/globalStorage/github.copilot-chat/mcp.jsonLinux:
~/.config/Code/User/globalStorage/github.copilot-chat/mcp.json
2. Add the Server Configuration
For Docker Container:
{
"mcpServers": {
"sql-query": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "DB_TYPE=mssql",
"-e", "DB_HOST=host.docker.internal",
"-e", "DB_PORT=1433",
"-e", "DB_USER=sa",
"-e", "DB_PASSWORD=YourPassword",
"-e", "DB_NAME=YourDatabase",
"mcp-sql-query-server"
]
}
}
}For Local Node.js:
{
"mcpServers": {
"sql-query": {
"command": "node",
"args": ["c:/Users/mzulber/personal-projects/mcp-servers/sql-server-query/dist/index.js"],
"env": {
"DB_TYPE": "mssql",
"DB_HOST": "localhost",
"DB_PORT": "1433",
"DB_USER": "sa",
"DB_PASSWORD": "YourPassword",
"DB_NAME": "YourDatabase"
}
}
}
}3. Restart VS Code
After adding the configuration, restart VS Code for the changes to take effect.
4. Using in VS Code
Once configured, you can use the SQL query tools in GitHub Copilot Chat:
Example prompts:
"List all tables in the database"
"Show me the schema for the Users table"
"Query the top 10 orders from last month"
"What columns are in the Products table?"
"Check the relationship between Orders, Customers and Products. Which foreign keys should I use to create a complex query?"
"Show me how the tables are related in this database"
The Copilot will use the MCP server to execute your queries safely.
Security Features
Query Validation: Only SELECT statements are allowed
Keyword Blocking: Blocks queries containing INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, TRUNCATE, EXEC, etc.
No Dynamic SQL: Prevents execution of stored procedures or dynamic SQL
Read-Only Access: Configure your database user with read-only permissions for additional security
Database-Specific Notes
SQL Server (MSSQL)
Default port: 1433
Supports both Windows and SQL Server authentication
For Azure SQL, set
DB_ENCRYPT=true
MySQL
Default port: 3306
Ensure user has SELECT privileges on the target database
PostgreSQL
Default port: 5432
Connects to specific database specified in
DB_NAME
Troubleshooting
Container can't connect to database on host machine
Use host.docker.internal instead of localhost for DB_HOST when running in Docker.
Connection timeout
Check firewall settings
Verify database is listening on the specified port
Ensure database allows connections from Docker network
VS Code doesn't see the tools
Check that the
mcp.jsonfile is in the correct locationRestart VS Code
Check VS Code Developer Tools Console for errors (Help > Toggle Developer Tools)
Development
Watch mode for development:
npm run watchBuild only:
npm run buildLicense
MIT
Available Tools
4 toolsexecute_select_queryB
Execute a SELECT query on the database. Only SELECT queries are allowed for security. Returns the query results with rows and column information.
Inputs: query (required).
get_database_schemaB
Get the complete database schema including all tables and columns with their data types
Inputs: no named parameters.
get_table_relationshipsA
Get foreign key relationships between tables. Shows which columns reference other tables, useful for understanding how to join tables and create complex queries.
Inputs: no named parameters.
list_tablesA
List all tables in the database
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool has a distinct action: running queries, fetching full schema, listing table names, and fetching foreign-key relationships. There is mild redundancy since list_tables and get_table_relationships return subsets of what get_database_schema already covers, but the descriptions make the intended use of each clear.
All four tools follow a clean verb_noun pattern (execute_select_query, get_database_schema, list_tables, get_table_relationships) with consistent snake_case and imperative verbs.
Four tools is on the thin side but appropriate for a deliberately narrow, read-only query server where each tool covers a distinct introspection or execution need. Slight overlap suggests one could be trimmed, but nothing is bloated.
The core read-only workflow — discover tables, inspect schema and joins, then run SELECTs — is fully covered with no dead ends. Minor gaps like explain_query, sample-row previews, or column search exist but are workarounds via execute_select_query.
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Draxlr's remote MCP server connects AI assistants to your SQL databases and dashboards. Explore schemas, run read-only queries, manage saved queries and dashboards, and export results, all with row-level security so each user sees only their own data.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely query and explore SQL Server and PostgreSQL databases with read-only access, supporting schema discovery, relationship exploration, and query execution.3MIT
- AlicenseNot gradedqualityDmaintenanceEnables read-only SQL querying and schema inspection across MSSQL, PostgreSQL, and MySQL databases via MCP tools.ISC
- FlicenseNot gradedqualityBmaintenanceProvides read-only access to databases for MCP-compatible AI tools, allowing schema exploration and SELECT queries without exposing credentials or risking data changes.3-
- AlicenseNot gradedqualityCmaintenanceEnables read-only, SELECT-only querying of any Postgres database through MCP-compatible clients like Claude, with schema introspection and guarded SQL execution.MIT