| connectA | Establish connection to the SQL Server database. Uses configuration from environment variables:
- MSSQL_HOST: Server hostname or IP
- MSSQL_USER: Username
- MSSQL_PASSWORD: Password
- MSSQL_DATABASE: Database name
- MSSQL_PORT: Port (default: 1433)
Returns:
Connection status and details including host, database, and timestamp.
|
| disconnectA | Close all connections to the SQL Server database. Returns:
Disconnection status and count of closed connections.
|
| list_connectionsB | List all active database connections. Returns:
List of active connections with their details (name, host, database,
connection time, and active status).
|
| read_rowsA | Read rows from a table by primary key or filter. Provide one of: id (single row), ids (multiple rows), or filter (WHERE clause).
Args:
table: Table name (can include schema: 'dbo.Users' or 'Users')
id: Single primary key value (for composite keys, use filter)
ids: List of primary key values
filter: WHERE clause without 'WHERE' keyword (e.g., "status = 'active'")
columns: List of columns to return (default: all columns)
max_rows: Maximum rows to return
Returns:
Dictionary with:
- table: Full table name
- rows: List of row dictionaries
- count: Number of rows returned
|
| insert_rowB | Insert a new row into a table. Args:
table: Table name (can include schema: 'dbo.Users' or 'Users')
data: Dictionary of column names and values to insert
Returns:
Dictionary with:
- status: 'success' or error
- table: Full table name
- inserted: The inserted row (including generated identity columns)
|
| update_rowA | Update an existing row by primary key. Args:
table: Table name (can include schema: 'dbo.Users' or 'Users')
id: Primary key value of the row to update
data: Dictionary of column names and new values
Returns:
Dictionary with:
- status: 'success' or error
- table: Full table name
- updated: The updated row
|
| delete_rowA | Delete a row by primary key. Args:
table: Table name (can include schema: 'dbo.Users' or 'Users')
id: Primary key value of the row to delete
Returns:
Dictionary with:
- status: 'deleted' or error
- table: Full table name
- id: The deleted row's ID
- rows_affected: Number of rows deleted (should be 1)
|
| list_databasesA | List all available databases on the SQL Server. Queries sys.databases to discover accessible databases. System databases
(master, tempdb, model, msdb) are excluded by default. Databases in the
blocklist (MSSQL_BLOCKED_DATABASES) are always excluded.
Args:
include_system: If True, include system databases in the list
Returns:
Dictionary with:
- databases: List of available database names
- current_database: The currently active database
- count: Number of databases returned
- blocked_count: Number of databases hidden due to blocklist
|
| switch_databaseA | Switch the active database context. Changes the current database using the USE statement. The database must
exist, be online, and not be in the blocklist (MSSQL_BLOCKED_DATABASES).
Args:
database_name: Name of the database to switch to
Returns:
Dictionary with:
- status: "switched" on success, "error" on failure
- database: The new active database name
- previous_database: The previously active database
- error: Error message if switch failed
|
| export_to_jsonA | Export query results to a JSON file. Args:
query: SQL SELECT query to execute
filename: Output filename (relative or absolute path)
Returns:
Dictionary with:
- status: 'success' or error
- path: Absolute path to created file
- row_count: Number of rows exported
- file_size: Size of created file in bytes
|
| export_to_csvA | Export query results to a CSV file. Args:
query: SQL SELECT query to execute
filename: Output filename (relative or absolute path)
delimiter: Field delimiter (default: comma)
Returns:
Dictionary with:
- status: 'success' or error
- path: Absolute path to created file
- row_count: Number of rows exported
- file_size: Size of created file in bytes
|
| save_knowledgeA | Save learned information about the SQL Server database. Use this to persist useful discoveries about the database schema,
table structures, query patterns, and data meanings. This information
will be available in future conversations.
Good things to save:
- Table purposes (e.g., "Customers contains customer master records")
- Column meanings (e.g., "In Orders, StatusCode 1=Pending, 2=Shipped")
- Working query patterns that produced good results
- Relationships between tables (foreign keys, joins)
- Data format notes (date formats, codes, etc.)
- Stored procedure documentation
Args:
topic: A short descriptive name for this knowledge
(e.g., "Customers table", "Order queries", "Status codes")
content: The knowledge to save. Use markdown formatting.
append: If True, add to existing topic. If False, replace it.
Returns:
Status of the save operation.
Examples:
save_knowledge("dbo.Customers", "Customer master table. PK is CustomerID.")
save_knowledge("Date formats", "Dates stored as datetime2. Use FORMAT() for display.")
|
| list_knowledgeA | List all saved knowledge topics. Returns a list of topics that have been saved about this database.
Use get_knowledge_topic to retrieve the full content of a specific topic,
or get_all_knowledge to retrieve everything at once.
Returns:
Dictionary containing list of topics with summaries.
|
| get_all_knowledgeA | Get ALL saved knowledge about this SQL Server database. IMPORTANT: Call this tool at the start of conversations to retrieve
previously learned information about the database. This includes:
- Table descriptions and purposes
- Column definitions and meanings
- Working query patterns
- Relationships between tables
- Data format notes and conventions
- Stored procedure documentation
This knowledge was saved from previous conversations to help you
work more efficiently with this specific database.
Returns:
All saved knowledge as markdown text.
|
| get_knowledge_topicB | Get saved knowledge for a specific topic. Retrieves the full content of a previously saved knowledge topic.
Args:
topic: The topic name to retrieve.
Returns:
The topic content or error if not found.
|
| search_knowledgeA | Search saved knowledge for specific information. Searches all saved knowledge for mentions of the query string.
Useful for finding previously learned information about specific
tables, columns, or concepts.
Args:
query: Text to search for (case-insensitive).
Returns:
List of matching topics and relevant lines.
|
| delete_knowledgeA | Delete a saved knowledge topic. Removes a topic from the knowledge base. Requires confirmation.
Args:
topic: The topic name to delete.
confirm: Must be True to execute the deletion.
Returns:
Status of the delete operation.
|
| execute_queryA | Execute a read-only SQL query and return results. Only SELECT statements are allowed. The query will have a row limit applied
automatically if not specified.
Args:
query: SQL SELECT statement to execute
max_rows: Maximum rows to return (overrides default, capped by MSSQL_MAX_ROWS)
Returns:
Dictionary with:
- query: The original query
- executed_query: The query that was actually executed (may include TOP)
- columns: List of column names
- rows: List of row dictionaries
- row_count: Number of rows returned
- max_rows: The effective row limit applied
|
| validate_queryA | Check if a query is safe to execute without running it. Validates the query against:
- Statement type (SELECT, INSERT, UPDATE, DELETE, DDL, EXEC)
- Blocked commands list
- Read-only mode compliance
- Potential issues (missing WHERE clause, unbounded SELECT)
Args:
query: SQL statement to validate
Returns:
Dictionary with:
- query: The original query
- valid: Whether the query is valid
- statement_type: Type of SQL statement
- warnings: List of warning messages
- suggestions: List of suggested improvements
- error: Error message if invalid
|
| list_stored_procsA | List available stored procedures in the database. Args:
schema: Filter by schema name (e.g., 'dbo')
pattern: Filter by name pattern using SQL LIKE syntax (e.g., 'sp_%', '%User%')
Returns:
Dictionary with:
- procedures: List of procedure info (schema, name, created, modified)
- count: Number of procedures found
|
| describe_stored_procB | Get parameter information for a stored procedure. Args:
procedure: Procedure name, optionally with schema (e.g., 'dbo.sp_GetUser' or 'sp_GetUser')
Returns:
Dictionary with:
- procedure: Full procedure name (schema.name)
- parameters: List of parameter info (name, type, direction, etc.)
|
| call_stored_procB | Execute a stored procedure. Args:
procedure: Procedure name, optionally with schema (e.g., 'dbo.sp_GetUser' or 'sp_GetUser')
params: Input parameter values as dictionary (parameter names without @)
Returns:
Dictionary with:
- procedure: Full procedure name
- result_sets: List of result sets (each is a list of row dictionaries)
- status: 'success' or error
|
| list_tablesA | List all tables and views in the database. Args:
schema: Filter by schema name (e.g., 'dbo'). If not specified, returns all schemas.
include_views: Include views in results (default: True)
pattern: Filter by name pattern using SQL LIKE syntax (e.g., 'Cust%', '%Order%')
Returns:
Dictionary with:
- tables: List of table/view info (schema, name, type)
- count: Number of results
|
| describe_tableA | Get detailed column information for a table. Retrieves column definitions, primary keys, foreign keys, and indexes.
Args:
table: Table name, optionally with schema (e.g., 'dbo.Users' or 'Users').
Defaults to 'dbo' schema if not specified.
Returns:
Dictionary with:
- table: Full table name (schema.table)
- columns: List of column info (name, type, nullable, etc.)
- primary_key: List of primary key column names
- foreign_keys: List of foreign key relationships
- indexes: List of index info
|
| begin_transactionA | Begin a database transaction. Starts a new transaction. All subsequent write operations (insert, update,
delete) will be part of this transaction until commit_transaction or
rollback_transaction is called.
Returns:
Dictionary containing:
- status: success or error
- in_transaction: True if transaction is now active
- started_at: Timestamp when transaction started
Note:
Only one transaction can be active at a time.
Attempting to start a new transaction while one is active will fail.
|
| commit_transactionA | Commit the current transaction. Saves all changes made since begin_transaction was called.
The transaction is closed after commit.
Returns:
Dictionary containing:
- status: success or error
- in_transaction: False after successful commit
- message: Confirmation message
Note:
If no transaction is active, returns an error.
|
| rollback_transactionA | Rollback the current transaction. Discards all changes made since begin_transaction was called.
The transaction is closed after rollback.
Returns:
Dictionary containing:
- status: success or error
- in_transaction: False after successful rollback
- message: Confirmation message
Note:
If no transaction is active, returns an error.
|
| get_transaction_statusA | Get the current transaction status. Returns information about whether a transaction is active
and when it was started.
Returns:
Dictionary containing:
- in_transaction: True if transaction is active
- started_at: Timestamp when transaction started (if active)
- read_only_mode: Whether server is in read-only mode
|