Repository navigation
feat: pin MCP client certificates and serve Streamable HTTP - #678
toasterbook88 wants to merge 6 commits into
Conversation
…reamable HTTP mcp serve
…able HTTP mcp serve
…coverage, spec sync)
|
⏸️ Skipped this review: 30/30 free PR reviews used this month for this organization. Reviews resume on December 1. Upgrade to review every pull request. |
There was a problem hiding this comment.
Devin Review found 5 potential issues.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| // shutdown. | ||
| func newStreamableHTTP(cached bool, cacheAddr string, token string) (http.Handler, *mcpserver.StreamableHTTPServer) { | ||
| mcpSrv := NewServer(cached, cacheAddr, nil) | ||
| streamSrv := mcpserver.NewStreamableHTTPServer(mcpSrv) |
There was a problem hiding this comment.
🔴 Abandoned MCP sessions accumulate indefinitely
When legacy clients disconnect without a successful DELETE, newStreamableHTTP leaves their sessions registered. The 30-second snapshot cache TTL limits reuse but never removes those entries. Memory grows with each abandoned session.
Learn more
The pinned mcp-go version registers a legacy session after POST initialize, even without a listening GET stream. Its default idle timeout is disabled, so losing the HTTP connection does not clean up the session. NewServer removes cached data only when the SDK unregisters that session. SessionCache checks whether a snapshot is fresh enough to reuse but never evicts expired entries.
Example: A client negotiates MCP 2025-03-26, calls cluster_snapshot, then exits before sending DELETE. The next client gets another session ID. Both sessions and their snapshot copies remain in memory after the cache TTL elapses.
Recommended fix: Configure a finite SDK session idle TTL and stop its sweeper on shutdown. Verify that expiry invokes the unregister hook and frees the snapshot cache entry even when a client never opens a listening stream.
Was this helpful? React with 👍 or 👎 to provide feedback.
| tr := &http.Transport{} | ||
| if defaults, ok := http.DefaultTransport.(*http.Transport); ok { | ||
| tr = defaults.Clone() | ||
| } | ||
| tr.TLSClientConfig = &tls.Config{ |
There was a problem hiding this comment.
🟡 Certificate pinning rejects HTTPS proxies
With an HTTPS proxy configured, NewHTTPClient checks the MCP server’s pin against the proxy’s certificate first. The connection fails before reaching the MCP server, even when its pin is correct.
Learn more
The default Go HTTP transport routes eligible hosts through ProxyFromEnvironment. Go 1.26.11 uses the transport's TLSClientConfig both for the outer TLS handshake to an HTTPS proxy and for the inner handshake after CONNECT. The pin callback here applies to both. runMCPClientTools surfaces the resulting handshake failure as a disconnected server.
Example: An operator pins mcp.example.com and sets HTTPS_PROXY=https://proxy.example.com. Axis rejects the proxy's certificate as a fingerprint mismatch and never contacts the pinned server.
Recommended fix: Keep ordinary certificate validation for the proxy and apply the leaf pin only inside its CONNECT tunnel. If encrypted proxies are unsupported in pinned mode, reject that configuration explicitly rather than reporting an endpoint pin mismatch.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if len(headers) > 0 { | ||
| opts = append(opts, transport.WithHTTPHeaders(headers)) |
There was a problem hiding this comment.
🟡 Legacy session close omits authentication
With a resolved bearer token, connectHTTP authenticates tool requests but not the legacy session’s closing DELETE. The server rejects the close, and the CLI exits without releasing the session.
Learn more
runMCPClientTools connects using the configured credentials and defers registry close. Registry.Close delegates to ServerConnection.Close. In mcp-go v1.5.0, StreamableHTTP.Close builds a legacy session DELETE directly instead of using the normal request path that adds WithHTTPHeaders. It closes the response body without checking the status. Modern stateless connections do not issue this DELETE and are unaffected.
Example: axis mcp client tools connects to a 2025-11-25 server that uses bearer_token_env and requires auth for DELETE. Tool discovery succeeds. On exit the server responds 401 to DELETE and retains the session until its own cleanup runs.
Recommended fix: Ensure session termination uses the same configured headers as other requests, either in the SDK or through a transport wrapper scoped to the configured origin. Keep the same-origin redirect policy and test an authenticated legacy session from initialization through close.
Was this helpful? React with 👍 or 👎 to provide feedback.
| var endpoint http.Handler = streamSrv | ||
| if token != "" { | ||
| endpoint = bearerAuthMiddleware(token, streamSrv) | ||
| } |
There was a problem hiding this comment.
🟥 Unauthenticated access to local MCP tools
Without --token-env, newStreamableHTTP lets any local account call the operator’s MCP tools. The lease tool writes to the operator’s private reservation ledger under the server’s account.
Was this helpful? React with 👍 or 👎 to provide feedback.
| func serveStreamableHTTPListener(ctx context.Context, ln net.Listener, cached bool, cacheAddr string, token string) error { | ||
| handler, streamSrv := newStreamableHTTP(cached, cacheAddr, token) | ||
| srv := &http.Server{ | ||
| Handler: handler, | ||
| ReadHeaderTimeout: 10 * time.Second, | ||
| } | ||
|
|
||
| errCh := make(chan error, 1) | ||
| go func() { | ||
| errCh <- srv.Serve(ln) |
There was a problem hiding this comment.
toasterbook88
left a comment
There was a problem hiding this comment.
AXIS Grok gate
Verdict: PASS-WITH-RISK
PR #678 feat: pin MCP client certificates and serve Streamable HTTP
Head: 154d8ff
Files: 12 (AGENTS.md, docs/current-state.md, docs/superpowers/specs/2026-11-22-mcpclient-tls-pin-and-http-serve-design.md, cmd/axis/mcp.go + tests, internal/config, internal/mcp/http.go, internal/mcpclient/connection.go, internal/agent/mcp_approval_test.go)
Invariant hits: none.
- Advisory/MCP surfaces remain subordinate to the fact plane; no override of observed state.
- HITL preserved: auto-approve only on exact tool name in
auto_approve_tools(regression tests pin this; server annotations ignored). - Cache path unchanged and still explicit (
--cached). - No secret_read, ssh_bypass, fleet_exec, spawn_subagent, self-authorize, or unattended config write. Secrets resolved at connect/serve time from env/file; config file left unchanged. Non-loopback HTTP bind refuses without token.
- Agent self-model stays advisory.
CI: all green (Test & Build success, govulncheck success, CodeQL success, Analyze success, Independent gates success). mergeable_state blocked.
Risks (non-blocking):
- New Streamable HTTP listen surface (default 127.0.0.1:42426; non-loopback requires
--token-env). mcp-go DNS-rebinding check left on. - TLS leaf pin uses
InsecureSkipVerify: truestrictly paired withVerifyPeerCertificate+ constant-time SHA-256 compare; tested against self-signed and mismatch. - Header
${VAR}expansion and bearer resolution fail closed on unset/blank; never mutates stored headers.
Recommended operator action: Merge after human review of the HTTP bind + token and TLS pin paths. No further gate work required on this SHA.
|
Read-only (Cursor, orchestration): confirms locked |
Summary
tls_cert_fingerprintand take its bearer token frombearer_token_envorbearer_token_file. Header values expand${VAR}once, at connect time, and the config file is left unchanged.axis mcp serve --transport httpserves the existing MCP tools over Streamable HTTP. The default listen address is loopback port 42426. A non-loopback address requires--token-env.auto_approve_tools.Test plan
tls_cert_fingerprintaccepts that self-signed leaf, and any other leaf is rejected${VAR},bearer_token_env, andbearer_token_filefail closed and do not rewrite the stored headersaxis mcp serve --transport httpanswers Streamable HTTP on its loopback address