MCP server middleware for aiogram Telegram bots.
aiogram-mcp lets you expose an existing aiogram bot to MCP clients such as Claude Desktop without rewriting handlers, routers, or business logic.
Beta — the core API is stable but may change before 1.0.
pip install aiogram-mcpRequirements:
- Python 3.10+
- aiogram 3.20+
from aiogram import Bot, Dispatcher
from aiogram_mcp import AiogramMCP
bot = Bot(token="YOUR_BOT_TOKEN")
dp = Dispatcher()
# Register your normal handlers here.
mcp = AiogramMCP(bot=bot, dp=dp)
await mcp.run_alongside_bot(transport="stdio")Available transports:
stdiofor Claude Desktop and local MCP clientsssefor remote HTTP-based MCP connections
Messaging:
send_messagesend_photoforward_messagedelete_messagepin_message
Users:
get_bot_infoget_chat_member_infoget_user_profile_photos
Chats:
get_chat_infoget_chat_members_countban_userunban_userset_chat_titleset_chat_description
Broadcast:
broadcastwhenenable_broadcast=True
Read-only data exposed to AI agents without tool calls:
| URI | Description |
|---|---|
telegram://bot/info |
Bot metadata (username, capabilities) |
telegram://config |
Server configuration and allowed chat IDs |
telegram://chats |
Active chats the bot has seen (requires middleware) |
telegram://chats/{chat_id}/history |
Recent message history for a chat |
Resources require MCPMiddleware to be attached for chat tracking and message history.
Ready-made workflows that give AI agents structured context instead of raw tools:
| Prompt | Arguments | Description |
|---|---|---|
moderation_prompt |
chat_id, user_id, reason |
Review user behavior with message history and suggest moderation action |
announcement_prompt |
topic, audience?, tone? |
Draft a Telegram announcement with formatting guidelines |
user_report_prompt |
chat_id, user_id |
Compile a comprehensive user activity report |
Prompts that access chat data require MCPMiddleware for message history and allowed_chat_ids for access control.
mcp = AiogramMCP(
bot=bot,
dp=dp,
name="my-bot",
allowed_chat_ids=[123456789, -1001234567890],
enable_broadcast=True,
max_broadcast_recipients=500,
)Use MCPMiddleware to track chats, users, and message history for MCP resources:
from aiogram_mcp import AiogramMCP, MCPMiddleware
tracker = MCPMiddleware(history_size=50)
dp.message.middleware(tracker)
mcp = AiogramMCP(bot=bot, dp=dp, middleware=tracker, enable_broadcast=True)pip install -e ".[dev]"
ruff check aiogram_mcp tests examples
mypy aiogram_mcp
pytest -vProject layout:
aiogram_mcp/package sourcetests/unit testsexamples/runnable usage examples.github/workflows/ci.ymlGitHub Actions pipeline
MIT. See LICENSE.