mcp-server.js: MCP HTTP server built with@modelcontextprotocol/sdk, registering the Telegram tools (listChannels,searchChannels,getChannelMessages,scheduleMessageSync,listMessageSyncJobs).telegram-client.js: Domain logic for MTProto login, dialog traversal, and message helpers.client.js: Example CLI harness for manual testing without the MCP layer.message-sync-service.js: Background worker that archives messages into a local SQLite database.- Store location: OS app-data dir (tgcli store; override with
TGCLI_STORE); keep runtime artifacts out of version control. - Documentation lives in
README.mdandLIBRARY.md; configuration relies on environment variables and the tgcli store.
npm install: Restore dependencies wheneverpackage-lock.jsonchanges.npm start: Boot the MCP server onhttp://localhost:8080/mcpusing Streamable HTTP transport; first run drives the Telegram login flow.node client.js: Run the sample script to exercise the client API and inspect dialog listings.npm run build: Currently a no-op placeholder—extend it only if a transpile/bundle step is introduced.npm test: Placeholder that echoes a notice; replace with real checks once tests exist.
- Use ES modules with semicolons, two-space indentation, and
camelCaseidentifiers. - Keep tool names descriptive and aligned with Telegram operations (
listChannels,searchChannels, etc.). - Emit log lines that explain side effects (login state, MTProto calls, sync progress) and reference chat IDs/titles.
- Keep message sync queue strictly sequential; jobs transition through
pending → in_progress → idleand may move toerrorif retries are needed. - Store secrets in
.env; never hard-code API credentials or session paths in commits.
- Add coverage when extending
telegram-client.jsormessage-sync-service.jsby mocking MTProto responses to validate session reuse and message archiving. - Name new test files
<module>.test.jsundertests/or co-locate in__tests__/; makenpm testexecute them. - Before pushing, run your test suite and a smoke
npm startto verify authentication prompts and cache initialization remain intact.
- Follow Conventional Commits (
type: subject) as seen indocs(readme): add detailed login guide...; use lowercase types for routine changes andfix:for bug patches. - Keep commits atomic; include body details when altering session management or cache persistence.
- PR descriptions should summarize intent, list manual verification (commands run, Telegram scenarios exercised), link related issues, and attach console excerpts when tool output changes.
- Confirm no sensitive credentials or runtime artifacts from the tgcli store are committed before requesting review.
- On startup, read
backlog.mdand pull tasks from it. - Thoroughly verify implemented functionality (tests, smoke runs, manual checks).
- Commit verified features before starting the next task.