managebac-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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Acharya Sukarth
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,180 @@
1
+ Metadata-Version: 2.4
2
+ Name: managebac-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server that gives AI assistants read-only access to ManageBac: classes, tasks, calendar, files, grades, CAS and more.
5
+ Keywords: managebac,mcp,model-context-protocol,ib,school,claude,ai
6
+ Author: Acharya Sukarth
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: End Users/Desktop
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Education
18
+ Requires-Dist: beautifulsoup4>=4.12
19
+ Requires-Dist: httpx>=0.27
20
+ Requires-Dist: keyring>=25.0
21
+ Requires-Dist: mcp>=2.3,<3
22
+ Requires-Dist: openpyxl>=3.1
23
+ Requires-Dist: pypdf>=5.0
24
+ Requires-Dist: python-docx>=1.1
25
+ Requires-Dist: python-pptx>=1.0
26
+ Requires-Dist: tzdata ; sys_platform == 'win32'
27
+ Requires-Python: >=3.11
28
+ Project-URL: Homepage, https://github.com/Sukarth/managebac-mcp
29
+ Project-URL: Repository, https://github.com/Sukarth/managebac-mcp
30
+ Project-URL: Issues, https://github.com/Sukarth/managebac-mcp/issues
31
+ Project-URL: Changelog, https://github.com/Sukarth/managebac-mcp/blob/main/CHANGELOG.md
32
+ Description-Content-Type: text/markdown
33
+
34
+ <p align="center">
35
+ <img src="assets/logo.svg" alt="" width="112" height="112">
36
+ </p>
37
+
38
+ <h1 align="center">ManageBac MCP</h1>
39
+
40
+ <p align="center">
41
+ <b>Let your AI assistant read ManageBac for you.</b>
42
+ <br>
43
+ Deadlines, tasks, calendar, class files, grades, CAS, EE and TOK, straight inside Claude, Cursor, VS Code and any other MCP client.
44
+ <br>
45
+ Read-only. Your password never reaches the AI.
46
+ </p>
47
+
48
+ <p align="center">
49
+ <a href="https://pypi.org/project/managebac-mcp/"><img src="https://img.shields.io/pypi/v/managebac-mcp?color=2563eb&label=pypi" alt="PyPI"></a>
50
+ <a href="https://pypi.org/project/managebac-mcp/"><img src="https://img.shields.io/pypi/pyversions/managebac-mcp?color=7c3aed" alt="Python versions"></a>
51
+ <a href="https://github.com/Sukarth/managebac-mcp/actions/workflows/ci.yml"><img src="https://github.com/Sukarth/managebac-mcp/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
52
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License"></a>
53
+ <a href="https://modelcontextprotocol.io"><img src="https://img.shields.io/badge/MCP-compatible-black" alt="MCP compatible"></a>
54
+ </p>
55
+
56
+ <p align="center">
57
+ <a href="#install">Install</a> ·
58
+ <a href="#what-you-can-ask">Examples</a> ·
59
+ <a href="docs/tools.md">All tools</a> ·
60
+ <a href="docs/configuration.md">Configuration</a> ·
61
+ <a href="docs/troubleshooting.md">Troubleshooting</a>
62
+ </p>
63
+
64
+ ---
65
+
66
+ ## What you can ask
67
+
68
+ > *"What's due this week, and which of it haven't I submitted?"*
69
+ >
70
+ > *"Summarise the IA checklist my chemistry teacher uploaded."*
71
+ >
72
+ > *"Which tasks are overdue? Draft a plan to catch up before Friday."*
73
+ >
74
+ > *"How many CAS hours do I have per strand, and which experiences still need reflections?"*
75
+ >
76
+ > *"Any new notifications from my teachers?"*
77
+
78
+ The assistant calls ManageBac on your behalf, reads what it needs, and answers in plain language.
79
+
80
+ ## Install
81
+
82
+ You need [uv](https://docs.astral.sh/uv/getting-started/installation/) (one command to install) and a ManageBac account that signs in with email and password.
83
+
84
+ **1. Save your login once** (stored in your system keychain: macOS Keychain, Windows Credential Manager or Linux Secret Service):
85
+
86
+ ```bash
87
+ uvx managebac-mcp login
88
+ ```
89
+
90
+ **2. Add the server to your AI app:**
91
+
92
+ <details open>
93
+ <summary><b>Claude Desktop</b></summary>
94
+
95
+ Settings → Developer → Edit Config, then add:
96
+
97
+ ```json
98
+ {
99
+ "mcpServers": {
100
+ "managebac": {
101
+ "command": "uvx",
102
+ "args": ["managebac-mcp"]
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ Restart Claude Desktop.
109
+ </details>
110
+
111
+ <details>
112
+ <summary><b>Claude Code</b></summary>
113
+
114
+ ```bash
115
+ claude mcp add managebac -- uvx managebac-mcp
116
+ ```
117
+ </details>
118
+
119
+ <details>
120
+ <summary><b>Cursor / Windsurf / VS Code / others</b></summary>
121
+
122
+ Use the same `command` and `args` as above in the client's MCP settings:
123
+
124
+ - **Cursor:** `~/.cursor/mcp.json` (same JSON as Claude Desktop)
125
+ - **VS Code:** `.vscode/mcp.json` → `{"servers": {"managebac": {"command": "uvx", "args": ["managebac-mcp"]}}}`
126
+ - **Windsurf:** `~/.codeium/windsurf/mcp_config.json` (same JSON as Claude Desktop)
127
+
128
+ More clients and options: [docs/configuration.md](docs/configuration.md).
129
+ </details>
130
+
131
+ > [!TIP]
132
+ > Skipped step 1? Just ask the assistant to connect ManageBac. It opens a private sign-in page on your computer, so you never type your password into the chat.
133
+
134
+ ## What it can do
135
+
136
+ | Area | What you get |
137
+ |---|---|
138
+ | **Tasks & deadlines** | Upcoming, past and overdue tasks with exact due times, status, grades and your submitted files |
139
+ | **Calendar** | Everything in a date range: tasks, deadlines, events, IB year-group dates |
140
+ | **Classes** | Your classes, teachers (with email), classmates, recent activity, units of study |
141
+ | **Files** | Browse class files and read PDFs, Word, PowerPoint and Excel files as text, or save them to your computer |
142
+ | **Grades** | Assessed tasks, category weights and completion stats per class |
143
+ | **Notifications** | Unread and recent messages, full text on demand |
144
+ | **IB** | CAS experiences, strands, hours and outcomes; Extended Essay and TOK status, prompts and documents |
145
+ | **Everything else** | Global search, discussions, groups, timetable, profile, and a safe reader for any other ManageBac page |
146
+
147
+ 28 tools in total. See the [full tool reference](docs/tools.md).
148
+
149
+ ## Privacy & safety
150
+
151
+ - **Read-only.** The server never submits, edits, deletes, joins or marks anything on ManageBac.
152
+ - **Your password stays on your computer.** It lives in your OS keychain (or environment variables if you prefer) and is only ever sent to your school's ManageBac site.
153
+ - **No third parties.** Nothing is sent anywhere except ManageBac and Faria's own notification service. No analytics.
154
+ - **You're in control.** Run `uvx managebac-mcp logout` to delete the saved login at any time.
155
+
156
+ Your AI client does see the ManageBac data the assistant reads (that's the point), so use a client you trust. More in [SECURITY.md](SECURITY.md).
157
+
158
+ ## How it works
159
+
160
+ ManageBac has no public API for students, so this server signs in like your browser does and reads the same pages and data feeds the website uses. Calendar items and notifications come from ManageBac's JSON feeds. Everything else is read from the web pages and turned into tidy, structured data for the assistant.
161
+
162
+ Technical details, architecture and how to contribute: [DEVELOPMENT.md](DEVELOPMENT.md) and [CONTRIBUTING.md](CONTRIBUTING.md).
163
+
164
+ ## Limitations
165
+
166
+ - Schools that only allow **Google or Microsoft single sign-on** aren't supported yet (see [troubleshooting](docs/troubleshooting.md)).
167
+ - Built and tested with **student** accounts in the IB Diploma Programme. Other programmes mostly work. Parent and teacher accounts aren't supported yet.
168
+ - If ManageBac redesigns a page, a tool may return less detail until the parser is updated. Please [open an issue](https://github.com/Sukarth/managebac-mcp/issues).
169
+
170
+ ## Disclaimer
171
+
172
+ This is an independent open-source project. It is not affiliated with, endorsed by, or supported by ManageBac or Faria Education Group. Use it with your own account and in line with your school's policies.
173
+
174
+ ## License
175
+
176
+ MIT. See [LICENSE](LICENSE).
177
+
178
+ ---
179
+
180
+ <p align="center">Built with ❤️ by <a href="https://github.com/Sukarth">Sukarth</a></p>
@@ -0,0 +1,147 @@
1
+ <p align="center">
2
+ <img src="assets/logo.svg" alt="" width="112" height="112">
3
+ </p>
4
+
5
+ <h1 align="center">ManageBac MCP</h1>
6
+
7
+ <p align="center">
8
+ <b>Let your AI assistant read ManageBac for you.</b>
9
+ <br>
10
+ Deadlines, tasks, calendar, class files, grades, CAS, EE and TOK, straight inside Claude, Cursor, VS Code and any other MCP client.
11
+ <br>
12
+ Read-only. Your password never reaches the AI.
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://pypi.org/project/managebac-mcp/"><img src="https://img.shields.io/pypi/v/managebac-mcp?color=2563eb&label=pypi" alt="PyPI"></a>
17
+ <a href="https://pypi.org/project/managebac-mcp/"><img src="https://img.shields.io/pypi/pyversions/managebac-mcp?color=7c3aed" alt="Python versions"></a>
18
+ <a href="https://github.com/Sukarth/managebac-mcp/actions/workflows/ci.yml"><img src="https://github.com/Sukarth/managebac-mcp/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
19
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License"></a>
20
+ <a href="https://modelcontextprotocol.io"><img src="https://img.shields.io/badge/MCP-compatible-black" alt="MCP compatible"></a>
21
+ </p>
22
+
23
+ <p align="center">
24
+ <a href="#install">Install</a> ·
25
+ <a href="#what-you-can-ask">Examples</a> ·
26
+ <a href="docs/tools.md">All tools</a> ·
27
+ <a href="docs/configuration.md">Configuration</a> ·
28
+ <a href="docs/troubleshooting.md">Troubleshooting</a>
29
+ </p>
30
+
31
+ ---
32
+
33
+ ## What you can ask
34
+
35
+ > *"What's due this week, and which of it haven't I submitted?"*
36
+ >
37
+ > *"Summarise the IA checklist my chemistry teacher uploaded."*
38
+ >
39
+ > *"Which tasks are overdue? Draft a plan to catch up before Friday."*
40
+ >
41
+ > *"How many CAS hours do I have per strand, and which experiences still need reflections?"*
42
+ >
43
+ > *"Any new notifications from my teachers?"*
44
+
45
+ The assistant calls ManageBac on your behalf, reads what it needs, and answers in plain language.
46
+
47
+ ## Install
48
+
49
+ You need [uv](https://docs.astral.sh/uv/getting-started/installation/) (one command to install) and a ManageBac account that signs in with email and password.
50
+
51
+ **1. Save your login once** (stored in your system keychain: macOS Keychain, Windows Credential Manager or Linux Secret Service):
52
+
53
+ ```bash
54
+ uvx managebac-mcp login
55
+ ```
56
+
57
+ **2. Add the server to your AI app:**
58
+
59
+ <details open>
60
+ <summary><b>Claude Desktop</b></summary>
61
+
62
+ Settings → Developer → Edit Config, then add:
63
+
64
+ ```json
65
+ {
66
+ "mcpServers": {
67
+ "managebac": {
68
+ "command": "uvx",
69
+ "args": ["managebac-mcp"]
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ Restart Claude Desktop.
76
+ </details>
77
+
78
+ <details>
79
+ <summary><b>Claude Code</b></summary>
80
+
81
+ ```bash
82
+ claude mcp add managebac -- uvx managebac-mcp
83
+ ```
84
+ </details>
85
+
86
+ <details>
87
+ <summary><b>Cursor / Windsurf / VS Code / others</b></summary>
88
+
89
+ Use the same `command` and `args` as above in the client's MCP settings:
90
+
91
+ - **Cursor:** `~/.cursor/mcp.json` (same JSON as Claude Desktop)
92
+ - **VS Code:** `.vscode/mcp.json` → `{"servers": {"managebac": {"command": "uvx", "args": ["managebac-mcp"]}}}`
93
+ - **Windsurf:** `~/.codeium/windsurf/mcp_config.json` (same JSON as Claude Desktop)
94
+
95
+ More clients and options: [docs/configuration.md](docs/configuration.md).
96
+ </details>
97
+
98
+ > [!TIP]
99
+ > Skipped step 1? Just ask the assistant to connect ManageBac. It opens a private sign-in page on your computer, so you never type your password into the chat.
100
+
101
+ ## What it can do
102
+
103
+ | Area | What you get |
104
+ |---|---|
105
+ | **Tasks & deadlines** | Upcoming, past and overdue tasks with exact due times, status, grades and your submitted files |
106
+ | **Calendar** | Everything in a date range: tasks, deadlines, events, IB year-group dates |
107
+ | **Classes** | Your classes, teachers (with email), classmates, recent activity, units of study |
108
+ | **Files** | Browse class files and read PDFs, Word, PowerPoint and Excel files as text, or save them to your computer |
109
+ | **Grades** | Assessed tasks, category weights and completion stats per class |
110
+ | **Notifications** | Unread and recent messages, full text on demand |
111
+ | **IB** | CAS experiences, strands, hours and outcomes; Extended Essay and TOK status, prompts and documents |
112
+ | **Everything else** | Global search, discussions, groups, timetable, profile, and a safe reader for any other ManageBac page |
113
+
114
+ 28 tools in total. See the [full tool reference](docs/tools.md).
115
+
116
+ ## Privacy & safety
117
+
118
+ - **Read-only.** The server never submits, edits, deletes, joins or marks anything on ManageBac.
119
+ - **Your password stays on your computer.** It lives in your OS keychain (or environment variables if you prefer) and is only ever sent to your school's ManageBac site.
120
+ - **No third parties.** Nothing is sent anywhere except ManageBac and Faria's own notification service. No analytics.
121
+ - **You're in control.** Run `uvx managebac-mcp logout` to delete the saved login at any time.
122
+
123
+ Your AI client does see the ManageBac data the assistant reads (that's the point), so use a client you trust. More in [SECURITY.md](SECURITY.md).
124
+
125
+ ## How it works
126
+
127
+ ManageBac has no public API for students, so this server signs in like your browser does and reads the same pages and data feeds the website uses. Calendar items and notifications come from ManageBac's JSON feeds. Everything else is read from the web pages and turned into tidy, structured data for the assistant.
128
+
129
+ Technical details, architecture and how to contribute: [DEVELOPMENT.md](DEVELOPMENT.md) and [CONTRIBUTING.md](CONTRIBUTING.md).
130
+
131
+ ## Limitations
132
+
133
+ - Schools that only allow **Google or Microsoft single sign-on** aren't supported yet (see [troubleshooting](docs/troubleshooting.md)).
134
+ - Built and tested with **student** accounts in the IB Diploma Programme. Other programmes mostly work. Parent and teacher accounts aren't supported yet.
135
+ - If ManageBac redesigns a page, a tool may return less detail until the parser is updated. Please [open an issue](https://github.com/Sukarth/managebac-mcp/issues).
136
+
137
+ ## Disclaimer
138
+
139
+ This is an independent open-source project. It is not affiliated with, endorsed by, or supported by ManageBac or Faria Education Group. Use it with your own account and in line with your school's policies.
140
+
141
+ ## License
142
+
143
+ MIT. See [LICENSE](LICENSE).
144
+
145
+ ---
146
+
147
+ <p align="center">Built with ❤️ by <a href="https://github.com/Sukarth">Sukarth</a></p>
@@ -0,0 +1,87 @@
1
+ [project]
2
+ name = "managebac-mcp"
3
+ version = "0.1.0"
4
+ description = "MCP server that gives AI assistants read-only access to ManageBac: classes, tasks, calendar, files, grades, CAS and more."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.11"
9
+ keywords = [
10
+ "managebac",
11
+ "mcp",
12
+ "model-context-protocol",
13
+ "ib",
14
+ "school",
15
+ "claude",
16
+ "ai",
17
+ ]
18
+ classifiers = [
19
+ "Development Status :: 4 - Beta",
20
+ "Intended Audience :: Education",
21
+ "Intended Audience :: End Users/Desktop",
22
+ "Operating System :: OS Independent",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Topic :: Education",
28
+ ]
29
+ dependencies = [
30
+ "beautifulsoup4>=4.12",
31
+ "httpx>=0.27",
32
+ "keyring>=25.0",
33
+ "mcp>=2.3,<3",
34
+ "openpyxl>=3.1",
35
+ "pypdf>=5.0",
36
+ "python-docx>=1.1",
37
+ "python-pptx>=1.0",
38
+ "tzdata ; sys_platform == 'win32'",
39
+ ]
40
+
41
+ [[project.authors]]
42
+ name = "Acharya Sukarth"
43
+
44
+ [project.urls]
45
+ Homepage = "https://github.com/Sukarth/managebac-mcp"
46
+ Repository = "https://github.com/Sukarth/managebac-mcp"
47
+ Issues = "https://github.com/Sukarth/managebac-mcp/issues"
48
+ Changelog = "https://github.com/Sukarth/managebac-mcp/blob/main/CHANGELOG.md"
49
+
50
+ [project.scripts]
51
+ managebac-mcp = "managebac_mcp.cli:main"
52
+
53
+ [dependency-groups]
54
+ dev = [
55
+ "pytest>=8",
56
+ "pytest-asyncio>=0.24",
57
+ "respx>=0.21",
58
+ "ruff>=0.6",
59
+ ]
60
+
61
+ [build-system]
62
+ requires = ["uv_build>=0.9.3,<0.10.0"]
63
+ build-backend = "uv_build"
64
+
65
+ [tool.ruff]
66
+ line-length = 120
67
+ target-version = "py311"
68
+
69
+ [tool.ruff.lint]
70
+ select = [
71
+ "E",
72
+ "F",
73
+ "I",
74
+ "B",
75
+ "UP",
76
+ "SIM",
77
+ "BLE",
78
+ ]
79
+ ignore = [
80
+ "SIM105",
81
+ "SIM108",
82
+ "E501",
83
+ ]
84
+
85
+ [tool.pytest.ini_options]
86
+ asyncio_mode = "auto"
87
+ testpaths = ["tests"]
@@ -0,0 +1,65 @@
1
+ [project]
2
+ name = "managebac-mcp"
3
+ version = "0.1.0"
4
+ description = "MCP server that gives AI assistants read-only access to ManageBac: classes, tasks, calendar, files, grades, CAS and more."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "Acharya Sukarth" }]
9
+ requires-python = ">=3.11"
10
+ keywords = ["managebac", "mcp", "model-context-protocol", "ib", "school", "claude", "ai"]
11
+ classifiers = [
12
+ "Development Status :: 4 - Beta",
13
+ "Intended Audience :: Education",
14
+ "Intended Audience :: End Users/Desktop",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Topic :: Education",
21
+ ]
22
+ dependencies = [
23
+ "beautifulsoup4>=4.12",
24
+ "httpx>=0.27",
25
+ "keyring>=25.0",
26
+ "mcp>=2.3,<3",
27
+ "openpyxl>=3.1",
28
+ "pypdf>=5.0",
29
+ "python-docx>=1.1",
30
+ "python-pptx>=1.0",
31
+ "tzdata ; sys_platform == 'win32'",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/Sukarth/managebac-mcp"
36
+ Repository = "https://github.com/Sukarth/managebac-mcp"
37
+ Issues = "https://github.com/Sukarth/managebac-mcp/issues"
38
+ Changelog = "https://github.com/Sukarth/managebac-mcp/blob/main/CHANGELOG.md"
39
+
40
+ [project.scripts]
41
+ managebac-mcp = "managebac_mcp.cli:main"
42
+
43
+ [dependency-groups]
44
+ dev = [
45
+ "pytest>=8",
46
+ "pytest-asyncio>=0.24",
47
+ "respx>=0.21",
48
+ "ruff>=0.6",
49
+ ]
50
+
51
+ [build-system]
52
+ requires = ["uv_build>=0.9.3,<0.10.0"]
53
+ build-backend = "uv_build"
54
+
55
+ [tool.ruff]
56
+ line-length = 120
57
+ target-version = "py311"
58
+
59
+ [tool.ruff.lint]
60
+ select = ["E", "F", "I", "B", "UP", "SIM", "BLE"]
61
+ ignore = ["SIM105", "SIM108", "E501"]
62
+
63
+ [tool.pytest.ini_options]
64
+ asyncio_mode = "auto"
65
+ testpaths = ["tests"]
@@ -0,0 +1,3 @@
1
+ """MCP server for ManageBac."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,127 @@
1
+ """Command line entry point: `managebac-mcp [serve|login|logout|status]`."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import asyncio
7
+ import getpass
8
+ import json
9
+ import logging
10
+ import sys
11
+
12
+ from . import __version__
13
+ from .client import Credentials, ManageBacClient, normalize_base_url
14
+ from .credentials import (
15
+ delete_credentials,
16
+ keyring_available,
17
+ load_stored_account,
18
+ resolve_credentials,
19
+ save_credentials,
20
+ )
21
+ from .errors import ManageBacError
22
+
23
+
24
+ def _login(args: argparse.Namespace) -> int:
25
+ if not keyring_available():
26
+ print(
27
+ "No system keychain is available. On Linux install and unlock a Secret Service provider "
28
+ "(GNOME Keyring or KWallet), or use the MANAGEBAC_URL / MANAGEBAC_EMAIL / MANAGEBAC_PASSWORD "
29
+ "environment variables instead.",
30
+ file=sys.stderr,
31
+ )
32
+ return 1
33
+ stored = load_stored_account()
34
+ default_url = stored.base_url.removeprefix("https://") if stored else ""
35
+ url = (
36
+ args.url
37
+ or input(f"School ManageBac address [{default_url or 'yourschool.managebac.com'}]: ").strip()
38
+ or default_url
39
+ )
40
+ email = (
41
+ args.email or input(f"Email [{stored.email if stored else ''}]: ").strip() or (stored.email if stored else "")
42
+ )
43
+ if not url or not email:
44
+ print("School address and email are required.", file=sys.stderr)
45
+ return 1
46
+ password = getpass.getpass("Password (hidden): ")
47
+ try:
48
+ creds = Credentials(normalize_base_url(url), email, password)
49
+ except ValueError as exc:
50
+ print(str(exc), file=sys.stderr)
51
+ return 1
52
+
53
+ async def verify() -> str | None:
54
+ async with ManageBacClient(creds) as c:
55
+ await c.login()
56
+ return c.role
57
+
58
+ print("Signing in to verify...")
59
+ try:
60
+ role = asyncio.run(verify())
61
+ except ManageBacError as exc:
62
+ print(f"Sign-in failed: {exc}", file=sys.stderr)
63
+ return 1
64
+ save_credentials(creds)
65
+ print(f"Saved to the system keychain. Signed in to {creds.base_url} as {role or 'user'}.")
66
+ return 0
67
+
68
+
69
+ def _logout(_: argparse.Namespace) -> int:
70
+ print("Removed saved credentials." if delete_credentials() else "No saved credentials found.")
71
+ return 0
72
+
73
+
74
+ def _status(_: argparse.Namespace) -> int:
75
+ try:
76
+ creds, source = resolve_credentials()
77
+ except ManageBacError as exc:
78
+ print(str(exc))
79
+ return 1
80
+
81
+ async def check() -> dict:
82
+ async with ManageBacClient(creds) as c:
83
+ await c.login()
84
+ return {"school_url": creds.base_url, "account": creds.email, "role": c.role, "credentials_source": source}
85
+
86
+ try:
87
+ print(json.dumps(asyncio.run(check()), indent=2))
88
+ except ManageBacError as exc:
89
+ print(f"Sign-in failed: {exc}", file=sys.stderr)
90
+ return 1
91
+ return 0
92
+
93
+
94
+ def _serve(_: argparse.Namespace) -> int:
95
+ from .server import main_stdio
96
+
97
+ main_stdio()
98
+ return 0
99
+
100
+
101
+ def main(argv: list[str] | None = None) -> int:
102
+ parser = argparse.ArgumentParser(prog="managebac-mcp", description="MCP server for ManageBac")
103
+ parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
104
+ parser.add_argument("-v", "--verbose", action="store_true", help="debug logging to stderr")
105
+ sub = parser.add_subparsers(dest="command")
106
+ sub.add_parser("serve", help="run the MCP server over stdio (default)")
107
+ p_login = sub.add_parser("login", help="save ManageBac credentials to the system keychain")
108
+ p_login.add_argument("--url", help="school ManageBac address, e.g. yourschool.managebac.com")
109
+ p_login.add_argument("--email", help="ManageBac login email")
110
+ sub.add_parser("logout", help="remove saved credentials")
111
+ sub.add_parser("status", help="check that saved credentials can sign in")
112
+ args = parser.parse_args(argv)
113
+
114
+ logging.basicConfig(
115
+ level=logging.DEBUG if args.verbose else logging.WARNING,
116
+ stream=sys.stderr,
117
+ format="%(levelname)s %(name)s: %(message)s",
118
+ )
119
+ handler = {"login": _login, "logout": _logout, "status": _status}.get(args.command or "serve", _serve)
120
+ try:
121
+ return handler(args)
122
+ except KeyboardInterrupt:
123
+ return 130
124
+
125
+
126
+ if __name__ == "__main__":
127
+ raise SystemExit(main())