mktotp 0.9.13__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 (39) hide show
  1. mktotp-0.9.13/.claude/CLAUDE.md +3 -0
  2. mktotp-0.9.13/.claude/settings.local.json +5 -0
  3. mktotp-0.9.13/.claude-plugin/plugin.json +10 -0
  4. mktotp-0.9.13/.gitignore +20 -0
  5. mktotp-0.9.13/.mcp.json +13 -0
  6. mktotp-0.9.13/.python-version +1 -0
  7. mktotp-0.9.13/.vscode/launch.json +56 -0
  8. mktotp-0.9.13/.vscode/mcp.json +16 -0
  9. mktotp-0.9.13/.vscode/settings.json +17 -0
  10. mktotp-0.9.13/.vscode/task.json +6 -0
  11. mktotp-0.9.13/AGENTS.md +81 -0
  12. mktotp-0.9.13/LICENSE +21 -0
  13. mktotp-0.9.13/PKG-INFO +254 -0
  14. mktotp-0.9.13/README.md +238 -0
  15. mktotp-0.9.13/README_ja.md +239 -0
  16. mktotp-0.9.13/mktotp.code-workspace +8 -0
  17. mktotp-0.9.13/pyproject.toml +38 -0
  18. mktotp-0.9.13/pytest.ini +4 -0
  19. mktotp-0.9.13/src/mktotp/__init__.py +3 -0
  20. mktotp-0.9.13/src/mktotp/__main__.py +202 -0
  21. mktotp-0.9.13/src/mktotp/cmdparam.py +182 -0
  22. mktotp-0.9.13/src/mktotp/func_impl.py +180 -0
  23. mktotp-0.9.13/src/mktotp/logutil.py +102 -0
  24. mktotp-0.9.13/src/mktotp/mcp_impl.py +282 -0
  25. mktotp-0.9.13/src/mktotp/mcp_server.py +201 -0
  26. mktotp-0.9.13/src/mktotp/permutil.py +81 -0
  27. mktotp-0.9.13/src/mktotp/py.typed +0 -0
  28. mktotp-0.9.13/src/mktotp/qrcode_util.py +110 -0
  29. mktotp-0.9.13/src/mktotp/secrets.py +491 -0
  30. mktotp-0.9.13/src/mktotp_main.py +23 -0
  31. mktotp-0.9.13/test/test_cmdparam.py +414 -0
  32. mktotp-0.9.13/test/test_filelock.py +265 -0
  33. mktotp-0.9.13/test/test_func_impl.py +483 -0
  34. mktotp-0.9.13/test/test_logutil.py +310 -0
  35. mktotp-0.9.13/test/test_main.py +495 -0
  36. mktotp-0.9.13/test/test_mcp_impl.py +417 -0
  37. mktotp-0.9.13/test/test_permutil.py +247 -0
  38. mktotp-0.9.13/test/test_qrcode_util.py +292 -0
  39. mktotp-0.9.13/test/test_secrets.py +534 -0
@@ -0,0 +1,3 @@
1
+
2
+ @../AGENTS.md
3
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "enabledMcpjsonServers": [
3
+ "zv-mktotp"
4
+ ]
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "mktotp-mcp",
3
+ "description": "Interactive TOTP (Time-based One-Time Password) manager. Helps create, list, and manage TOTP secrets and generate one-time passwords.",
4
+ "version": "0.9.13",
5
+ "author": {
6
+ "name": "kanok-one",
7
+ "email": "zervoid77@gmail.com"
8
+ },
9
+ "license": "MIT"
10
+ }
@@ -0,0 +1,20 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+ .pytest_cache/
9
+ temp/
10
+ tmp/
11
+
12
+ # Virtual environments
13
+ .venv
14
+
15
+ # uv.lock
16
+ uv.lock
17
+
18
+ # temporary test files
19
+ nonexistent_secrets.lock
20
+ nonexistent_secrets.json
@@ -0,0 +1,13 @@
1
+ {
2
+ "mcpServers": {
3
+ "zv-mktotp": {
4
+ "command": "uv",
5
+ "args": [
6
+ "run",
7
+ "${CLAUDE_PLUGIN_ROOT:-.}/src/mktotp_main.py",
8
+ "mcp",
9
+ "--mcp-server"
10
+ ]
11
+ }
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,56 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ // プラグインデバッグ用
5
+ {
6
+ "name": "Python Plugin Debug (Attach)",
7
+ "type": "debugpy",
8
+ "request": "attach",
9
+ "connect": {
10
+ "host": "localhost", // replace this with remote machine name
11
+ "port": 5678
12
+ },
13
+ "justMyCode": false
14
+ },
15
+ {
16
+ "name": "Python debug current file",
17
+ "type": "debugpy",
18
+ "request": "launch",
19
+ "program": "${file}",
20
+ "console" : "integratedTerminal",
21
+ // "stopOnEntry": true,
22
+ "env": {
23
+
24
+ }
25
+ },
26
+ {
27
+ "name": "Python: 'mktotp'",
28
+ "type": "debugpy",
29
+ "request": "launch",
30
+ "module": "mktotp",
31
+ "args": [
32
+ "list",
33
+ ],
34
+ "console": "integratedTerminal",
35
+ // "stopOnEntry": true,
36
+ "env": {
37
+
38
+ }
39
+ },
40
+ {
41
+ "name": "Python: 'mktotp help'",
42
+ "type": "debugpy",
43
+ "request": "launch",
44
+ "module": "mktotp",
45
+ "args": [
46
+ "-h",
47
+ ],
48
+ "console": "integratedTerminal",
49
+ // "stopOnEntry": true,
50
+ "env": {
51
+
52
+ }
53
+ }
54
+ ],
55
+ "compounds": []
56
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "servers": {
3
+ "mktotp-ws": {
4
+ "type": "stdio",
5
+ "command": "uv",
6
+ "args": [
7
+ "run",
8
+ "${workspaceFolder}/src/mktotp_main.py",
9
+ "mcp",
10
+ "--mcp-server"
11
+ ],
12
+ "env": {},
13
+ }
14
+ },
15
+ "inputs": []
16
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ // 単体テストツールとしてpytestを有効化
3
+ "python.testing.pytestEnabled": true,
4
+ // ファイル保存時にテスト対象コードを自動的に探索
5
+ "python.testing.autoTestDiscoverOnSaveEnabled": true,
6
+ "python.testing.pytestArgs": [
7
+ "test"
8
+ ],
9
+ "python.testing.unittestEnabled": false,
10
+ "python-envs.pythonProjects": [
11
+ {
12
+ "path": "",
13
+ "envManager": "ms-python.python:venv",
14
+ "packageManager": "ms-python.python:pip"
15
+ }
16
+ ],
17
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+
5
+ ]
6
+ }
@@ -0,0 +1,81 @@
1
+ # mktotp project
2
+
3
+ TOTP(二要素認証のワンタイムパスワード)のシークレットを管理する CUI ツール兼ローカル MCP サーバー。
4
+ QR コード画像からシークレットを登録し、登録済みシークレットからトークンを生成する。
5
+ MCP 経由で操作される前提のため、シークレット文字列そのものを LLM 側へ返さないことを設計上の原則としている。
6
+
7
+ ## 技術スタック
8
+
9
+ - Python 3.12 以上、パッケージ管理は uv、ビルドは hatchling
10
+ - 主な依存: `pyotp`(TOTP 生成)、`fastmcp`(MCP サーバー)、`opencv-python` / `pillow` / `cairosvg`(QR コード読み取り、SVG 対応)、`filelock`(排他制御)、`pydantic`
11
+ - テスト: pytest + pytest-asyncio(`asyncio_mode = auto`)
12
+
13
+ ## ディレクトリ構成
14
+
15
+ ```text
16
+ src/mktotp/
17
+ __main__.py CLI エントリポイント(main)とサブコマンドのハンドラ
18
+ cmdparam.py argparse のサブコマンド定義(add / get / list / remove / rename / mcp)
19
+ func_impl.py CLI と MCP で共有する業務ロジック(SecretMgr を with で開いて操作)
20
+ secrets.py SecretMgr: シークレット JSON の読み書き、ロック、TOTP 生成
21
+ qrcode_util.py QR コード画像のデコード(otpauth:// URI を取り出す)
22
+ permutil.py シークレットファイルの権限設定(Unix は 600、Windows は icacls)
23
+ logutil.py ロガー(出力は stderr。MCP の stdio を汚さないため)
24
+ mcp_server.py FastMCP のツール定義(薄いラッパー)
25
+ mcp_impl.py MCP ツールの実装、入力検証、例外を ValueError に揃える共通処理
26
+ src/mktotp_main.py Claude プラグイン用の MCP 起動スクリプト(PEP 723 のインライン依存を持つ)
27
+ test/ モジュールごとの pytest
28
+ .claude-plugin/ Claude Code プラグインのマニフェスト
29
+ .mcp.json プラグイン用 MCP サーバー設定(uv run src/mktotp_main.py mcp --mcp-server)
30
+ ```
31
+
32
+ 処理の流れは、CLI なら `__main__.py` → `func_impl.py` → `secrets.py`、MCP なら `mcp_server.py` → `mcp_impl.py` → `func_impl.py` → `secrets.py` となる。
33
+
34
+ ## CLI
35
+
36
+ ```bash
37
+ mktotp add -nn <name> -f <qr_image> # QR コード画像から登録
38
+ mktotp add -nn <name> -ss <secret> # シークレット文字列を直接登録(CLI のみ)
39
+ mktotp get -n <name> # トークン生成
40
+ mktotp list # 一覧
41
+ mktotp remove -n <name> # 削除
42
+ mktotp rename -n <old> -nn <new> # 名前変更
43
+ mktotp mcp --mcp-server # MCP サーバーとして起動(オプションなしならツール一覧を表示)
44
+ ```
45
+
46
+ 共通オプションは `-v, --verbose`(0: 通常、1: 詳細、2: デバッグ)と `-s, --secrets-file`。
47
+
48
+ ## MCP ツール
49
+
50
+ | ツール | 内容 |
51
+ | --- | --- |
52
+ | `mktotp_register_secret` | QR コード画像から登録 |
53
+ | `mktotp_generate_token` | トークン生成 |
54
+ | `mktotp_get_secret_info_list` | 一覧(name / account / issuer のみ。シークレット値は含めない) |
55
+ | `mktotp_remove_secrets` | 複数名を指定して削除 |
56
+ | `mktotp_rename_secret` | 名前変更 |
57
+
58
+ 各ツールは `secrets_file` を必須引数に取り、空文字列なら既定のファイルを使う。
59
+ シークレット文字列の直接登録は MCP には公開していない。
60
+
61
+ ## データ保存
62
+
63
+ - 既定の保存先は `~/.mktotp/data/secrets.json`(ディレクトリは 0700、ファイルは 600)
64
+ - 形式は `{"secrets": [{"name", "account", "issuer", "secret", ...}], "version": "1.0", "last_update": ...}`
65
+ - 同じ場所の `secrets.lock` を使い、`filelock` で排他制御する
66
+ - 読み込み時に権限が緩ければ自動で修正する
67
+
68
+ ## 開発
69
+
70
+ ```bash
71
+ uv sync # 依存のインストール
72
+ uv run pytest # テスト実行
73
+ uv run mktotp --help # ローカル実行
74
+ ```
75
+
76
+ ## 変更時の注意
77
+
78
+ - MCP ツールの戻り値やログにシークレット値を含めない。`list_secrets(include_secret=False)` の挙動を崩さない
79
+ - ログや print は stderr に出す。stdout は MCP の stdio 通信に使われる
80
+ - 依存を変えるときは `pyproject.toml` と `src/mktotp_main.py` のインライン依存の両方を更新する
81
+ - バージョンは `pyproject.toml` と `.claude-plugin/plugin.json` の両方にある
mktotp-0.9.13/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 kanok-one
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.
mktotp-0.9.13/PKG-INFO ADDED
@@ -0,0 +1,254 @@
1
+ Metadata-Version: 2.5
2
+ Name: mktotp
3
+ Version: 0.9.13
4
+ Summary: A Simple TOTP Secret Manager with MCP Server Support
5
+ Author-email: kanok-one <zervoid77@gmail.com>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: cairosvg>=2.8.2
9
+ Requires-Dist: fastmcp>=2.11.3
10
+ Requires-Dist: filelock>=3.18.0
11
+ Requires-Dist: opencv-python>=4.12.0.88
12
+ Requires-Dist: pillow>=10.0.0
13
+ Requires-Dist: pydantic>=2.11.7
14
+ Requires-Dist: pyotp>=2.9.0
15
+ Description-Content-Type: text/markdown
16
+
17
+ # mktotp
18
+
19
+ A simple CUI-based TOTP secret management tool and local MCP server for multi-factor authentication (MFA)
20
+
21
+ English | [日本語](README_ja.md)
22
+
23
+ <!-- TOC tocDepth:2..3 chapterDepth:2..6 -->
24
+
25
+ - [mktotp](#mktotp)
26
+ - [1. Overview](#1-overview)
27
+ - [2. Features](#2-features)
28
+ - [3. Runtime Environment](#3-runtime-environment)
29
+ - [4. Installation/Usage](#4-installationusage)
30
+ - [4-1. Install as a uv tool](#4-1-install-as-a-uv-tool)
31
+ - [4-1-1. Installation](#4-1-1-installation)
32
+ - [4-1-2. Registering as an MCP server](#4-1-2-registering-as-an-mcp-server)
33
+ - [4-2. Registering as an MCP server via the Claude plugin](#4-2-registering-as-an-mcp-server-via-the-claude-plugin)
34
+ - [5. CUI Tool Command Options](#5-cui-tool-command-options)
35
+ - [5-1. Common Options](#5-1-common-options)
36
+ - [5-2. `add` Command](#5-2-add-command)
37
+ - [5-2-1. Adding from a QR code image file](#5-2-1-adding-from-a-qr-code-image-file)
38
+ - [5-2-2. Registering a TOTP secret directly (CUI tool only)](#5-2-2-registering-a-totp-secret-directly-cui-tool-only)
39
+ - [5-3. `get` Command](#5-3-get-command)
40
+ - [5-4. `list` Command](#5-4-list-command)
41
+ - [5-5. `remove` Command](#5-5-remove-command)
42
+ - [5-6. `rename` Command](#5-6-rename-command)
43
+ - [5-7. `mcp` Command](#5-7-mcp-command)
44
+ - [6. File Storage Location](#6-file-storage-location)
45
+ - [7. Security Notes](#7-security-notes)
46
+ - [8. License](#8-license)
47
+
48
+ <!-- /TOC -->
49
+
50
+ ## 1. Overview
51
+
52
+ mktotp is a command-line tool for managing TOTP (Time-based One-Time Password) secrets and generating authentication tokens for multi-factor authentication services.
53
+ It also works as a local MCP server, so you can operate it from MCP-compatible Agent tools.
54
+
55
+ ## 2. Features
56
+
57
+ - Register TOTP secrets from QR code image files in PNG, JPEG, BMP, TIFF, or SVG format
58
+ - Generate TOTP tokens for registered secrets
59
+ - List all registered secrets
60
+ - Remove and rename secrets
61
+ - Can be operated from MCP-compatible Agent tools when running as a local MCP server
62
+ While running as an MCP server, mktotp is designed so that secret strings are not sent to the LLM.
63
+
64
+ ## 3. Runtime Environment
65
+
66
+ This project uses uv as the package manager.
67
+
68
+ For how to install uv, see the following page.
69
+
70
+ - [Installing uv](https://docs.astral.sh/uv/getting-started/installation/)
71
+
72
+ ## 4. Installation/Usage
73
+
74
+ ### 4-1. Install as a uv tool
75
+
76
+ Install mktotp into a uv environment and use it.
77
+ Use this method when you use mktotp as a CLI tool.
78
+
79
+ #### 4-1-1. Installation
80
+
81
+ ```bash
82
+ # Install directly from git repository
83
+ uv tool install git+{mktotp_repository_URL}
84
+ ```
85
+
86
+ After installation, you can run the `mktotp` command directly.
87
+
88
+ ```bash
89
+ mktotp --help
90
+ ```
91
+
92
+ #### 4-1-2. Registering as an MCP server
93
+
94
+ By registering mktotp as an MCP server, you can also operate `mktotp` from Agent tools.
95
+ For how to register an MCP server, refer to the manual of the Agent tool you use.
96
+
97
+ ```jsonc
98
+ {
99
+ // Example configuration for registering as an MCP server
100
+ //
101
+ // (Note)
102
+ // Registration keys differ depending on the Agent tool.
103
+ // Refer to the manual of the Agent tool you use for detailed procedures.
104
+ "mcpServers": {
105
+ // Configuration for starting mktotp as an MCP server using uv
106
+ "mktotp-uv": {
107
+ "type": "stdio",
108
+ "command": "mktotp",
109
+ "args": [
110
+ "mcp",
111
+ "--mcp-server"
112
+ ],
113
+ "env": {}
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ ### 4-2. Registering as an MCP server via the Claude plugin
120
+
121
+ mktotp can be installed as a Claude plugin.
122
+
123
+ ```bash
124
+ # Add the marketplace
125
+ /plugin marketplace add zv-louis/zv-plugin-marketplace
126
+ # Install from the marketplace
127
+ /plugin install mktotp-mcp@zv-plugins
128
+ ```
129
+
130
+ ## 5. CUI Tool Command Options
131
+
132
+ ### 5-1. Common Options
133
+
134
+ - `-v, --verbose LEVEL`: Set the output verbosity (0: normal, 1: verbose, 2: debug)
135
+ - `-s, --secrets-file FILE`: Path to the JSON file where secrets are stored
136
+
137
+ ### 5-2. `add` Command
138
+
139
+ Add a new secret.
140
+ Specify either `-f` (QR code image) or `-ss` (secret string).
141
+ If neither is given, the command fails with an error.
142
+ If both are given, `-f` takes precedence and `-ss` is ignored.
143
+
144
+ - `-nn, --new-name`: Name for the secret (required)
145
+
146
+ If a secret with the same name is already registered, it is overwritten.
147
+
148
+ #### 5-2-1. Adding from a QR code image file
149
+
150
+ Add a new secret from a QR code image.
151
+
152
+ ```bash
153
+ mktotp add -nn <new_name> -f <QR_code_image_file>
154
+ ```
155
+
156
+ - `-f, --qrcode-file`: Path to the image file containing the QR code
157
+ PNG, JPEG, BMP, TIFF, and SVG are supported (for TIFF, only the `.tiff` extension is accepted)
158
+
159
+ The account and issuer are taken from the QR code.
160
+ If the image contains multiple QR codes, all of them are registered.
161
+ The second and later secrets get a `_2`, `_3` ... suffix (e.g. `<new_name>_2`).
162
+
163
+ #### 5-2-2. Registering a TOTP secret directly (CUI tool only)
164
+
165
+ Add a new secret by specifying the secret string directly.
166
+
167
+ ```bash
168
+ mktotp add -nn <new_name> -ss <secret_string> [-i <issuer>] [-a <account>]
169
+ ```
170
+
171
+ - `-ss, --secret-string`: Secret string in Base32 format
172
+ - `-i, --issuer`: Issuer. Defaults to the secret name
173
+ - `-a, --account`: Account. Defaults to the secret name
174
+
175
+ Whitespace in the secret string (such as groups of 4 characters) and trailing `=` padding are removed before saving.
176
+ An invalid Base32 string results in an error.
177
+ The error message shows only the positions of the invalid characters, counted from the start of the input (whitespace included). It never shows the secret itself.
178
+
179
+ > The string given with `-ss` may remain in your shell history and the process list.
180
+
181
+ ### 5-3. `get` Command
182
+
183
+ Generate a TOTP token for the specified secret name.
184
+
185
+ ```bash
186
+ mktotp get -n <secret_name>
187
+ ```
188
+
189
+ - `-n, --name`: Name of the secret to operate on (required)
190
+
191
+ ### 5-4. `list` Command
192
+
193
+ Display all registered secrets.
194
+
195
+ ```bash
196
+ mktotp list
197
+ ```
198
+
199
+ ### 5-5. `remove` Command
200
+
201
+ Remove the specified secret.
202
+
203
+ ```bash
204
+ mktotp remove -n <secret_name>
205
+ ```
206
+
207
+ - `-n, --name`: Name of the secret to remove (required)
208
+
209
+ ### 5-6. `rename` Command
210
+
211
+ Rename a registered secret.
212
+
213
+ ```bash
214
+ mktotp rename -n <current_name> -nn <new_name>
215
+ ```
216
+
217
+ - `-n, --name`: Current secret name (required)
218
+ - `-nn, --new-name`: New secret name (required)
219
+
220
+ ### 5-7. `mcp` Command
221
+
222
+ Start mktotp as a local MCP server.
223
+ You can operate mktotp from Agent tools.
224
+
225
+ ```bash
226
+ mktotp mcp --mcp-server
227
+ ```
228
+
229
+ If the `--mcp-server` option is not specified, it outputs the MCP tool list.
230
+
231
+ ```bash
232
+ mktotp mcp
233
+ ```
234
+
235
+ ## 6. File Storage Location
236
+
237
+ By default, secrets are stored in the following location.
238
+
239
+ ```text
240
+ ~/.mktotp/data/secrets.json
241
+ ```
242
+
243
+ You can specify a different location with the `-s` option.
244
+
245
+ ## 7. Security Notes
246
+
247
+ - Secret files contain sensitive information, so protect them with permissions that prevent anyone but the owner from reading or writing them. When saving, mktotp automatically sets permissions that allow only the owner to read and write (600 on Unix-like systems).
248
+ - When creating backups, we recommend using encrypted storage.
249
+ - Remove unnecessary secrets with the `remove` command.
250
+
251
+ ## 8. License
252
+
253
+ This project is licensed under the MIT License.
254
+ See the [LICENSE](LICENSE) file for details.