Repository navigation
fix(prebuilt/sqlite): list generated columns in list_tables - #4566
beskvladimir-create wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the SQLite prebuilt configuration to use pragma_table_xinfo instead of pragma_table_info, allowing the list_tables tool to include generated columns (both STORED and VIRTUAL) while continuing to exclude hidden columns of virtual tables. A new integration test is added to verify this behavior. The review feedback highlights two important improvements for the new test: adding the missing blank import for the SQLite driver (modernc.org/sqlite) to prevent test failures, and using http.NewRequestWithContext instead of http.Post to avoid potential indefinite hangs by respecting the context timeout.
| import ( | ||
| "bytes" | ||
| "context" | ||
| "database/sql" | ||
| "encoding/json" | ||
| "io" | ||
| "net/http" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/googleapis/mcp-toolbox/internal/testutils" | ||
| "github.com/googleapis/mcp-toolbox/tests" | ||
| ) |
There was a problem hiding this comment.
The test uses sql.Open("sqlite", dbPath) to set up the test database, but the SQLite driver (modernc.org/sqlite) is not imported in this test file or package. This will cause the test to fail with sql: unknown driver "sqlite". Please add the blank import for the SQLite driver.
| import ( | |
| "bytes" | |
| "context" | |
| "database/sql" | |
| "encoding/json" | |
| "io" | |
| "net/http" | |
| "path/filepath" | |
| "regexp" | |
| "strings" | |
| "testing" | |
| "time" | |
| "github.com/googleapis/mcp-toolbox/internal/testutils" | |
| "github.com/googleapis/mcp-toolbox/tests" | |
| ) | |
| import ( | |
| "bytes" | |
| "context" | |
| "database/sql" | |
| "encoding/json" | |
| "io" | |
| "net/http" | |
| "path/filepath" | |
| "regexp" | |
| "strings" | |
| "testing" | |
| "time" | |
| "github.com/googleapis/mcp-toolbox/internal/testutils" | |
| "github.com/googleapis/mcp-toolbox/tests" | |
| _ "modernc.org/sqlite" | |
| ) |
| resp, err := http.Post(api, "application/json", bytes.NewReader(reqBody)) | ||
| if err != nil { | ||
| t.Fatalf("unable to send request: %v", err) | ||
| } |
There was a problem hiding this comment.
Using http.Post without a context or client timeout can cause the test to hang indefinitely if the server does not respond. Since a ctx with a timeout is already available, it is safer and more idiomatic to use http.NewRequestWithContext to ensure the request respects the context timeout.
| resp, err := http.Post(api, "application/json", bytes.NewReader(reqBody)) | |
| if err != nil { | |
| t.Fatalf("unable to send request: %v", err) | |
| } | |
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, api, bytes.NewReader(reqBody)) | |
| if err != nil { | |
| t.Fatalf("unable to create request: %v", err) | |
| } | |
| req.Header.Set("Content-Type", "application/json") | |
| resp, err := http.DefaultClient.Do(req) | |
| if err != nil { | |
| t.Fatalf("unable to send request: %v", err) | |
| } |
Description
The sqlite prebuilt
list_tablesread table columns frompragma_table_info, which does not return generated columns (GENERATED ALWAYS AS (...) STORED/VIRTUAL). Those columns were silently missing fromcolumns, and theordinal_positionof the regular columns declared after them was shifted (details and repro in #4565).This change reads the columns from
pragma_table_xinfoinstead and skips onlyhidden = 1, the hidden columns of virtual tables (e.g. the FTS5rankcolumn), so those stay excluded as before. Generated columns (hidden = 2/3) are now listed with their real positions. Constraints, indexes and triggers are unchanged.Testing: ran the current and the changed statement side by side on SQLite 3.53.1 over a database with a plain table, a composite-key table, a table with generated columns plus a foreign key and a unique column, and an FTS5 virtual table with its shadow tables: the output is identical for every table except the one with generated columns, which now lists all its columns with positions matching
PRAGMA table_xinfo.PRAGMA table_xinfoneeds SQLite 3.26.0+; the pinned modernc.org/sqlite is much newer. AddedTestSQLitePrebuiltListTablesGeneratedColumns(new filetests/sqlite/sqlite_prebuilt_list_tables_test.go): it starts Toolbox with--prebuilt sqliteon a temporary database with a STORED and a VIRTUAL generated column and checks the returned column names and positions. I could not run the Go tests locally (my environment cannot download the Go 1.27 toolchain), so CI is the real check for the Go test.Security: no new input path; the
table_namesandoutput_formatparameters are handled exactly as before.PR Checklist
!if this involve a breaking change (not breaking)🛠️ Fixes #4565