qb-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.
- qb_mcp-0.1.0/.github/workflows/ci.yml +93 -0
- qb_mcp-0.1.0/.github/workflows/release.yml +58 -0
- qb_mcp-0.1.0/.gitignore +34 -0
- qb_mcp-0.1.0/CHANGELOG.md +73 -0
- qb_mcp-0.1.0/LICENSE +202 -0
- qb_mcp-0.1.0/PKG-INFO +218 -0
- qb_mcp-0.1.0/README.md +187 -0
- qb_mcp-0.1.0/README.zh-CN.md +178 -0
- qb_mcp-0.1.0/docs/TESTLIST.md +285 -0
- qb_mcp-0.1.0/docs/VERIFICATION_ENV.md +976 -0
- qb_mcp-0.1.0/examples/claude-desktop.json +10 -0
- qb_mcp-0.1.0/examples/octop.json +11 -0
- qb_mcp-0.1.0/instances.example.json +16 -0
- qb_mcp-0.1.0/pyproject.toml +54 -0
- qb_mcp-0.1.0/scripts/env_check.py +271 -0
- qb_mcp-0.1.0/scripts/mcp_smoke.py +63 -0
- qb_mcp-0.1.0/src/qb_mcp/__init__.py +3 -0
- qb_mcp-0.1.0/src/qb_mcp/client.py +181 -0
- qb_mcp-0.1.0/src/qb_mcp/config.py +183 -0
- qb_mcp-0.1.0/src/qb_mcp/server.py +712 -0
- qb_mcp-0.1.0/tests/conftest.py +63 -0
- qb_mcp-0.1.0/tests/live/test_live_qb.py +85 -0
- qb_mcp-0.1.0/tests/test_client.py +126 -0
- qb_mcp-0.1.0/tests/test_config.py +90 -0
- qb_mcp-0.1.0/tests/test_config_paths.py +140 -0
- qb_mcp-0.1.0/tests/test_coverage_gaps.py +118 -0
- qb_mcp-0.1.0/tests/test_diagnose.py +225 -0
- qb_mcp-0.1.0/tests/test_entry.py +429 -0
- qb_mcp-0.1.0/tests/test_tools.py +75 -0
- qb_mcp-0.1.0/tests/test_transport.py +186 -0
- qb_mcp-0.1.0/tests/test_write_tools.py +393 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
# -- Class A: offline behaviour tests across supported Python versions ----
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: ${{ matrix.python-version }}
|
|
21
|
+
- name: Install
|
|
22
|
+
run: pip install -e ".[dev]"
|
|
23
|
+
|
|
24
|
+
- name: Lint
|
|
25
|
+
run: ruff check .
|
|
26
|
+
|
|
27
|
+
- name: Type check
|
|
28
|
+
run: mypy src
|
|
29
|
+
|
|
30
|
+
# Fail fast if the interpreter is not the clean shape we think it is
|
|
31
|
+
# (mcp major version, package resolves to this checkout, test count).
|
|
32
|
+
- name: Environment gate
|
|
33
|
+
run: python scripts/env_check.py --env A --no-net --expect-tests 130
|
|
34
|
+
|
|
35
|
+
- name: "Class A - offline behaviour"
|
|
36
|
+
run: pytest -q --ignore=tests/live --cov=qb_mcp --cov-report=term-missing
|
|
37
|
+
|
|
38
|
+
# -- Class B: the only job that talks to a real qBittorrent ---------------
|
|
39
|
+
# Runs on main only. Any failure here means a belief encoded in Class A has
|
|
40
|
+
# gone stale, so it is not treated as flaky.
|
|
41
|
+
live:
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
needs: test
|
|
44
|
+
if: github.ref == 'refs/heads/main'
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v4
|
|
47
|
+
- uses: actions/setup-python@v5
|
|
48
|
+
with:
|
|
49
|
+
python-version: "3.12"
|
|
50
|
+
- name: Install
|
|
51
|
+
run: pip install -e ".[dev]"
|
|
52
|
+
|
|
53
|
+
- name: Start qBittorrent container
|
|
54
|
+
run: |
|
|
55
|
+
docker run -d --name qb -p 8080:8080 \
|
|
56
|
+
qbittorrentofficial/qbittorrent-nox:latest
|
|
57
|
+
for i in $(seq 90); do
|
|
58
|
+
code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8080/ || true)
|
|
59
|
+
if [ -n "$code" ] && [ "$code" != "000" ]; then
|
|
60
|
+
echo "WebUI answered HTTP $code after ${i}s"
|
|
61
|
+
break
|
|
62
|
+
fi
|
|
63
|
+
sleep 1
|
|
64
|
+
done
|
|
65
|
+
echo "--- container log ---"
|
|
66
|
+
docker logs qb 2>&1 | tail -30
|
|
67
|
+
|
|
68
|
+
- name: Resolve temporary password
|
|
69
|
+
id: qbpass
|
|
70
|
+
run: |
|
|
71
|
+
PW=$(docker logs qb 2>&1 \
|
|
72
|
+
| grep -i "temporary password" \
|
|
73
|
+
| tail -1 \
|
|
74
|
+
| sed -E 's/.*session: *//' \
|
|
75
|
+
| tr -d '\r' | tr -d ' ')
|
|
76
|
+
if [ -z "$PW" ]; then
|
|
77
|
+
echo "::error::temporary password not found in container log"
|
|
78
|
+
docker logs qb 2>&1 | tail -40
|
|
79
|
+
exit 1
|
|
80
|
+
fi
|
|
81
|
+
echo "::add-mask::$PW"
|
|
82
|
+
echo "value=$PW" >> "$GITHUB_OUTPUT"
|
|
83
|
+
|
|
84
|
+
- name: "Class B - live qBittorrent"
|
|
85
|
+
env:
|
|
86
|
+
QB_TEST_URL: http://127.0.0.1:8080
|
|
87
|
+
QB_TEST_USER: admin
|
|
88
|
+
QB_TEST_PASS: ${{ steps.qbpass.outputs.value }}
|
|
89
|
+
run: pytest tests/live -q -rs
|
|
90
|
+
|
|
91
|
+
- name: Container log on failure
|
|
92
|
+
if: failure()
|
|
93
|
+
run: docker logs qb 2>&1 | tail -60
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
# A tag can be pushed from an unverified commit, so re-run the checks here
|
|
10
|
+
# rather than trusting that CI already ran on this exact tree.
|
|
11
|
+
verify:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- name: Install
|
|
19
|
+
run: pip install -e ".[dev]"
|
|
20
|
+
- name: Lint
|
|
21
|
+
run: ruff check .
|
|
22
|
+
- name: Type check
|
|
23
|
+
run: mypy src
|
|
24
|
+
- name: Offline tests
|
|
25
|
+
run: pytest -q --ignore=tests/live
|
|
26
|
+
|
|
27
|
+
build:
|
|
28
|
+
needs: verify
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@v4
|
|
32
|
+
- uses: actions/setup-python@v5
|
|
33
|
+
with:
|
|
34
|
+
python-version: "3.12"
|
|
35
|
+
- name: Build sdist and wheel
|
|
36
|
+
run: |
|
|
37
|
+
pip install build twine
|
|
38
|
+
python -m build
|
|
39
|
+
twine check dist/*
|
|
40
|
+
- uses: actions/upload-artifact@v4
|
|
41
|
+
with:
|
|
42
|
+
name: dist
|
|
43
|
+
path: dist/
|
|
44
|
+
|
|
45
|
+
# Trusted Publishing: no API token is stored anywhere. PyPI verifies the
|
|
46
|
+
# OIDC identity of this workflow instead.
|
|
47
|
+
publish:
|
|
48
|
+
needs: build
|
|
49
|
+
runs-on: ubuntu-latest
|
|
50
|
+
environment: pypi
|
|
51
|
+
permissions:
|
|
52
|
+
id-token: write
|
|
53
|
+
steps:
|
|
54
|
+
- uses: actions/download-artifact@v4
|
|
55
|
+
with:
|
|
56
|
+
name: dist
|
|
57
|
+
path: dist/
|
|
58
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
qb_mcp-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# 凭据(务必保持在最前)
|
|
2
|
+
.instances.json
|
|
3
|
+
.env
|
|
4
|
+
.env.*
|
|
5
|
+
!.env.example
|
|
6
|
+
*.secret
|
|
7
|
+
*.pem
|
|
8
|
+
*.key
|
|
9
|
+
|
|
10
|
+
# Python
|
|
11
|
+
__pycache__/
|
|
12
|
+
*.py[cod]
|
|
13
|
+
*.egg-info/
|
|
14
|
+
dist/
|
|
15
|
+
build/
|
|
16
|
+
.venv/
|
|
17
|
+
venv/
|
|
18
|
+
.uv/
|
|
19
|
+
|
|
20
|
+
# 工具缓存
|
|
21
|
+
.pytest_cache/
|
|
22
|
+
.mypy_cache/
|
|
23
|
+
.ruff_cache/
|
|
24
|
+
.coverage
|
|
25
|
+
htmlcov/
|
|
26
|
+
|
|
27
|
+
# 运行产物
|
|
28
|
+
*.log
|
|
29
|
+
*.sqlite
|
|
30
|
+
*.db
|
|
31
|
+
|
|
32
|
+
# 系统
|
|
33
|
+
.DS_Store
|
|
34
|
+
Thumbs.db
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-11-03
|
|
9
|
+
|
|
10
|
+
First public release.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **11 MCP tools**, grouped by intent rather than by API endpoint:
|
|
15
|
+
- read: `qb_instances`, `qb_overview`, `qb_list`, `qb_detail`, `qb_diagnose`
|
|
16
|
+
- write: `qb_control`, `qb_set_limit`, `qb_set_share`, `qb_add`, `qb_remove`,
|
|
17
|
+
`qb_category`
|
|
18
|
+
- **`qb_diagnose`** explains *why* an instance is or is not uploading instead of
|
|
19
|
+
dumping raw fields: it checks connection state, tracker health, listening
|
|
20
|
+
port, peer supply, speed limits and torrent states, then states a verdict.
|
|
21
|
+
- **Arbitrary many instances**, each with its own credentials.
|
|
22
|
+
- **Three password forms**: plain text, `${ENV_VAR}` placeholder, or
|
|
23
|
+
`{"file": "/path/to/secret"}`.
|
|
24
|
+
- **Two transports**: `stdio` for local MCP clients, `streamable-http` for a
|
|
25
|
+
network server.
|
|
26
|
+
- Slimmed responses — the raw qBittorrent payloads are trimmed to the fields
|
|
27
|
+
worth spending context on.
|
|
28
|
+
- Write operations echo the before/after value so the caller can verify the
|
|
29
|
+
change.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
Three behaviours that are not in the qBittorrent documentation and only show up
|
|
34
|
+
against a live instance:
|
|
35
|
+
|
|
36
|
+
- `Referer` and `Origin` must match the request `Host` **including the port**,
|
|
37
|
+
otherwise the WebUI rejects the login.
|
|
38
|
+
- A wrong password returns **HTTP 200** with the body `Fails.`. Treating any
|
|
39
|
+
200 as success turns a bad password into a confusing string of 403s later.
|
|
40
|
+
- A reverse proxy may return **204 with an empty body** on a successful login
|
|
41
|
+
instead of `200 Ok.`.
|
|
42
|
+
|
|
43
|
+
Two more issues fixed during bring-up against real instances:
|
|
44
|
+
|
|
45
|
+
- Cumulative totals (`alltime_ul`, `alltime_dl`, `global_ratio`,
|
|
46
|
+
`total_peer_connections`) live in `sync/maindata` under `server_state`.
|
|
47
|
+
`transfer/info` only carries live speeds and rate limits, so reading totals
|
|
48
|
+
from there returns zeros.
|
|
49
|
+
- `qb_diagnose` treated "a speed limit is configured" as "the speed limit is
|
|
50
|
+
the bottleneck". It now requires throughput to reach 80 % of the configured
|
|
51
|
+
cap, and requires at least 10 leechers before blaming peer reachability.
|
|
52
|
+
|
|
53
|
+
### Security
|
|
54
|
+
|
|
55
|
+
- `delete_files` defaults to `false`; removing a torrent never deletes data
|
|
56
|
+
unless explicitly requested.
|
|
57
|
+
- An explicitly configured `.instances.json` path is strict — a typo raises
|
|
58
|
+
instead of silently falling back to a file in the working directory.
|
|
59
|
+
- The config file's permissions are checked and a warning is printed when it is
|
|
60
|
+
readable by group or others.
|
|
61
|
+
|
|
62
|
+
### Testing
|
|
63
|
+
|
|
64
|
+
- 124 test cases, split into two classes:
|
|
65
|
+
- **offline behaviour** (118) — no socket ever opened, runs on Python
|
|
66
|
+
3.10 / 3.11 / 3.12
|
|
67
|
+
- **live qBittorrent** (6) — a container started by CI, the only path that can
|
|
68
|
+
tell when an assumption about the real API has gone stale
|
|
69
|
+
- 100 % statement coverage of `qb_mcp` (543 statements).
|
|
70
|
+
- CI also runs an environment gate that fails the build when the interpreter is
|
|
71
|
+
not the clean shape the tests assume.
|
|
72
|
+
|
|
73
|
+
[0.1.0]: https://github.com/zxw060810/qb-mcp/releases/tag/v0.1.0
|
qb_mcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
qb_mcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: qb-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server for qBittorrent - manage torrents with natural language
|
|
5
|
+
Project-URL: Homepage, https://github.com/zxw060810/qb-mcp
|
|
6
|
+
Project-URL: Issues, https://github.com/zxw060810/qb-mcp/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/zxw060810/qb-mcp/blob/main/CHANGELOG.md
|
|
8
|
+
Author: zxw060810
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai,llm,mcp,model-context-protocol,qbittorrent,torrent
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: System :: Networking
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: mcp>=1.0
|
|
22
|
+
Requires-Dist: requests>=2.31
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
29
|
+
Requires-Dist: types-requests; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# qb-mcp
|
|
33
|
+
|
|
34
|
+
**An MCP server for qBittorrent — manage torrents with natural language.**
|
|
35
|
+
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
[](pyproject.toml)
|
|
38
|
+
[](https://modelcontextprotocol.io)
|
|
39
|
+
|
|
40
|
+
> This is an unofficial project. It is not affiliated with, endorsed by, or
|
|
41
|
+
> supported by the qBittorrent project.
|
|
42
|
+
|
|
43
|
+
**English** | [简体中文](README.zh-CN.md)
|
|
44
|
+
|
|
45
|
+
`qb-mcp` wraps the qBittorrent WebUI API v2 and exposes it as eleven tools that
|
|
46
|
+
an AI agent can call. It manages **any number of instances**, each with its own
|
|
47
|
+
credentials, so a single agent can drive a home NAS and a remote seedbox at once.
|
|
48
|
+
|
|
49
|
+
## Why this exists
|
|
50
|
+
|
|
51
|
+
qBittorrent has a complete HTTP API but no MCP interface. Wrapping it means an
|
|
52
|
+
agent can answer "why isn't it uploading?" by actually checking tracker health,
|
|
53
|
+
listening ports, speed limits and peer supply — instead of guessing.
|
|
54
|
+
|
|
55
|
+
The eleven tools are grouped by **user intent**, not by API endpoint: mapping all
|
|
56
|
+
80+ endpoints one-to-one would produce a tool list no model can choose from.
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
- **Multiple instances**, each with independent credentials
|
|
61
|
+
- **`qb_diagnose`** — turns "why is nothing uploading?" into one call
|
|
62
|
+
- **Field-trimmed responses** — the API returns 30+ fields per torrent; this returns 12
|
|
63
|
+
- **Before/after reporting** on every write operation
|
|
64
|
+
- **`delete_files` is opt-in** — removing a torrent never deletes data by default
|
|
65
|
+
- **stdio and HTTP** transports
|
|
66
|
+
- Credentials never leave your machine; nothing is logged
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install qb-mcp
|
|
72
|
+
cp instances.example.json .instances.json
|
|
73
|
+
# edit .instances.json with your qBittorrent URL and credentials
|
|
74
|
+
chmod 600 .instances.json
|
|
75
|
+
qb-mcp
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Configuration
|
|
79
|
+
|
|
80
|
+
`qb-mcp` reads `.instances.json` from the current directory, or the path in
|
|
81
|
+
`QB_MCP_CONFIG`.
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"instances": {
|
|
86
|
+
"nas": {
|
|
87
|
+
"label": "Home NAS",
|
|
88
|
+
"url": "http://192.168.1.100:8080",
|
|
89
|
+
"username": "admin",
|
|
90
|
+
"password": "${QB_PASS_NAS}"
|
|
91
|
+
},
|
|
92
|
+
"seedbox": {
|
|
93
|
+
"url": "https://seedbox.example.com",
|
|
94
|
+
"username": "me",
|
|
95
|
+
"password": {"file": "~/.secrets/seedbox"}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
| Field | Required | Default | Notes |
|
|
102
|
+
|---|---|---|---|
|
|
103
|
+
| `url` | ✅ | — | Must start with `http://` or `https://` |
|
|
104
|
+
| `username` | ✅ | — | Per-instance; instances may use different accounts |
|
|
105
|
+
| `password` | ✅ | — | Literal, `"${ENV_VAR}"`, or `{"file": "/path"}` |
|
|
106
|
+
| `label` | — | key | Display name |
|
|
107
|
+
| `verify_ssl` | — | `true` | Set `false` for self-signed certificates |
|
|
108
|
+
| `timeout` | — | `8.0` | Per-request timeout in seconds |
|
|
109
|
+
|
|
110
|
+
**Keep `.instances.json` out of version control.** It is already listed in
|
|
111
|
+
`.gitignore`. `qb-mcp` prints a warning if the file is readable by group or others.
|
|
112
|
+
|
|
113
|
+
## Tools
|
|
114
|
+
|
|
115
|
+
### Read (safe)
|
|
116
|
+
|
|
117
|
+
| Tool | Purpose |
|
|
118
|
+
|---|---|
|
|
119
|
+
| `qb_instances` | List configured instances and whether each is reachable |
|
|
120
|
+
| `qb_overview` | Global status for one or all instances |
|
|
121
|
+
| `qb_list` | Torrent list with filtering, sorting and a row limit |
|
|
122
|
+
| `qb_detail` | One torrent in depth, including tracker status |
|
|
123
|
+
| `qb_diagnose` | Explain why an instance is or is not uploading |
|
|
124
|
+
|
|
125
|
+
### Write (state-changing)
|
|
126
|
+
|
|
127
|
+
| Tool | Purpose |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `qb_control` | `pause` / `resume` / `reannounce` / `force_start` |
|
|
130
|
+
| `qb_set_limit` | Global or per-torrent speed limits |
|
|
131
|
+
| `qb_set_share` | Ratio and seeding-time limits |
|
|
132
|
+
| `qb_add` | Add from magnet, URL or a local `.torrent` (paused by default) |
|
|
133
|
+
| `qb_remove` | Remove torrents; `delete_files` is opt-in |
|
|
134
|
+
| `qb_category` | Assign categories and tags |
|
|
135
|
+
|
|
136
|
+
## Client setup
|
|
137
|
+
|
|
138
|
+
**stdio** (Claude Desktop, Cursor, most local clients):
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"mcpServers": {
|
|
143
|
+
"qbittorrent": {
|
|
144
|
+
"command": "qb-mcp",
|
|
145
|
+
"env": { "QB_MCP_CONFIG": "/absolute/path/to/.instances.json" }
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**HTTP** (remote or multi-client):
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
qb-mcp --transport http --host 127.0.0.1 --port 17890
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"servers": {
|
|
160
|
+
"qbittorrent": {
|
|
161
|
+
"url": "http://127.0.0.1:17890/mcp",
|
|
162
|
+
"transport": "streamable_http"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Compatibility
|
|
169
|
+
|
|
170
|
+
| qBittorrent | WebUI API | Status |
|
|
171
|
+
|---|---|---|
|
|
172
|
+
| 4.x | 2.8+ | Supported |
|
|
173
|
+
| 5.x | 2.11+ | Supported (tested on 5.2.4) |
|
|
174
|
+
|
|
175
|
+
Both official builds and third-party NAS packages (QNAP QPKG, Synology SPK) work,
|
|
176
|
+
with the proxy quirks below already handled.
|
|
177
|
+
|
|
178
|
+
## Troubleshooting
|
|
179
|
+
|
|
180
|
+
### `login rejected (Fails.)`
|
|
181
|
+
|
|
182
|
+
qBittorrent returns **HTTP 200 even when the password is wrong** — the body is
|
|
183
|
+
`Fails.` instead of `Ok.`. `qb-mcp` inspects the body, so this message means the
|
|
184
|
+
credentials are genuinely wrong.
|
|
185
|
+
|
|
186
|
+
### Login fails behind a reverse proxy
|
|
187
|
+
|
|
188
|
+
The official API requires `Referer` or `Origin` to match the request `Host`
|
|
189
|
+
**exactly, including the port**. `qb-mcp` sets both from your configured `url`,
|
|
190
|
+
so make sure `url` uses the same host and port you would type in a browser.
|
|
191
|
+
|
|
192
|
+
### Works with curl but not through a proxy
|
|
193
|
+
|
|
194
|
+
Some reverse proxies (QNAP QTS is one) return **`204 No Content` with an empty
|
|
195
|
+
body** on a successful login instead of `200 Ok.`. `qb-mcp` treats any status
|
|
196
|
+
below 400 with an empty or `Ok.` body as success.
|
|
197
|
+
|
|
198
|
+
### `login blocked - too many failed attempts`
|
|
199
|
+
|
|
200
|
+
qBittorrent temporarily bans an IP after repeated failures. Wait a few minutes,
|
|
201
|
+
or check the WebUI's ban list.
|
|
202
|
+
|
|
203
|
+
## Development
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
git clone https://github.com/zxw060810/qb-mcp.git
|
|
207
|
+
cd qb-mcp
|
|
208
|
+
pip install -e ".[dev]"
|
|
209
|
+
ruff check .
|
|
210
|
+
mypy src
|
|
211
|
+
pytest
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Tests mock the qBittorrent API; no live instance is required.
|
|
215
|
+
|
|
216
|
+
## License
|
|
217
|
+
|
|
218
|
+
[Apache-2.0](LICENSE)
|