Repository navigation
Add an MCP initialize readiness check - #6374
Conversation
Expose a protocol-level preflight for Agent harnesses and CI. The check performs only transport setup and the MCP initialize handshake, then reports negotiated metadata without enumerating or invoking capabilities. Signed-off-by: XD <[email protected]>
Keep mcp check flags isolated from sibling commands and route text and JSON results through Cobra output writers. Add real initialize-only and CLI regression coverage, then regenerate the command documentation. Signed-off-by: XD <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6374 +/- ##
==========================================
+ Coverage 82.40% 82.43% +0.03%
==========================================
Files 937 937
Lines 95821 95847 +26
==========================================
+ Hits 78962 79014 +52
+ Misses 16854 16828 -26
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
rdimitrov
left a comment
There was a problem hiding this comment.
Thanks for this, the shape is right: Connect and its callers are untouched, the new flags are local to check, and JSON on stdout is clean enough to pipe into jq.
I built the branch and ran thv mcp check against:
- Real workloads, by name and by URL: a stdio server behind the streamable proxy, the same server behind the SSE proxy, and a native streamable-http server. All reported
readywith the right transport. After 5 back-to-back checks,thv mcp liststill worked against the stdio backend, so the cached-initialize path from #6153 holds up. With the backend container paused, the check failed correctly (by name and by URL). - Local test servers: one with no capabilities, an SSE-only server, a stateless server (negotiated
2026-07-28), and a server that returns 405 on DELETE. All passed. Servers returning 401, returning 503, hanging, or not listening all failed with exit 1.
Two things need fixing before this works as a CI gate. Details are inline.
In auto mode the readiness check collapsed every failure into one generic message, hiding whether a server rejected credentials (fix config) or was not ready yet (retry). Keep each transport attempt's error so the cause reaches the user. A failed session-teardown DELETE also marked a server that completed the initialize handshake as not ready, and in auto mode triggered a pointless SSE fallback. Readiness now depends only on the handshake; close failures are logged at WARN, matching the other thv mcp commands. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
rdimitrov
left a comment
There was a problem hiding this comment.
Both findings are fixed in c08744c. I re-ran the same local servers against the rebuilt branch:
- In auto mode, the error now names each transport and its real cause: 401, 503
backend not ready, connection refused, andcontext deadline exceededfor the hanging server. - When the server resets the connection on the closing DELETE, the check reports
ready(exit 0) in both auto and explicitstreamable-httpmode. The close error is logged as a WARN on stderr, so--format json | jqstill parses.
Both new tests fail against the previous client.go and pass with -race -count=5, so they would catch a regression. LGTM once CI is green.
Summary
Agent harnesses and CI need a protocol-level readiness signal, but
thv mcp listperforms capability enumeration after initialize and is unsuitable for servers that intentionally expose no tools, resources, or prompts. A lightweight preflight should validate the MCP session handshake itself.thv mcp checkwithauto, SSE, and streamable HTTP transport support.initialize, and connection close.Type of change
Test plan
task -t Taskfile.focused.yml test, using the repository's-raceand linker settings for./pkg/mcp/clientand./cmd/thv/app)task test-e2e)task lint-fix)Regenerated all CLI, Swagger, and Helm documentation with
task docs, then verified the CLI documentation byte-for-byte against a freshgo run cmd/help/main.gooutput directory.API Compatibility
v1beta1API.Changes
pkg/mcp/client/client.goProbeAPI that returns initialize metadata and the selected transport without enumerating capabilities.pkg/mcp/client/client_test.gocmd/thv/app/mcp_check.gocmd/thv/app/mcp_check_test.gocmd/thv/app/mcp.godocs/cli/thv_mcp_check.mddocs/cli/thv_mcp.mdDoes this introduce a user-facing change?
Yes. Users can now use
thv mcp check --server ... --format jsonas an MCP-native readiness gate for CI, GitOps, and Agent harnesses.Special notes for reviewers
The new probe intentionally does not call
tools/list,resources/list,prompts/list, or any tool. ExistingConnectcallers retain their behavior and API.