Skip to content

fix(sqlite): add MCP metadata migration - #4060

Merged
lyingbug merged 1 commit into
Tencent:mainfrom
hahahahahayesyeseys:fix/sqlite-mcp-metadata-schema
Oct 10, 2026
Merged

lyingbug merged 1 commit into
Tencent:mainfrom
hahahahahayesyeseys:fix/sqlite-mcp-metadata-schema

Conversation

@hahahahahayesyeseys

Copy link
Copy Markdown
Contributor

Summary

  • add the missing SQLite migration for mcp_services.usage_instructions
  • create the SQLite mcp_metadata table used by persisted MCP tool directories
  • cover fresh databases and v33 upgrades, including repeated startup and existing service preservation

Fixes #4058

Problem

Lite selects migrations/sqlite, but that migration set stopped at version 33
while the application already reads and writes mcp_services.usage_instructions
and mcp_metadata. PostgreSQL received the equivalent schema in migration
000092_mcp_metadata, so the two deployment modes had drifted.

On Lite, the missing schema causes errors such as:

table mcp_services has no column named usage_instructions
no such table: mcp_metadata

These failures affect MCP service creation and editing, tool-directory refresh,
usage-instruction persistence, and the Agent's persisted MCP directory path.

Changes

  • add SQLite migration 000034_mcp_metadata
    • add mcp_services.usage_instructions with the same non-null empty-string default as PostgreSQL
    • create mcp_metadata with tenant/service/principal identity and SQLite-compatible JSON text storage
  • add the corresponding down migration
  • extend the SQLite schema parity test to require the new table and column
  • add an upgrade regression test that starts from v33 and verifies:
    • existing MCP service rows and descriptions survive
    • repeated startup does not replay the migration
    • usage instructions can be inserted and updated
    • metadata upserts keep separate shared and user-scoped snapshots
    • SQLite JSON tool counts remain queryable

Testing

  • go test ./internal/database -count=1
  • go test ./internal/database -run 'TestSQLiteMigrations(CreateVersionedSchema|UpgradeV33PreservesMCPServices)$' -count=1 -v
  • go test ./internal/database -run '^TestSQLiteMigrationsUpgradeV33PreservesMCPServices$' -count=20
  • go vet ./internal/database
  • golangci-lint run --new-from-rev=origin/main ./...
  • go test -tags desktop ./internal/container
  • go build ./cmd/server

The same upgrade regression fails on the unpatched base with
no such column: usage_instructions and passes with this migration. The patch
was also applied to the latest origin/main snapshot and the targeted fresh and
upgrade tests passed there.

@lyingbug

Copy link
Copy Markdown
Collaborator

Review of 25cc74921c3d.

Please coordinate the SQLite migration version with #4053 and #3644 before merging these changes together.

All three PRs add version 000034. Combining this PR's actual migration files with either branch makes the real migration loader fail during source initialization with duplicate migration file: 000034_*.down.sql. The application catches the migration error, logs a warning and continues startup, so the metadata schema can remain missing even though the service starts.

Assign a unique version to whichever migration lands later and rerun the complete SQLite migration sequence after integration. This PR's standalone database tests pass; the failure is in the combined migration directory.

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.

[Bug]: SQLite migrations omit the MCP metadata schema used by Lite

2 participants