telegram-mcp/scripts/smoke.py
2026-11-05 14:26:28 +03:00

32 lines
1.3 KiB
Python

"""Offline real stdio handshake. Does not call Telegram or require a login."""
import asyncio
import json
from pathlib import Path
import sys
import tempfile
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
ROOT = Path(__file__).resolve().parents[1]
async def main():
with tempfile.TemporaryDirectory(prefix="telegram-mcp-smoke-") as state:
params = StdioServerParameters(command=sys.executable,
args=[str(ROOT / "mcp_server" / "server.py")], env={"TG_MCP_STATE_DIR": state})
async with stdio_client(params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools = (await session.list_tools()).tools
assert len(tools) == 61, len(tools)
result = await session.call_tool("telegram_send_reply", {
"account": "main", "chat": "me", "text": "offline preview"})
assert not result.isError
data = json.loads(result.content[0].text)
assert data["data"]["dry_run"] is True
assert not list(Path(state).iterdir()), "Offline check touched account state"
print("PASS: 61 tool schemas; stdio initialize/list_tools/call_tool; offline preview")
if __name__ == "__main__":
asyncio.run(main())