{"id":28814914,"url":"https://github.com/devsenweb/mcp-server-for-db","last_synced_at":"2026-05-03T10:38:37.329Z","repository":{"id":298598298,"uuid":"1000496282","full_name":"devsenweb/mcp-server-for-db","owner":"devsenweb","description":"A lightweight, extensible MCP server for executing schema-aware SQL queries. Built on FastMCP and compatible with any SQLAlchemy-supported database.","archived":false,"fork":false,"pushed_at":"2025-06-15T01:47:56.000Z","size":54,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-03T10:38:04.972Z","etag":null,"topics":["database","fastmcp","llm","mcp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devsenweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-11T22:01:48.000Z","updated_at":"2026-01-29T14:58:03.000Z","dependencies_parsed_at":"2025-06-11T23:37:58.033Z","dependency_job_id":"9602111a-128d-4ee8-af3c-f055310e5636","html_url":"https://github.com/devsenweb/mcp-server-for-db","commit_stats":null,"previous_names":["devsenweb/mcp-server-for-db"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devsenweb/mcp-server-for-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsenweb%2Fmcp-server-for-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsenweb%2Fmcp-server-for-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsenweb%2Fmcp-server-for-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsenweb%2Fmcp-server-for-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devsenweb","download_url":"https://codeload.github.com/devsenweb/mcp-server-for-db/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsenweb%2Fmcp-server-for-db/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32566444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","fastmcp","llm","mcp"],"created_at":"2025-06-18T16:03:15.959Z","updated_at":"2026-05-03T10:38:37.310Z","avatar_url":"https://github.com/devsenweb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 🗃️ MCP Server for Databases\n\n![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)\n![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)\n\nA lightweight implementation of the **Model Context Protocol (MCP)** for database operations. This server enables AI models to interact with SQL databases through a structured, tool-based interface, providing safe and efficient database access.\n\n---\n\n## 📚 Table of Contents\n\n- [🚀 Key Capabilities](#-key-capabilities)\n- [🔧 Getting Started](#-getting-started)\n- [🧠 MCP Interface](#-mcp-interface)\n- [🤖 MCP Client Integration](#-mcp-client-integration)\n- [🧩 LLM Integration](#-llm-integration)\n- [❗ Error Handling](#-error-handling)\n- [🛠️ IDE and Tool Integration](#-ide-and-tool-integration)\n- [⚙️ Development](#-development)\n- [🤝 Contributing](#-contributing)\n- [📄 License](#-license)\n- [⚙️ MCP Server Configuration Reference](#-mcp-server-configuration-reference)\n- [🙏 Acknowledgments](#-acknowledgments)\n\n---\n\n## 🚀 Key Capabilities\n\n### 🛠️ MCP Tool Integration\n- Exposes database operations as MCP tools for AI model interaction\n- Supports natural language prompts for database exploration\n- Provides schema-aware query building assistance\n\n### 💾 Database Support\n- Works with any SQLAlchemy-compatible database (SQLite, PostgreSQL, MySQL, etc.)\n- Automatic schema inspection and reflection\n- Transaction support for multi-statement operations\n\n### 📡 MCP Features\n- Native MCP tools, resources, and prompts\n- Support for multiple transport protocols (http, WebSocket, stdio)\n- Structured error handling and validation\n\n---\n\n## 🔧 Getting Started\n\n### ✅ Prerequisites\n- Python 3.8+\n- SQLite or any other SQLAlchemy-supported database\n\n### ⚙️ Installation\n\n```bash\ngit clone https://github.com/devsenweb/mcp-server-for-db.git\ncd mcp-server-for-db\npython -m venv .venv\nsource .venv/bin/activate  # macOS/Linux\n# OR\n.venv\\Scripts\\activate  # Windows\npip install -r requirements.txt\n```\n\n### 🛠️ Configuration\n\nEdit `config.yaml`:\n\n```yaml\ndb:\n  uri: sqlite:///./example.db  # Supports any SQLAlchemy URI\n```\n\n(Optional) Create a sample DB:\n\n```bash\npython create_database.py\n```\n\n### ▶️ Starting the MCP Server\n\n```bash\npython -m mcp_server.server --transport http --port 8080\n# or\npython -m mcp_server.server --transport ws --port 8080\n# or\npython -m mcp_server.server --transport stdio\n```\n\n---\n\n## 🧠 MCP Interface\n\n### 📌 Tool Definitions\n\n#### `execute_query`\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"method\": \"tools/execute_query\",\n  \"params\": {\n    \"sql\": \"SELECT * FROM users WHERE age \u003e 25\"\n  },\n  \"id\": 1\n}\n```\n\n#### `validate_sql`\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"method\": \"tools/validate_sql\",\n  \"params\": {\n    \"sql\": \"SELECT * FROM users\"\n  },\n  \"id\": 2\n}\n```\n\n---\n\n### 📁 Resource Endpoints\n\n#### `db://schema`\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"method\": \"resources/get\",\n  \"params\": {\n    \"uri\": \"db://schema\"\n  },\n  \"id\": 3\n}\n```\n\n#### `db://tables`\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"method\": \"resources/get\",\n  \"params\": {\n    \"uri\": \"db://tables\"\n  },\n  \"id\": 4\n}\n```\n\n## 🛠️ IDE and Tool Integration\n\n### (Cursor IDE) .cursor/mcp.json\n```json\n{\n  \"mcpServers\": {\n    \"database-query\": {\n      \"url\": \"http://localhost:8000/mcp\",\n      \"transport\": \"http\"\n    }\n  }\n}\n```\n\n### MCP Inspector\n```bash\nnpm install -g @modelcontextprotocol/inspector\nmcp-inspector --transport http --url http://localhost:8000/mcp\n# Visit http://localhost:3000\n```\n\n---\n\n## ⚙️ Development\n\n```bash\npip install -r requirements-dev.txt\npytest tests/\n```\n\n### 📁 Project Structure\n\n```\nmcp-server-for-db/\n├── mcp_server/\n│   ├── __init__.py\n│   ├── server.py\n│   └── db_adapter.py\n├── config.yaml\n├── create_database.py\n└── requirements.txt\n```\n\n---\n\n## 🤝 Contributing\n\nContributions are welcome! Feel free to submit a Pull Request.\n\n---\n\n## 📄 License\n\nLicensed under the MIT License. See [LICENSE](LICENSE) for details.\n\n---\n\n## ⚙️ MCP Server Configuration Reference\n\n```bash\npython -m mcp_server.server   --host 0.0.0.0   --port 8000   --transport http   --config ./config.yaml\n```\n\n---\n\n## 🙏 Acknowledgments\n\n- Powered by [SQLAlchemy](https://www.sqlalchemy.org/)\n- Based on the Model Context Protocol (MCP) standard\n\n## ⚠️ Disclaimer\n\nThis project is a **demo implementation** of an MCP-compatible server for database interaction. It does **not include SQL safety mechanisms**, input sanitization, authentication, or permission controls.\n\n\u003e ⚠️ **Use at your own risk.** This server executes raw SQL and is intended for experimentation, prototyping, and local development only.  \n\u003e  \n\u003e It is the responsibility of the user to implement proper **guardrails**, **validation**, and **security measures** before using this in any production or sensitive environment.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevsenweb%2Fmcp-server-for-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevsenweb%2Fmcp-server-for-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevsenweb%2Fmcp-server-for-db/lists"}