fastmcp-tools-database 0.1.0__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.
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastmcp-tools-database
3
+ Version: 0.1.0
4
+ Summary: Database tools for fastmcp-server
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.11
7
+ Provides-Extra: postgres
8
+ Requires-Dist: psycopg2-binary>=2.9; extra == "postgres"
9
+ Provides-Extra: mysql
10
+ Requires-Dist: pymysql>=1.1; extra == "mysql"
11
+ Provides-Extra: all
12
+ Requires-Dist: psycopg2-binary>=2.9; extra == "all"
13
+ Requires-Dist: pymysql>=1.1; extra == "all"
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "fastmcp-tools-database"
7
+ version = "0.1.0"
8
+ description = "Database tools for fastmcp-server"
9
+ license = "MIT"
10
+ requires-python = ">=3.11"
11
+ dependencies = []
12
+
13
+ [project.optional-dependencies]
14
+ postgres = ["psycopg2-binary>=2.9"]
15
+ mysql = ["pymysql>=1.1"]
16
+ all = ["psycopg2-binary>=2.9", "pymysql>=1.1"]
17
+
18
+ [project.entry-points."fastmcp_tools"]
19
+ database = "fastmcp_tools_database"
20
+
21
+ [tool.setuptools.packages.find]
22
+ where = ["src"]
23
+ include = ["fastmcp_tools_database*"]
24
+
25
+
26
+ [tool.setuptools.package-data]
27
+ "fastmcp_tools_database" = ["*.py"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ """FastMCP Tools — Database collection."""
2
+
3
+ from pathlib import Path
4
+
5
+ TOOLS_DIR = Path(__file__).parent
@@ -0,0 +1,63 @@
1
+ """Execute read-only queries on MySQL.
2
+
3
+ Requires: pymysql
4
+ """
5
+
6
+ __tags__ = ["database", "read"]
7
+ __timeout__ = 30.0
8
+ __rate_limit__ = "30/min"
9
+
10
+
11
+ def query_mysql(
12
+ query: str,
13
+ host: str = "",
14
+ port: int = 3306,
15
+ user: str = "",
16
+ password: str = "",
17
+ database: str = "",
18
+ ) -> str:
19
+ """Execute a read-only SQL query on MySQL.
20
+
21
+ Falls back to MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD,
22
+ MYSQL_DATABASE env vars if parameters are empty.
23
+ Only SELECT queries are allowed.
24
+ """
25
+ import os
26
+
27
+ host = host or os.environ.get("MYSQL_HOST", "localhost")
28
+ port = port or int(os.environ.get("MYSQL_PORT", "3306"))
29
+ user = user or os.environ.get("MYSQL_USER", "root")
30
+ password = password or os.environ.get("MYSQL_PASSWORD", "")
31
+ database = database or os.environ.get("MYSQL_DATABASE", "")
32
+
33
+ query_upper = query.strip().upper()
34
+ if not query_upper.startswith("SELECT") and not query_upper.startswith("WITH"):
35
+ return "Error: Only SELECT/WITH queries are allowed"
36
+
37
+ import pymysql
38
+
39
+ conn = pymysql.connect(
40
+ host=host,
41
+ port=port,
42
+ user=user,
43
+ password=password,
44
+ database=database,
45
+ read_timeout=15,
46
+ )
47
+ try:
48
+ with conn.cursor() as cur:
49
+ cur.execute(query)
50
+ columns = [desc[0] for desc in cur.description] if cur.description else []
51
+ rows = cur.fetchall()
52
+
53
+ lines = [" | ".join(columns)]
54
+ lines.append("-" * len(lines[0]))
55
+ for row in rows[:100]:
56
+ lines.append(" | ".join(str(v) for v in row))
57
+
58
+ if len(rows) > 100:
59
+ lines.append(f"... ({len(rows)} total rows, showing first 100)")
60
+
61
+ return "\n".join(lines)
62
+ finally:
63
+ conn.close()
@@ -0,0 +1,51 @@
1
+ """Execute read-only queries on PostgreSQL.
2
+
3
+ Requires: psycopg2-binary
4
+ """
5
+
6
+ __tags__ = ["database", "read"]
7
+ __timeout__ = 30.0
8
+ __rate_limit__ = "30/min"
9
+
10
+
11
+ def query_postgres(
12
+ query: str,
13
+ connection_string: str = "",
14
+ ) -> str:
15
+ """Execute a read-only SQL query on PostgreSQL.
16
+
17
+ Connection string format: postgresql://user:pass@host:5432/dbname
18
+ Falls back to DATABASE_URL env var if connection_string is empty.
19
+ Only SELECT queries are allowed.
20
+ """
21
+ import os
22
+
23
+ conn_str = connection_string or os.environ.get("DATABASE_URL", "")
24
+ if not conn_str:
25
+ return "Error: No connection string provided and DATABASE_URL not set"
26
+
27
+ query_upper = query.strip().upper()
28
+ if not query_upper.startswith("SELECT") and not query_upper.startswith("WITH"):
29
+ return "Error: Only SELECT/WITH queries are allowed"
30
+
31
+ import psycopg2
32
+
33
+ conn = psycopg2.connect(conn_str)
34
+ try:
35
+ conn.set_session(readonly=True, autocommit=True)
36
+ with conn.cursor() as cur:
37
+ cur.execute(query)
38
+ columns = [desc[0] for desc in cur.description] if cur.description else []
39
+ rows = cur.fetchall()
40
+
41
+ lines = [" | ".join(columns)]
42
+ lines.append("-" * len(lines[0]))
43
+ for row in rows[:100]:
44
+ lines.append(" | ".join(str(v) for v in row))
45
+
46
+ if len(rows) > 100:
47
+ lines.append(f"... ({len(rows)} total rows, showing first 100)")
48
+
49
+ return "\n".join(lines)
50
+ finally:
51
+ conn.close()
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastmcp-tools-database
3
+ Version: 0.1.0
4
+ Summary: Database tools for fastmcp-server
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.11
7
+ Provides-Extra: postgres
8
+ Requires-Dist: psycopg2-binary>=2.9; extra == "postgres"
9
+ Provides-Extra: mysql
10
+ Requires-Dist: pymysql>=1.1; extra == "mysql"
11
+ Provides-Extra: all
12
+ Requires-Dist: psycopg2-binary>=2.9; extra == "all"
13
+ Requires-Dist: pymysql>=1.1; extra == "all"
@@ -0,0 +1,10 @@
1
+ pyproject.toml
2
+ src/fastmcp_tools_database/__init__.py
3
+ src/fastmcp_tools_database/query_mysql.py
4
+ src/fastmcp_tools_database/query_postgres.py
5
+ src/fastmcp_tools_database.egg-info/PKG-INFO
6
+ src/fastmcp_tools_database.egg-info/SOURCES.txt
7
+ src/fastmcp_tools_database.egg-info/dependency_links.txt
8
+ src/fastmcp_tools_database.egg-info/entry_points.txt
9
+ src/fastmcp_tools_database.egg-info/requires.txt
10
+ src/fastmcp_tools_database.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [fastmcp_tools]
2
+ database = fastmcp_tools_database
@@ -0,0 +1,10 @@
1
+
2
+ [all]
3
+ psycopg2-binary>=2.9
4
+ pymysql>=1.1
5
+
6
+ [mysql]
7
+ pymysql>=1.1
8
+
9
+ [postgres]
10
+ psycopg2-binary>=2.9