Skip to content

feat(mcp): add structured connection diagnostics - #2669

Merged
benjaminshafii merged 3 commits into
different-ai:devfrom
reachjalil:feature/mcp-connection-diagnostics
Jul 12, 2026
Merged

benjaminshafii merged 3 commits into
different-ai:devfrom
reachjalil:feature/mcp-connection-diagnostics

Conversation

@reachjalil

@reachjalil reachjalil commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

Important

Parent MCP diagnostics release: #2674

Parent integration status: Not integrated. Verified by Jalil: Not started.

This source PR remains the workspace for its focused fixes and evidence. After Jalil reviews and accepts this level, the verified change will be integrated into feature/mcp-diagnostics-release and the parent ledger will be updated. Because the parent branch intentionally exists only on Jalil's fork, GitHub cannot use it as the literal base of an upstream-repository PR; this PR therefore remains based on dev while pointing to the parent release tracker.

Before and after: structured errors

Before this PR Added by this PR Administrator/support outcome
A Den-managed MCP failure could collapse into a generic handshake or connection error such as fetch failed. A typed diagnostic model classifies configuration, DNS, TCP, TLS, HTTP routing, OAuth, MCP protocol, catalog, provider execution, continuity, and shutdown failures. The first failing source layer is named instead of leaving support to infer it.
Error responses did not provide a consistent support contract. Safe envelopes add a diagnostic reference, stable code, phase, highest passed health, retryability, action owner, and operator action. An administrator gets a safe explanation; support can correlate the reference with structured logs.
A provider permission failure, expired credential, protocol error, and transport success could be confused. Authentication, provider policy, MCP isError, throttling, and protocol outcomes are normalized separately. Reconnect advice is no longer used for every failure; the result points to the correct source and next action.
Callback and transport failures could expose inconsistent or overly technical text. Admin-visible messages are allowlisted and provider details are retained only as redacted structured evidence. Errors become useful without exposing tokens, query values, provider bodies, or tenant content.

Not added here: the persistent live timeline belongs to #2672, and the enterprise test server belongs to #2670. The standard Connect alert remains concise; it does not render every diagnostic field inline.

Intent

Make MCP connection failures diagnosable end to end. Operators should see the failing phase, a stable safe error code, retry guidance, and an actionable owner without exposing credentials, provider bodies, or tenant data.

What changed

Area Change
Diagnostic model Added phase-specific, typed MCP diagnostics covering configuration, DNS/TCP/TLS/HTTP, OAuth, transport, initialization, catalog, execution, continuity, and shutdown.
Den API Normalizes connection failures into safe envelopes with reference IDs, retryability, action owner, operator guidance, provider IDs, and hashed paths.
OAuth + transport Adds bounded discovery/token/resource errors, guarded redirects, HTTPS policy, response limits, stable timeouts, and post-token MCP validation.
Catalog + search Adds page/tool/schema/cursor/aggregate limits, bounded depth, duplicate/cycle checks, shared deadlines, concurrency limits, and hard top-20 pruning.
UI Renders safe actionable failures and callback states while handling rejected requests without leaking raw URLs or query values.

Security and correctness

  • Hosted connections require HTTPS; private-network mode is explicit, and browser HTTP remains loopback-only.
  • Redirects are validated at every hop, HTTPS downgrade is rejected, cross-origin bodies are not replayed, and sensitive headers are stripped across origins.
  • OAuth and MCP response bodies are capped before parsing; catalog aggregation and search fan-out have hard memory, concurrency, and wall-clock ceilings.
  • Diagnostic payloads exclude tokens, cookies, raw provider bodies, raw query strings, and unredacted paths.
  • Lifecycle deadlines are shared across the operation and abort active work; late workers cannot mutate returned results.

Reviewer focus

  • ee/apps/den-api/src/lib/mcp-connection-diagnostics.ts
  • ee/apps/den-api/src/lib/mcp-external-client.ts
  • OAuth callback and agent MCP route error normalization
  • MCP connection UI error and URL handling

Validation

  • Den API focused suite: 166 tests / 437 assertions
  • Web focused suite: 7 tests / 9 assertions
  • Independent adversarial review: 126 focused tests / 273 assertions, including canonical IPv6 SSRF probes, cross-origin header stripping, shared-deadline fan-out, and cross-realm oversized bodies
  • Den API and Den Web TypeScript checks
  • Den API and Den Web production builds
  • Fraimz proof: 3/3 frames passed, including cleanup and voiceover checks
  • git diff --check
  • ./bin/openwork-hub check mcp mcp-connection-diagnostics

This is the first of three independent MCP diagnostic PRs. The mock enterprise server and live tracing changes are intentionally separate; overlapping MCP client surfaces will need normal merge sequencing.

What an administrator sees after clicking Connect

This PR replaces the former generic “Failed to connect” outcome for Den-managed Connect with a safe, source-specific message. A failure before the provider authorization page is shown appears in the Den page alert and beneath the connection row in this form:

Could not connect “”: . Reference: .

For example, a refused or unreachable provider endpoint reads:

Could not connect “ServiceNow”: Den resolved the MCP host but could not establish a network connection. Reference: <reference>.

The safe explanation changes for DNS, TCP/network, TLS/certificate verification, endpoint routing, OAuth resource or issuer discovery, client registration, token exchange, provider consent, MCP version, catalog, and provider-operation failures. The API response also carries the structured phase, stable code, highestPassed, retryable, actionOwner, and operatorAction fields.

The ordinary Connect alert intentionally presents only the safe explanation and reference; it does not render the entire structured envelope. If failure occurs after the provider authorization tab opens, the callback page shows Connection failed, the same safe layer-specific explanation, and the diagnostic reference. The full phase timeline, highest proven health, first failure, owner, and remediation are presented by the separate Diagnose experience in #2672. Connect does not currently open Diagnose automatically.

@vercel

vercel Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-landing Ready Ready Preview, Comment, Open in v0 Jul 11, 2026 8:32pm

@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

@reachjalil is attempting to deploy a commit to the Different AI Team on Vercel.

A member of the Team first needs to authorize it.

@reachjalil

Copy link
Copy Markdown
Member Author

Agent integration rehearsal update — 2026-07-11

This source branch is published at 7b99407 and was exercised in the independent combined rehearsal, #2675.

The rehearsal confirmed and regression-tested the Level 1 fixes for callback origin, lifecycle and late-write fencing, stale post-token validation, owned 401 versus 403 failures, and structured provider tool-result errors.

Status remains deliberately separate:

This PR remains based on upstream dev because the controlled parent branch exists only on the Jalil fork. #2674 is the approval ledger; this PR is the source and evidence branch.

@benjaminshafii
benjaminshafii marked this pull request as ready for review July 12, 2026 18:31
@benjaminshafii
benjaminshafii merged commit b9499f9 into different-ai:dev Jul 12, 2026
9 checks passed

Copy link
Copy Markdown
Member

Validation update from the isolated MCP diagnostics pass:

  • Re-ran the exact structured-diagnostics compatibility suite: 52/52 passed.
  • Den API typecheck/build and the broader URL guard, redaction, OAuth, timeout, and agent error suites passed.
  • Verified the structured code/reference contract remains compatible in the cumulative end-to-end implementation.

This was the only PR merged during this pass. No follow-up merge or branch mutation was made here after the no-auto-merge instruction.

This branch was successfully deployed

1 active deployment
Preview – openwork-landing — 7b99407c Deployed Jul 11, 2026 by vercel[bot]
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