database-mcp-server
Provides read-only access to a SQLite database, enabling schema inspection, query execution, and query performance monitoring.
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., "@database-mcp-servershow me the users table schema"
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.
Database MCP Server
A Python-based Model Context Protocol (MCP) server that exposes a SQLite database to MCP clients through structured tools for database inspection, read-only SQL execution, and query performance monitoring.
This project was built to understand how MCP servers expose capabilities to AI applications through the MCP protocol.
Features
Inspect database schema dynamically
List tables, columns, and foreign-key relationships
Execute read-only
SELECTqueriesReturn structured query results
Record query execution time
Inspect recently executed queries
MCP communication over stdio
Built with the official Python MCP SDK
Related MCP server: sqlite-mcp-local
Architecture
MCP Client
(MCP Inspector / Claude)
│
│ MCP / stdio
▼
┌─────────────┐
│ server.py │
│ MCP Server │
└──────┬──────┘
│
MCP Tools
│
▼
┌─────────────┐
│ tools.py │
│ │
│ • Schema │
│ • SQL │
│ • Monitoring│
└──────┬──────┘
│
Database Logic
│
▼
┌─────────────┐
│ db.py │
└──────┬──────┘
│
▼
┌─────────────┐
│ SQLite DB │
│ app.db │
└─────────────┘MCP Tools
get_database_schema
Returns the database structure, including:
Tables
Columns
Data types
Primary keys
Foreign keys
Example result:
{
"database": "SQLite",
"tables": {
"orders": {
"columns": [],
"foreign_keys": []
},
"users": {
"columns": [],
"foreign_keys": []
}
}
}execute_read_only_query
Executes a SQL query against the database.
Only SELECT queries are permitted.
Example:
SELECT users.name, orders.product, orders.amount
FROM users
JOIN orders ON users.id = orders.user_id;The tool returns:
Query success/failure
Rows
Row count
Execution time
Write operations such as INSERT, UPDATE, and DELETE are rejected.
get_slow_queries
Returns queries recorded during the current MCP server session, including:
SQL query
Execution duration
Number of returned rows
Queries can be filtered by minimum execution time and limited by result count.
Query history is stored in memory and is reset when the MCP server restarts. This is intentional for this learning project.
Database
The project uses a small SQLite database containing two related tables:
users
-----
id
name
email
orders
------
id
user_id
product
amountRelationship:
users.id
│
│
└──────< orders.user_idSample data is included automatically when the database is initialized.
Project Structure
Database_MCP_Server/
│
├── database/
│ └── app.db
│
├── src/
│ ├── db.py
│ ├── tools.py
│ └── server.py
│
├── .gitignore
├── LICENSE
├── requirements.txt
└── README.mdsrc/db.py
Handles SQLite database operations:
Database initialization
Connections
Table discovery
Column inspection
Foreign-key inspection
SQL execution
src/tools.py
Contains the actual capabilities exposed through MCP:
Database schema inspection
Read-only SQL execution
Query performance logging
src/server.py
Creates the MCP server and exposes the Python functions as MCP tools.
The server communicates using stdio transport.
Requirements
Python 3.12+
Node.js / npm
MCP Python SDK 2.x
Installation
Clone the repository:
git clone https://github.com/MSHAH-byte/database-mcp-server.gitEnter the project directory:
cd database-mcp-serverCreate a virtual environment:
python -m venv .venvActivate it on Windows PowerShell:
.venv\Scripts\Activate.ps1Install dependencies:
pip install -r requirements.txtDatabase Initialization
The sample database can be initialized by running:
python .\src\db.pyThis creates:
database/app.dbwith the sample users and orders tables.
Running the MCP Server
The server uses stdio transport and is intended to be launched by an MCP client.
Run:
python .\src\server.pyThe terminal will wait for MCP communication rather than displaying a normal application interface.
Testing with MCP Inspector
MCP Inspector can be used to connect to and interact with the server.
Run:
npx @modelcontextprotocol/inspector python .\src\server.pyInspector should connect to the server and discover the available tools.
You can then test:
get_database_schema
execute_read_only_query
get_slow_queriesExample Query
SELECT * FROM users;Expected sample users:
Ali
Sara
AhmedExample JOIN
SELECT users.name, orders.product, orders.amount
FROM users
JOIN orders ON users.id = orders.user_id;Read-Only Protection
Attempting:
DELETE FROM users;returns an error because the server only permits SELECT queries.
Security Considerations
This project intentionally exposes a limited database capability.
The SQL tool:
Allows only
SELECTstatementsRejects multiple SQL statements
Does not expose database write operations
Does not expose arbitrary filesystem access
Does not contain API keys or credentials
This is a learning implementation rather than a production database security layer.
For a production system, SQL validation, authentication, authorization, database permissions, auditing, query limits, and resource controls would require substantially more robust implementation.
What This Project Demonstrates
The main purpose of this project is understanding the MCP architecture.
Without MCP:
AI Application
│
└── custom integration
│
└── databaseWith MCP:
AI Application
│
▼
MCP Client
│
│ MCP
▼
MCP Server
│
▼
Tools
│
▼
DatabaseThe MCP client can discover the capabilities exposed by the server through the protocol instead of requiring the database integration to be hard-coded into every AI application.
Key MCP Concepts Learned
MCP client/server architecture
MCP server initialization
stdio transport
Tool registration
Tool discovery
Tool descriptions and schemas
Tool invocation
Structured tool results
Separating MCP tools from application logic
Restricting tool permissions
Connecting AI applications to external capabilities
Limitations
This project intentionally keeps the scope small.
SQLite only
Query history is stored in memory
No authentication
No persistent monitoring system
No production-grade SQL parser
No database write operations
No remote transport
No multi-server architecture
These limitations keep the project focused on learning the core MCP concepts.
Next Step
The next MCP project will extend these concepts into a multi-server DevOps / Incident Response system, where an AI agent interacts with multiple independent MCP servers for system logs and GitHub operations, with human approval before side-effecting actions.
License
This project is licensed under the MIT License. See LICENSE.
This server cannot be deployed
Maintenance
Related MCP Connectors
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Explore your Messages SQLite database to browse tables and inspect schemas with ease. Run flexible…
Paid remote MCP for governed database query review, SQL simulation, approvals, and audits.
Related MCP Servers
- AlicenseAqualityDmaintenanceRead-only SQLite database explorer for MCP clients. Allows discovery of tables and columns via resources and running SELECT queries via a tool.2MIT
- FlicenseNot gradedqualityBmaintenanceEnables read-only querying of a local SQLite database via MCP, with tools to list tables, retrieve schema, and execute SELECT/WITH/EXPLAIN queries.-
- AlicenseNot gradedqualityBmaintenanceEnables read-only access to SQLite databases via MCP, with tools for browsing tables, schemas, and executing SELECT queries securely.MIT
- FlicenseAqualityCmaintenanceEnables AI agents to safely inspect and query a SQLite database through read-only MCP tools for listing tables, describing schemas, and running paginated SELECT queries.3-