tplink-deco-mcp-server 1.0.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.
Files changed (65) hide show
  1. tplink_deco_mcp_server-1.0.0/.dockerignore +12 -0
  2. tplink_deco_mcp_server-1.0.0/.github/CODEOWNERS +1 -0
  3. tplink_deco_mcp_server-1.0.0/.github/FUNDING.yml +1 -0
  4. tplink_deco_mcp_server-1.0.0/.github/dependabot.yml +49 -0
  5. tplink_deco_mcp_server-1.0.0/.github/workflows/auto-assign.yml +23 -0
  6. tplink_deco_mcp_server-1.0.0/.github/workflows/ci.yml +51 -0
  7. tplink_deco_mcp_server-1.0.0/.github/workflows/codeql.yml +18 -0
  8. tplink_deco_mcp_server-1.0.0/.github/workflows/release.yml +90 -0
  9. tplink_deco_mcp_server-1.0.0/.gitignore +8 -0
  10. tplink_deco_mcp_server-1.0.0/.idea/.gitignore +3 -0
  11. tplink_deco_mcp_server-1.0.0/.idea/inspectionProfiles/profiles_settings.xml +6 -0
  12. tplink_deco_mcp_server-1.0.0/.idea/misc.xml +7 -0
  13. tplink_deco_mcp_server-1.0.0/.idea/modules.xml +8 -0
  14. tplink_deco_mcp_server-1.0.0/.idea/tplink-deco-mcp-server.iml +12 -0
  15. tplink_deco_mcp_server-1.0.0/.idea/vcs.xml +6 -0
  16. tplink_deco_mcp_server-1.0.0/.pre-commit-config.yaml +21 -0
  17. tplink_deco_mcp_server-1.0.0/.release-please-manifest.json +3 -0
  18. tplink_deco_mcp_server-1.0.0/CHANGELOG.md +8 -0
  19. tplink_deco_mcp_server-1.0.0/CLAUDE.md +93 -0
  20. tplink_deco_mcp_server-1.0.0/CODE_STYLE.md +156 -0
  21. tplink_deco_mcp_server-1.0.0/Dockerfile +31 -0
  22. tplink_deco_mcp_server-1.0.0/LICENSE +21 -0
  23. tplink_deco_mcp_server-1.0.0/PKG-INFO +176 -0
  24. tplink_deco_mcp_server-1.0.0/README.md +153 -0
  25. tplink_deco_mcp_server-1.0.0/pyproject.toml +109 -0
  26. tplink_deco_mcp_server-1.0.0/release-please-config.json +82 -0
  27. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/__init__.py +8 -0
  28. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/__main__.py +7 -0
  29. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/cli.py +51 -0
  30. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/router/__init__.py +8 -0
  31. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/router/router_failure.py +32 -0
  32. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/router/router_session.py +81 -0
  33. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/router/router_settings.py +51 -0
  34. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/server.py +62 -0
  35. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/summaries/__init__.py +36 -0
  36. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/summaries/address_reservation_summary.py +57 -0
  37. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/summaries/blocked_client_summary.py +25 -0
  38. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/summaries/client_summary.py +51 -0
  39. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/summaries/internet_status_summary.py +86 -0
  40. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/summaries/node_summary.py +58 -0
  41. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/summaries/performance_summary.py +39 -0
  42. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/summaries/wifi_configuration_summary.py +164 -0
  43. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/__init__.py +21 -0
  44. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/address_reservation_tools.py +110 -0
  45. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/blocklist_tools.py +89 -0
  46. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/client_tools.py +95 -0
  47. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/internet_tools.py +40 -0
  48. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/mesh_tools.py +50 -0
  49. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/tool_parameters.py +22 -0
  50. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/tool_registration.py +44 -0
  51. tplink_deco_mcp_server-1.0.0/src/tplink_deco_mcp_server/tools/wifi_tools.py +51 -0
  52. tplink_deco_mcp_server-1.0.0/tests/__init__.py +0 -0
  53. tplink_deco_mcp_server-1.0.0/tests/conftest.py +53 -0
  54. tplink_deco_mcp_server-1.0.0/tests/factories.py +171 -0
  55. tplink_deco_mcp_server-1.0.0/tests/test_address_reservation_tools.py +78 -0
  56. tplink_deco_mcp_server-1.0.0/tests/test_blocklist_tools.py +70 -0
  57. tplink_deco_mcp_server-1.0.0/tests/test_cli.py +38 -0
  58. tplink_deco_mcp_server-1.0.0/tests/test_client_tools.py +85 -0
  59. tplink_deco_mcp_server-1.0.0/tests/test_mesh_and_internet_tools.py +99 -0
  60. tplink_deco_mcp_server-1.0.0/tests/test_router_failure.py +45 -0
  61. tplink_deco_mcp_server-1.0.0/tests/test_router_session.py +103 -0
  62. tplink_deco_mcp_server-1.0.0/tests/test_router_settings.py +53 -0
  63. tplink_deco_mcp_server-1.0.0/tests/test_server.py +67 -0
  64. tplink_deco_mcp_server-1.0.0/tests/test_wifi_tools.py +128 -0
  65. tplink_deco_mcp_server-1.0.0/uv.lock +991 -0
@@ -0,0 +1,12 @@
1
+ .git
2
+ .github
3
+ .idea
4
+ .venv
5
+ .vscode
6
+ .pytest_cache
7
+ .ruff_cache
8
+ .mypy_cache
9
+ .coverage
10
+ dist
11
+ tests
12
+ .env
@@ -0,0 +1 @@
1
+ * @roquerodrigo
@@ -0,0 +1 @@
1
+ github: roquerodrigo
@@ -0,0 +1,49 @@
1
+ # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
2
+ version: 2
3
+ updates:
4
+ - package-ecosystem: "github-actions"
5
+ directory: "/"
6
+ schedule:
7
+ interval: "weekly"
8
+ day: "monday"
9
+ time: "09:00"
10
+ timezone: "America/Sao_Paulo"
11
+ groups:
12
+ github-actions:
13
+ patterns:
14
+ - "*"
15
+
16
+ commit-message:
17
+ prefix: "deps"
18
+ include: "scope"
19
+
20
+ - package-ecosystem: "uv"
21
+ directory: "/"
22
+ schedule:
23
+ interval: "weekly"
24
+ day: "monday"
25
+ time: "09:00"
26
+ timezone: "America/Sao_Paulo"
27
+ groups:
28
+ python-deps:
29
+ patterns:
30
+ - "*"
31
+ commit-message:
32
+ prefix: "deps"
33
+ prefix-development: "deps-dev"
34
+ include: "scope"
35
+
36
+ - package-ecosystem: "docker"
37
+ directory: "/"
38
+ schedule:
39
+ interval: "weekly"
40
+ day: "monday"
41
+ time: "09:00"
42
+ timezone: "America/Sao_Paulo"
43
+ groups:
44
+ docker:
45
+ patterns:
46
+ - "*"
47
+ commit-message:
48
+ prefix: "deps"
49
+ include: "scope"
@@ -0,0 +1,23 @@
1
+ name: Auto-assign
2
+
3
+ on:
4
+ issues:
5
+ types: [opened, reopened]
6
+ pull_request_target:
7
+ types: [opened, reopened]
8
+ schedule:
9
+ - cron: "17 6 * * *"
10
+ workflow_dispatch:
11
+
12
+ concurrency:
13
+ group: auto-assign
14
+ cancel-in-progress: false
15
+
16
+ permissions: {}
17
+
18
+ jobs:
19
+ auto-assign:
20
+ permissions:
21
+ issues: write
22
+ pull-requests: write
23
+ uses: roquerodrigo/workflows/.github/workflows/auto-assign.yml@main
@@ -0,0 +1,51 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ concurrency:
9
+ group: ci-${{ github.ref }}
10
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
11
+
12
+ permissions:
13
+ contents: read
14
+
15
+ jobs:
16
+ lint:
17
+ uses: roquerodrigo/workflows/.github/workflows/python-lint.yml@main
18
+
19
+ tests:
20
+ needs: lint
21
+ uses: roquerodrigo/workflows/.github/workflows/python-test.yml@main
22
+
23
+ docker:
24
+ name: Docker image
25
+ needs: lint
26
+ runs-on: ubuntu-latest
27
+ timeout-minutes: 15
28
+ steps:
29
+ - name: Check out
30
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
31
+ with:
32
+ persist-credentials: false
33
+
34
+ - name: Set up Buildx
35
+ uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
36
+
37
+ - name: Build
38
+ uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
39
+ with:
40
+ context: .
41
+ push: false
42
+ cache-from: type=gha
43
+ cache-to: type=gha,mode=max
44
+
45
+ update-pr-branch:
46
+ if: github.event_name == 'pull_request'
47
+ needs: [lint, tests, docker]
48
+ permissions:
49
+ contents: write
50
+ pull-requests: write
51
+ uses: roquerodrigo/workflows/.github/workflows/update-pr-branch.yml@main
@@ -0,0 +1,18 @@
1
+ name: CodeQL
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ schedule:
8
+ - cron: "0 0 * * 0"
9
+
10
+ permissions: {}
11
+
12
+ jobs:
13
+ codeql:
14
+ permissions:
15
+ actions: read
16
+ contents: read
17
+ security-events: write
18
+ uses: roquerodrigo/workflows/.github/workflows/codeql.yml@main
@@ -0,0 +1,90 @@
1
+ name: Release
2
+
3
+ # release-please grooms the release pull request and tags it; the tag is then
4
+ # published to PyPI and to GitHub Container Registry under the same version.
5
+ #
6
+ # The `workflow_run.event == 'push'` condition is what stops a pull request with
7
+ # green CI from cutting a release.
8
+
9
+ on:
10
+ workflow_run:
11
+ workflows: [CI]
12
+ types: [completed]
13
+ branches: [main]
14
+
15
+ permissions: {}
16
+
17
+ jobs:
18
+ release:
19
+ if: >-
20
+ github.event.workflow_run.event == 'push' &&
21
+ github.event.workflow_run.conclusion == 'success'
22
+ permissions:
23
+ contents: write
24
+ pull-requests: write
25
+ uses: roquerodrigo/workflows/.github/workflows/release-please.yml@main
26
+ secrets:
27
+ release-token: ${{ secrets.RELEASE_PLEASE_PAT }}
28
+
29
+ publish:
30
+ needs: release
31
+ if: needs.release.outputs.release-created == 'true'
32
+ permissions:
33
+ contents: read
34
+ uses: roquerodrigo/workflows/.github/workflows/publish-pypi.yml@main
35
+ with:
36
+ package: tplink-deco-mcp-server
37
+ ref: ${{ needs.release.outputs.tag-name }}
38
+ secrets:
39
+ pypi-token: ${{ secrets.PYPI_API_TOKEN }}
40
+
41
+ publish-docker:
42
+ name: Publish Docker image
43
+ needs: release
44
+ if: needs.release.outputs.release-created == 'true'
45
+ runs-on: ubuntu-latest
46
+ timeout-minutes: 30
47
+ permissions:
48
+ contents: read
49
+ packages: write
50
+ steps:
51
+ - name: Check out the released ref
52
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
53
+ with:
54
+ ref: ${{ needs.release.outputs.tag-name }}
55
+ persist-credentials: false
56
+
57
+ - name: Set up QEMU
58
+ uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
59
+
60
+ - name: Set up Buildx
61
+ uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
62
+
63
+ - name: Log in to GitHub Container Registry
64
+ uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
65
+ with:
66
+ registry: ghcr.io
67
+ username: ${{ github.actor }}
68
+ password: ${{ secrets.GITHUB_TOKEN }}
69
+
70
+ - name: Resolve tags and labels
71
+ id: metadata
72
+ uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
73
+ with:
74
+ images: ghcr.io/${{ github.repository }}
75
+ tags: |
76
+ type=semver,pattern={{version}},value=${{ needs.release.outputs.tag-name }}
77
+ type=semver,pattern={{major}}.{{minor}},value=${{ needs.release.outputs.tag-name }}
78
+ type=semver,pattern={{major}},value=${{ needs.release.outputs.tag-name }}
79
+ type=raw,value=latest
80
+
81
+ - name: Build and push
82
+ uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
83
+ with:
84
+ context: .
85
+ platforms: linux/amd64,linux/arm64
86
+ push: true
87
+ tags: ${{ steps.metadata.outputs.tags }}
88
+ labels: ${{ steps.metadata.outputs.labels }}
89
+ cache-from: type=gha
90
+ cache-to: type=gha,mode=max
@@ -0,0 +1,8 @@
1
+ .env
2
+ .venv/
3
+ __pycache__/
4
+ *.pyc
5
+ .pytest_cache/
6
+ dist/
7
+ *.egg-info/
8
+ .coverage
@@ -0,0 +1,3 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Black">
4
+ <option name="sdkName" value="uv (tplink-deco-mcp-server)" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="uv (tplink-deco-mcp-server)" project-jdk-type="Python SDK" />
7
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/tplink-deco-mcp-server.iml" filepath="$PROJECT_DIR$/.idea/tplink-deco-mcp-server.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
6
+ <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
7
+ <excludeFolder url="file://$MODULE_DIR$/.venv" />
8
+ </content>
9
+ <orderEntry type="jdk" jdkName="uv (tplink-deco-mcp-server)" jdkType="Python SDK" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,21 @@
1
+ # Run with: pre-commit install
2
+ # CI mirrors these checks via roquerodrigo/.github/sdk-lint.yml
3
+ repos:
4
+ - repo: https://github.com/astral-sh/ruff-pre-commit
5
+ rev: v0.15.12
6
+ hooks:
7
+ - id: ruff-check
8
+ args: [--fix]
9
+ - id: ruff-format
10
+
11
+ - repo: https://github.com/pre-commit/pre-commit-hooks
12
+ rev: v6.0.0
13
+ hooks:
14
+ - id: trailing-whitespace
15
+ - id: end-of-file-fixer
16
+ - id: check-yaml
17
+ - id: check-json
18
+ - id: check-toml
19
+ - id: check-merge-conflict
20
+ - id: mixed-line-ending
21
+ args: [--fix=lf]
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "1.0.0"
3
+ }
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (2026-10-14)
4
+
5
+
6
+ ### Features
7
+
8
+ * add the TP-Link Deco MCP server ([a25d89a](https://github.com/roquerodrigo/tplink-deco-mcp-server/commit/a25d89a4059f54e41c5a17cfb75f3c5ad3e70f2d))
@@ -0,0 +1,93 @@
1
+ # tplink-deco-mcp-server
2
+
3
+ MCP ([Model Context Protocol](https://modelcontextprotocol.io)) server that
4
+ exposes a TP-Link Deco mesh as tools an LLM client can call, built on the
5
+ sibling SDK [`tplink-deco-api`](https://github.com/roquerodrigo/tplink-deco-api)
6
+ and on the official `mcp` Python SDK (2.x, `MCPServer`). It talks to the router
7
+ on the LAN; there is no cloud API and no cache — every tool call is a live
8
+ router request.
9
+
10
+ Published to PyPI as `tplink-deco-mcp-server` (`uvx tplink-deco-mcp-server`)
11
+ and as a Docker image at `ghcr.io/roquerodrigo/tplink-deco-mcp-server`.
12
+
13
+ **Read `CODE_STYLE.md` before adding or restructuring code** — naming, typing,
14
+ docstrings, logging, error format, commit conventions and releasing live there.
15
+
16
+ ## Structure
17
+
18
+ - `router/` — `RouterSettings` (env → settings), `RouterSession` (the single
19
+ authenticated `DecoClient`, behind a lock) and `router_failure.py` (which SDK
20
+ errors mean "session dropped", and how failures are phrased).
21
+ - `summaries/` — pydantic models the tools return; they decide what the model
22
+ sees (field names, units, descriptions) and keep SDK shapes out of the
23
+ contract.
24
+ - `tools/` — one class per router feature (`MeshTools`, `InternetTools`,
25
+ `WifiTools`, `ClientTools`, `BlocklistTools`, `AddressReservationTools`). Each
26
+ method is a tool; `register()` publishes them through `register_tool`.
27
+ - `server.py` builds the `MCPServer` (instructions, tool groups, `/healthz`);
28
+ `cli.py` is the `tplink-deco-mcp-server` entry point.
29
+
30
+ ## Run / verify
31
+
32
+ ```sh
33
+ uv sync
34
+ uv run ruff format . && uv run ruff check . --fix && uv run mypy
35
+ uv run pytest
36
+ DECO_HOST=… DECO_PASSWORD=… uv run tplink-deco-mcp-server # stdio
37
+ DECO_HOST=… DECO_PASSWORD=… uv run tplink-deco-mcp-server --transport streamable-http
38
+ ```
39
+
40
+ Tests are network-free: they mock `DecoClient` behind a real `RouterSession`
41
+ and drive the tools through an in-process `mcp.Client`, so the JSON schemas,
42
+ structured output and error results are exercised end to end. Coverage is
43
+ gated at 90%.
44
+
45
+ ## Docker image
46
+
47
+ Two stages: the first builds the wheel and exports `uv.lock` to a hashed
48
+ requirements file; the second `pip install --require-hashes` those, then the
49
+ wheel with `--no-deps`. The default command serves Streamable HTTP on
50
+ `0.0.0.0:8000` (`/mcp`, health at `/healthz`); passing
51
+ `tplink-deco-mcp-server` as the command gives stdio.
52
+
53
+ ```sh
54
+ docker build -t tplink-deco-mcp-server:dev .
55
+ docker run --rm -e DECO_HOST=… -e DECO_PASSWORD=… -p 8000:8000 tplink-deco-mcp-server:dev
56
+ ```
57
+
58
+ ## CI and releasing
59
+
60
+ `ci.yml` runs the shared `python-lint`/`python-test` reusables from
61
+ `roquerodrigo/workflows` plus a single-platform `docker` build, so a broken
62
+ `Dockerfile` fails the PR instead of the release. `release-please` owns the
63
+ version in `pyproject.toml` and `uv.lock` and the `CHANGELOG.md`; merging its PR
64
+ publishes to PyPI (`PYPI_API_TOKEN` secret) and pushes the multi-arch image to
65
+ ghcr tagged `<version>`, `<major>.<minor>`, `<major>` and `latest`.
66
+
67
+ ## Gotchas
68
+
69
+ - **One router session per account.** Every login — this server, the Deco app,
70
+ the `ha-tplink-deco` Home Assistant integration — evicts the previous holder.
71
+ `RouterSession` keeps its session open and logs in again only when a request
72
+ is rejected (`ApiError`, `AuthenticationError`, HTTP 401/403); a call can
73
+ therefore cost one extra login when something else took the session in
74
+ between. Don't "fix" this by logging in per call: that evicts everyone else
75
+ on every request.
76
+ - **Never write to stdout.** Over stdio, stdout is the JSON-RPC stream. Logging
77
+ is configured to stderr in `cli.py`.
78
+ - **Tool descriptions are the method docstrings** (`inspect.cleandoc`), and
79
+ argument descriptions are the `Field(description=…)` in each `Annotated`
80
+ parameter. Both are model-facing: write them for the LLM choosing the tool.
81
+ - **Tool signatures are read at runtime** to build the input schema, so types
82
+ used in them (`MacAddress`, summaries) must be imported at module level —
83
+ hence the `TC001` per-file ignore under `tools/`.
84
+ - **`ValueError` from the SDK is input validation** (malformed MAC/IP); it
85
+ becomes a `ToolError` without dropping the session. `DecoError`/`OSError`
86
+ drop the session so the next call logs in fresh.
87
+ - **Passwords stay out by default.** `get_wifi_configuration` returns Wi-Fi
88
+ passwords only with `include_passwords: true`.
89
+ - The MCP server version comes from the installed package metadata, so it
90
+ always matches the release.
91
+ - Repo is **public with branch protection** on `main` (reconciled weekly by the
92
+ repository policy in `roquerodrigo/workflows`): land changes through a PR with
93
+ green CI, merged with **rebase merge only**.
@@ -0,0 +1,156 @@
1
+ # Code Style Guide
2
+
3
+ Style conventions for `tplink-deco-mcp-server`, an MCP server exposing TP-Link
4
+ Deco mesh routers as tools for LLM clients. Run
5
+ `uv run ruff format . && uv run ruff check . --fix && uv run mypy` before
6
+ committing — all three must exit cleanly. `uv run pytest` follows.
7
+
8
+ **Always read this file before adding or restructuring code.**
9
+
10
+ ## Language
11
+
12
+ - Code is written in **English**: file names, class names, function names,
13
+ variable names, dictionary keys, tool names and descriptions.
14
+ - The conversation language with the user can be Portuguese or anything else;
15
+ what is committed to disk stays English.
16
+
17
+ ## File organization
18
+
19
+ - **Source layout is `src/tplink_deco_mcp_server/`**, tests in `tests/`,
20
+ packaging in `pyproject.toml`. Hatchling is the build backend.
21
+ - **Split by context.** `router/` owns the connection to the router,
22
+ `summaries/` the response shapes, `tools/` the tool groups. A new router
23
+ feature gets its own tool group class (`<feature>_tools.py`) and, when it
24
+ returns data, its own summary module.
25
+ - **One top-level class per file.** Leaf models parsed from a single payload
26
+ may share the module named after the top-level model
27
+ (`internet_status_summary.py` holds `IpConnectionSummary`,
28
+ `WanAddressSummary`, …).
29
+ - **Public surface goes through each package's `__init__.py`.** Module-level
30
+ private helpers are prefixed `_`.
31
+
32
+ ## Naming
33
+
34
+ - Classes are `CapWords`, describing what they are: `RouterSession`,
35
+ `ClientSummary`, `BlocklistTools`.
36
+ - Functions, methods and variables are `snake_case`. **No abbreviations**:
37
+ `download_kilobytes_per_second`, not `down_kbps`.
38
+ - **Tool names are the method names**, `snake_case` verbs: `list_clients`,
39
+ `block_client`, `get_internet_status`.
40
+ - Summary fields are named for the model reading them, not after the router's
41
+ wire keys (`network` instead of `interface`, `firmware_version` instead of
42
+ `software_ver`).
43
+
44
+ ## Typing
45
+
46
+ **Strict typing. No `Any`, no bare collection generics.** Mypy enforces this
47
+ with `disallow_any_explicit`.
48
+
49
+ - Response shapes are frozen pydantic models (`model_config =
50
+ ConfigDict(frozen=True)`); their `Field(description=…)` ends up in the
51
+ tool's output schema.
52
+ - Tool arguments are `Annotated[<type>, Field(description=…)]`; shared ones live
53
+ in `tools/tool_parameters.py` (`MacAddress`).
54
+ - `MCPServer` is always parametrized: `MCPServer[None]`.
55
+ - Always type return values explicitly.
56
+
57
+ ## Imports
58
+
59
+ - Every module starts with `from __future__ import annotations`.
60
+ - Same-package relative imports (`from .module import …`) are the default.
61
+ - Type-only imports go into a `TYPE_CHECKING` block — **except** what tool
62
+ signatures and pydantic fields reference: the MCP server and pydantic resolve
63
+ those annotations at runtime.
64
+ - `noqa` comments require a written justification inline.
65
+
66
+ ## Docstrings
67
+
68
+ - Every public class, function and method has a docstring; a module docstring
69
+ opens every file.
70
+ - **A tool method's docstring is its model-facing description.** Lead with
71
+ what the tool does and when to use it, then what it returns. Mention
72
+ related tools by name when the model should call one first or instead.
73
+
74
+ ## Comments
75
+
76
+ - Default to **no comments**. Add one only when the *why* is not obvious: a
77
+ hidden constraint, a router quirk, an MCP-protocol detail.
78
+ - **No section dividers.** Split into files instead.
79
+
80
+ ## Logging
81
+
82
+ - Module-level logger with an explicit dotted name:
83
+ `log: logging.Logger = logging.getLogger("tplink_deco_mcp_server.<area>")`.
84
+ - Lazy `%`-formatting, never f-strings.
85
+ - **Never write to stdout** — it is the JSON-RPC stream over stdio. Logging is
86
+ configured to stderr in `cli.py`; no `print`.
87
+ - Never log the router password, session tokens or Wi-Fi passwords.
88
+
89
+ ## Error messages
90
+
91
+ - Format: `"Failed to <verb> <object>: <cause>"`. Keep them short and
92
+ grep-able — the model reads them to decide what to do next.
93
+ - Tool code raises `ValueError` for bad input and lets SDK errors propagate;
94
+ `RouterSession.run` turns both into a `ToolError`, which the server returns
95
+ as `isError: true` content. Don't raise anything else across the tool
96
+ boundary: the server hides other exceptions behind a generic message.
97
+ - Bind the message to a local before raising: `message = "…"` then
98
+ `raise ValueError(message)`.
99
+
100
+ ## Public API surface
101
+
102
+ - **The MCP tool list is the public contract.** Adding a tool is `feat`;
103
+ removing or renaming a tool, an argument or a summary field is a
104
+ `BREAKING CHANGE:` — clients and prompts hard-code them.
105
+ - Read-only tools carry `READ_ONLY` annotations; tools that change settings
106
+ carry `CHANGES_SETTINGS` or, when they discard something, `DISCARDS_SETTINGS`.
107
+
108
+ ## Pre-commit hooks
109
+
110
+ The repository ships `.pre-commit-config.yaml` mirroring the lint commands;
111
+ install once per clone with `pre-commit install`.
112
+
113
+ ## Conventional commits
114
+
115
+ All commits follow [Conventional Commits](https://www.conventionalcommits.org/),
116
+ in **English**, which `release-please` parses to bump the version and generate
117
+ `CHANGELOG.md`:
118
+
119
+ | Type | Meaning | Bump |
120
+ |---|---|---|
121
+ | `feat` | New feature (e.g. new tool) | minor |
122
+ | `fix` | Bug fix | patch |
123
+ | `perf` | Performance improvement | patch |
124
+ | `deps` | Dependency bump | patch |
125
+ | `docs` | Documentation only | none |
126
+ | `refactor` | Refactor without behavior change | none |
127
+ | `test` | Test-only change | none |
128
+ | `ci` | CI / tooling change | none |
129
+ | `chore` | Anything else (rarely) | none |
130
+
131
+ - Subject line: imperative mood, lowercase, no trailing period.
132
+ - Use scopes when useful: `feat(tools): add guest network toggle`.
133
+ - A `BREAKING CHANGE:` footer (or `!` after type) bumps the major version.
134
+
135
+ ## Packaging
136
+
137
+ - `requires-python = ">=3.14"`, matching `tplink-deco-api`.
138
+ - Runtime dependencies use `>=` lower bounds; `uv.lock` pins what CI and the
139
+ Docker image install.
140
+ - `[project.scripts]` exposes `tplink-deco-mcp-server`.
141
+
142
+ ## Releasing
143
+
144
+ - `release-please` opens a release PR with the next version and
145
+ `CHANGELOG.md`. Merging it publishes to PyPI and pushes the Docker image to
146
+ ghcr.
147
+ - Don't manually edit the version in `pyproject.toml` — release-please owns it.
148
+
149
+ ## Testing
150
+
151
+ - `uv run pytest` runs the suite, gated at **90%** coverage.
152
+ - The suite is **network-free**: mock `DecoClient` (see `tests/conftest.py`)
153
+ and drive tools through the in-process `mcp.Client` fixture `call_tool`, so
154
+ schemas, structured output and error results are covered as clients see them.
155
+ - Build SDK records through `tests/factories.py`, overriding only the fields a
156
+ test cares about.
@@ -0,0 +1,31 @@
1
+ FROM --platform=$BUILDPLATFORM python:3.14-slim AS build
2
+
3
+ COPY --from=ghcr.io/astral-sh/uv:0.11.8 /uv /usr/local/bin/uv
4
+
5
+ WORKDIR /build
6
+
7
+ COPY pyproject.toml uv.lock README.md LICENSE ./
8
+ COPY src ./src
9
+
10
+ RUN uv build --wheel --out-dir dist \
11
+ && uv export --frozen --no-default-groups --no-emit-project --format requirements-txt \
12
+ --output-file dist/requirements.txt
13
+
14
+ FROM python:3.14-slim
15
+
16
+ ENV PYTHONDONTWRITEBYTECODE=1 \
17
+ PYTHONUNBUFFERED=1
18
+
19
+ RUN --mount=type=bind,from=build,source=/build/dist,target=/dist \
20
+ pip install --no-cache-dir --require-hashes --requirement /dist/requirements.txt \
21
+ && pip install --no-cache-dir --no-deps /dist/*.whl \
22
+ && useradd --system --uid 10001 --no-create-home mcp
23
+
24
+ USER mcp
25
+
26
+ EXPOSE 8000
27
+
28
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
29
+ CMD ["python", "-c", "import urllib.request, sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=5).status < 500 else 1)"]
30
+
31
+ CMD ["tplink-deco-mcp-server", "--transport", "streamable-http", "--host", "0.0.0.0", "--port", "8000"]
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rodrigo Roque
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.