Telegram MCP Server

by kfastov
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Handles configuration management through environment variables, specifically for storing Telegram API credentials including API ID, API hash, and phone number.

  • Enables interaction with Telegram messaging platform, providing tools to search channels by keywords, list available channels, retrieve messages from channels, and filter messages by regex patterns.

Telegram 클라이언트 라이브러리 및 MCP 서버

이 프로젝트는 AI 어시스턴트가 Telegram과 상호 작용할 수 있도록 Telegram 클라이언트 라이브러리와 MCP(Model Context Protocol) 서버를 모두 제공합니다.

특징

Telegram 클라이언트 라이브러리

  • Telegram을 통한 인증(2FA 지원 포함)
  • 세션 관리(기존 세션의 자동 재사용)
  • 채팅/대화 검색
  • 특정 채팅에서 메시지 가져오기
  • 패턴(예: 정규식)으로 메시지 필터링

MCP 서버

  • 키워드로 채널 검색 - 이름에 키워드를 검색하여 Telegram 채널을 찾으세요
  • 사용 가능한 채널 나열 - 액세스 가능한 모든 채널 보기
  • 채널에서 메시지 가져오기 - 액세스 가능한 모든 채널에서 메시지 검색
  • 패턴으로 메시지 필터링 - 정규식 패턴을 적용하여 메시지 필터링

설정

  1. Telegram API 자격 증명으로 .env 파일을 만듭니다.

지엑스피1

  1. 종속성 설치:
npm install

용법

Telegram 클라이언트 라이브러리 사용

const TelegramClient = require("./telegram-client"); const dotenv = require("dotenv"); dotenv.config(); async function main() { // Create a new client instance const client = new TelegramClient( process.env.TELEGRAM_API_ID, process.env.TELEGRAM_API_HASH, process.env.TELEGRAM_PHONE_NUMBER ); // Login to Telegram await client.login(); // Get all chats/dialogs const { chats } = await client.getDialogs(); // Print all chats chats.forEach((chat) => { if (chat.title) { console.log(`Chat: ${chat.title}`); } }); } main().catch(console.error);

예제 클라이언트를 실행합니다.

npm run client

MCP 서버 사용

  1. MCP 서버를 시작합니다.
npm start
  1. MCP 서버는 다음 위치에서 사용할 수 있습니다.
http://localhost:3000/mcp
  1. 포함된 클라이언트를 사용하여 MCP 서버를 테스트할 수 있습니다.
npm run mcp-client

MCP 서버에 대한 자세한 내용은 MCP-README.md를 참조하세요.
코드 아키텍처에 대한 자세한 내용은 CODE_STRUCTURE.md를 참조하세요.

API 참조

텔레그램클라이언트

건설자

const client = new TelegramClient(apiId, apiHash, phoneNumber, sessionPath);
  • apiId : Telegram API ID
  • apiHash : Telegram API 해시
  • phoneNumber : 국제 형식으로 된 귀하의 전화번호
  • sessionPath : (선택 사항) 세션 파일을 저장할 경로(기본값: './data/session.json')

행동 양식

  • login() : Telegram으로 인증합니다(새로운 로그인과 세션 재사용을 모두 처리합니다)
  • getDialogs(limit, offset) : 대화 상자(채팅) 목록을 가져옵니다.
  • getChatMessages(chat, limit) : 특정 채팅에서 메시지를 가져옵니다.
  • filterMessagesByPattern(messages, pattern) : 정규식 패턴으로 메시지 배열을 필터링합니다.
  • hasSession() : 유효한 세션이 존재하는지 확인합니다.

이 저장소의 파일

  • telegram-client.js : 주요 클라이언트 라이브러리
  • client.js : 추가 도우미 기능이 있는 클라이언트 예시
  • index.js : 클라이언트 라이브러리를 사용한 원본 예제
  • mcp-server.js : MCP 서버의 주요 진입점
  • telegram-mcp.js : Telegram 도구를 사용한 MCP 서버 구현
  • http-server.js : HTTP/SSE 서버 전송 계층
  • mcp-client-example.js : MCP 서버를 테스트하는 간단한 클라이언트

Claude 또는 기타 MCP 호환 어시스턴트와 함께 사용

MCP 서버는 Claude 또는 다른 MCP 호환 어시스턴트와 함께 사용할 수 있습니다. 연결되면 어시스턴트는 서버에서 제공하는 도구를 통해 Telegram 채널과 메시지에 접근할 수 있습니다.

워크플로 예시:

  1. MCP 서버를 시작합니다
  2. MCP URL을 사용하여 Claude를 MCP 서버에 연결합니다.
  3. Claude에게 채널 검색, 메시지 검색 또는 패턴별 메시지 필터링을 요청하세요.

특허

MIT

-
security - not tested
F
license - not found
-
quality - not tested

AI 어시스턴트가 Telegram과 상호 작용하여 채널을 검색하고, 사용 가능한 채널을 나열하고, 메시지를 검색하고, 정규식 패턴으로 메시지를 필터링할 수 있도록 하는 모델 컨텍스트 프로토콜 서버입니다.

  1. Features
    1. Telegram Client Library
    2. MCP Server
  2. Setup
    1. Usage
      1. Using the Telegram Client Library
      2. Using the MCP Server
    2. API Reference
      1. TelegramClient
    3. Files in this Repository
      1. Using with Claude or other MCP-compatible Assistants
        1. License
          ID: b91b7wxzlu