tool_adapter¶
- mcp_ohmy_sql.adapter.tool_adapter.format_query_result(duration: float, query_result_text: str)[source]¶
Format query execution results with timing information for MCP tool output.
- class mcp_ohmy_sql.adapter.tool_adapter.ToolAdapterMixin[source]¶
MCP tools low level implementation.
- tool_list_databases() str[source]¶
List all configured databases with identifiers and basic information.
Use this tool to discover available databases before exploring schemas or executing queries. Returns database identifiers needed for other tools.
Sample Output:
Available Databases: Database( identifier='production_db', db_type=postgres, description=Production PostgreSQL database, number_of_schemas=3, all_schemas=public, ) Database( identifier='chinook_sqlite', db_type=sqlite, description=Sample music store database, number_of_schemas=1, )
- Returns:
Formatted list of databases with identifiers, types, schema counts, and descriptions.
- tool_list_tables(database_identifier: str, schema_name: str | None = None) str[source]¶
List tables, views, and materialized views in a database schema.
Provides quick overview of available database objects with column counts and comments. Use this for discovery before getting detailed schema information.
Sample Output:
Available Tables, Views, and Materialized Views: - Table 'Album': 3 columns, Music album information - Table 'Artist': 2 columns, Recording artist details - Table 'Customer': 13 columns, Customer contact information - View 'AlbumSalesStats': 8 columns, Pre-calculated album sales metrics
- Parameters:
database_identifier – Database identifier from list_databases.
schema_name – Optional schema name (uses default if None).
- Returns:
List of tables/views with column counts and descriptions.
- tool_get_all_database_details() str[source]¶
Get complete schema information for all configured databases.
Returns detailed metadata for all databases, schemas, tables, columns, and relationships. Use this for comprehensive database discovery or when you need schema details across multiple databases.
Output Format:
<db_type> Database <identifier>( Schema <name>( Table <name>( column:TYPE*CONSTRAINTS, ... ) ... ) ... )
Constraints:
*PK(Primary Key),*FK->Table.Column(Foreign Key),*NN(Not Null),*UQ(Unique),*IDX(Indexed)Sample Output:
sqlite Database chinook( Schema default( Table Album( AlbumId:INT*PK*NN, Title:STR*NN, ArtistId:INT*NN*FK->Artist.ArtistId, ) Table Artist( ArtistId:INT*PK*NN, Name:STR, ) ) )
Important
It is possible that the database connection is misconfigured or the database user doesn’t have enough permission to get database schema, the response will explicitly state the error information.
- Returns:
Complete schema information for all configured databases.
- tool_get_schema_details(database_identifier: str, schema_name: str | None = None) str[source]¶
CRITICAL FOR SQL WRITING: Get detailed schema for a specific database.
ALWAYS use this tool before writing SQL queries to get exact table structures, column names, data types, and relationships for accurate SQL generation.
Output Format:
Schema <name>( Table <name>( column:TYPE*CONSTRAINTS, ... ) View <name>( column:TYPE*CONSTRAINTS, ... ) ... )
Constraints:
*PK(Primary Key),*FK->Table.Column(Foreign Key),*NN(Not Null),*UQ(Unique),*IDX(Indexed)Sample Output:
Schema default( Table Album( AlbumId:INT*PK*NN, Title:STR*NN, ArtistId:INT*NN*FK->Artist.ArtistId, ) Table Artist( ArtistId:INT*PK*NN, Name:STR, ) View AlbumSalesStats( AlbumId:INT, AlbumTitle:STR, TotalRevenue:DEC, ) )
- Parameters:
database_identifier – Database identifier from list_databases.
schema_name – Optional schema name (uses default if None).
- Returns:
Schema structure with tables, columns, types, and relationships.
- tool_execute_select_statement(database_identifier: str, sql: str, params: dict[str, Any] | None = None) str[source]¶
Execute SELECT queries with performance timing and formatted results.
Read-only tool that executes SELECT statements and returns execution time plus Markdown-formatted results. Use execution time (>1s = slow, >5s = needs optimization) to guide query performance decisions.
Sample Output:
# Execution Time 0.045 seconds # Query Result | id | name | email | |----|----------|--------------------| | 1 | John Doe | john@example.com | | 2 | Alice | alice@example.com |
Usage Examples:
# Simple query execute_select_statement("chinook_sqlite", "SELECT * FROM Album LIMIT 5") # Parameterized query (recommended for dynamic values) execute_select_statement( "chinook_sqlite", "SELECT * FROM Album WHERE ArtistId = :artist_id", {"artist_id": 1} )
- Parameters:
database_identifier – Database identifier from list_databases.
sql – SELECT statement only (DDL/DML not permitted).
params – Optional parameters for safe value substitution.
- Returns:
Execution time and query results in Markdown table format.