Skip to content

CLI Commands

The Claude Code CLI provides several commands for interacting with MSSQL databases.

Ventana de terminal
go run claude-code/db-connector.go [command] [arguments]

Tests the database connection.

Ventana de terminal
go run claude-code/db-connector.go test

Output: Confirms if the connection was successful or displays connection errors.

Gets general information about the connected database.

Ventana de terminal
go run claude-code/db-connector.go info

Output: Server information, version, and configuration.

Lists all available tables in the database.

Ventana de terminal
go run claude-code/db-connector.go tables

Output: List of table names with their schemas.

Describes the structure of a specific table.

Ventana de terminal
go run claude-code/db-connector.go describe TABLE_NAME

Arguments:

  • TABLE_NAME: Name of the table to describe

Output: Columns, data types, constraints, and indexes of the table.

Executes a custom SQL query.

Ventana de terminal
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.

Before running any command, make sure to configure the environment variables:

Ventana de terminal
# Copy template
cp .env.example .env
# Edit .env with your credentials
# Load variables (Linux/Mac)
source .env
# Windows PowerShell
Get-Content .env | ForEach-Object {
$name, $value = $_ -split '=', 2
[Environment]::SetEnvironmentVariable($name, $value)
}

Required variables:

  • MSSQL_SERVER: SQL Server
  • MSSQL_DATABASE: Database
  • MSSQL_USER: User
  • MSSQL_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
Ventana de terminal
go run claude-code/db-connector.go test
Ventana de terminal
go run claude-code/db-connector.go tables
Ventana de terminal
go run claude-code/db-connector.go describe Users
Ventana de terminal
go run claude-code/db-connector.go query "SELECT TOP 10 * FROM Users WHERE Active = 1"
Ventana de terminal
go run claude-code/db-connector.go query "SELECT u.Name, o.OrderDate FROM Users u JOIN Orders o ON u.Id = o.UserId"

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.

Verify that environment variables are configured:

Ventana de terminal
echo "Server: $MSSQL_SERVER"
echo "Database: $MSSQL_DATABASE"
echo "User: $MSSQL_USER"

If you see certificate errors, set DEVELOPER_MODE=true for development:

Ventana de terminal
export DEVELOPER_MODE=true

Warning: Do not use DEVELOPER_MODE=true in production.

Check firewall and verify that SQL Server port (1433) is open.