mcp-db-server 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2}/PKG-INFO +7 -5
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2}/README.md +5 -3
- mcp_db_server-0.1.2/mcp_db/__init__.py +69 -0
- mcp_db_server-0.1.2/mcp_db/__main__.py +4 -0
- mcp_db_server-0.1.2/mcp_db/db/__init__.py +0 -0
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2}/mcp_db_server.egg-info/PKG-INFO +7 -5
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2}/mcp_db_server.egg-info/SOURCES.txt +6 -3
- mcp_db_server-0.1.2/mcp_db_server.egg-info/entry_points.txt +2 -0
- mcp_db_server-0.1.2/mcp_db_server.egg-info/top_level.txt +1 -0
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2}/pyproject.toml +3 -3
- mcp_db_server-0.1.0/mcp_db_server.egg-info/entry_points.txt +0 -2
- mcp_db_server-0.1.0/mcp_db_server.egg-info/top_level.txt +0 -1
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2/mcp_db}/db/mysql_repository.py +0 -0
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2/mcp_db}/db/repository.py +0 -0
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2/mcp_db}/db/sqlite_repository.py +0 -0
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2}/mcp_db_server.egg-info/dependency_links.txt +0 -0
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2}/mcp_db_server.egg-info/requires.txt +0 -0
- {mcp_db_server-0.1.0 → mcp_db_server-0.1.2}/setup.cfg +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcp-db-server
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: MCP Database Server with read-only access
|
|
5
|
-
Author-email:
|
|
5
|
+
Author-email: Suphachai Phetthamrong <suphachaiphetthamrong@gmail.com>
|
|
6
6
|
License: MIT
|
|
7
7
|
Requires-Python: >=3.10
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
@@ -26,10 +26,12 @@ A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server implem
|
|
|
26
26
|
|
|
27
27
|
## Project Structure
|
|
28
28
|
|
|
29
|
-
- `
|
|
30
|
-
- `
|
|
31
|
-
- `
|
|
29
|
+
- `mcp_db/`: Main Python package for the MCP server.
|
|
30
|
+
- `__init__.py`: Entry point and server initialization.
|
|
31
|
+
- `db/`: Repository implementations (`sqlite_repository.py`, `mysql_repository.py`).
|
|
32
|
+
- `seed.py`: Utility script to populate the database (write access).
|
|
32
33
|
- `Makefile`: Automation for common tasks.
|
|
34
|
+
- `pyproject.toml`: Package configuration and dependencies.
|
|
33
35
|
|
|
34
36
|
## Quick Start
|
|
35
37
|
|
|
@@ -12,10 +12,12 @@ A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server implem
|
|
|
12
12
|
|
|
13
13
|
## Project Structure
|
|
14
14
|
|
|
15
|
-
- `
|
|
16
|
-
- `
|
|
17
|
-
- `
|
|
15
|
+
- `mcp_db/`: Main Python package for the MCP server.
|
|
16
|
+
- `__init__.py`: Entry point and server initialization.
|
|
17
|
+
- `db/`: Repository implementations (`sqlite_repository.py`, `mysql_repository.py`).
|
|
18
|
+
- `seed.py`: Utility script to populate the database (write access).
|
|
18
19
|
- `Makefile`: Automation for common tasks.
|
|
20
|
+
- `pyproject.toml`: Package configuration and dependencies.
|
|
19
21
|
|
|
20
22
|
## Quick Start
|
|
21
23
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from mcp.server.fastmcp import FastMCP
|
|
2
|
+
from .db.repository import DatabaseRepository
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
def create_server(repository: DatabaseRepository) -> FastMCP:
|
|
6
|
+
mcp = FastMCP("db-server")
|
|
7
|
+
|
|
8
|
+
@mcp.tool()
|
|
9
|
+
def list_tables() -> str:
|
|
10
|
+
"""List all tables in the database."""
|
|
11
|
+
tables = repository.list_tables()
|
|
12
|
+
if not tables:
|
|
13
|
+
return "No tables found or error occurred."
|
|
14
|
+
return "Tables: " + ", ".join(tables)
|
|
15
|
+
|
|
16
|
+
@mcp.tool()
|
|
17
|
+
def describe_table(table_name: str) -> str:
|
|
18
|
+
"""Get the schema information for a specific table."""
|
|
19
|
+
return repository.describe_table(table_name)
|
|
20
|
+
|
|
21
|
+
@mcp.tool()
|
|
22
|
+
def read_query(query: str) -> str:
|
|
23
|
+
"""
|
|
24
|
+
Execute a read-only SQL query (SELECT).
|
|
25
|
+
Strictly forbids INSERT, UPDATE, DELETE, DROP, ALTER, etc.
|
|
26
|
+
"""
|
|
27
|
+
return repository.read_query(query)
|
|
28
|
+
|
|
29
|
+
return mcp
|
|
30
|
+
|
|
31
|
+
def main():
|
|
32
|
+
from dotenv import load_dotenv
|
|
33
|
+
from .db.sqlite_repository import SqliteRepository
|
|
34
|
+
from .db.mysql_repository import MysqlRepository
|
|
35
|
+
|
|
36
|
+
load_dotenv()
|
|
37
|
+
|
|
38
|
+
# Read config
|
|
39
|
+
db_engine = os.getenv("DB_ENGINE", "sqlite")
|
|
40
|
+
db_address = os.getenv("DB_ADDRESS", "test.db")
|
|
41
|
+
db_port = int(os.getenv("DB_PORT", 3306))
|
|
42
|
+
|
|
43
|
+
# Credentials (unused for SQLite)
|
|
44
|
+
db_user = os.getenv("DB_USER")
|
|
45
|
+
db_password = os.getenv("DB_PASSWORD")
|
|
46
|
+
db_schema = os.getenv("DB_SCHEMA")
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
repo = None
|
|
50
|
+
if db_engine.lower() == "sqlite":
|
|
51
|
+
repo = SqliteRepository(db_address)
|
|
52
|
+
elif db_engine.lower() == "mysql":
|
|
53
|
+
repo = MysqlRepository(
|
|
54
|
+
host=db_address,
|
|
55
|
+
user=db_user,
|
|
56
|
+
password=db_password,
|
|
57
|
+
database=db_schema,
|
|
58
|
+
port=db_port
|
|
59
|
+
)
|
|
60
|
+
else:
|
|
61
|
+
raise ValueError(f"Unsupported DB_ENGINE: {db_engine}")
|
|
62
|
+
|
|
63
|
+
mcp = create_server(repo)
|
|
64
|
+
mcp.run()
|
|
65
|
+
except Exception as e:
|
|
66
|
+
print(f"Error starting server: {e}")
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
main()
|
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcp-db-server
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: MCP Database Server with read-only access
|
|
5
|
-
Author-email:
|
|
5
|
+
Author-email: Suphachai Phetthamrong <suphachaiphetthamrong@gmail.com>
|
|
6
6
|
License: MIT
|
|
7
7
|
Requires-Python: >=3.10
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
@@ -26,10 +26,12 @@ A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server implem
|
|
|
26
26
|
|
|
27
27
|
## Project Structure
|
|
28
28
|
|
|
29
|
-
- `
|
|
30
|
-
- `
|
|
31
|
-
- `
|
|
29
|
+
- `mcp_db/`: Main Python package for the MCP server.
|
|
30
|
+
- `__init__.py`: Entry point and server initialization.
|
|
31
|
+
- `db/`: Repository implementations (`sqlite_repository.py`, `mysql_repository.py`).
|
|
32
|
+
- `seed.py`: Utility script to populate the database (write access).
|
|
32
33
|
- `Makefile`: Automation for common tasks.
|
|
34
|
+
- `pyproject.toml`: Package configuration and dependencies.
|
|
33
35
|
|
|
34
36
|
## Quick Start
|
|
35
37
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
README.md
|
|
2
2
|
pyproject.toml
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
db/
|
|
3
|
+
mcp_db/__init__.py
|
|
4
|
+
mcp_db/__main__.py
|
|
5
|
+
mcp_db/db/__init__.py
|
|
6
|
+
mcp_db/db/mysql_repository.py
|
|
7
|
+
mcp_db/db/repository.py
|
|
8
|
+
mcp_db/db/sqlite_repository.py
|
|
6
9
|
mcp_db_server.egg-info/PKG-INFO
|
|
7
10
|
mcp_db_server.egg-info/SOURCES.txt
|
|
8
11
|
mcp_db_server.egg-info/dependency_links.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mcp_db
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mcp-db-server"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "MCP Database Server with read-only access"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = {text = "MIT"}
|
|
12
12
|
authors = [
|
|
13
|
-
{name = "
|
|
13
|
+
{name = "Suphachai Phetthamrong", email = "suphachaiphetthamrong@gmail.com"}
|
|
14
14
|
]
|
|
15
15
|
dependencies = [
|
|
16
16
|
"mcp",
|
|
@@ -21,4 +21,4 @@ dependencies = [
|
|
|
21
21
|
]
|
|
22
22
|
|
|
23
23
|
[project.scripts]
|
|
24
|
-
mcp-db-server = "
|
|
24
|
+
mcp-db-server = "mcp_db:main"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
db
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|