MCP server middleware for aiogram Telegram bots — expose your bot to AI agents via the Model Context Protocol
Project description
aiogram-mcp
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.
Status
Beta — the core API is stable but may change before 1.0.
Installation
pip install aiogram-mcp
Requirements:
- Python 3.10+
- aiogram 3.20+
Quickstart
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
Built-in Tools
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
Events:
subscribe_eventsunsubscribe_events
Broadcast:
broadcastwhenenable_broadcast=True
MCP Resources
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 |
telegram://events/queue |
Real-time event queue (requires EventManager) |
Resources require MCPMiddleware to be attached for chat tracking and message history.
MCP Prompts
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.
Real-time Event Streaming
AI agents can receive Telegram events in real time instead of polling:
| Component | Type | Description |
|---|---|---|
subscribe_events |
Tool | Subscribe to events with chat/type filters |
unsubscribe_events |
Tool | Remove a subscription by ID |
telegram://events/queue |
Resource | Read queued events with auto-incrementing IDs |
from aiogram_mcp import AiogramMCP, EventManager, MCPMiddleware
event_manager = EventManager()
middleware = MCPMiddleware(event_manager=event_manager)
dp.message.middleware(middleware)
mcp = AiogramMCP(
bot=bot, dp=dp,
middleware=middleware,
event_manager=event_manager,
)
When subscribed, AI clients receive MCP notifications/resources/updated on new events and can read the queue resource to get event data. Event types: message, command.
Safety Controls
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)
Development
pip install -e ".[dev]"
ruff check aiogram_mcp tests examples
mypy aiogram_mcp
pytest -v
Project layout:
aiogram_mcp/package sourcetests/unit testsexamples/runnable usage examples.github/workflows/ci.ymlGitHub Actions pipeline
Examples
License
MIT. See LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiogram_mcp-0.4.0.tar.gz.
File metadata
- Download URL: aiogram_mcp-0.4.0.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6625db850bfdb3f57e9fb5f3536e40181298654c073b206099b9ae60a8bab346
|
|
| MD5 |
2c10bec20a35a6b923e0c21289fef694
|
|
| BLAKE2b-256 |
63df8bac1acf5960a03490d3a0952d3d1600ea1cc1c42cdb80a2ce227a4cf7d4
|
Provenance
The following attestation bundles were made for aiogram_mcp-0.4.0.tar.gz:
Publisher:
publish.yml on Py2755/aiogram-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiogram_mcp-0.4.0.tar.gz -
Subject digest:
6625db850bfdb3f57e9fb5f3536e40181298654c073b206099b9ae60a8bab346 - Sigstore transparency entry: 1089077730
- Sigstore integration time:
-
Permalink:
Py2755/aiogram-mcp@a50d389a2083ec7d7af153bc9fc87ddb111f65c7 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/Py2755
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a50d389a2083ec7d7af153bc9fc87ddb111f65c7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aiogram_mcp-0.4.0-py3-none-any.whl.
File metadata
- Download URL: aiogram_mcp-0.4.0-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
696c961b4561a9a11f73b3a3df6f8257ede96f7ca96081e1c970cc10e8bdfbb9
|
|
| MD5 |
dfa034eb45923b4015febc77c3e9fc83
|
|
| BLAKE2b-256 |
554c02c8588040513c07b6832c0883a81306fb09bb0601bfcfeeee126f0e2b00
|
Provenance
The following attestation bundles were made for aiogram_mcp-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on Py2755/aiogram-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiogram_mcp-0.4.0-py3-none-any.whl -
Subject digest:
696c961b4561a9a11f73b3a3df6f8257ede96f7ca96081e1c970cc10e8bdfbb9 - Sigstore transparency entry: 1089077848
- Sigstore integration time:
-
Permalink:
Py2755/aiogram-mcp@a50d389a2083ec7d7af153bc9fc87ddb111f65c7 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/Py2755
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a50d389a2083ec7d7af153bc9fc87ddb111f65c7 -
Trigger Event:
push
-
Statement type: