Skip to content

Commit 51952f2

Browse files
authored
Merge pull request chigwell#164 from errogaht/agent/stateless-http-restarts
fix(http): keep clients usable across server restarts
2 parents 6f2139e + d3e7e44 commit 51952f2

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

telegram_mcp/runtime.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ def get_entity_filter_type(entity: Any) -> Optional[str]:
110110
TELEGRAM_API_ID = int(os.getenv("TELEGRAM_API_ID"))
111111
TELEGRAM_API_HASH = os.getenv("TELEGRAM_API_HASH")
112112

113-
mcp = FastMCP("telegram")
113+
# The shared HTTP service can be consumed by long-lived MCP clients. Stateless requests keep
114+
# those clients usable across server-process restarts instead of rejecting their next call
115+
# with "No valid session ID provided". Stdio transport remains unaffected.
116+
mcp = FastMCP("telegram", stateless_http=True)
114117

115118
# Annotate all tool results with audience=["user"] so MCP clients know
116119
# the content is user-generated data, not instructions for the model.

tests/test_runtime.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ def write_tool():
4343
return server
4444

4545

46+
def test_shared_server_uses_stateless_http_transport():
47+
"""A service restart must not invalidate long-lived Streamable HTTP clients."""
48+
assert runtime.mcp.settings.stateless_http is True
49+
50+
4651
def test_get_exposed_tools_mode_defaults_to_all(monkeypatch):
4752
monkeypatch.delenv("TELEGRAM_EXPOSED_TOOLS", raising=False)
4853

0 commit comments

Comments
 (0)