Aiogram MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
pip install aiogram-mcp
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add -e "BOT_TOKEN=${BOT_TOKEN}" aiogram-mcp -- python "<FULL_PATH_TO_AIOGRAM_MCP>/dist/index.js"

Replace <FULL_PATH_TO_AIOGRAM_MCP>/dist/index.js with the actual folder you prepared in step 1.

Required:BOT_TOKEN
README.md

Connect your Telegram bot to AI agents via the Model Context Protocol.

aiogram-mcp

Connect your Telegram bot to AI agents via the Model Context Protocol.

aiogram-mcp turns any aiogram bot into an MCP server. AI clients like Claude Desktop can then send messages, read chat history, build interactive menus, and react to events in real time — all through your existing bot, without rewriting a single handler.

Why aiogram-mcp?

Most Telegram MCP servers are thin wrappers with 3-5 tools. aiogram-mcp goes further:

  • 30 tools — messaging, rich media, moderation, interactive keyboards, event subscriptions, broadcasting
  • 7 resources — bot info, config, chat lists, message history, event queue, file metadata, audit log
  • 3 prompts — ready-made moderation, announcement, and user report workflows
  • Structured output — every tool returns typed Pydantic models with outputSchema for programmatic parsing
  • Real-time events — the bot pushes Telegram events to AI clients via MCP notifications (no polling)
  • Interactive messages — AI agents create inline keyboard menus, handle button presses, edit messages
  • Rate limiting — built-in token bucket prevents Telegram 429 errors
  • Permission levels — restrict AI agents to read-only, messaging, moderation, or full admin access
  • Audit logging — track every tool invocation with timestamps and arguments
  • Zero rewrite — add 5 lines to your existing bot, keep all your handlers

How It Works

Telegram users                Your aiogram bot              AI agent (Claude Desktop)
      |                             |                              |
      |  send messages, tap buttons |                              |
      | --------------------------> |                              |
      |                             |  MCP server (stdio or SSE)   |
      |                             | <------------------------->  |
      |                             |  tools / resources / events  |
      |                             |                              |
      |  bot replies, shows menus   |   send_message, edit, ban    |
      | <-------------------------- | <--------------------------- |

The bot runs normally for Telegram users. The MCP server runs alongside it, giving AI agents access to the same bot via tools and resources.

Installation

pip install aiogram-mcp

Requires Python 3.10+ and aiogram 3.20+.

Quickstart

1. Add aiogram-mcp to your bot

import asyncio
from aiogram import Bot, Dispatcher
from aiogram_mcp import AiogramMCP, EventManager, MCPMiddleware

bot = Bot(token="YOUR_BOT_TOKEN")
dp = Dispatcher()

# Middleware tracks chats, users, message history, and events
event_manager = EventManager()
middleware = MCPMiddleware(event_manager=event_manager)
dp.message.middleware(middleware)
dp.callback_query.middleware(middleware)  # for interactive buttons

# Register your normal handlers here
# @dp.message(...)
# async def my_handler(message): ...

# Create the MCP server
mcp = AiogramMCP(
    bot=bot,
    dp=dp,
    name="my-bot",
    middleware=middleware,
    event_manager=event_manager,
    allowed_chat_ids=[123456789],  # optional: restrict which chats AI can access
)

async def main():
    await mcp.run_alongside_bot(transport="stdio")

asyncio.run(main())

2. Connect Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "my-telegram-bot": {
      "command": "python",
      "args": ["path/to/your/bot.py"],
      "env": {
        "BOT_TOKEN": "123456:ABC-DEF..."
      }
    }
  }
}

Now Claude can send messages, read history, create button menus, and react to events in your Telegram bot.

Built-in Tools

Messaging (5 tools)

Tool Description
send_message Send text with HTML/Markdown formatting
send_photo Send a photo by URL with optional caption
forward_message Forward a message between chats
delete_message Delete a message
pin_message Pin a message in a chat

Interactive Messages (3 tools)

Tool Description
send_interactive_message Send a message with inline keyboard buttons (callback or URL)
edit_message Edit text and/or keyboard of an existing message
answer_callback_query Respond to a button press with a toas

Tools (8)

send_messageSend text with HTML/Markdown formatting
send_photoSend a photo by URL with optional caption
forward_messageForward a message between chats
delete_messageDelete a message
pin_messagePin a message in a chat
send_interactive_messageSend a message with inline keyboard buttons
edit_messageEdit text and/or keyboard of an existing message
answer_callback_queryRespond to a button press with a toast

Environment Variables

BOT_TOKENrequiredThe Telegram Bot API token provided by BotFather

Configuration

claude_desktop_config.json
{"mcpServers": {"my-telegram-bot": {"command": "python", "args": ["path/to/your/bot.py"], "env": {"BOT_TOKEN": "123456:ABC-DEF..."}}}}

Try it

Send a welcome message to the group chat with ID 123456789.
Create an interactive menu for users to select their preferred support topic.
Pin the latest announcement message in the main channel.
Edit the previous message to update the status of the current task.

Frequently Asked Questions

What are the key features of Aiogram MCP?

30 tools for messaging, rich media, moderation, and interactive keyboards. 7 resources including chat lists, message history, and audit logs. Real-time event streaming from Telegram to AI clients. Built-in rate limiting to prevent Telegram 429 errors. Permission levels for read-only, messaging, or admin access.

What can I use Aiogram MCP for?

Automating customer support responses directly within Telegram. Building AI-driven interactive menus and workflows for bot users. Monitoring and moderating Telegram group activity via AI agents. Broadcasting announcements and managing pinned messages programmatically.

How do I install Aiogram MCP?

Install Aiogram MCP by running: pip install aiogram-mcp

What MCP clients work with Aiogram MCP?

Aiogram MCP works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Aiogram MCP docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare