Upstreaming four changes from our fork: per-server endpoints, non-expiring agent tokens, cheaper token-savings polls, health-check tolerance
Thanks for MCPProxy! I run 40 to 60 Claude Code sessions in parallel, and they kept signing each other out of remote MCP servers by racing on rotating refresh tokens. Putting MCPProxy in front of those servers fixed that: one process holds the tokens and refreshes them once for everyone. I wrote up the setup here: https://docspring.com/blog/posts/claude-code-mcp-oauth-reauthentication/
To make it work for my setup I made four changes in a fork (https://github.com/DocSpring/mcpproxy-go/tree/docspring/per-server-endpoints, three commits on top of f8b3c598). I'd like to offer them upstream, and wanted to ask which ones you'd be open to before opening PRs. Happy to rework any of them to fit how you'd rather do it.
1. Single-server endpoints: /mcp/s/<server>
Commit: https://github.com/DocSpring/mcpproxy-go/commit/b2c566a2fef071ce1875dd29035df0fbb98a21ab
Serves one upstream server per URL, with its own tool names (no server__ prefix) and its own instructions, as if the client had connected to that server directly. describe_tool is translated to the bare names too. It goes through the existing require_mcp_auth, agent-token server scoping, tool filters and quarantine, and a token that isn't allowed a server gets a 404 for it.
Why: Claude Code names tools mcp__<server>__<tool>, and our permission rules, skills and agent instructions all use those names. With retrieve_tools or the server__tool direct mode, every name changes. With one URL per server, a session sees exactly what it saw before, and only the sign-in moves into MCPProxy. Each server also stays a separate entry in the client that you can disable or reconnect on its own.
2. Agent tokens that never expire: token create --expires never
Commit: https://github.com/DocSpring/mcpproxy-go/commit/afba1be59d4c0fc010b2da42ce7a2496c4276546
Agent tokens are capped at 365 days. For a token that never leaves a single-user machine (stored in the macOS Keychain and read by Claude Code's headersHelper), an expiry only brings back a yearly sign-out across every session. Only an admin minting a token over REST or the CLI can pass never, and it's stored as a zero ExpiresAt, which agent tokens already treat as never expiring. The default stays 30 days, durations are still capped at 365 days, and the MCP create_token tool and client credentials keep their required expiry.
3. Token savings without a live tools/list on every poll
Commit: https://github.com/DocSpring/mcpproxy-go/commit/0dcca4af53aa63b413554dfba1c2a3bf554bf989
The tray app polls /api/v1/activity/usage about every 35 seconds, and CalculateTokenSavings called ListTools on every connected upstream for each poll, then tokenized every tool definition. With twelve upstreams that was about 1,000 upstream calls an hour, 3 to 7 seconds per poll, and minutes when the machine was busy. The change reads tool lists from the Supervisor's StateView and caches the tokenized estimate, keyed by each server's discovery epoch and tool count, so it only recounts when a server's tools change. The real retrieve_tools average is still applied on every call. The poll now takes about 2 ms.
4. Health checks that tolerate a loaded host
Same commit. The background health check gave each ping 5 seconds and marked a server failed after 3 slow pings. When I restart all my sessions at once, the machine is overloaded for a few minutes, every ping times out, and MCPProxy disconnected and reconnected every upstream while sessions were mid-request. Now a ping gets 15 seconds and a server needs 5 slow pings in a row. Refused connections and DNS failures still count straight away. These could be config options instead of constants if you'd prefer.
Which of these would you take? I can open separate PRs for the ones you're interested in, rebased onto current main.
Thank you for the write-up and for offering these upstream, @ndbroadbent.
Item 3 (token savings without a live tools/list on every poll) has landed in #1912, which is merged to main. The first commit there is your change from DocSpring/mcpproxy-go@0dcca4af, kept under your authorship, with the health-check part left out so it can be looked at on its own.
Two things changed on top of your commit:
- Cache key. Discovery epoch plus tool count stayed the same when a tool's description or schema was edited on the same connection (the epoch is the connection token, so a
tools/list_changedre-discovery keeps it). The key is now a digest of the tool definitions. - Removed servers. The StateView lags a removal commit, so a removed or same-name-replaced server could be counted for a moment. Those rows are now skipped.
The same bug was reported from the Web UI side in #1911, so your fix closes that one too.
I will reply separately on items 1, 2 and 4.
@ndbroadbent, here are the other three items. Each PR starts with your commit from the DocSpring fork under your authorship. I added follow-ups on top, then ran an independent cross-review on each.
- Item 1,
/mcp/s/<server>: #1916. Changes on top of your commit:- Admission: the endpoint now checks the caller's effective profile as well as the token allow-list. A pinned token, a client binding or the anonymous profile that doesn't reach the server gets the same 404.
- Instructions: forwarded only for an enabled, non-quarantined server. They are scanned for tool-poisoning patterns and capped at 8 KiB.
describe_tool: confined to that server.- Session ids: bound to the endpoint, so a session can't be replayed on another
/mcp/s/<other>. - Routing: the surface re-registers when a tool's tier or schema changes, even if the listing is byte-identical.
- Item 2,
--expires never: #1914. Only an admin can mint one, over REST or the CLI. The MCPcredentialstool and per-client credentials still need a capped expiry. These surfaces now show "Never expires" instead of "Expired":- Web UI
- CLI
- macOS tray
- the access explainer
- Item 4, health-check tolerance: #1913. The change is as you wrote it: 15s per probe and 5 consecutive timeouts. I added a test pinning that hard failures (connection refused, DNS, auth) still trip on the first miss.
Related: #1915 fixes #1910. Streamable-HTTP upstreams that advertise tools.listChanged now get a held GET stream, so their tool changes show up within seconds instead of at the next discovery poll.
Thanks again, this was a very useful set of patches.
All four items are now on main: item 1 in #1916, item 2 in #1914, item 3 in #1912, item 4 in #1913. Thanks again, @ndbroadbent.