Skip to content

feat: add reconnect_on_use for on-demand upstream reconnection - #363

Merged
Dumbris merged 4 commits into
mainfrom
fix/354-reconnect-on-use
Apr 2, 2026
Merged

Dumbris merged 4 commits into
mainfrom
fix/354-reconnect-on-use

Conversation

@Dumbris

@Dumbris Dumbris commented Apr 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds opt-in reconnect_on_use per-server config option that triggers a bounded synchronous reconnect attempt (15s timeout) when a tool call targets a disconnected upstream server
  • If reconnection succeeds, the tool call proceeds automatically; if it fails, the normal error is returned
  • Prevents reconnect storms via the existing reconnectInProgress mutex flag; concurrent callers wait for in-progress reconnect rather than spawning duplicates
  • Reconnection is skipped for user-logged-out, quarantined, disabled, or already-connecting servers

Changed files

File Change
internal/config/config.go New ReconnectOnUse field on ServerConfig
internal/upstream/managed/client.go New TryReconnectSync() and waitForReconnectCompletion() methods
internal/upstream/manager.go Reconnect-on-use logic in CallTool() with lock release during reconnect
docs/configuration.md Document new field in server config table
oas/swagger.yaml + oas/docs.go Regenerated OpenAPI spec

Test plan

  • Config field defaults to false (no behavior change for existing users)
  • Config field parses correctly from JSON (true/false/omitted)
  • Config field round-trips through JSON serialization
  • reconnect_on_use: false does not trigger reconnect on disconnected server
  • reconnect_on_use: true attempts reconnect when server is disconnected
  • Reconnect skipped when user has logged out (OAuth)
  • Reconnect skipped when server is quarantined
  • Reconnect skipped when server is already connecting
  • Reconnect skipped when server is disabled
  • Concurrent TryReconnectSync calls don't cause storms (5 goroutines)
  • TryReconnectSync respects context cancellation
  • All tests pass with -race flag
  • Full build succeeds

Fixes #354

🤖 Generated with Claude Code

claude added 2 commits April 2, 2026 06:32
When enabled per-server, tool calls targeting a disconnected upstream
will trigger a bounded immediate reconnect attempt (15s timeout)
before failing. If reconnection succeeds, the tool call is retried
automatically. This improves UX for intermittent servers like remote
devtools, SSH tunnels, and OAuth-backed services.

Key implementation details:
- New `reconnect_on_use` field in ServerConfig (opt-in, default false)
- New `TryReconnectSync()` method on managed.Client for synchronous
  reconnection (vs ForceReconnect which is async)
- Manager.CallTool() releases m.mu.RLock during reconnect to avoid
  blocking other operations
- Reconnect is skipped for user-logged-out, quarantined, or
  already-connecting servers
- Uses existing reconnectInProgress flag to prevent storms
- Concurrent callers wait for in-progress reconnect via polling

Fixes #354

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8764c38
Status: ✅  Deploy successful!
Preview URL: https://c4edf839.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-354-reconnect-on-use.mcpproxy-docs.pages.dev

View logs

claude added 2 commits April 2, 2026 06:51
The reconnect_on_use config field was only added to the config struct
and manager logic but was missing from the full persistence chain:
- REST API AddServerRequest and PatchServer handler
- BBolt storage (UpstreamRecord, Save/Get/List)
- Runtime server map for StateView
- Management service ListServers converter
- Contract types for API response
- CLI client AddServerRequest
- UpdateServer method in server.go

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/354-reconnect-on-use

Available Artifacts

  • archive-darwin-amd64 (25 MB)
  • archive-darwin-arm64 (23 MB)
  • archive-linux-amd64 (14 MB)
  • archive-linux-arm64 (13 MB)
  • archive-windows-amd64 (25 MB)
  • archive-windows-arm64 (22 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (19 MB)
  • installer-dmg-darwin-arm64 (17 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 23882900028 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit d98458b into main Apr 2, 2026
24 checks passed
@Dumbris
Dumbris deleted the fix/354-reconnect-on-use branch April 2, 2026 04:52
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.

Add optional on-demand reconnect when a tool is invoked for a disconnected upstream

2 participants