diff --git a/INSTALLATION_GUIDE.md b/INSTALLATION_GUIDE.md index 01a7c85..84661c2 100644 --- a/INSTALLATION_GUIDE.md +++ b/INSTALLATION_GUIDE.md @@ -190,6 +190,25 @@ Completely quit and restart Claude Desktop to load the MCP server. } ``` +### MS-SQL + +```json +{ + "databases": { + "my_mssql": { + "type": "mssql", + "host": "localhost", + "port": 1433, + "database": "mydb", + "username": "root", + "password": "password", + "driver": "ODBC Driver 18 for SQL Server", + "read_only": true + } + } +} +``` + ### Multiple Databases ```json diff --git a/README.md b/README.md index 02f88c7..46199c1 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,8 @@ Your agent will automatically use the appropriate tools to query your database. "username": "user", // Required for most databases "password": "pass", // Required for most databases "read_only": true, // Optional: default true (recommended) + "driver": "ODBC Driver 17 for SQL Server", + // Optional: mssql only, default "ODBC Driver 17 for SQL Server" "pool_size": 5, // Optional: connection pool size (default 5) "max_overflow": 2, // Optional: max extra connections (default 2) "pool_timeout": 30 // Optional: connection timeout (default 30s) diff --git a/src/db_mcp/config.py b/src/db_mcp/config.py index 7791d77..46e2e2b 100644 --- a/src/db_mcp/config.py +++ b/src/db_mcp/config.py @@ -29,6 +29,7 @@ def __init__(self, name: str, config: Dict[str, Any]): self.pool_size = config.get("pool_size", 5) self.max_overflow = config.get("max_overflow", 2) self.pool_timeout = config.get("pool_timeout", 30) + self.driver = config.get("driver", "ODBC Driver 17 for SQL Server") # For SQL Server # Validate configuration self._validate() @@ -83,8 +84,8 @@ def get_connection_string(self) -> str: return f"mysql+mysqlconnector://{auth}{self.host}{port_str}/{self.database}" elif self.type == "mssql": # For SQL Server, we need to specify the driver - driver = "ODBC+Driver+17+for+SQL+Server" - return f"mssql+pyodbc://{auth}{self.host}{port_str}/{self.database}?driver={driver}" + driver = self.driver.replace(" ", "+") # Encode spaces for URL + return f"mssql+pyodbc://{auth}{self.host}{port_str}/{self.database}?driver={driver}&encrypt=no" raise ValueError(f"Unknown database type: {self.type}") diff --git a/src/db_mcp/server.py b/src/db_mcp/server.py index 0522010..6877a38 100644 --- a/src/db_mcp/server.py +++ b/src/db_mcp/server.py @@ -190,6 +190,16 @@ def generate_example_config(): "type": "sqlite", "path": "./database.db", "read_only": False + }, + "my_mssql_db": { + "type": "mssql", + "host": "localhost", + "port": 1433, + "database": "mydb", + "username": "root", + "password": "password", + "driver": "ODBC Driver 18 for SQL Server", + "read_only": True } } } @@ -207,10 +217,11 @@ def generate_example_config(): print("\n" + "="*60) print("SUCCESS: config.json created!") print("="*60) - print("\nGenerated example configuration file with 3 databases:") + print("\nGenerated example configuration file with 4 databases:") print(" - my_postgres_db (PostgreSQL)") print(" - my_mysql_db (MySQL)") print(" - my_sqlite_db (SQLite)") + print(" - my_mssql_db (SQL Server)") print("\nNext steps:") print("1. Edit config.json with your actual database details") print("2. Remove database entries you don't need")