backlog-tiny-mcp 0.35.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 (97) hide show
  1. backlog_tiny_mcp-0.35.0/PKG-INFO +84 -0
  2. backlog_tiny_mcp-0.35.0/README.md +65 -0
  3. backlog_tiny_mcp-0.35.0/pyproject.toml +93 -0
  4. backlog_tiny_mcp-0.35.0/pyproject.toml.orig +81 -0
  5. backlog_tiny_mcp-0.35.0/src/backlog_mcp/__init__.py +29 -0
  6. backlog_tiny_mcp-0.35.0/src/backlog_mcp/__main__.py +10 -0
  7. backlog_tiny_mcp-0.35.0/src/backlog_mcp/auth.py +199 -0
  8. backlog_tiny_mcp-0.35.0/src/backlog_mcp/backlog.py +696 -0
  9. backlog_tiny_mcp-0.35.0/src/backlog_mcp/cli.py +2046 -0
  10. backlog_tiny_mcp-0.35.0/src/backlog_mcp/client.py +320 -0
  11. backlog_tiny_mcp-0.35.0/src/backlog_mcp/computer.py +33 -0
  12. backlog_tiny_mcp-0.35.0/src/backlog_mcp/database.py +80 -0
  13. backlog_tiny_mcp-0.35.0/src/backlog_mcp/embeddings.py +900 -0
  14. backlog_tiny_mcp-0.35.0/src/backlog_mcp/global_rules.md +126 -0
  15. backlog_tiny_mcp-0.35.0/src/backlog_mcp/guidance.py +11 -0
  16. backlog_tiny_mcp-0.35.0/src/backlog_mcp/guide/index.md +11 -0
  17. backlog_tiny_mcp-0.35.0/src/backlog_mcp/guide/memory.md +27 -0
  18. backlog_tiny_mcp-0.35.0/src/backlog_mcp/guide/projects.md +16 -0
  19. backlog_tiny_mcp-0.35.0/src/backlog_mcp/guide/search.md +72 -0
  20. backlog_tiny_mcp-0.35.0/src/backlog_mcp/guide/tasks.md +40 -0
  21. backlog_tiny_mcp-0.35.0/src/backlog_mcp/guide/workflow.md +22 -0
  22. backlog_tiny_mcp-0.35.0/src/backlog_mcp/httpd.py +270 -0
  23. backlog_tiny_mcp-0.35.0/src/backlog_mcp/migrate.py +113 -0
  24. backlog_tiny_mcp-0.35.0/src/backlog_mcp/migrations/0001-initial.sql +194 -0
  25. backlog_tiny_mcp-0.35.0/src/backlog_mcp/migrations/0002-task-assignment.sql +2 -0
  26. backlog_tiny_mcp-0.35.0/src/backlog_mcp/migrations/0003-task-edit-claims.sql +5 -0
  27. backlog_tiny_mcp-0.35.0/src/backlog_mcp/migrations/0004-memory-visibility.sql +42 -0
  28. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/CITATION.bib +9 -0
  29. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/LICENSE +202 -0
  30. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/README.md +12 -0
  31. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/UPSTREAM.md +2053 -0
  32. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/config.json +12 -0
  33. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/model.safetensors +4 -0
  34. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/modules.json +14 -0
  35. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/provenance.json +16 -0
  36. backlog_tiny_mcp-0.35.0/src/backlog_mcp/model/tokenizer.json +1 -0
  37. backlog_tiny_mcp-0.35.0/src/backlog_mcp/models.py +581 -0
  38. backlog_tiny_mcp-0.35.0/src/backlog_mcp/names.py +35 -0
  39. backlog_tiny_mcp-0.35.0/src/backlog_mcp/paths.py +53 -0
  40. backlog_tiny_mcp-0.35.0/src/backlog_mcp/protocol_storage.py +104 -0
  41. backlog_tiny_mcp-0.35.0/src/backlog_mcp/queries.py +7 -0
  42. backlog_tiny_mcp-0.35.0/src/backlog_mcp/queries.sql +531 -0
  43. backlog_tiny_mcp-0.35.0/src/backlog_mcp/records.py +215 -0
  44. backlog_tiny_mcp-0.35.0/src/backlog_mcp/render.py +479 -0
  45. backlog_tiny_mcp-0.35.0/src/backlog_mcp/server.py +2864 -0
  46. backlog_tiny_mcp-0.35.0/src/backlog_mcp/skills/autopilot/SKILL.md +96 -0
  47. backlog_tiny_mcp-0.35.0/src/backlog_mcp/skills/planning/SKILL.md +106 -0
  48. backlog_tiny_mcp-0.35.0/src/backlog_mcp/skills/planning/references/splitting.md +45 -0
  49. backlog_tiny_mcp-0.35.0/src/backlog_mcp/skills/triage/SKILL.md +104 -0
  50. backlog_tiny_mcp-0.35.0/src/backlog_mcp/skills/triage/references/conventions.md +43 -0
  51. backlog_tiny_mcp-0.35.0/src/backlog_mcp/skills.py +56 -0
  52. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/agent-config.js +20 -0
  53. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/app.css +1950 -0
  54. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/app.js +1301 -0
  55. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/assignments.js +96 -0
  56. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/breadcrumbs.js +54 -0
  57. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/comment-composer.js +95 -0
  58. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/connect.css +98 -0
  59. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/connect.html +74 -0
  60. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/connect.js +160 -0
  61. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/credentials.js +72 -0
  62. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/diagrams.js +128 -0
  63. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/dom.js +162 -0
  64. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/editor-claim.js +104 -0
  65. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/editor.js +355 -0
  66. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/index.html +137 -0
  67. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/markdown.css +33 -0
  68. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/markdown.js +72 -0
  69. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/mcp.js +177 -0
  70. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/memory-append.js +34 -0
  71. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/memory-editor.js +173 -0
  72. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/memory.js +279 -0
  73. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/package.json +1 -0
  74. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/project-form.js +71 -0
  75. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/project-settings.js +225 -0
  76. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/scope.js +90 -0
  77. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/statistics.js +87 -0
  78. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/task-browser.js +100 -0
  79. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/task-pagination.js +94 -0
  80. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/task-picker.js +164 -0
  81. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/task-table.js +74 -0
  82. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/README.md +12 -0
  83. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/dompurify-LICENSE +202 -0
  84. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/highlight-LICENSE +29 -0
  85. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/highlight-dark.css +118 -0
  86. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/highlight-light.css +118 -0
  87. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/highlight.min.js +1262 -0
  88. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/marked-LICENSE +44 -0
  89. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/marked.esm.js +80 -0
  90. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/marked.esm.js.map +7 -0
  91. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/mermaid-LICENSE +21 -0
  92. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/mermaid.min.js +4376 -0
  93. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/purify.es.mjs +2722 -0
  94. backlog_tiny_mcp-0.35.0/src/backlog_mcp/static/vendor/purify.es.mjs.map +1 -0
  95. backlog_tiny_mcp-0.35.0/src/backlog_mcp/transaction.py +47 -0
  96. backlog_tiny_mcp-0.35.0/src/backlog_mcp/version.py +79 -0
  97. backlog_tiny_mcp-0.35.0/src/backlog_mcp/webui.py +63 -0
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.3
2
+ Name: backlog-tiny-mcp
3
+ Version: 0.35.0
4
+ Summary: A project backlog over MCP: projects scoped to directories, tasks scoped to projects
5
+ Author: Dmitry Orlov
6
+ Author-email: Dmitry Orlov <orlovdl@gmail.com>
7
+ Requires-Dist: aiohttp-tiny-mcp[jwt,skills]~=0.10.1
8
+ Requires-Dist: aiosql>=15.0
9
+ Requires-Dist: aiosqlite>=0.21.0
10
+ Requires-Dist: argclass>=1.11.0
11
+ Requires-Dist: bcrypt>=5.0.0
12
+ Requires-Dist: model2vec>=0.9.0
13
+ Requires-Dist: numpy>=2.0
14
+ Requires-Dist: rich>=15.0.0
15
+ Requires-Dist: rtoml>=0.13.0
16
+ Requires-Python: >=3.14
17
+ Project-URL: Documentation, https://mosquito.github.io/backlog-mcp/
18
+ Description-Content-Type: text/markdown
19
+
20
+ # backlog-mcp
21
+
22
+ A task tracker and a memory for AI agents over the Model Context Protocol (MCP). People use the
23
+ same data from the terminal and from a browser.
24
+
25
+ A project has many participants, and each of them works with agents. backlog-mcp keeps what
26
+ the agents did and why in one place, and its semantic search gives it to every agent of every
27
+ participant: an agent asks a question in its own words and gets the tasks that answer it.
28
+
29
+ ```text
30
+ Anna: Why are the sign-in rate limits kept in a database table?
31
+ Redis is the usual choice.
32
+
33
+ Agent: Michael built it this way in task #42. Redis was considered and
34
+ rejected: the team does not run Redis in production and did not
35
+ want to add a service for one feature.
36
+ ```
37
+
38
+ Anna's agent never saw this code or Michael's conversation. It made one semantic search in the
39
+ backlog; the search matches meaning, not words, and runs on a model that ships with the package.
40
+ [How it works](https://mosquito.github.io/backlog-mcp/#how-it-works).
41
+
42
+ Documentation: https://mosquito.github.io/backlog-mcp/
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ uv tool install backlog-tiny-mcp
48
+ ```
49
+
50
+ The package on PyPI is `backlog-tiny-mcp`; it installs two commands: `backlog` and
51
+ `backlog-mcp`. To run the server in Docker or Kubernetes, see
52
+ [Installation](https://mosquito.github.io/backlog-mcp/install.html).
53
+
54
+ ## Choose how to run it
55
+
56
+ **Local MCP server over stdio.** An agent on your computer starts the server itself. The data
57
+ stays in a local SQLite file. `backlog install` registers the server with Claude Code and Codex.
58
+ See [Local MCP server over stdio](https://mosquito.github.io/backlog-mcp/stdio.html).
59
+
60
+ ```bash
61
+ backlog mcp
62
+ ```
63
+
64
+ **Remote MCP server over HTTP.** One server for several computers, agents and people, with Basic
65
+ or JWT authentication, a browser interface and a page that generates the agent configuration.
66
+ See [Remote MCP server over HTTP](https://mosquito.github.io/backlog-mcp/http.html).
67
+
68
+ ```bash
69
+ backlog mcp --protocol=http --auth-basic=alice:secret
70
+ ```
71
+
72
+ **Command line.** The `backlog` command works with a local database or with a remote server.
73
+ See [Command line](https://mosquito.github.io/backlog-mcp/cli.html). To make every command use
74
+ the remote server, put `url` and the credentials into `~/.config/backlog-mcp/config.toml`; see
75
+ [Always use a remote server](https://mosquito.github.io/backlog-mcp/cli.html#always-use-a-remote-server).
76
+
77
+ ```bash
78
+ backlog task add "Fix the login form"
79
+ backlog --url https://backlog.example/mcp --user alice --password secret task list
80
+ ```
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,65 @@
1
+ # backlog-mcp
2
+
3
+ A task tracker and a memory for AI agents over the Model Context Protocol (MCP). People use the
4
+ same data from the terminal and from a browser.
5
+
6
+ A project has many participants, and each of them works with agents. backlog-mcp keeps what
7
+ the agents did and why in one place, and its semantic search gives it to every agent of every
8
+ participant: an agent asks a question in its own words and gets the tasks that answer it.
9
+
10
+ ```text
11
+ Anna: Why are the sign-in rate limits kept in a database table?
12
+ Redis is the usual choice.
13
+
14
+ Agent: Michael built it this way in task #42. Redis was considered and
15
+ rejected: the team does not run Redis in production and did not
16
+ want to add a service for one feature.
17
+ ```
18
+
19
+ Anna's agent never saw this code or Michael's conversation. It made one semantic search in the
20
+ backlog; the search matches meaning, not words, and runs on a model that ships with the package.
21
+ [How it works](https://mosquito.github.io/backlog-mcp/#how-it-works).
22
+
23
+ Documentation: https://mosquito.github.io/backlog-mcp/
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ uv tool install backlog-tiny-mcp
29
+ ```
30
+
31
+ The package on PyPI is `backlog-tiny-mcp`; it installs two commands: `backlog` and
32
+ `backlog-mcp`. To run the server in Docker or Kubernetes, see
33
+ [Installation](https://mosquito.github.io/backlog-mcp/install.html).
34
+
35
+ ## Choose how to run it
36
+
37
+ **Local MCP server over stdio.** An agent on your computer starts the server itself. The data
38
+ stays in a local SQLite file. `backlog install` registers the server with Claude Code and Codex.
39
+ See [Local MCP server over stdio](https://mosquito.github.io/backlog-mcp/stdio.html).
40
+
41
+ ```bash
42
+ backlog mcp
43
+ ```
44
+
45
+ **Remote MCP server over HTTP.** One server for several computers, agents and people, with Basic
46
+ or JWT authentication, a browser interface and a page that generates the agent configuration.
47
+ See [Remote MCP server over HTTP](https://mosquito.github.io/backlog-mcp/http.html).
48
+
49
+ ```bash
50
+ backlog mcp --protocol=http --auth-basic=alice:secret
51
+ ```
52
+
53
+ **Command line.** The `backlog` command works with a local database or with a remote server.
54
+ See [Command line](https://mosquito.github.io/backlog-mcp/cli.html). To make every command use
55
+ the remote server, put `url` and the credentials into `~/.config/backlog-mcp/config.toml`; see
56
+ [Always use a remote server](https://mosquito.github.io/backlog-mcp/cli.html#always-use-a-remote-server).
57
+
58
+ ```bash
59
+ backlog task add "Fix the login form"
60
+ backlog --url https://backlog.example/mcp --user alice --password secret task list
61
+ ```
62
+
63
+ ## License
64
+
65
+ MIT
@@ -0,0 +1,93 @@
1
+ [project]
2
+ name = "backlog-tiny-mcp"
3
+ version = "0.35.0"
4
+ description = "A project backlog over MCP: projects scoped to directories, tasks scoped to projects"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ dependencies = [
8
+ "aiohttp-tiny-mcp[jwt,skills]~=0.10.1",
9
+ "aiosql>=15.0",
10
+ "aiosqlite>=0.21.0",
11
+ "argclass>=1.11.0",
12
+ "bcrypt>=5.0.0",
13
+ "model2vec>=0.9.0",
14
+ "numpy>=2.0",
15
+ "rich>=15.0.0",
16
+ "rtoml>=0.13.0",
17
+ ]
18
+
19
+ [[project.authors]]
20
+ name = "Dmitry Orlov"
21
+ email = "orlovdl@gmail.com"
22
+
23
+ [project.urls]
24
+ Documentation = "https://mosquito.github.io/backlog-mcp/"
25
+
26
+ [project.scripts]
27
+ backlog = "backlog_mcp.cli:main"
28
+ backlog-mcp = "backlog_mcp.cli:server_main"
29
+
30
+ [build-system]
31
+ requires = ["uv_build>=0.12.9,<0.13.0"]
32
+ build-backend = "uv_build"
33
+
34
+ [tool.uv.build-backend]
35
+ module-name = "backlog_mcp"
36
+
37
+ [tool.ruff]
38
+ line-length = 100
39
+ target-version = "py314"
40
+
41
+ [tool.ruff.lint]
42
+ select = [
43
+ "E",
44
+ "F",
45
+ "I",
46
+ "W",
47
+ "UP",
48
+ "B",
49
+ "C4",
50
+ "RET",
51
+ "SIM",
52
+ "TID",
53
+ ]
54
+
55
+ [tool.ruff.lint.per-file-ignores]
56
+ "benchmarks/**" = ["E501"]
57
+
58
+ [tool.mypy]
59
+ python_version = "3.14"
60
+ strict = true
61
+ warn_unused_ignores = true
62
+ disallow_untyped_defs = true
63
+ disallow_untyped_decorators = false
64
+
65
+ [[tool.mypy.overrides]]
66
+ module = ["argclass"]
67
+ ignore_missing_imports = true
68
+
69
+ [tool.pytest.ini_options]
70
+ asyncio_mode = "auto"
71
+ addopts = "-q"
72
+ testpaths = ["tests"]
73
+
74
+ [tool.coverage.report]
75
+ exclude_also = [
76
+ "if TYPE_CHECKING:",
77
+ "raise NotImplementedError",
78
+ ]
79
+
80
+ [dependency-groups]
81
+ dev = [
82
+ "markdown-pytest>=0.6.6",
83
+ "mypy>=1.14",
84
+ "pytest>=8.3",
85
+ "pytest-asyncio>=0.25",
86
+ "pytest-cov>=6.0",
87
+ "ruff>=0.9",
88
+ ]
89
+ docs = [
90
+ "furo>=2025.12.19",
91
+ "myst-parser>=4.0.1",
92
+ "sphinx>=8.1.3",
93
+ ]
@@ -0,0 +1,81 @@
1
+ [project]
2
+ name = "backlog-tiny-mcp"
3
+ version = "0.35.0"
4
+ description = "A project backlog over MCP: projects scoped to directories, tasks scoped to projects"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Dmitry Orlov", email = "orlovdl@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.14"
10
+ dependencies = [
11
+ "aiohttp-tiny-mcp[jwt,skills]~=0.10.1",
12
+ "aiosql>=15.0",
13
+ "aiosqlite>=0.21.0",
14
+ "argclass>=1.11.0",
15
+ "bcrypt>=5.0.0",
16
+ "model2vec>=0.9.0",
17
+ "numpy>=2.0",
18
+ "rich>=15.0.0",
19
+ "rtoml>=0.13.0",
20
+ ]
21
+
22
+ [project.urls]
23
+ Documentation = "https://mosquito.github.io/backlog-mcp/"
24
+
25
+ [project.scripts]
26
+ backlog = "backlog_mcp.cli:main"
27
+ backlog-mcp = "backlog_mcp.cli:server_main"
28
+
29
+ [build-system]
30
+ requires = ["uv_build>=0.12.9,<0.13.0"]
31
+ build-backend = "uv_build"
32
+
33
+ # The PyPI name differs from the import package: `backlog-mcp` on PyPI is another project.
34
+ [tool.uv.build-backend]
35
+ module-name = "backlog_mcp"
36
+
37
+ [dependency-groups]
38
+ dev = [
39
+ "markdown-pytest>=0.6.6",
40
+ "mypy>=1.14",
41
+ "pytest>=8.3",
42
+ "pytest-asyncio>=0.25",
43
+ "pytest-cov>=6.0",
44
+ "ruff>=0.9",
45
+ ]
46
+ docs = [
47
+ "furo>=2025.12.19",
48
+ "myst-parser>=4.0.1",
49
+ "sphinx>=8.1.3",
50
+ ]
51
+
52
+ [tool.ruff]
53
+ line-length = 100
54
+ target-version = "py314"
55
+
56
+ [tool.ruff.lint]
57
+ select = ["E", "F", "I", "W", "UP", "B", "C4", "RET", "SIM", "TID"]
58
+
59
+ [tool.ruff.lint.per-file-ignores]
60
+ # Benchmark data: long literal rows and model identifiers.
61
+ "benchmarks/**" = ["E501"]
62
+
63
+ [tool.mypy]
64
+ python_version = "3.14"
65
+ strict = true
66
+ warn_unused_ignores = true
67
+ disallow_untyped_defs = true
68
+ # The registry decorators in aiohttp-tiny-mcp are unannotated; the handlers below them are not.
69
+ disallow_untyped_decorators = false
70
+
71
+ [[tool.mypy.overrides]]
72
+ module = ["argclass"]
73
+ ignore_missing_imports = true
74
+
75
+ [tool.pytest.ini_options]
76
+ asyncio_mode = "auto"
77
+ addopts = "-q"
78
+ testpaths = ["tests"]
79
+
80
+ [tool.coverage.report]
81
+ exclude_also = ["if TYPE_CHECKING:", "raise NotImplementedError"]
@@ -0,0 +1,29 @@
1
+ """backlog-mcp: a project backlog on the command line and over MCP, on stdio or over HTTP.
2
+
3
+ Tasks belong to projects, and a project is a directory tree. The working directory therefore
4
+ decides which backlog a command works on, with nothing to pass. `backlog mcp` serves the same
5
+ data over MCP: on stdio by default, or over HTTP behind Basic auth with `--protocol=http`.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from .backlog import Backlog, UnknownProject
11
+ from .cli import CLI, build, main, server_main
12
+ from .database import Database
13
+ from .models import Priority, Status
14
+ from .server import VERSION, registry, use
15
+
16
+ __all__ = [
17
+ "CLI",
18
+ "VERSION",
19
+ "Backlog",
20
+ "Priority",
21
+ "Status",
22
+ "Database",
23
+ "UnknownProject",
24
+ "build",
25
+ "main",
26
+ "registry",
27
+ "server_main",
28
+ "use",
29
+ ]
@@ -0,0 +1,10 @@
1
+ """`python -m backlog_mcp`, for a client that has no console script on its PATH."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+
7
+ from .cli import main
8
+
9
+ if __name__ == "__main__":
10
+ sys.exit(main())
@@ -0,0 +1,199 @@
1
+ """Basic and JWT credentials verified against trusted server configuration."""
2
+
3
+ import asyncio
4
+ import re
5
+ from base64 import b64decode
6
+ from collections.abc import Sequence
7
+ from concurrent.futures import ThreadPoolExecutor
8
+ from dataclasses import replace
9
+ from functools import partial
10
+
11
+ import bcrypt
12
+ from aiohttp import web
13
+ from aiohttp_tiny_mcp import Authentication, BasicAuth, Principal, Unauthorized
14
+ from aiohttp_tiny_mcp.auth import TokenVerifier
15
+
16
+
17
+ def decode_pair(token: str) -> tuple[str, str] | None:
18
+ """`user:password` from base64, standard or URL-safe alphabet, or `None` when malformed."""
19
+ stripped = token.strip()
20
+ padded = stripped + "=" * (-len(stripped) % 4)
21
+ for altchars in (None, b"-_"):
22
+ try:
23
+ decoded = b64decode(padded, altchars=altchars, validate=True).decode("utf-8")
24
+ except ValueError, UnicodeDecodeError:
25
+ continue
26
+ user, separator, password = decoded.partition(":")
27
+ return (user, password) if separator else None
28
+ return None
29
+
30
+
31
+ REALM = "backlog-mcp"
32
+ BCRYPT_COST = 10
33
+
34
+
35
+ def user_identity(username: str) -> str:
36
+ """A username identifies one account across supported authentication methods."""
37
+ if (
38
+ not username
39
+ or username != username.strip()
40
+ or any(ord(c) < 32 or ord(c) == 127 for c in username)
41
+ ):
42
+ raise ValueError("principal must be a non-empty username without control characters")
43
+ return username
44
+
45
+
46
+ # Trusted request-local result from the pre-dispatch authentication middleware.
47
+ VERIFIED: web.RequestKey[dict[Authentication, Principal | None]] = web.RequestKey(
48
+ "backlog_verified_principals", dict
49
+ )
50
+
51
+
52
+ def request_token(request: web.Request, *, scheme: str, query_parameter: str) -> str:
53
+ """Read query credentials only when no Authorization header is present."""
54
+ if "Authorization" in request.headers:
55
+ parts = request.headers["Authorization"].split()
56
+ return parts[1] if len(parts) == 2 and parts[0].lower() == scheme.lower() else ""
57
+ token = request.query.get(query_parameter, "")
58
+ return token.replace(" ", "+") if scheme == "Basic" else token
59
+
60
+
61
+ def credentials(request: web.Request) -> tuple[str, str] | None:
62
+ """Decode Basic credentials from the header or the auth query parameter."""
63
+ return decode_pair(request_token(request, scheme="Basic", query_parameter="auth"))
64
+
65
+
66
+ def validate_account(username: str, password: str) -> None:
67
+ """Reject values that cannot be represented by HTTP Basic credentials."""
68
+ user_identity(username)
69
+ if (
70
+ not password
71
+ or ":" in username
72
+ or any(ord(char) < 32 or ord(char) == 127 for char in password)
73
+ ):
74
+ raise ValueError(
75
+ "Basic accounts need a non-empty password without controls "
76
+ "and a username without a colon"
77
+ )
78
+
79
+
80
+ def validate_bcrypt_cost(value: int | str) -> int:
81
+ """Accept the bcrypt work-factor range."""
82
+ if isinstance(value, bool) or not isinstance(value, (int, str)):
83
+ raise ValueError("Bcrypt cost must be an integer between 4 and 31")
84
+ cost = int(value)
85
+ if not 4 <= cost <= 31:
86
+ raise ValueError("Bcrypt cost must be between 4 and 31")
87
+ return cost
88
+
89
+
90
+ def bcrypt_account(value: str, cost: int = BCRYPT_COST) -> str:
91
+ """Convert one plaintext entry or validate an existing bcrypt entry."""
92
+ cost = validate_bcrypt_cost(cost)
93
+ if value.startswith("bcrypt|") and ":" not in value:
94
+ username, separator, hashed = value.removeprefix("bcrypt|").rpartition("|")
95
+ if not separator or not re.fullmatch(
96
+ r"\$2[aby]\$(?:0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{53}", hashed
97
+ ):
98
+ raise ValueError("Use bcrypt|username|<hash> with a valid bcrypt hash")
99
+ validate_account(username, hashed)
100
+ return value
101
+ username, separator, password = value.partition(":")
102
+ if not separator:
103
+ raise ValueError("Use username:password or bcrypt|username|<hash> for Basic accounts")
104
+ validate_account(username, password)
105
+ encoded = password.encode("utf-8")
106
+ if len(encoded) > 72:
107
+ raise ValueError("Bcrypt passwords must not exceed 72 UTF-8 bytes")
108
+ hashed = bcrypt.hashpw(encoded, bcrypt.gensalt(rounds=cost)).decode("ascii")
109
+ return f"bcrypt|{username}|{hashed}"
110
+
111
+
112
+ def normalize_accounts(values: Sequence[str], cost: int = BCRYPT_COST) -> list[str]:
113
+ """Hash configuration values in a worker while keeping existing hashes unchanged."""
114
+ cost = validate_bcrypt_cost(cost)
115
+ if not values:
116
+ return []
117
+ with ThreadPoolExecutor(max_workers=1) as executor:
118
+ return list(executor.map(partial(bcrypt_account, cost=cost), values))
119
+
120
+
121
+ class BasicAuthentication(BasicAuth):
122
+ """Verify bcrypt passwords over Basic headers and query credentials."""
123
+
124
+ def __init__(
125
+ self,
126
+ *accounts: tuple[str, str],
127
+ hashed_accounts: Sequence[tuple[str, str]] = (),
128
+ cost: int = BCRYPT_COST,
129
+ ) -> None:
130
+ super().__init__(realm=REALM)
131
+ if not accounts and not hashed_accounts:
132
+ raise ValueError("At least one Basic account is required")
133
+ for username, password in (*accounts, *hashed_accounts):
134
+ validate_account(username, password)
135
+ normalized = normalize_accounts(
136
+ [f"{username}:{password}" for username, password in accounts]
137
+ + [f"bcrypt|{username}|{hashed}" for username, hashed in hashed_accounts],
138
+ cost=cost,
139
+ )
140
+ self.password_hashes: dict[str, bytes] = {}
141
+ for value in normalized:
142
+ username, hashed = value.removeprefix("bcrypt|").rsplit("|", 1)
143
+ if username in self.password_hashes:
144
+ raise ValueError("Basic account usernames must be unique")
145
+ self.password_hashes[username] = hashed.encode("ascii")
146
+
147
+ async def verify(self, username: str, password: str) -> Principal | None:
148
+ hashed = self.password_hashes.get(username)
149
+ expected = hashed if hashed is not None else next(iter(self.password_hashes.values()))
150
+ encoded = password.encode("utf-8")
151
+ if len(encoded) > 72:
152
+ return None
153
+ try:
154
+ matched = await asyncio.to_thread(bcrypt.checkpw, encoded, expected)
155
+ except ValueError:
156
+ return None
157
+ return Principal(subject=username) if hashed is not None and matched else None
158
+
159
+ async def authenticate(self, request: web.Request) -> Principal | None:
160
+ verified: dict[Authentication, Principal | None] = request.setdefault(VERIFIED, {})
161
+ if self in verified:
162
+ return verified[self]
163
+ given = credentials(request)
164
+ if given is None or any(ord(char) < 32 or ord(char) == 127 for char in "".join(given)):
165
+ verified[self] = None
166
+ return None
167
+ principal = await self.verify(*given)
168
+ verified[self] = (
169
+ replace(principal, namespace=user_identity(given[0])) if principal else None
170
+ )
171
+ return verified[self]
172
+
173
+
174
+ class JWTAuthentication(Authentication):
175
+ """Authenticate externally issued JWTs without advertising an OAuth server."""
176
+
177
+ def __init__(self, verifier: TokenVerifier) -> None:
178
+ super().__init__()
179
+ self.verifier = verifier
180
+
181
+ async def authenticate(self, request: web.Request) -> Principal | None:
182
+ verified: dict[Authentication, Principal | None] = request.setdefault(VERIFIED, {})
183
+ if self in verified:
184
+ return verified[self]
185
+ token = request_token(request, scheme="Bearer", query_parameter="token")
186
+ principal = await self.verifier.verify(token) if token else None
187
+ if principal and principal.subject:
188
+ try:
189
+ identity = user_identity(principal.subject)
190
+ except ValueError:
191
+ verified[self] = None
192
+ else:
193
+ verified[self] = replace(principal, namespace=identity)
194
+ else:
195
+ verified[self] = None
196
+ return verified[self]
197
+
198
+ def challenge(self, refusal: Unauthorized) -> str:
199
+ return f'Bearer realm="{REALM}"'