aiogram-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aiogram_mcp-0.1.0/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- aiogram_mcp-0.1.0/.github/ISSUE_TEMPLATE/config.yml +1 -0
- aiogram_mcp-0.1.0/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- aiogram_mcp-0.1.0/.github/pull_request_template.md +12 -0
- aiogram_mcp-0.1.0/.github/workflows/ci.yml +37 -0
- aiogram_mcp-0.1.0/.github/workflows/publish.yml +29 -0
- aiogram_mcp-0.1.0/.gitignore +10 -0
- aiogram_mcp-0.1.0/CHANGELOG.md +8 -0
- aiogram_mcp-0.1.0/CODE_OF_CONDUCT.md +23 -0
- aiogram_mcp-0.1.0/CONTRIBUTING.md +42 -0
- aiogram_mcp-0.1.0/LICENSE +21 -0
- aiogram_mcp-0.1.0/PKG-INFO +156 -0
- aiogram_mcp-0.1.0/README.md +123 -0
- aiogram_mcp-0.1.0/RELEASE.md +40 -0
- aiogram_mcp-0.1.0/SECURITY.md +17 -0
- aiogram_mcp-0.1.0/aiogram_mcp/__init__.py +16 -0
- aiogram_mcp-0.1.0/aiogram_mcp/context.py +22 -0
- aiogram_mcp-0.1.0/aiogram_mcp/middleware.py +33 -0
- aiogram_mcp-0.1.0/aiogram_mcp/py.typed +1 -0
- aiogram_mcp-0.1.0/aiogram_mcp/server.py +111 -0
- aiogram_mcp-0.1.0/aiogram_mcp/tools/__init__.py +1 -0
- aiogram_mcp-0.1.0/aiogram_mcp/tools/broadcast.py +96 -0
- aiogram_mcp-0.1.0/aiogram_mcp/tools/chats.py +123 -0
- aiogram_mcp-0.1.0/aiogram_mcp/tools/messaging.py +147 -0
- aiogram_mcp-0.1.0/aiogram_mcp/tools/users.py +84 -0
- aiogram_mcp-0.1.0/examples/basic_bot.py +50 -0
- aiogram_mcp-0.1.0/examples/incident_alert_bot.py +78 -0
- aiogram_mcp-0.1.0/pyproject.toml +73 -0
- aiogram_mcp-0.1.0/tests/test_core.py +931 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Report a defect or regression
|
|
4
|
+
title: "[Bug] "
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: ""
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Summary
|
|
10
|
+
|
|
11
|
+
Describe the bug clearly.
|
|
12
|
+
|
|
13
|
+
## Environment
|
|
14
|
+
|
|
15
|
+
- Python version:
|
|
16
|
+
- aiogram version:
|
|
17
|
+
- aiogram-mcp version:
|
|
18
|
+
- MCP client:
|
|
19
|
+
|
|
20
|
+
## Reproduction
|
|
21
|
+
|
|
22
|
+
1.
|
|
23
|
+
2.
|
|
24
|
+
3.
|
|
25
|
+
|
|
26
|
+
## Expected behavior
|
|
27
|
+
|
|
28
|
+
What should have happened?
|
|
29
|
+
|
|
30
|
+
## Actual behavior
|
|
31
|
+
|
|
32
|
+
What happened instead?
|
|
33
|
+
|
|
34
|
+
## Logs or traceback
|
|
35
|
+
|
|
36
|
+
```text
|
|
37
|
+
paste logs here
|
|
38
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
blank_issues_enabled: false
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest a capability or API improvement
|
|
4
|
+
title: "[Feature] "
|
|
5
|
+
labels: enhancement
|
|
6
|
+
assignees: ""
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Problem
|
|
10
|
+
|
|
11
|
+
What user or developer problem does this solve?
|
|
12
|
+
|
|
13
|
+
## Proposed solution
|
|
14
|
+
|
|
15
|
+
Describe the API or behavior you want.
|
|
16
|
+
|
|
17
|
+
## Alternatives considered
|
|
18
|
+
|
|
19
|
+
List any alternatives or workarounds.
|
|
20
|
+
|
|
21
|
+
## Additional context
|
|
22
|
+
|
|
23
|
+
Anything else maintainers should know.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
## Summary
|
|
2
|
+
|
|
3
|
+
Describe the change.
|
|
4
|
+
|
|
5
|
+
## Checklist
|
|
6
|
+
|
|
7
|
+
- [ ] I ran `ruff check aiogram_mcp tests examples`
|
|
8
|
+
- [ ] I ran `mypy aiogram_mcp`
|
|
9
|
+
- [ ] I ran `pytest -v`
|
|
10
|
+
- [ ] I updated tests if behavior changed
|
|
11
|
+
- [ ] I updated docs or examples if public behavior changed
|
|
12
|
+
- [ ] I updated `CHANGELOG.md` for user-visible changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install uv
|
|
25
|
+
uses: astral-sh/setup-uv@v3
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: uv pip install -e ".[dev]" --system
|
|
29
|
+
|
|
30
|
+
- name: Lint with ruff
|
|
31
|
+
run: ruff check aiogram_mcp tests examples
|
|
32
|
+
|
|
33
|
+
- name: Type check with mypy
|
|
34
|
+
run: mypy aiogram_mcp
|
|
35
|
+
|
|
36
|
+
- name: Run tests
|
|
37
|
+
run: pytest -v --tb=short
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Set up Python
|
|
18
|
+
uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
|
|
22
|
+
- name: Install build tooling
|
|
23
|
+
run: python -m pip install --upgrade build
|
|
24
|
+
|
|
25
|
+
- name: Build distributions
|
|
26
|
+
run: python -m build
|
|
27
|
+
|
|
28
|
+
- name: Publish to PyPI
|
|
29
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- Initial public package structure.
|
|
6
|
+
- Added MCP server core, middleware, tool registry, tests, and examples.
|
|
7
|
+
- Added GitHub workflows, issue templates, PR template, and release docs.
|
|
8
|
+
- Replaced the private-domain example with a generic incident alerting example.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Standard
|
|
4
|
+
|
|
5
|
+
This project expects respectful, direct, and professional collaboration.
|
|
6
|
+
|
|
7
|
+
Examples of acceptable behavior:
|
|
8
|
+
|
|
9
|
+
- giving constructive technical feedback
|
|
10
|
+
- assuming good intent
|
|
11
|
+
- keeping discussions focused on the code and product
|
|
12
|
+
|
|
13
|
+
Examples of unacceptable behavior:
|
|
14
|
+
|
|
15
|
+
- personal attacks
|
|
16
|
+
- harassment
|
|
17
|
+
- discriminatory language or behavior
|
|
18
|
+
- publishing private information without consent
|
|
19
|
+
|
|
20
|
+
## Enforcement
|
|
21
|
+
|
|
22
|
+
Project maintainers may remove comments, issues, pull requests, or contributors
|
|
23
|
+
that violate this code of conduct.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for contributing to `aiogram-mcp`.
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python -m venv .venv
|
|
9
|
+
. .venv/bin/activate
|
|
10
|
+
pip install -e ".[dev]"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
On Windows PowerShell:
|
|
14
|
+
|
|
15
|
+
```powershell
|
|
16
|
+
python -m venv .venv
|
|
17
|
+
.venv\Scripts\Activate.ps1
|
|
18
|
+
pip install -e ".[dev]"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Local Checks
|
|
22
|
+
|
|
23
|
+
Run these before opening a pull request:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
ruff check aiogram_mcp tests examples
|
|
27
|
+
mypy aiogram_mcp
|
|
28
|
+
pytest -v
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Pull Request Guidelines
|
|
32
|
+
|
|
33
|
+
- Keep PRs focused.
|
|
34
|
+
- Add or update tests when behavior changes.
|
|
35
|
+
- Update `README.md` when public APIs or examples change.
|
|
36
|
+
- Update `CHANGELOG.md` for user-visible changes.
|
|
37
|
+
|
|
38
|
+
## Release Expectations
|
|
39
|
+
|
|
40
|
+
- Public API changes should be documented.
|
|
41
|
+
- New MCP tools must have basic tests and safety notes.
|
|
42
|
+
- Examples should be generic and safe to publish.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Py2755
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aiogram-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server middleware for aiogram Telegram bots — expose your bot to AI agents via the Model Context Protocol
|
|
5
|
+
Project-URL: Homepage, https://github.com/Py2755/aiogram-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/Py2755/aiogram-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/Py2755/aiogram-mcp/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Py2755/aiogram-mcp/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Py2755
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai,aiogram,anthropic,bot,claude,mcp,model-context-protocol,telegram
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Framework :: AsyncIO
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Communications :: Chat
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: aiogram>=3.20.0
|
|
26
|
+
Requires-Dist: fastmcp>=2.0.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: mypy>=1.10.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# aiogram-mcp
|
|
35
|
+
|
|
36
|
+
[](https://github.com/Py2755/aiogram-mcp/actions/workflows/ci.yml)
|
|
37
|
+
[](https://www.python.org/downloads/)
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
[](https://pypi.org/project/aiogram-mcp/)
|
|
40
|
+
|
|
41
|
+
MCP server middleware for aiogram Telegram bots.
|
|
42
|
+
|
|
43
|
+
`aiogram-mcp` lets you expose an existing [aiogram](https://github.com/aiogram/aiogram) bot to [MCP](https://modelcontextprotocol.io/) clients such as Claude Desktop without rewriting handlers, routers, or business logic.
|
|
44
|
+
|
|
45
|
+
## Status
|
|
46
|
+
|
|
47
|
+
**Beta** — the core API is stable but may change before 1.0.
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install aiogram-mcp
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Requirements:
|
|
56
|
+
|
|
57
|
+
- Python 3.10+
|
|
58
|
+
- aiogram 3.20+
|
|
59
|
+
|
|
60
|
+
## Quickstart
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from aiogram import Bot, Dispatcher
|
|
64
|
+
from aiogram_mcp import AiogramMCP
|
|
65
|
+
|
|
66
|
+
bot = Bot(token="YOUR_BOT_TOKEN")
|
|
67
|
+
dp = Dispatcher()
|
|
68
|
+
|
|
69
|
+
# Register your normal handlers here.
|
|
70
|
+
|
|
71
|
+
mcp = AiogramMCP(bot=bot, dp=dp)
|
|
72
|
+
await mcp.run_alongside_bot(transport="stdio")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Available transports:
|
|
76
|
+
|
|
77
|
+
- `stdio` for Claude Desktop and local MCP clients
|
|
78
|
+
- `sse` for remote HTTP-based MCP connections
|
|
79
|
+
|
|
80
|
+
## Built-in Tools
|
|
81
|
+
|
|
82
|
+
Messaging:
|
|
83
|
+
|
|
84
|
+
- `send_message`
|
|
85
|
+
- `send_photo`
|
|
86
|
+
- `forward_message`
|
|
87
|
+
- `delete_message`
|
|
88
|
+
- `pin_message`
|
|
89
|
+
|
|
90
|
+
Users:
|
|
91
|
+
|
|
92
|
+
- `get_bot_info`
|
|
93
|
+
- `get_chat_member_info`
|
|
94
|
+
- `get_user_profile_photos`
|
|
95
|
+
|
|
96
|
+
Chats:
|
|
97
|
+
|
|
98
|
+
- `get_chat_info`
|
|
99
|
+
- `get_chat_members_count`
|
|
100
|
+
- `ban_user`
|
|
101
|
+
- `unban_user`
|
|
102
|
+
- `set_chat_title`
|
|
103
|
+
- `set_chat_description`
|
|
104
|
+
|
|
105
|
+
Broadcast:
|
|
106
|
+
|
|
107
|
+
- `broadcast` when `enable_broadcast=True`
|
|
108
|
+
|
|
109
|
+
## Safety Controls
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
mcp = AiogramMCP(
|
|
113
|
+
bot=bot,
|
|
114
|
+
dp=dp,
|
|
115
|
+
name="my-bot",
|
|
116
|
+
allowed_chat_ids=[123456789, -1001234567890],
|
|
117
|
+
enable_broadcast=True,
|
|
118
|
+
max_broadcast_recipients=500,
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Use `MCPMiddleware` to track recent chats and build recipient lists:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from aiogram_mcp import AiogramMCP, MCPMiddleware
|
|
126
|
+
|
|
127
|
+
tracker = MCPMiddleware()
|
|
128
|
+
dp.message.middleware(tracker)
|
|
129
|
+
|
|
130
|
+
mcp = AiogramMCP(bot=bot, dp=dp, enable_broadcast=True)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
pip install -e ".[dev]"
|
|
137
|
+
ruff check aiogram_mcp tests examples
|
|
138
|
+
mypy aiogram_mcp
|
|
139
|
+
pytest -v
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Project layout:
|
|
143
|
+
|
|
144
|
+
- `aiogram_mcp/` package source
|
|
145
|
+
- `tests/` unit tests
|
|
146
|
+
- `examples/` runnable usage examples
|
|
147
|
+
- `.github/workflows/ci.yml` GitHub Actions pipeline
|
|
148
|
+
|
|
149
|
+
## Examples
|
|
150
|
+
|
|
151
|
+
- [basic_bot.py](examples/basic_bot.py)
|
|
152
|
+
- [incident_alert_bot.py](examples/incident_alert_bot.py)
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# aiogram-mcp
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Py2755/aiogram-mcp/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://pypi.org/project/aiogram-mcp/)
|
|
7
|
+
|
|
8
|
+
MCP server middleware for aiogram Telegram bots.
|
|
9
|
+
|
|
10
|
+
`aiogram-mcp` lets you expose an existing [aiogram](https://github.com/aiogram/aiogram) bot to [MCP](https://modelcontextprotocol.io/) clients such as Claude Desktop without rewriting handlers, routers, or business logic.
|
|
11
|
+
|
|
12
|
+
## Status
|
|
13
|
+
|
|
14
|
+
**Beta** — the core API is stable but may change before 1.0.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install aiogram-mcp
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requirements:
|
|
23
|
+
|
|
24
|
+
- Python 3.10+
|
|
25
|
+
- aiogram 3.20+
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from aiogram import Bot, Dispatcher
|
|
31
|
+
from aiogram_mcp import AiogramMCP
|
|
32
|
+
|
|
33
|
+
bot = Bot(token="YOUR_BOT_TOKEN")
|
|
34
|
+
dp = Dispatcher()
|
|
35
|
+
|
|
36
|
+
# Register your normal handlers here.
|
|
37
|
+
|
|
38
|
+
mcp = AiogramMCP(bot=bot, dp=dp)
|
|
39
|
+
await mcp.run_alongside_bot(transport="stdio")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Available transports:
|
|
43
|
+
|
|
44
|
+
- `stdio` for Claude Desktop and local MCP clients
|
|
45
|
+
- `sse` for remote HTTP-based MCP connections
|
|
46
|
+
|
|
47
|
+
## Built-in Tools
|
|
48
|
+
|
|
49
|
+
Messaging:
|
|
50
|
+
|
|
51
|
+
- `send_message`
|
|
52
|
+
- `send_photo`
|
|
53
|
+
- `forward_message`
|
|
54
|
+
- `delete_message`
|
|
55
|
+
- `pin_message`
|
|
56
|
+
|
|
57
|
+
Users:
|
|
58
|
+
|
|
59
|
+
- `get_bot_info`
|
|
60
|
+
- `get_chat_member_info`
|
|
61
|
+
- `get_user_profile_photos`
|
|
62
|
+
|
|
63
|
+
Chats:
|
|
64
|
+
|
|
65
|
+
- `get_chat_info`
|
|
66
|
+
- `get_chat_members_count`
|
|
67
|
+
- `ban_user`
|
|
68
|
+
- `unban_user`
|
|
69
|
+
- `set_chat_title`
|
|
70
|
+
- `set_chat_description`
|
|
71
|
+
|
|
72
|
+
Broadcast:
|
|
73
|
+
|
|
74
|
+
- `broadcast` when `enable_broadcast=True`
|
|
75
|
+
|
|
76
|
+
## Safety Controls
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
mcp = AiogramMCP(
|
|
80
|
+
bot=bot,
|
|
81
|
+
dp=dp,
|
|
82
|
+
name="my-bot",
|
|
83
|
+
allowed_chat_ids=[123456789, -1001234567890],
|
|
84
|
+
enable_broadcast=True,
|
|
85
|
+
max_broadcast_recipients=500,
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Use `MCPMiddleware` to track recent chats and build recipient lists:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from aiogram_mcp import AiogramMCP, MCPMiddleware
|
|
93
|
+
|
|
94
|
+
tracker = MCPMiddleware()
|
|
95
|
+
dp.message.middleware(tracker)
|
|
96
|
+
|
|
97
|
+
mcp = AiogramMCP(bot=bot, dp=dp, enable_broadcast=True)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pip install -e ".[dev]"
|
|
104
|
+
ruff check aiogram_mcp tests examples
|
|
105
|
+
mypy aiogram_mcp
|
|
106
|
+
pytest -v
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Project layout:
|
|
110
|
+
|
|
111
|
+
- `aiogram_mcp/` package source
|
|
112
|
+
- `tests/` unit tests
|
|
113
|
+
- `examples/` runnable usage examples
|
|
114
|
+
- `.github/workflows/ci.yml` GitHub Actions pipeline
|
|
115
|
+
|
|
116
|
+
## Examples
|
|
117
|
+
|
|
118
|
+
- [basic_bot.py](examples/basic_bot.py)
|
|
119
|
+
- [incident_alert_bot.py](examples/incident_alert_bot.py)
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Release Process
|
|
2
|
+
|
|
3
|
+
## Before Tagging
|
|
4
|
+
|
|
5
|
+
1. Update `CHANGELOG.md`.
|
|
6
|
+
2. Run:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
ruff check aiogram_mcp tests examples
|
|
10
|
+
mypy aiogram_mcp
|
|
11
|
+
pytest -v
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
3. Verify at least one real bot can start with:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
python examples/basic_bot.py
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
4. Verify one MCP client can connect over the intended transport.
|
|
21
|
+
5. Confirm package metadata and README are current.
|
|
22
|
+
|
|
23
|
+
## Create a Release
|
|
24
|
+
|
|
25
|
+
1. Bump the version in `pyproject.toml`.
|
|
26
|
+
2. Commit the release changes.
|
|
27
|
+
3. Create and push a tag:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
git tag v0.1.0
|
|
31
|
+
git push origin v0.1.0
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
4. Confirm GitHub Actions completed successfully.
|
|
35
|
+
5. Publish GitHub release notes from the changelog.
|
|
36
|
+
|
|
37
|
+
## After Release
|
|
38
|
+
|
|
39
|
+
1. Smoke test the published package in a clean virtual environment.
|
|
40
|
+
2. Open a follow-up issue for anything deferred from the release.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
Do not open a public GitHub issue for security-sensitive problems.
|
|
6
|
+
|
|
7
|
+
Instead:
|
|
8
|
+
|
|
9
|
+
1. Report via [GitHub Security Advisories](https://github.com/Py2755/aiogram-mcp/security/advisories/new).
|
|
10
|
+
2. Include a clear reproduction or proof of concept.
|
|
11
|
+
3. Include impact, affected versions, and suggested mitigations if known.
|
|
12
|
+
|
|
13
|
+
We will respond within 7 days of your report.
|
|
14
|
+
|
|
15
|
+
## Supported Versions
|
|
16
|
+
|
|
17
|
+
Security fixes are expected for the latest release line only until the project has multiple maintained versions.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Public package exports for aiogram-mcp."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
6
|
+
|
|
7
|
+
from .context import BotContext
|
|
8
|
+
from .middleware import MCPMiddleware
|
|
9
|
+
from .server import AiogramMCP
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
__version__ = version("aiogram-mcp")
|
|
13
|
+
except PackageNotFoundError:
|
|
14
|
+
__version__ = "0.1.0"
|
|
15
|
+
|
|
16
|
+
__all__ = ["AiogramMCP", "BotContext", "MCPMiddleware", "__version__"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Shared runtime context for MCP tools."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from aiogram import Bot, Dispatcher
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(slots=True)
|
|
11
|
+
class BotContext:
|
|
12
|
+
"""Dependencies shared by all tool handlers."""
|
|
13
|
+
|
|
14
|
+
bot: Bot
|
|
15
|
+
dp: Dispatcher
|
|
16
|
+
allowed_chat_ids: list[int] | None = None
|
|
17
|
+
|
|
18
|
+
def is_chat_allowed(self, chat_id: int) -> bool:
|
|
19
|
+
"""Return whether the MCP server may act on a chat."""
|
|
20
|
+
if self.allowed_chat_ids is None:
|
|
21
|
+
return True
|
|
22
|
+
return chat_id in self.allowed_chat_ids
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Middleware utilities exposed by the package."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Awaitable, Callable
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from aiogram import BaseMiddleware
|
|
9
|
+
from aiogram.types import TelegramObject
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MCPMiddleware(BaseMiddleware):
|
|
13
|
+
"""Track active chats and users for later MCP-driven broadcasts."""
|
|
14
|
+
|
|
15
|
+
def __init__(self) -> None:
|
|
16
|
+
self.active_chat_ids: set[int] = set()
|
|
17
|
+
self.active_user_ids: set[int] = set()
|
|
18
|
+
|
|
19
|
+
async def __call__(
|
|
20
|
+
self,
|
|
21
|
+
handler: Callable[[TelegramObject, dict[str, Any]], Awaitable[Any]],
|
|
22
|
+
event: TelegramObject,
|
|
23
|
+
data: dict[str, Any],
|
|
24
|
+
) -> Any:
|
|
25
|
+
chat = getattr(event, "chat", None)
|
|
26
|
+
if chat is not None and getattr(chat, "id", None) is not None:
|
|
27
|
+
self.active_chat_ids.add(chat.id)
|
|
28
|
+
|
|
29
|
+
user = getattr(event, "from_user", None)
|
|
30
|
+
if user is not None and getattr(user, "id", None) is not None:
|
|
31
|
+
self.active_user_ids.add(user.id)
|
|
32
|
+
|
|
33
|
+
return await handler(event, data)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|