Loading
Draft: fix(mcp): wrap non-object outputs as valid structuredContent
Summary
Strict MCP clients (notably Claude Desktop) reject structuredContent that isn't a JSON object, breaking glab mr list --output json and glab issue list --output json when called via the MCP tool surface. This MR adds an ensureStructuredRecord wrapper around non-object payloads before they land in CallToolResult.StructuredContent:
- Object → passthrough.
- Array →
{"data": [...]}. - Scalar / nil →
{"value": ...}.
The accompanying TextContent block still carries the raw payload unchanged, so existing clients that read the textual content see no difference.
Fixes #8302 (closed).
Context
This is the first MR in a 6-MR stack split out from the closed MR !3154. That MR did too much; this stack lands each piece independently. See the bug report at #8302 (closed) for the SDK contract citation and the strict-client repro.
Test plan
-
go test ./internal/commands/mcp/serve/...passes — coversensureStructuredRecordfor object passthrough, array wrap, scalar wrap, and nil. - Manually invoke
glab mr list --output jsonvia Claude Desktop's MCP client and confirm the response is accepted (was previously rejected asexpected record / invalid_type). - No change to the CLI's JSON output shape —
glab mr list --output jsonstill emits a top-level array on stdout.