Skip to content

feat: pin MCP client certificates and serve Streamable HTTP - #678

Open
toasterbook88 wants to merge 6 commits into
mainfrom
feat/mcpclient-tls-pin-and-http-serve
Open

toasterbook88 wants to merge 6 commits into
mainfrom
feat/mcpclient-tls-pin-and-http-serve

Conversation

@toasterbook88

@toasterbook88 toasterbook88 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • An MCP HTTP client can pin the peer leaf certificate with tls_cert_fingerprint and take its bearer token from bearer_token_env or bearer_token_file. Header values expand ${VAR} once, at connect time, and the config file is left unchanged.
  • axis mcp serve --transport http serves the existing MCP tools over Streamable HTTP. The default listen address is loopback port 42426. A non-loopback address requires --token-env.
  • A tool is called without confirmation only when its exact name is in auto_approve_tools.

Test plan

  • GitHub CI on this branch
  • A matching tls_cert_fingerprint accepts that self-signed leaf, and any other leaf is rejected
  • Unset or blank ${VAR}, bearer_token_env, and bearer_token_file fail closed and do not rewrite the stored headers
  • axis mcp serve --transport http answers Streamable HTTP on its loopback address

Devin Review

@testdriverai

testdriverai Bot commented Nov 22, 2026

Copy link
Copy Markdown

⏸️ 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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 5 potential issues.

3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread internal/mcp/http.go
// shutdown.
func newStreamableHTTP(cached bool, cacheAddr string, token string) (http.Handler, *mcpserver.StreamableHTTPServer) {
mcpSrv := NewServer(cached, cacheAddr, nil)
streamSrv := mcpserver.NewStreamableHTTPServer(mcpSrv)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +241 to +245
tr := &http.Transport{}
if defaults, ok := http.DefaultTransport.(*http.Transport); ok {
tr = defaults.Clone()
}
tr.TLSClientConfig = &tls.Config{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +205 to +206
if len(headers) > 0 {
opts = append(opts, transport.WithHTTPHeaders(headers))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread internal/mcp/http.go
Comment on lines +26 to +29
var endpoint http.Handler = streamSrv
if token != "" {
endpoint = bearerAuthMiddleware(token, streamSrv)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟥 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread internal/mcp/http.go
Comment on lines +95 to +104
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟥 Cleartext bearer tokens on network listeners

On a non-loopback bind, serveStreamableHTTPListener accepts bearer credentials over plain HTTP. A network observer can capture the token and reuse it to access diagnostics and reservation tools.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@toasterbook88 toasterbook88 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: true strictly paired with VerifyPeerCertificate + 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.

#678

@toasterbook88

Copy link
Copy Markdown
Owner Author

Read-only (Cursor, orchestration): confirms locked MCPServerConfig fields match what AxisMCP dev already emits via AxisConnectMacSnippets.axisNodesYAMLFragment / scripts/configure_axis_mcp.py (bearer_token_env, tls_cert_fingerprint with optional sha256:, auto_approve_tools allowlist). CI green at 154d8ff. No second PR. Field-name sync to m3-agy already filed by agy. Remaining AxisMCP TF gap is draft #248 (floor ≥319), not this PR.

This branch has not been deployed

No deployments
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.

2 participants