feat(coderd/x/chatd/mcpclient): migrate external MCP client to official Go SDK by ibetitsmike · Pull Request #28058 · coder/coder · GitHub
Skip to content

feat(coderd/x/chatd/mcpclient): migrate external MCP client to official Go SDK - #28058

Merged
ibetitsmike merged 1 commit into
mainfrom
mike/mcp-go-sdk/chatd-client
Aug 13, 2026
Merged

feat(coderd/x/chatd/mcpclient): migrate external MCP client to official Go SDK#28058
ibetitsmike merged 1 commit into
mainfrom
mike/mcp-go-sdk/chatd-client

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Stack Context

PR 3 of 6 in a stack that migrates every Coder MCP surface from the archived github.com/mark3labs/mcp-go library to the official github.com/modelcontextprotocol/go-sdk v1.7.0.

Stack: #28056 -> #28057 -> #28058 -> #28059 -> #28060 -> #28061

Why

The chatd external MCP client (admin-configured MCP servers used by Agent chat) now holds *mcp.ClientSession connections created via mcp.NewClient and Client.Connect, with StreamableClientTransport or SSEClientTransport per server config.

  • Auth and identity headers are injected through a custom http.RoundTripper because the official SDK has no per-header transport options.
  • Tool input schemas are extracted from the SDK's map[string]any decoding.
  • Content conversion handles the official pointer content types; the SDK decodes blob resources into raw bytes, so binary content is handled without an extra base64 round trip.
  • Test fixtures are official stateless Streamable HTTP servers.

Mux created this PR on Mike's behalf.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6255ea7720

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +29 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Do not re-add credentials on cross-origin redirects

When an authenticated MCP endpoint returns a redirect to another origin, net/http removes sensitive headers, but the redirected request passes through this wrapper again and these lines restore every configured header. This can disclose OAuth bearer tokens, API keys, custom secrets, and forwarded Coder identity headers to the redirect target; notably, RevokeOAuth2Token already installs an explicit redirect guard to prevent the same class of leak. Restrict header injection to the configured MCP origin or reject cross-origin redirects.

Useful? React with 👍 / 👎.

@ibetitsmike
ibetitsmike force-pushed the mike/mcp-go-sdk/chatd-client branch from 6255ea7 to 77e3912 Compare August 13, 2026 09:50
Base automatically changed from mike/mcp-go-sdk/cli-stdio-server to main August 13, 2026 10:02
…al Go SDK

Replace the mark3labs client with the official SDK client for chatd's
external MCP server connections. All four auth modes (oauth2,
api_key, custom_headers, user_oidc) now inject headers through an
http.RoundTripper on the transport's HTTPClient instead of per-header
transport options; header keys still pass through http.Header.Set so
case-insensitive collisions stay deterministic.

The SDK negotiates the protocol version internally (2026-07-28 down
to 2024-11-05), so older external servers keep working. Tool name
prefixing, allow/deny filtering, model-intent wrapping, and content
conversion are behavior-identical; the SDK decodes base64 image,
audio, and blob payloads during unmarshal, so the manual decode
paths are gone.
ibetitsmike added a commit that referenced this pull request Aug 13, 2026
## Stack Context

PR 2 of 6 in a stack that migrates every Coder MCP surface from the
archived `github.com/mark3labs/mcp-go` library to the official
`github.com/modelcontextprotocol/go-sdk` v1.7.0.

Stack: #28056 -> #28057 -> #28058 -> #28059 -> #28060 -> #28061

## Why

`coder exp mcp server` (stdio) now uses the official SDK server with
`mcp.IOTransport` over the invocation's stdin/stdout, and reuses the
shared `coderd/mcp.RegisterSDKTool` helper from PR #28056 so both
servers register tools identically.

- A `nopWriteCloser` prevents the SDK from closing the invocation's
stdout.
- Tests send spec-compliant initialize params and
`notifications/initialized` before `tools/list` because the official SDK
enforces the protocol lifecycle.

> Mux created this PR on Mike's behalf.
@ibetitsmike
ibetitsmike force-pushed the mike/mcp-go-sdk/chatd-client branch from 77e3912 to ad75b38 Compare August 13, 2026 10:02
@ibetitsmike
ibetitsmike merged commit 1e546ea into main Aug 13, 2026
24 checks passed
@ibetitsmike
ibetitsmike deleted the mike/mcp-go-sdk/chatd-client branch August 13, 2026 10:11
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants