mcpproxy-go icon indicating copy to clipboard operation
mcpproxy-go copied to clipboard

[Feature]: Let enabled MCP servers sleep when idle (per-server timers, optional smart mode)

Open DScoNOIZ opened this issue 6 days ago • 1 comments

Problem / motivation

Hello. A quick note about who is writing: this text was prepared by an AI assistant following a human operator's instructions. The operator reviewed and approved the idea. I am trying to write it in plain words.

Imagine every MCP server is a lamp. Today MCPProxy keeps all enabled lamps on all the time. On my PC there are 21 servers; 19 of them are small Python/Node programs. Together they use about 2.4 GB of RAM. Most sit untouched for hours. It is like heating an empty house.

MCPProxy already has half of the answer: reconnect_on_use wakes a server when an agent calls it. The other half is missing — nothing puts it back to sleep. Every 30 seconds the supervisor sees "enabled but not connected" and connects it again (internal/runtime/supervisor/supervisor.go:352, :563-583). So switching a server off by hand does not stick.

You already did the traffic half of this job: #609 stopped idle polling, #1013 uses slow probes, #1910 avoids extra connections, and #1911 is the report saying the instance "never scales down and is billed the whole time". This request is the memory half of the same story.

Proposed solution

Add a third state: sleeping.

  • The server stays enabled and visible. Agents still see its tools.
  • Its process is stopped, so it uses no memory.
  • The first tool call wakes it. The agent waits a moment; the reconnect_on_use path already gives you that.
  • After N minutes without calls, it sleeps again.
  • N is set globally and per server. 0 means "never sleep", so today's setups do not change at all. Default off.

Optional second step — small "smart timers"

If it can stay simple, a tiny helper could adjust the timers by itself:

  • keep a short count of how often each server is called and when it was last used;
  • busy servers wait longer before sleeping, quiet ones sleep sooner;
  • if a server is used around the same time every day, keep it warm around that time;
  • a human can always overwrite any timer by hand.

Please keep it to counters and simple rules — a real learning model would be overkill and could surprise people. Log every sleep and wake so it is easy to see what happened.

Why this is not an exotic idea

Other tools already ship it:

  • https://github.com/askmegit/mcp-snooze — "starts your MCP server on the first tool call and stops it when idle", --idle 600
  • https://github.com/ni-c/mcp-hub — sleeps after 60 idle minutes, answers from a saved tool list, wake_server/sleep_server
  • https://github.com/elis132/mcp-ondemand — 10 minutes idle, per-server settings
  • Hermes MCP config has idle_timeout_seconds and max_lifetime_seconds: https://github.com/NousResearch/hermes-agent/blob/main/website/docs/reference/mcp-config-reference.md
  • Docker MCP Gateway starts a container on call and stops it after: https://docs.docker.com/ai/mcp-catalog-and-toolkit/mcp-gateway/
  • The MCP 2026-07-28 spec removes protocol-level sessions, which makes this easier: https://modelcontextprotocol.io/specification/2026-07-28/changelog

So I am not asking for something strange. I am asking for it inside the hub I already use.

Alternatives considered

  • enabled: false — saves memory, but the server disappears from the hub. Not what I want.
  • activity_* config keys — I checked the code, they are audit retention only, they do not stop processes.
  • A small proxy in front of each server — works, but duplicates what the hub already knows.

Where it could live (from reading your code, no patch attached)

Config field next to reconnect_on_use (internal/config/config.go:804); a "sleep" decision in the supervisor next to ActionConnect (supervisor.go:563-583); mark a server sleeping without unregistering it (internal/upstream/manager.go:111, manager_generation.go:364-375); Disconnect already exists at internal/upstream/managed/client.go:827. Wake on the next CallTool/ListTools. Keep the last good tool list so agents still see tools while the process is down, refresh on wake. Default off, so no behaviour changes for existing users.

Before submitting

  • [x] I searched issues, PRs and discussions for "lazy", "idle disconnect", "unload", "scale to zero". I found related work (#354, #363, #609, #1013, #1911) but no request for idle sleeping of an enabled server.

Edition: Both / not sure (I use Personal; Server users would benefit too).

DScoNOIZ avatar Nov 28 '26 21:11 DScoNOIZ

Thanks for the idea! A draft spec for the first step (a basic idle timer for stdio servers, off by default, global plus per-server idle_sleep_timeout, 0s = never) is up in #2137.

One finding from reading the code: reconnect_on_use does not give wake-on-call on the default routes today (call_tool_* and code_execution refuse a disconnected server first), so the spec adds a proper Sleeping state and a wake on every route. The "smart timers" step is left for later. Feedback on the spec is welcome.

Dumbris avatar Dec 03 '26 17:12 Dumbris