mcp telegram
A bridge allowing Claude Desktop to access Telegram chats and messages via the Model Context Protocol, providing read-only capabilities to retrieve dialogs and messages from Telegram.
A bridge allowing Claude Desktop to access Telegram chats and messages via the Model Context Protocol, providing read-only capabilities to retrieve dialogs and messages from Telegram.
The server is a bridge between the Telegram API and the AI assistants and is based on the Model Context Protocol.
[!IMPORTANT] Ensure that you have read and understood the Telegram API Terms of Service before using this server. Any misuse of the Telegram API may result in the suspension of your account.
The Model Context Protocol (MCP) is a system that lets AI apps, like Claude Desktop, connect to external tools and data sources. It gives a clear and safe way for AI assistants to work with local services and APIs while keeping the user in control.
As of not, the server provides read-only access to the Telegram API.
uv tool install git+https://github.com/sparfenyuk/mcp-telegram
[!NOTE] If you have already installed the server, you can update it using
uv tool upgrade --reinstall
command.[!NOTE] If you want to delete the server, use the
uv tool uninstall mcp-telegram
command.
Before you can use the server, you need to connect to the Telegram API.
mcp-telegram sign-in --api-id <your-api-id> --api-hash <your-api-hash> --phone-number <your-phone-number>
Enter the code you received from Telegram to connect to the API.
The password may be required if you have two-factor authentication enabled.
[!NOTE] To log out from the Telegram API, use the
mcp-telegram logout
command.
Configure Claude Desktop to recognize the Exa MCP server.
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%Claudeclaude_desktop_config.json
Note: You can also find claude_desktop_config.json inside the settings of Claude Desktop app
Add the server configuration
{
"mcpServers": {
"mcp-telegram": {
"command": "mcp-server",
"env": {
"TELEGRAM_API_ID": "<your-api-id>",
"TELEGRAM_API_HASH": "<your-api-hash>",
},
}
}
}
}
Before working with Telegram’s API, you need to get your own API ID and hash:
uv sync
uv run mcp-telegram --help
Tools can be added to the src/mcp_telegram/tools.py
file.
How to add a new tool:
class NewTool(ToolArgs):
"""Description of the new tool."""
pass
Attributes of the class will be used as arguments for the tool. The class docstring will be used as the tool description.
@tool_runner.register
async def new_tool(args: NewTool) -> t.Sequence[TextContent | ImageContent | EmbeddedResource]:
pass
The function should return a sequence of TextContent, ImageContent or EmbeddedResource. The function should be async and accept a single argument of the new class.
Validation can accomplished either through Claude Desktop or by running the tool directly.
To run the tool directly, use the following command:
# List all available tools
uv run cli.py list-tools
# Run the concrete tool
uv run cli.py call-tool --name ListDialogs --arguments '{"unread": true}'
The MCP inspector is a tool that helps to debug the server using fancy UI. To run it, use the following command:
npx @modelcontextprotocol/inspector uv run mcp-telegram
[!WARNING] Do not forget to define Environment Variables TELEGRAM_API_ID and TELEGRAM_API_HASH in the inspector.
If you see the message 'Could not connect to MCP server mcp-telegram' in Claude Desktop, it means that the server configuration is incorrect.
Try the following:
uv
binary in the configuration file[
{
"description": "List available dialogs, chats and channels.",
"inputSchema": {
"description": "List available dialogs, chats and channels.",
"properties": {
"archived": {
"default": false,
"title": "Archived",
"type": "boolean"
},
"ignore_pinned": {
"default": false,
"title": "Ignore Pinned",
"type": "boolean"
},
"unread": {
"default": false,
"title": "Unread",
"type": "boolean"
}
},
"title": "ListDialogs",
"type": "object"
},
"name": "ListDialogs"
},
{
"description": " List messages in a given dialog, chat or channel. The messages are listed in order from newest to oldest. If `unread` is set to `true`, only unread messages will be listed. Once a message is read, it will not be listed again. If `limit` is set, only the last `limit` messages will be listed. If `unread` is set, the limit will be the minimum between the unread messages and the limit. ",
"inputSchema": {
"description": "List messages in a given dialog, chat or channel. The messages are listed in order from newest to oldest. If `unread` is set to `true`, only unread messages will be listed. Once a message is read, it will not be listed again. If `limit` is set, only the last `limit` messages will be listed. If `unread` is set, the limit will be the minimum between the unread messages and the limit.",
"properties": {
"dialog_id": {
"title": "Dialog Id",
"type": "integer"
},
"limit": {
"default": 100,
"title": "Limit",
"type": "integer"
},
"unread": {
"default": false,
"title": "Unread",
"type": "boolean"
}
},
"required": [
"dialog_id"
],
"title": "ListMessages",
"type": "object"
},
"name": "ListMessages"
}
]