mcp-db-server 0.1.0__tar.gz → 0.1.3__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.
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp-db-server
3
- Version: 0.1.0
3
+ Version: 0.1.3
4
4
  Summary: MCP Database Server with read-only access
5
- Author-email: User <user@example.com>
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
- - `server.py`: Main entry point for the MCP server.
30
- - `db/`: Contains the Repository interface and implementations (`sqlite_repository.py`, `mysql_repository.py`).
31
- - `seed.py`: Utility script to populate the database (since the server itself is read-only).
29
+ - `mcp_db_server/`: 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
- - `server.py`: Main entry point for the MCP server.
16
- - `db/`: Contains the Repository interface and implementations (`sqlite_repository.py`, `mysql_repository.py`).
17
- - `seed.py`: Utility script to populate the database (since the server itself is read-only).
15
+ - `mcp_db_server/`: 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()
@@ -0,0 +1,4 @@
1
+ from . import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
File without changes
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp-db-server
3
- Version: 0.1.0
3
+ Version: 0.1.3
4
4
  Summary: MCP Database Server with read-only access
5
- Author-email: User <user@example.com>
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
- - `server.py`: Main entry point for the MCP server.
30
- - `db/`: Contains the Repository interface and implementations (`sqlite_repository.py`, `mysql_repository.py`).
31
- - `seed.py`: Utility script to populate the database (since the server itself is read-only).
29
+ - `mcp_db_server/`: 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
 
@@ -0,0 +1,14 @@
1
+ README.md
2
+ pyproject.toml
3
+ mcp_db_server/__init__.py
4
+ mcp_db_server/__main__.py
5
+ mcp_db_server.egg-info/PKG-INFO
6
+ mcp_db_server.egg-info/SOURCES.txt
7
+ mcp_db_server.egg-info/dependency_links.txt
8
+ mcp_db_server.egg-info/entry_points.txt
9
+ mcp_db_server.egg-info/requires.txt
10
+ mcp_db_server.egg-info/top_level.txt
11
+ mcp_db_server/db/__init__.py
12
+ mcp_db_server/db/mysql_repository.py
13
+ mcp_db_server/db/repository.py
14
+ mcp_db_server/db/sqlite_repository.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mcp-db-server = mcp_db_server:main
@@ -0,0 +1 @@
1
+ mcp_db_server
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "mcp-db-server"
7
- version = "0.1.0"
7
+ version = "0.1.3"
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 = "User", email = "user@example.com"}
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 = "server:main" # Assuming we refactor server.py to have a main() function exposed
24
+ mcp-db-server = "mcp_db_server:main"
@@ -1,11 +0,0 @@
1
- README.md
2
- pyproject.toml
3
- db/mysql_repository.py
4
- db/repository.py
5
- db/sqlite_repository.py
6
- mcp_db_server.egg-info/PKG-INFO
7
- mcp_db_server.egg-info/SOURCES.txt
8
- mcp_db_server.egg-info/dependency_links.txt
9
- mcp_db_server.egg-info/entry_points.txt
10
- mcp_db_server.egg-info/requires.txt
11
- mcp_db_server.egg-info/top_level.txt
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- mcp-db-server = server:main
File without changes