Skip to content

fix(http): keep clients usable across server restarts - #164

Merged
chigwell merged 3 commits into
chigwell:mainfrom
errogaht:agent/stateless-http-restarts
Jul 24, 2026
Merged

fix(http): keep clients usable across server restarts#164
chigwell merged 3 commits into
chigwell:mainfrom
errogaht:agent/stateless-http-restarts

Conversation

@errogaht

Copy link
Copy Markdown
Contributor

Problem

The shared Streamable HTTP server is intended for long-lived clients such as
Codex, Claude, and Cursor. With FastMCP's stateful HTTP sessions, those clients
retain an MCP session ID. After the Telegram MCP service restarts, the new
server process no longer knows that ID, so the client's next request can fail
with:

No valid session ID provided

The Telegram connection may be healthy at that point; the failure is in the
HTTP transport session left behind by the previous process. Users then have to
re-register or restart otherwise healthy MCP clients.

Change

Construct the shared FastMCP server with stateless_http=True.

Each Streamable HTTP request can then be handled after a process restart
without relying on an in-memory session created by the old process. Telegram
authentication and the long-lived Telethon client remain owned by the server
process as before.

This setting affects Streamable HTTP transport semantics only. The default
stdio flow remains unchanged.

Validation

  • Added a regression test asserting that the shared server is configured for
    stateless HTTP.
  • uv run pytest tests/test_runtime.py -q — 45 passed.
  • uv run pytest — 164 passed.
  • uv run black --check telegram_mcp/runtime.py tests/test_runtime.py
  • uv run flake8 telegram_mcp/runtime.py tests/test_runtime.py --count --select=E9,F63,F7,F82 --show-source --statistics
  • git diff --check
  • Restarted the shared HTTP service and verified both:
    • a fresh MCP connection could call get_me;
    • an already configured MCP client could call get_me after the restart.

@chigwell
chigwell merged commit 78923cc into chigwell:main Jul 24, 2026
4 checks passed
KiaroSama pushed a commit to KiaroSama/telegram-mcp that referenced this pull request Aug 25, 2026
…starts

fix(http): keep clients usable across server restarts
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