Sponsored by Deepsite.site

Telegram MCP Server

Created By
wolderufael8 months ago
Content

Telegram MCP Server

A powerful Telegram integration server that provides various tools for managing contacts, sending messages, and retrieving channel information through MCP (Multi-Client Protocol).

Features

  • Contact Management

    • Get list of contacts
    • Search contacts
    • Get last interactions
  • Messaging

    • Send messages to contacts by name or phone number
    • Get chat history with date range filtering
    • View last interactions
  • Channel Features

    • Get posts from channels
    • Search channels
    • View channel information
    • Filter posts by date range

Prerequisites

  • Python 3.8 or higher
  • Node.js 14 or higher (for npx installation)
  • Telegram API credentials (api_id and api_hash)
  • A Telegram account

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/telegram-MCP-server.git
cd telegram-MCP-server
  1. Install required dependencies:
uv venv .venv  # Create a virtual environment
source .venv/bin/activate  # Activate it (Linux/macOS)
.\venv\Scripts\activate  # Activate it (Windows)
uv pip install

  1. Create a .env file in the project root with your Telegram credentials:
TG_API_ID=your_api_id
TG_API_HASH=your_api_hash
phone=your_phone_number  # Format: +1234567890

Integration with Cursor/Claude Desktop

Copy the below json with the appropriate {{PATH}} values:

{
  "mcpServers": {
    "whatsapp": {
      "command": "{{PATH_TO_UV}}", // Run `which uv` and place the output here
      "args": [
        "--directory",
        "{{PATH_TO_SRC}}/whatsapp-mcp/whatsapp-mcp-server", // cd into the repo, run `pwd` and enter the output here + "/whatsapp-mcp-server"
        "run",
        "main.py"
      ]
    }
  }
}

For Claude, save this as claude_desktop_config.json in your Claude Desktop configuration directory at:

~/Library/Application Support/Claude/claude_desktop_config.json

For Cursor, save this as mcp.json in your Cursor configuration directory at:

~/.cursor/mcp.json

Tool Documentation

get_contacts()

Returns a list of all your Telegram contacts with their names, phone numbers, and usernames.

send_message_by_identifier(identifier: str, message: str)

Sends a message to a contact identified by either their name or phone number.

  • identifier: Contact's name or phone number
  • message: Text message to send

get_last_interaction(identifier: str)

Returns the most recent message exchanged with a specific contact.

  • identifier: Contact's name or phone number

get_chat_history(identifier: str, start_date: str = None, end_date: str = None, limit: int = 20)

Retrieves chat history with a contact within a specified timeframe.

  • identifier: Contact's name or phone number
  • start_date: Optional start date (YYYY-MM-DD)
  • end_date: Optional end date (YYYY-MM-DD)
  • limit: Maximum number of messages to return

get_channel_posts(channel_name: str, start_date: str = None, end_date: str = None, limit: int = 20)

Gets posts from a Telegram channel.

  • channel_name: Channel username or name
  • start_date: Optional start date (YYYY-MM-DD)
  • end_date: Optional end date (YYYY-MM-DD)
  • limit: Maximum number of posts to return

Error Handling

The server includes comprehensive error handling for:

  • Invalid credentials
  • Network issues
  • Rate limiting
  • Invalid parameters
  • Permission errors

Security Considerations

  • Store API credentials securely
  • Never share your .env file
  • Use environment variables in production
  • Implement rate limiting for production use
  • Monitor usage and implement logging

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • Telethon library for Telegram API integration
  • FastMCP for the server framework
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
CursorThe AI Code Editor
Playwright McpPlaywright MCP server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
DeepChatYour AI Partner on Desktop
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Serper MCP ServerA Serper MCP Server
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
WindsurfThe new purpose-built IDE to harness magic
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
ChatWiseThe second fastest AI chatbot™
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Amap Maps高德地图官方 MCP Server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code