8000 fix(prebuilt/sqlite): list generated columns in list_tables by beskvladimir-create · Pull Request #4566 · googleapis/mcp-toolbox · GitHub
[go: up one dir, main page]

Skip to content

fix(prebuilt/sqlite): list generated columns in list_tables - #4566

Open
beskvladimir-create wants to merge 1 commit into
googleapis:mainfrom
beskvladimir-create:fix/sqlite-list-tables-generated-columns
Open

beskvladimir-create wants to merge 1 commit into
googleapis:mainfrom
beskvladimir-create:fix/sqlite-list-tables-generated-columns

Conversation

@beskvladimir-create
Copy link
Copy Markdown
Contributor

Description

The sqlite prebuilt list_tables read table columns from pragma_table_info, which does not return generated columns (GENERATED ALWAYS AS (...) STORED / VIRTUAL). Those columns were silently missing from columns, and the ordinal_position of the regular columns declared after them was shifted (details and repro in #4565).

This change reads the columns from pragma_table_xinfo instead and skips only hidden = 1, the hidden columns of virtual tables (e.g. the FTS5 rank column), 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_xinfo needs SQLite 3.26.0+; the pinned modernc.org/sqlite is much newer. Added TestSQLitePrebuiltListTablesGeneratedColumns (new file tests/sqlite/sqlite_prebuilt_list_tables_test.go): it starts Toolbox with --prebuilt sqlite on 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_names and output_format parameters are handled exactly as before.

PR Checklist

  • Make sure you reviewed CONTRIBUTING.md
  • Make sure to open an issue as a bug/issue before writing your code
  • Ensure you have manually reviewed the entire diff before requesting a review
  • Ensure the tests and linter pass (left to CI, see Testing above)
  • Code coverage does not decrease (integration test added)
  • Appropriate docs were updated (no docs change needed)
  • Make sure to add ! if this involve a breaking change (not breaking)

🛠️ Fixes #4565

@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +17 to +32
8000
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"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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"
)

Comment on lines +84 to +87
resp, err := http.Post(api, "application/json", bytes.NewReader(reqBody))
if err != nil {
t.Fatalf("unable to send request: %v", err)
}
Copy link
8000 Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite prebuilt list_tables: generated columns (GENERATED ALWAYS AS ... STORED/VIRTUAL) are missing from the detailed output

2 participants

0