Skip to content

Unify JSON output format for connect commands to array of entries#218

Open
jancurn wants to merge 3 commits intomainfrom
claude/unify-connect-output-11VHQ
Open

Unify JSON output format for connect commands to array of entries#218
jancurn wants to merge 3 commits intomainfrom
claude/unify-connect-output-11VHQ

Conversation

@jancurn
Copy link
Copy Markdown
Member

@jancurn jancurn commented May 8, 2026

Summary

Refactors the JSON output format for all mcpc connect commands to return a unified array of ConnectResultEntry objects instead of nested structures with separate results, skipped, and discovered fields. This provides a consistent, flat schema that consumers can always treat as an array of session connection results.

Key Changes

  • New ConnectResultEntry type: Defines a unified structure that mirrors MCP's InitializeResult (protocolVersion, capabilities, serverInfo, instructions) extended with toolNames and an _mcpc metadata block containing session details, status, and error information.

  • New helper functions:

    • buildConnectResultEntry(): Connects to a session and builds a populated entry from its InitializeResult and tools list
    • buildBulkConnectEntries(): Processes bulk-connect results in parallel, fetching InitializeResult for successful entries and creating minimal entries for failures
  • Unified JSON output: All connect commands (connectSession, connectAllFromConfig, connectAllFromStandardConfigs) now output a flat array of ConnectResultEntry objects where:

    • Connected sessions have status 'created' or 'active' with full InitializeResult data
    • Failed sessions have status 'failed' with error details
    • Skipped entries have status 'skipped' with skipReason ('stdio' or 'duplicate')
  • Consistent error handling: Both human-readable and JSON modes now handle connection failures uniformly, with JSON mode emitting a failed entry instead of silent success.

  • Updated help text: Clarified documentation for server formats, auto-discovery locations, and JSON output schema to reflect the new array-based format.

Implementation Details

  • The _mcpc metadata block is always populated, while InitializeResult fields are conditionally included only for successful connections
  • Server config headers are redacted in the output for security
  • Bulk operations fetch InitializeResult data in parallel for efficiency
  • Failed entries during bulk operations are downgraded from 'created'/'active' to 'failed' if the bridge becomes unresponsive

https://claude.ai/code/session_01KAWhWQStTysF6nnemZe5Ev

claude and others added 3 commits April 28, 2026 22:55
…objects

The connect command previously emitted three different JSON shapes depending
on what was being connected:

  - Single server  → `{ protocolVersion, capabilities, serverInfo, ..., _mcpc }`
  - Config file    → `{ configFile, results: [...], skipped: [...] }`
  - Auto-discovery → `{ discovered, results, skipped }`

`mcpc help connect` only documented the single-server shape, leaving scripts
and AI agents to reverse-engineer the bulk shapes from source.

All three paths now emit an array of `InitializeResult` objects (extended
with `toolNames` and `_mcpc` metadata), one entry per session. Single-server
connects emit a one-element array; bulk connects emit one entry per session.
Failed and skipped entries carry their state in `_mcpc.status` (`created` |
`active` | `failed` | `skipped`) plus `_mcpc.skipReason` / `_mcpc.error`,
and the `_mcpc` block also includes `configFile` / `entry` for entries that
came from a config file. Bulk connects now fetch InitializeResult per
successful entry in parallel via the bridge.

The connect help text is also tightened: tighter prose in the session-name
and stdio-server sections, regrouped auto-discovery locations into
project/global/system/env-var, and an updated JSON-output line that shows
the new array shape and `_mcpc` keys.

https://claude.ai/code/session_01KAWhWQStTysF6nnemZe5Ev
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.

3 participants