Skip to main content

MCP server middleware for aiogram Telegram bots — expose your bot to AI agents via the Model Context Protocol

Project description

aiogram-mcp

CI Python 3.10+ License: MIT PyPI version

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:

  • stdio for Claude Desktop and local MCP clients
  • sse for remote HTTP-based MCP connections

Built-in Tools

Messaging:

  • send_message
  • send_photo
  • forward_message
  • delete_message
  • pin_message

Users:

  • get_bot_info
  • get_chat_member_info
  • get_user_profile_photos

Chats:

  • get_chat_info
  • get_chat_members_count
  • ban_user
  • unban_user
  • set_chat_title
  • set_chat_description

Broadcast:

  • broadcast when enable_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

Resources require MCPMiddleware to be attached for chat tracking and message history.

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 source
  • tests/ unit tests
  • examples/ runnable usage examples
  • .github/workflows/ci.yml GitHub 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

aiogram_mcp-0.2.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiogram_mcp-0.2.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file aiogram_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: aiogram_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiogram_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c58d12095690576081a4053bcd29598ac178833bc085b7b64477f009b389f2ce
MD5 d339a2d0177e17a0564f85b3e5401012
BLAKE2b-256 37dc4b2403c108b790c817417e2a398a90cd5b52518b2222a8ce6ea270acb021

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_mcp-0.2.0.tar.gz:

Publisher: publish.yml on Py2755/aiogram-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiogram_mcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aiogram_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiogram_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b464060dc7ae80edeb094ccf18a6a3879e58cc24b1c30aea9d0aff2046b6420
MD5 027099c6b4febe4ff1dc97f28dcdc4bb
BLAKE2b-256 53a9cc7c13fc713b32c9b75fb8371a9502e24e3cd7e25a4a2c0b91ffde91366b

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_mcp-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Py2755/aiogram-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page