Commit Graph
6 Commits
Author SHA1 Message Date
Ethan 016df8cbab feat(coderd/x/chatd/mcpclient): add hardened connect path for inline MCP servers (#29518)
Third PR in the inline MCP servers stack, on top of
https://github.com/coder/coder/pull/29517. This adds the `mcpclient`
side that chatd will use to talk to servers a chat owner declared by
value on the chat. Nothing in chatd calls the new functions yet.

`mcpclient` now owns its input type. `ConnectAll` and the new
`ConnectInline` both take `[]mcpclient.Server`, and `ServerFromConfig`
converts an org-configured row at the boundary, so a caller never has to
fake a `database.MCPServerConfig` for a server that has no row. The org
path behaves as before with two exceptions: `connectAllWithHooks` no
longer skips disabled servers (the call site in `generation_preparer.go`
filters them), and a `custom_headers` row with malformed JSON or an
unknown auth type used to connect without those headers, whereas now
conversion fails and the caller skips the server with a warning.

Org-configured servers were set up by an admin, so we don't put many
limits on them. Inline ones are supplied by whoever created the chat, so
`ConnectInline` treats the server as untrusted. HTTP response bodies are
capped at 1 MiB, a server can expose at most 64 tools with each
definition under 64 KiB and 256 KiB in total, and tool results are
capped at 256 KiB. If a server blows the tool caps we skip the whole
server rather than hand the model a partial tool set, and an oversized
result comes back to the model as a tool error rather than being
truncated silently. Everything the server sends that we log or hand to
the model (tool names, descriptions, schemas, results, connect errors)
has the values in `Server.SensitiveValues` replaced with `[REDACTED]`;
chatd sets that to the URL and header values. Header names aren't
redacted, as they're public and short enough that redacting them would
rewrite ordinary text. For the same reason the redactor ignores anything
shorter than `MinSensitiveValueBytes` (8), and #29546 rejects header
values that short at the API. The slug is caller-supplied too, so it
also goes through the redactor wherever it lands in a tool name, connect
summary or log field.

`AppendInline` merges the resulting tools into an existing tool list
with the existing names winning, so an inline server can't shadow a
builtin or org-configured tool. Collisions are logged once per server
with the `config_id`.

Lastly, every `tools/call` (for both kinds of server) now carries the
model's tool call ID in `_meta` under `com.coder/tool_call_id`. It's a
correlation ID that's stable across chatd retries of the same call, so a
server can use it to dedupe if it wants to. We make no other idempotency
promise.


Part of CODAGT-1131
2026-09-25 18:51:54 +10:00
Thomas Kosiewski 60cc826f2b feat: sign forwarded MCP identity headers (#29669) 2026-09-22 11:11:08 +02:00
Michael Suchacz d6b67e8e31 feat: enforce SSRF protection for MCP config-directed traffic (#28242)
Routes all MCP config-directed traffic from coderd and chatd through a
shared SSRF-protected HTTP client, now that organization admins, not
only deployment admins, control MCP server URLs (#27942 and its stack
below).

## Summary

- Uses the [`coder/safedial`](https://github.com/coder/safedial)
library: it blocks private and special-purpose destinations at dial time
(validating resolved addresses at connection time so DNS rebinding
cannot bypass the check) and rejects cross-origin redirects.
- Covers the complete traffic surface: OAuth2 discovery, dynamic client
registration, code exchange, token refresh, revocation, and runtime MCP
connections from chatd.
- Deployments that intentionally host internal MCP servers opt in via
the new `--mcp-allowed-private-cidrs`
(`CODER_MCP_ALLOWED_PRIVATE_CIDRS`) option.
- Includes the deployment configuration surface, generated docs, CLI
goldens, TypeScript types, and regression coverage for each traffic
path.

## Merge window

This protection originally lived inside #27942 and was split out to keep
that diff reviewable. Until this PR lands, the stack below ships with
only main's existing discovery IP-range guard
(`CODER_MCP_OAUTH2_DISCOVERY_ALLOWED_IP_RANGES`), while org admins can
already point MCP configs at arbitrary URLs. This PR should merge
promptly after the stack below it.

Top of the MCP org-separation stack (CODAGT-711 -> CODAGT-717 audit ->
CODAGT-712 ACLs -> CODAGT-806 token RBAC -> CODAGT-714 org picker ->
this PR).

> Mux (AI agent) authored this PR on Mike's behalf.

<!-- mux-attribution: model=claude-fable-5 thinking=high -->
2026-08-30 13:09:17 +02:00
Michael Suchacz 5cc2f2c103 feat: add MCP connect and generation-prep observability (#28402)
## Stack context

Follow-up to the MCP connect-stall incident (chats on dev.coder.com
stalled ~15 min/turn while a configured MCP server black-holed
requests). The stack: #28400 makes the 10s MCP connect budget actually
hold; this PR makes connect and preparation slowness observable so the
next incident shows up in logs and the chat debug UI instead of as a
silent timeline gap.

## Why

During the incident, each stalled turn looked like a silent gap before
the first debug step: no per-server connect durations anywhere, no
warning that preparation was slow, and the only signal was a generic
"connection failure" log without timing.

## Changes

- `mcpclient.ConnectAll` now returns per-server `ConnectSummary` values
(config ID, slug, outcome `connected`/`timeout`/`error`/`no_tools`,
duration, tool count, redacted error). Failure logs include the
duration, and successful connects slower than 5s log a `slow MCP server
connect` warning.
- Connect summaries are seeded into the chat debug run summary under an
`mcp_connect` key (seeded keys survive `FinalizeRun`'s aggregation), and
the debug panel's run card renders them as a per-server list with
outcome badges, durations, tool counts, and errors.
- `prepareGeneration` logs a `slow generation preparation` warning when
a turn's preparation exceeds 30s.

## Tests

- Go: connect summary assertions added to the budget tests
(outcome/duration/tool count for black-holed vs healthy servers); `go
test ./coderd/x/chatd/...` green.
- Frontend: new `coerceRunSummary` unit tests for `mcp_connect` coercion
(malformed entries dropped, non-array ignored) and a
`RunWithMCPConnectSummary` story whose play function expands the run and
asserts the rendered outcomes, durations, tool counts, and error text.
`pnpm check`, `lint:types`, unit and storybook projects green.

> 🤖 Mux authored this PR on Mike's behalf.

<!-- mux-attribution: model=anthropic:claude-opus-4-6 thinking=high -->
2026-08-27 10:22:33 +02:00
Michael Suchacz e92fd8e96f chore: retire mark3labs/mcp-go dependency (#28061)
## Stack Context

PR 6 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

With every production surface migrated, this PR removes the mark3labs
dependency entirely and converts the remaining test fixtures.

- Migrates the remaining mark3labs test fixtures (coderd MCP e2e tests,
chatd fixtures, mcpclient fixtures, and the Force On MCP policy tests)
to official stateless SDK servers.
- Removes `github.com/mark3labs/mcp-go` from `go.mod` and drops the
corresponding dependabot ignore entry. Zero references remain repo-wide.
- Updates the MCP docs for the 2026-07-28 protocol: stateless Streamable
HTTP behavior, the supported 2024-11-05 through 2026-07-28 protocol
range, and explicit non-features (resources, prompts, structured output,
elicitation, MCP Tasks).
- The e2e ping assertion is removed because MCP 2026-07-28 removed the
ping method.

> Mux created this PR on Mike's behalf.
2026-08-13 10:47:14 +00:00
Kyle Carberry b0b07536fc feat: add opt-in Coder identity headers for MCP servers (#25153) 2026-05-12 08:54:53 -04:00