refactor: structured SQLResult.messages (DatabaseMessage[])#327
Merged
Conversation
Promote the informational-messages field added in #307 from a bare string[] to a structured DatabaseMessage[] so severity, code, and line are preserved instead of discarded. This is a cross-database shape: PostgreSQL NOTICE/WARNING and MySQL warnings can populate the same type later without a breaking interface change. - interface.ts: add DatabaseMessage type; SQLResult.messages is now DatabaseMessage[] - sqlserver: map the mssql `info` event (message/class/number/lineNumber) into DatabaseMessage; severity lets clients distinguish PRINT from warnings - execute_sql forwards the structured array unchanged - update SQL Server integration tests to assert on `.text` Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors SQLResult.messages from a lossy string[] into a structured DatabaseMessage[] so database informational output can carry per-message metadata (severity/code/line) rather than being flattened to plain text.
Changes:
- Introduces
DatabaseMessagein the connector interface and updatesSQLResult.messagestoDatabaseMessage[]. - Updates the SQL Server connector to map
mssqlinfoevents into{ text, severity, code, line }. - Adjusts SQL Server integration tests to assert on
msg.textinstead of raw string messages.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/connectors/interface.ts | Adds DatabaseMessage type and updates SQLResult.messages to use it. |
| src/connectors/sqlserver/index.ts | Collects SQL Server info events into structured DatabaseMessage objects. |
| src/connectors/tests/sqlserver.integration.test.ts | Updates assertions to use DatabaseMessage.text. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #307. That PR added
SQLResult.messages?: string[]to surface SQL Server informational output (SET STATISTICS TIME/IO,PRINT, warnings) to MCP clients. This PR promotes that field from a barestring[]to a structuredDatabaseMessage[]so per-message metadata is preserved instead of flattened away.Why
string[]is lossy. Themssqlinfoevent carriesmessage,class(severity),number, andlineNumber— all discarded by the string form. Most importantly, severity lets a client tell a benignPRINTfrom an actual warning.It's also a genuinely cross-database concept, not a SQL-Server quirk: PostgreSQL emits
NOTICE/WARNINGand MySQL/MariaDB emit warnings. Doing the structured shape now — while there's exactly one producer — means those connectors can populate the same type later without a breaking interface change.Changes
src/connectors/interface.ts: addDatabaseMessage { text; severity?; code?; line? };SQLResult.messagesis nowDatabaseMessage[]. Onlytextis guaranteed — the rest are populated when the driver exposes them.src/connectors/sqlserver/index.ts: map theinfoevent intoDatabaseMessage(text/severity/code/line) instead of pushing the raw string.src/tools/execute-sql.ts: unchanged — it already forwardsresult.messagesas-is, so clients now receive the structured objects automatically.src/connectors/__tests__/sqlserver.integration.test.ts: assertions updated to read.text.Notes
messagesfield shape changes fromstring[]to objects, but feat(sqlserver): surface informational messages (STATISTICS, PRINT) in query results #307 has not shipped in a release yet, so no consumers depend on the old form.severityis intentionally a generalstring(PG level name vs. SQL Server numeric class as a string), documented per-engine, rather than a SQL-Server-specific field name.Verification
npx tsc --noEmit: zero new errors (135 pre-existing on bothmainand this branch; CI builds via tsup).pnpm run build: ✓🤖 Generated with Claude Code