DB Explorer

v0.1.0
io.github.AYUSH-148/db-explorer-mcp-server Checked 3 hours ago Published 1 month ago

Read-only SQL for PostgreSQL, MySQL and SQLite: schema, safe SELECTs, EXPLAIN, index advice

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

explore_schema Explore Schema

List the database's tables and views, or describe one in detail. Every result names the SQL dialect to write queries in. Table and column comments stored in the database come with table_name or detail=true, not with the default listing. CHECK constraints, triggers and view definitions are never included, so their absence here says nothing about the database. A listing comes in pages. A page can hold fewer tables than limit when it reaches the size cap, so continue with offset=next_offset, never offset+limit.

ParameterTypeDescription
detailbooleanList each table with its columns, keys and indexes instead of a column count. Use this, not one table_name call per table, when a question touches several tables. Pages get larger, so narrow a big sch…
include_sample_databooleanWith table_name, also return 3 sample rows.
limitintegerTables per page, 1 to 1000.
name_patternFilter tables by name, case-insensitive. Plain text matches a substring ('order'); *, ? and [] make it a glob ('order_*').
offsetintegerTables to skip. Pass the previous page's next_offset.
table_nameExact name of one table or view. Returns its columns, keys and indexes, plus a row count for a table; the listing parameters are ignored.

execute_query Execute Query

Run one read-only SELECT and return its rows. The result is capped by row_limit and by size. truncated=true means more rows exist: filter with WHERE or aggregate rather than raising row_limit. Repeated column names come back labelled name:1, name:2; alias them in the query.

ParameterTypeDescription
sql *stringOne SELECT statement (WITH ... SELECT is fine), in the dialect explore_schema reports. No comments, no second statement, no FOR UPDATE or FOR SHARE.
row_limitintegerMost rows to return, at least 1. Values above 1000 are treated as 1000.

explain_query Explain Query

Return the database's execution plan for one SELECT, without running it.

ParameterTypeDescription
sql *stringOne SELECT statement (WITH ... SELECT is fine), in the dialect explore_schema reports. No comments, no second statement, no FOR UPDATE or FOR SHARE.

validate_schema Validate Schema

Check tables for missing primary keys, unindexed foreign keys, very wide tables and tables with no indexes. A page of tables leaves views out.

ParameterTypeDescription
limitintegerTables per page, 1 to 1000.
name_patternFilter tables by name, case-insensitive. Plain text matches a substring ('order'); *, ? and [] make it a glob ('order_*').
offsetintegerTables to skip. Pass the previous page's next_offset.
table_nameOne table to check; a view is refused as not found. Omit it to check a page of tables.

suggest_index Suggest Index

Suggest indexes for one table or one query. With table_name, returns a CREATE INDEX for each foreign key no index covers. With query, reports the full table scans in its plan, without generated SQL. Nothing is created: the caller decides whether to run a suggestion.

ParameterTypeDescription
queryOne SELECT whose plan to check for full table scans, under the same rules as execute_query. Pass this or table_name, not both.
table_nameA table whose foreign keys to check for a covering index. Pass this or query, not both.

migration_context Migration Context

Return dialect and one page of table detail for client-side migration drafting. A page can hold fewer tables than limit when it reaches the size cap, so continue with offset=next_offset, never offset+limit.

ParameterTypeDescription
limitintegerTables per page, 1 to 1000.
name_patternFilter tables by name, case-insensitive. Plain text matches a substring ('order'); *, ? and [] make it a glob ('order_*').
offsetintegerTables to skip. Pass the previous page's next_offset.

validate_migration Validate Migration

Check migration scripts without executing them. Reports each statement's type and rejects SELECT, comments and unbalanced parentheses. It does not check syntax: the database reports other errors when the script is run.

ParameterTypeDescription
down_sql *stringStatements that undo up_sql, in the same form.
up_sql *stringStatements that apply the change, separated by semicolons, with no comments.