CLI Commands
Available Commands
Section titled “Available Commands”The Claude Code CLI provides several commands for interacting with MSSQL databases.
Basic Usage
Section titled “Basic Usage”go run claude-code/db-connector.go [command] [arguments]Commands
Section titled “Commands”Tests the database connection.
go run claude-code/db-connector.go testOutput: Confirms if the connection was successful or displays connection errors.
Gets general information about the connected database.
go run claude-code/db-connector.go infoOutput: Server information, version, and configuration.
tables
Section titled “tables”Lists all available tables in the database.
go run claude-code/db-connector.go tablesOutput: List of table names with their schemas.
describe
Section titled “describe”Describes the structure of a specific table.
go run claude-code/db-connector.go describe TABLE_NAMEArguments:
TABLE_NAME: Name of the table to describe
Output: Columns, data types, constraints, and indexes of the table.
Executes a custom SQL query.
go run claude-code/db-connector.go query "SELECT * FROM table WHERE condition"Arguments:
- SQL query in quotes
Output: Query results in tabular format.
Security note: The CLI uses prepared statements to prevent SQL injection.
Required Environment Variables
Section titled “Required Environment Variables”Before running any command, make sure to configure the environment variables:
# Copy templatecp .env.example .env
# Edit .env with your credentials# Load variables (Linux/Mac)source .env
# Windows PowerShellGet-Content .env | ForEach-Object { $name, $value = $_ -split '=', 2 [Environment]::SetEnvironmentVariable($name, $value)}Required variables:
MSSQL_SERVER: SQL ServerMSSQL_DATABASE: DatabaseMSSQL_USER: UserMSSQL_PASSWORD: Password
Optional variables:
MSSQL_PORT: Port (default: 1433)DEVELOPER_MODE: Development mode (true/false)MSSQL_READ_ONLY: Read-only mode (true/false)MSSQL_WHITELIST_TABLES: Allowed tables in read-only mode
Usage Examples
Section titled “Usage Examples”Test connection
Section titled “Test connection”go run claude-code/db-connector.go testList tables
Section titled “List tables”go run claude-code/db-connector.go tablesView table structure
Section titled “View table structure”go run claude-code/db-connector.go describe UsersExecute SELECT query
Section titled “Execute SELECT query”go run claude-code/db-connector.go query "SELECT TOP 10 * FROM Users WHERE Active = 1"Query with JOIN
Section titled “Query with JOIN”go run claude-code/db-connector.go query "SELECT u.Name, o.OrderDate FROM Users u JOIN Orders o ON u.Id = o.UserId"Security
Section titled “Security”The CLI implements the same security features as the MCP server:
- Encrypted TLS connections
- Prepared statements to prevent SQL injection
- Input validation
- Security logging
- Read-only mode support
See Security for more details.
Troubleshooting
Section titled “Troubleshooting”Error: “Database not connected”
Section titled “Error: “Database not connected””Verify that environment variables are configured:
echo "Server: $MSSQL_SERVER"echo "Database: $MSSQL_DATABASE"echo "User: $MSSQL_USER"TLS certificate error
Section titled “TLS certificate error”If you see certificate errors, set DEVELOPER_MODE=true for development:
export DEVELOPER_MODE=trueWarning: Do not use DEVELOPER_MODE=true in production.
Network error
Section titled “Network error”Check firewall and verify that SQL Server port (1433) is open.