mcp-win-stdio-db 0.2.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.
@@ -0,0 +1,60 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ .Python
6
+ build/
7
+ develop-eggs/
8
+ dist/
9
+ downloads/
10
+ eggs/
11
+ .eggs/
12
+ lib/
13
+ lib64/
14
+ parts/
15
+ sdist/
16
+ var/
17
+ wheels/
18
+ share/python-wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+ MANIFEST
23
+
24
+ *.manifest
25
+ *.spec
26
+ api.txt
27
+ pip-log.txt
28
+ pip-delete-this-directory.txt
29
+ pypi api.txt
30
+ htmlcov/
31
+ .tox/
32
+ .nox/
33
+ .coverage
34
+ .coverage.*
35
+ .cache
36
+ nosetests.xml
37
+ coverage.xml
38
+ *.cover
39
+ *.py,cover
40
+ .hypothesis/
41
+ .pytest_cache/
42
+ cover/
43
+
44
+ *.mo
45
+ *.pot
46
+
47
+ .env
48
+ .venv
49
+ env/
50
+ venv/
51
+ ENV/
52
+ env.bak/
53
+ venv.bak/
54
+
55
+ .idea/
56
+ .vscode/
57
+ *.swp
58
+ *.swo
59
+
60
+ *.log
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.5
2
+ Name: mcp-win-stdio-db
3
+ Version: 0.2.3
4
+ Summary: Unified Database Model Context Protocol (MCP) server for PostgreSQL & MySQL: 20 tools for multi-server querying, DBA operations (create, drop, clone, dump, terminate), and cross-schema auto-resolution.
5
+ Author: Mohan Kumar Indala
6
+ License-Expression: MIT
7
+ Keywords: ai,claude,database,dba,llm,mariadb,mcp,mysql,postgres,postgresql
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Environment :: Win32 (MS Windows)
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Database
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: mcp-win-stdio>=0.2.3
22
+ Requires-Dist: mcp>=1.2.0
23
+ Requires-Dist: psycopg2-binary>=2.9.0
24
+ Requires-Dist: pymysql>=1.1.0
25
+ Description-Content-Type: text/markdown
26
+
27
+ # mcp-win-stdio-db
28
+
29
+ Unified Database Model Context Protocol (MCP) server for **PostgreSQL** and **MySQL** with multi-server in-memory pooling, sibling database auto-derivation, cross-schema resolution, and complete DBA operations.
30
+
31
+ Part of the **`mcp-win-stdio`** Windows-optimized suite.
32
+
33
+ ---
34
+
35
+ ## 🚀 Features (20 Tools)
36
+
37
+ - **Polyglot Database Engine**: Handles PostgreSQL (`psycopg2`) and MySQL (`pymysql`) transparently side-by-side.
38
+ - **In-Memory Connection Pooling**: Fast continuous queries with zero reconnection latency and persistent `use_database` sticky state.
39
+ - **Detailed Diagnostic Error Reporting**: Forwards native PostgreSQL error codes (e.g. 23503 FK violation), offending constraint names, column names, and error details directly to Claude so issues can be diagnosed immediately.
40
+ - **Sibling Database Auto-Derivation**: On PostgreSQL (`localhost:5432`), auto-discovers sibling databases (`showreel`, `dsr`, `location_booking`, `sap`, etc.) on the fly.
41
+ - **DBA & Management Tools**: `create_database`, `drop_database` (with safety guard), `clone_database` (instant template clone), `terminate_connections`, `list_active_queries`, `dump_database`, and `restore_database`.
42
+ - **Self-Contained `SERVERS` JSON**: Configure multiple database instances in one environment variable without external files.
43
+
44
+ ---
45
+
46
+ ## 🛠️ Included Tools (20 Tools)
47
+
48
+ 1. `list_connections`: Lists all active and configured database connections.
49
+ 2. `use_database`: Switches active connection or switches database on current server.
50
+ 3. `list_databases`: Lists all databases on the active server.
51
+ 4. `list_schemas`: Lists all schemas in the active PostgreSQL database.
52
+ 5. `describe_table`: Detailed schema inspection (columns, nullability, PKs, FKs, indexes). Auto-resolves cross-schema tables in PostgreSQL.
53
+ 6. `schema_overview`: Compact overview of all user tables and views.
54
+ 7. `get_table_sample`: Returns sample rows and estimated row count.
55
+ 8. `search_schema`: Case-insensitive regex search for table, view, or column names.
56
+ 9. `read_query`: Safe SELECT queries returning structured JSON with row counts.
57
+ 10. `execute_query`: Executes DML / DDL statements with transaction commit/rollback and detailed error forwarding.
58
+ 11. `explain_query`: Generates EXPLAIN query execution plan.
59
+ 12. `get_database_stats`: Table sizes, row estimates, index sizes, and total database size.
60
+ 13. `add_connection`: Dynamically adds a new PostgreSQL or MySQL connection string at runtime.
61
+ 14. `create_database`: Creates a new database on the active server.
62
+ 15. `drop_database`: Safety-guarded DROP DATABASE (requires `confirmName` matching target name).
63
+ 16. `clone_database`: Fast database cloning using PostgreSQL TEMPLATE mechanism.
64
+ 17. `terminate_connections`: Terminates active connections to a specific database (PostgreSQL only).
65
+ 18. `list_active_queries`: Lists running queries, connection duration, and process IDs.
66
+ 19. `dump_database`: Dumps database to SQL file using native `pg_dump` or `mysqldump`.
67
+ 20. `restore_database`: Restores database from SQL dump file using native `psql` or `mysql`.
68
+
69
+ ---
70
+
71
+ ## 📦 Installation
72
+
73
+ ```powershell
74
+ pip install mcp-win-stdio-db
75
+ ```
76
+ *(Installing this package automatically installs `mws` CLI orchestrator)*.
77
+
78
+ ---
79
+
80
+ ## 🚀 One-Command Claude Setup
81
+
82
+ ```powershell
83
+ mws setup db
84
+ # or:
85
+ mws add db
86
+ ```
87
+
88
+ ### Manual Configuration Example
89
+ In `%APPDATA%\Claude\claude_desktop_config.json`:
90
+ ```json
91
+ {
92
+ "mcpServers": {
93
+ "db": {
94
+ "command": "python",
95
+ "args": ["-m", "mcp_win_stdio.db"],
96
+ "env": {
97
+ "SERVERS": "{\"postgres\":\"postgresql://postgres:password@localhost:5432/mydb\",\"mysql\":\"mysql://user:pass@localhost:3306/mydb\"}"
98
+ }
99
+ }
100
+ }
101
+ }
102
+ ```
103
+
104
+ ---
105
+
106
+ ## 📖 CLI Commands & Interactive Guide
107
+
108
+ ```powershell
109
+ mws db guide # Complete tool reference & prompt recipes
110
+ mws db doctor # Verify PostgreSQL/MySQL adapters and native dump tools
111
+ mws db setup # Configure Claude Desktop / Claude Code
112
+ mws db run # Launch server over stdio
113
+ ```
114
+
115
+ ---
116
+
117
+ ## 📜 License
118
+ MIT License. Copyright (c) 2026 Mohan Kumar Indala.
@@ -0,0 +1,92 @@
1
+ # mcp-win-stdio-db
2
+
3
+ Unified Database Model Context Protocol (MCP) server for **PostgreSQL** and **MySQL** with multi-server in-memory pooling, sibling database auto-derivation, cross-schema resolution, and complete DBA operations.
4
+
5
+ Part of the **`mcp-win-stdio`** Windows-optimized suite.
6
+
7
+ ---
8
+
9
+ ## 🚀 Features (20 Tools)
10
+
11
+ - **Polyglot Database Engine**: Handles PostgreSQL (`psycopg2`) and MySQL (`pymysql`) transparently side-by-side.
12
+ - **In-Memory Connection Pooling**: Fast continuous queries with zero reconnection latency and persistent `use_database` sticky state.
13
+ - **Detailed Diagnostic Error Reporting**: Forwards native PostgreSQL error codes (e.g. 23503 FK violation), offending constraint names, column names, and error details directly to Claude so issues can be diagnosed immediately.
14
+ - **Sibling Database Auto-Derivation**: On PostgreSQL (`localhost:5432`), auto-discovers sibling databases (`showreel`, `dsr`, `location_booking`, `sap`, etc.) on the fly.
15
+ - **DBA & Management Tools**: `create_database`, `drop_database` (with safety guard), `clone_database` (instant template clone), `terminate_connections`, `list_active_queries`, `dump_database`, and `restore_database`.
16
+ - **Self-Contained `SERVERS` JSON**: Configure multiple database instances in one environment variable without external files.
17
+
18
+ ---
19
+
20
+ ## 🛠️ Included Tools (20 Tools)
21
+
22
+ 1. `list_connections`: Lists all active and configured database connections.
23
+ 2. `use_database`: Switches active connection or switches database on current server.
24
+ 3. `list_databases`: Lists all databases on the active server.
25
+ 4. `list_schemas`: Lists all schemas in the active PostgreSQL database.
26
+ 5. `describe_table`: Detailed schema inspection (columns, nullability, PKs, FKs, indexes). Auto-resolves cross-schema tables in PostgreSQL.
27
+ 6. `schema_overview`: Compact overview of all user tables and views.
28
+ 7. `get_table_sample`: Returns sample rows and estimated row count.
29
+ 8. `search_schema`: Case-insensitive regex search for table, view, or column names.
30
+ 9. `read_query`: Safe SELECT queries returning structured JSON with row counts.
31
+ 10. `execute_query`: Executes DML / DDL statements with transaction commit/rollback and detailed error forwarding.
32
+ 11. `explain_query`: Generates EXPLAIN query execution plan.
33
+ 12. `get_database_stats`: Table sizes, row estimates, index sizes, and total database size.
34
+ 13. `add_connection`: Dynamically adds a new PostgreSQL or MySQL connection string at runtime.
35
+ 14. `create_database`: Creates a new database on the active server.
36
+ 15. `drop_database`: Safety-guarded DROP DATABASE (requires `confirmName` matching target name).
37
+ 16. `clone_database`: Fast database cloning using PostgreSQL TEMPLATE mechanism.
38
+ 17. `terminate_connections`: Terminates active connections to a specific database (PostgreSQL only).
39
+ 18. `list_active_queries`: Lists running queries, connection duration, and process IDs.
40
+ 19. `dump_database`: Dumps database to SQL file using native `pg_dump` or `mysqldump`.
41
+ 20. `restore_database`: Restores database from SQL dump file using native `psql` or `mysql`.
42
+
43
+ ---
44
+
45
+ ## 📦 Installation
46
+
47
+ ```powershell
48
+ pip install mcp-win-stdio-db
49
+ ```
50
+ *(Installing this package automatically installs `mws` CLI orchestrator)*.
51
+
52
+ ---
53
+
54
+ ## 🚀 One-Command Claude Setup
55
+
56
+ ```powershell
57
+ mws setup db
58
+ # or:
59
+ mws add db
60
+ ```
61
+
62
+ ### Manual Configuration Example
63
+ In `%APPDATA%\Claude\claude_desktop_config.json`:
64
+ ```json
65
+ {
66
+ "mcpServers": {
67
+ "db": {
68
+ "command": "python",
69
+ "args": ["-m", "mcp_win_stdio.db"],
70
+ "env": {
71
+ "SERVERS": "{\"postgres\":\"postgresql://postgres:password@localhost:5432/mydb\",\"mysql\":\"mysql://user:pass@localhost:3306/mydb\"}"
72
+ }
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ ---
79
+
80
+ ## 📖 CLI Commands & Interactive Guide
81
+
82
+ ```powershell
83
+ mws db guide # Complete tool reference & prompt recipes
84
+ mws db doctor # Verify PostgreSQL/MySQL adapters and native dump tools
85
+ mws db setup # Configure Claude Desktop / Claude Code
86
+ mws db run # Launch server over stdio
87
+ ```
88
+
89
+ ---
90
+
91
+ ## 📜 License
92
+ MIT License. Copyright (c) 2026 Mohan Kumar Indala.
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "mcp-win-stdio-db"
7
+ version = "0.2.3"
8
+ description = "Unified Database Model Context Protocol (MCP) server for PostgreSQL & MySQL: 20 tools for multi-server querying, DBA operations (create, drop, clone, dump, terminate), and cross-schema auto-resolution."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "Mohan Kumar Indala" }
14
+ ]
15
+ keywords = ["mcp", "claude", "database", "postgres", "postgresql", "mysql", "mariadb", "dba", "ai", "llm"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Environment :: Win32 (MS Windows)",
19
+ "Intended Audience :: Developers",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: Microsoft :: Windows",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Topic :: Database",
29
+ ]
30
+
31
+ dependencies = [
32
+ "mcp-win-stdio>=0.2.3",
33
+ "mcp>=1.2.0",
34
+ "psycopg2-binary>=2.9.0",
35
+ "pymysql>=1.1.0",
36
+ ]
37
+
38
+ [project.scripts]
39
+ mcp-win-stdio-db = "mcp_win_stdio.db.cli:main"
40
+ mws-db = "mcp_win_stdio.db.cli:main"
41
+
42
+ [tool.hatch.build.targets.wheel]
43
+ packages = ["src/mcp_win_stdio"]
@@ -0,0 +1,5 @@
1
+ """
2
+ Unified Database MCP Server for mcp-win-stdio (PostgreSQL & MySQL).
3
+ """
4
+
5
+ __version__ = "0.2.3"
@@ -0,0 +1,8 @@
1
+ """
2
+ Direct module execution for mcp_win_stdio.db.
3
+ """
4
+
5
+ from mcp_win_stdio.db.server import mcp
6
+
7
+ if __name__ == "__main__":
8
+ mcp.run()
@@ -0,0 +1,87 @@
1
+ """
2
+ CLI entry point for mcp-win-stdio-db.
3
+ """
4
+
5
+ import argparse
6
+ import sys
7
+ from mcp_win_stdio.db import __version__
8
+ from mcp_win_stdio.db.server import mcp
9
+
10
+
11
+ def cmd_run(args: argparse.Namespace) -> None:
12
+ """Run Database MCP server over stdio."""
13
+ mcp.run()
14
+
15
+
16
+ def cmd_doctor(args: argparse.Namespace) -> None:
17
+ """Check Database MCP health and dependencies."""
18
+ print(f"\n=== mcp-win-stdio-db Doctor Diagnostic (v{__version__}) ===\n")
19
+ print(f"[OK] Python: {sys.version.split()[0]} ({sys.executable})")
20
+
21
+ for dep in ("mcp", "psycopg2", "pymysql"):
22
+ try:
23
+ __import__(dep)
24
+ print(f"[OK] Driver: {dep:<12}")
25
+ except ImportError:
26
+ print(f"[FAIL] Driver: {dep:<12} (MISSING - run `pip install {dep}`)")
27
+
28
+ print("\n--- Native DB Dump Utilities ---")
29
+ import shutil
30
+ for util in ("pg_dump", "psql", "mysqldump", "mysql"):
31
+ loc = shutil.which(util)
32
+ if loc:
33
+ print(f"[OK] Tool: {util:<12} -> {loc}")
34
+ else:
35
+ print(f"[INFO] Tool: {util:<12} -> (Not on PATH, fallback SQL execution used)")
36
+
37
+ print("\nDiagnostic complete.\n")
38
+
39
+
40
+ def cmd_guide(args: argparse.Namespace) -> None:
41
+ """Print guide and prompt recipes."""
42
+ print("""
43
+ === mcp-win-stdio-db Guide & Recipes ===
44
+
45
+ Tools Provided:
46
+ - list_connections, use_database, list_databases, list_schemas
47
+ - describe_table, schema_overview, get_table_sample, search_schema
48
+ - read_query, execute_query, explain_query, get_database_stats
49
+ - create_database, drop_database, clone_database, terminate_connections
50
+ - list_active_queries, dump_database, restore_database
51
+
52
+ Configuration:
53
+ Pass SERVERS env var as JSON:
54
+ SERVERS='{"showreel":"postgresql://...","dsr":"postgresql://...","ijitest":"mysql://..."}'
55
+
56
+ Run in Claude / Copilot:
57
+ python -m mcp_win_stdio.db.server
58
+ """)
59
+
60
+
61
+ def main() -> None:
62
+ parser = argparse.ArgumentParser(
63
+ prog="mcp-win-stdio-db",
64
+ description="Unified Database MCP Server CLI (PostgreSQL & MySQL)",
65
+ )
66
+ parser.add_argument("--version", "-v", action="version", version=f"%(prog)s {__version__}")
67
+ subparsers = parser.add_subparsers(dest="command", help="Command to execute")
68
+
69
+ sub_guide = subparsers.add_parser("guide", help="View usage guide and recipes")
70
+ sub_guide.set_defaults(func=cmd_guide)
71
+
72
+ sub_doctor = subparsers.add_parser("doctor", help="Check database drivers and native tools")
73
+ sub_doctor.set_defaults(func=cmd_doctor)
74
+
75
+ sub_run = subparsers.add_parser("run", help="Run Database MCP server over stdio")
76
+ sub_run.set_defaults(func=cmd_run)
77
+
78
+ args = parser.parse_args()
79
+ if hasattr(args, "func"):
80
+ args.func(args)
81
+ else:
82
+ # Default action is run
83
+ cmd_run(args)
84
+
85
+
86
+ if __name__ == "__main__":
87
+ main()
@@ -0,0 +1,165 @@
1
+ """
2
+ Usage guide and prompt recipes for Database MCP server (mcp-win-stdio.db).
3
+ """
4
+
5
+ def print_db_guide() -> None:
6
+ guide_text = """
7
+ ================================================================================
8
+ Polyglot Database MCP Server (mcp-win-stdio.db)
9
+ ================================================================================
10
+
11
+ Description:
12
+ Unified Model Context Protocol server for PostgreSQL and MySQL databases.
13
+ Supports cross-database switching, cross-schema auto-resolution, fast JSON queries,
14
+ DBA administrative tools (safe DROP, CREATE, CLONE), native DUMP / RESTORE,
15
+ DDL reconstruction, PII-safe sampling, database-wide health auditing, and
16
+ schema diff with auto-generated migration SQL.
17
+
18
+ Available Tools (23 Tools):
19
+ --------------------------------------------------------------------------------
20
+ CONNECTION MANAGEMENT
21
+ 1. list_connections
22
+ - Lists all active and configured database connections from SERVERS env.
23
+
24
+ 2. use_database
25
+ - Switches active connection or switches database on current server.
26
+ - Args: name (str), database (optional str)
27
+
28
+ 3. add_connection
29
+ - Dynamically adds a new PostgreSQL or MySQL connection string at runtime.
30
+ - Args: name (str), url (str)
31
+
32
+ SCHEMA INSPECTION
33
+ 4. list_databases
34
+ - Lists all databases on the active server.
35
+
36
+ 5. list_schemas
37
+ - Lists all schemas in the active PostgreSQL database.
38
+
39
+ 6. describe_table
40
+ - Full schema inspection: columns, data types, nullability, defaults, PKs,
41
+ foreign keys, and indexes. Auto-resolves cross-schema tables in PostgreSQL.
42
+ - Args: tableName (str), schemaName (optional str)
43
+
44
+ 7. schema_overview
45
+ - Compact overview of all user tables and views.
46
+ - Args: schemaName (optional str)
47
+
48
+ 8. compact_schema_overview [NEW v0.2.3]
49
+ - Ultra-compact one-liner per table: schema.table (col: type PK, col2: FK->ref)
50
+ - Ideal for large databases — fits entire schema in minimal tokens.
51
+ - Args: schemaName (optional str), connection (optional str)
52
+
53
+ 9. get_table_ddl [NEW v0.2.3]
54
+ - Reconstructs the full CREATE TABLE DDL with column types, NOT NULL,
55
+ defaults, all constraints (PK, FK, UNIQUE, CHECK), and extra indexes.
56
+ - PostgreSQL only (MySQL falls back to SHOW CREATE TABLE).
57
+ - Args: tableName (str), schema (optional str), connection (optional str)
58
+
59
+ 10. search_schema
60
+ - Case-insensitive regex search for table, view, or column names.
61
+ - Args: query (str)
62
+
63
+ DATA ACCESS
64
+ 11. get_table_sample [NEW v0.2.3]
65
+ - Returns sample rows (default: 5) and estimated row count for quick inspection.
66
+ - mask_sensitive=True (default) auto-redacts PII columns (password, token,
67
+ secret, ssn, api_key, credit_card, etc.) as [REDACTED_SENSITIVE].
68
+ - Args: tableName (str), schemaName (optional str), limit (optional int),
69
+ mask_sensitive (optional bool, default: True)
70
+
71
+ 12. read_query
72
+ - Safe SELECT queries returning structured JSON with row counts.
73
+ - Args: sql (str), limit (optional int)
74
+
75
+ 13. execute_query
76
+ - Executes DML / DDL statements (INSERT, UPDATE, DELETE, CREATE, ALTER) with
77
+ transaction commit/rollback and affected row counts.
78
+ - Args: sql (str), dry_run (optional bool)
79
+
80
+ 14. explain_query
81
+ - Generates EXPLAIN query execution plan.
82
+ - Args: sql (str), analyze (optional bool)
83
+
84
+ DIAGNOSTICS & HEALTH
85
+ 15. get_database_stats
86
+ - Table size, row estimates, index sizes, and total database size.
87
+
88
+ 16. list_active_queries
89
+ - Lists running queries, connection duration, and process IDs.
90
+
91
+ 17. audit_database_health [NEW v0.2.3]
92
+ - Database-wide health audit (PostgreSQL only). Returns three categories:
93
+ • unindexed_foreign_keys: FK columns lacking a supporting index (slow JOINs).
94
+ • unused_indexes: Indexes with zero scans — candidates for DROP.
95
+ • bloated_tables: Tables with >20% dead tuples needing VACUUM.
96
+ - Each finding includes a 'fix' field with the recommended SQL statement.
97
+ - Args: schema (optional str, default: 'public', use '*' for all schemas),
98
+ connection (optional str)
99
+
100
+ 18. compare_schemas [ENHANCED]
101
+ - Compares two connections: missing tables, missing columns, type mismatches.
102
+ - Now includes migration_sql: auto-generated ALTER/CREATE statements to bring
103
+ target schema up to source.
104
+ - Args: source_connection (str), target_connection (str), schema (optional str)
105
+
106
+ DBA MANAGEMENT
107
+ 19. create_database
108
+ - Creates a new database on the active server.
109
+ - Args: name (str), template (optional str, Postgres only), encoding (optional str)
110
+
111
+ 20. drop_database
112
+ - Safety-guarded DROP DATABASE (requires confirmName matching target name).
113
+ - Args: name (str), confirmName (str), force (optional bool)
114
+
115
+ 21. clone_database
116
+ - Fast database cloning using PostgreSQL TEMPLATE mechanism.
117
+ - Args: sourceDb (str), targetDb (str)
118
+
119
+ 22. terminate_connections
120
+ - Terminates active connections to a specific database (PostgreSQL only).
121
+ - Args: dbName (str)
122
+
123
+ 23. dump_database / restore_database
124
+ - dump_database: Dumps database to SQL file using native pg_dump or mysqldump.
125
+ Args: outputPath (str), tables (optional list)
126
+ - restore_database: Restores database from SQL dump file using native psql or mysql.
127
+ Args: inputPath (str), targetDb (optional str)
128
+
129
+ --------------------------------------------------------------------------------
130
+ Error Handling:
131
+ --------------------------------------------------------------------------------
132
+ All tools return rich PostgreSQL error details when a query fails:
133
+ • pgcode — PostgreSQL error code (e.g. 23503 for FK violation)
134
+ • severity — ERROR / FATAL / WARNING
135
+ • detail — Full PostgreSQL DETAIL message
136
+ • hint — PostgreSQL HINT for resolution
137
+ • constraint — Constraint name (for constraint violations)
138
+ • table — Table name from error context
139
+ • suggestion — Human-readable fix suggestion from the built-in suggestion map
140
+
141
+ --------------------------------------------------------------------------------
142
+ Environment Variables:
143
+ --------------------------------------------------------------------------------
144
+ * SERVERS: JSON dictionary mapping server names to connection strings.
145
+ Example:
146
+ {
147
+ "showreel": "postgresql://postgres:pass@localhost:5432/showreel",
148
+ "dsr": "postgresql://postgres:pass@localhost:5432/dsr",
149
+ "ijitest": "mysql://user:pass@srv604.hstgr.io:3306/db_name"
150
+ }
151
+
152
+ --------------------------------------------------------------------------------
153
+ Example Prompts for Claude:
154
+ --------------------------------------------------------------------------------
155
+ * "What databases are configured and what tables are in the active database?"
156
+ * "Switch to the ijitest database and describe the users table."
157
+ * "Show me the full DDL for the orders table."
158
+ * "Show a sample of the users table — mask any sensitive columns."
159
+ * "Run a health audit on the showreel database and tell me what to fix."
160
+ * "Compare the dev and prod schemas and generate migration SQL for differences."
161
+ * "Create a clone of the showreel database named showreel_backup."
162
+ * "Show the active queries running on PostgreSQL right now."
163
+ ================================================================================
164
+ """
165
+ print(guide_text)