harmonyos-dev-mcp 0.7.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 (62) hide show
  1. harmonyos_dev_mcp-0.7.0/.gitignore +57 -0
  2. harmonyos_dev_mcp-0.7.0/PKG-INFO +11 -0
  3. harmonyos_dev_mcp-0.7.0/docs/logs_query.md +141 -0
  4. harmonyos_dev_mcp-0.7.0/docs/query_package.md +139 -0
  5. harmonyos_dev_mcp-0.7.0/pyproject.toml +26 -0
  6. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/__init__.py +27 -0
  7. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/__main__.py +9 -0
  8. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/config.py +393 -0
  9. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/container.py +53 -0
  10. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/server.py +42 -0
  11. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/__init__.py +16 -0
  12. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/build.py +291 -0
  13. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/device_base.py +64 -0
  14. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/e2e.py +277 -0
  15. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/general.py +161 -0
  16. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/log/__init__.py +18 -0
  17. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/log/crash_parser.py +257 -0
  18. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/log/historian.py +244 -0
  19. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/log/parser.py +284 -0
  20. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/log/query.py +392 -0
  21. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/log/time_utils.py +155 -0
  22. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/response.py +245 -0
  23. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/tools/ui.py +672 -0
  24. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/types.py +240 -0
  25. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/__init__.py +20 -0
  26. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/__init__.py +11 -0
  27. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/hdc_app.py +168 -0
  28. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/hdc_base.py +238 -0
  29. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/hdc_device.py +148 -0
  30. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/hdc_file.py +263 -0
  31. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/hdc_package.py +565 -0
  32. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/hdc_screenshot.py +211 -0
  33. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/hdc_ui.py +110 -0
  34. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/hdc/hdc_wrapper.py +88 -0
  35. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/logger.py +15 -0
  36. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/normalizers/__init__.py +13 -0
  37. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/normalizers/element.py +100 -0
  38. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/normalizers/window.py +21 -0
  39. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/parsers/__init__.py +5 -0
  40. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/parsers/window_manager.py +85 -0
  41. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/retry.py +34 -0
  42. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/selectors/__init__.py +5 -0
  43. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/selectors/window_selector.py +71 -0
  44. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/ui_common.py +35 -0
  45. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/uitree_parser.py +264 -0
  46. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/wrappers/__init__.py +15 -0
  47. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/wrappers/hilogtool_wrapper.py +304 -0
  48. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/wrappers/hvigor_wrapper.py +550 -0
  49. harmonyos_dev_mcp-0.7.0/src/harmonyos_mcp/utils/wrappers/ui_operations.py +578 -0
  50. harmonyos_dev_mcp-0.7.0/tests/__init__.py +3 -0
  51. harmonyos_dev_mcp-0.7.0/tests/conftest.py +242 -0
  52. harmonyos_dev_mcp-0.7.0/tests/unit/__init__.py +3 -0
  53. harmonyos_dev_mcp-0.7.0/tests/unit/test_build.py +282 -0
  54. harmonyos_dev_mcp-0.7.0/tests/unit/test_config.py +306 -0
  55. harmonyos_dev_mcp-0.7.0/tests/unit/test_device.py +355 -0
  56. harmonyos_dev_mcp-0.7.0/tests/unit/test_e2e_tools.py +63 -0
  57. harmonyos_dev_mcp-0.7.0/tests/unit/test_hdc_app.py +57 -0
  58. harmonyos_dev_mcp-0.7.0/tests/unit/test_hdc_device.py +103 -0
  59. harmonyos_dev_mcp-0.7.0/tests/unit/test_hvigor_wrapper.py +445 -0
  60. harmonyos_dev_mcp-0.7.0/tests/unit/test_retry_and_registry.py +238 -0
  61. harmonyos_dev_mcp-0.7.0/tests/unit/test_server_runtime.py +55 -0
  62. harmonyos_dev_mcp-0.7.0/tests/unit/test_ui.py +347 -0
@@ -0,0 +1,57 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual Environment
24
+ venv/
25
+ env/
26
+ ENV/
27
+
28
+ # IDE
29
+ .vscode/
30
+ .idea/
31
+ *.swp
32
+ *.swo
33
+ *~
34
+
35
+ # OS
36
+ .DS_Store
37
+ Thumbs.db
38
+
39
+ # Logs
40
+ *.log
41
+ logs/
42
+ hm_logs/
43
+
44
+ # Test
45
+ .pytest_cache/
46
+ .coverage
47
+ htmlcov/
48
+
49
+ # Config
50
+ .env
51
+ *.local
52
+
53
+ # Misc
54
+ get-pip.py
55
+
56
+ # AI Tools
57
+ .opencode/
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: harmonyos-dev-mcp
3
+ Version: 0.7.0
4
+ Requires-Python: >=3.10
5
+ Requires-Dist: fastmcp>=3.0.0
6
+ Requires-Dist: harmonyos-mcp-common
7
+ Requires-Dist: json5>=0.9.14
8
+ Requires-Dist: loguru>=0.7.0
9
+ Requires-Dist: psutil>=5.9.0
10
+ Requires-Dist: requests>=2.31.0
11
+ Requires-Dist: typing-extensions>=4.8.0
@@ -0,0 +1,141 @@
1
+ # logs_query
2
+
3
+ 统一日志查询工具,覆盖:
4
+ - 实时日志抓取
5
+ - 历史日志抓取(按时间自动切换)
6
+ - 本地文件分析
7
+ - 过滤、统计、诊断、崩溃信息聚合
8
+ - 可选快照保存
9
+
10
+ ## 参数
11
+
12
+ ### 数据源参数
13
+
14
+ | 参数 | 类型 | 默认值 | 说明 |
15
+ |---|---|---|---|
16
+ | `device_id` | string | `null` | 设备 ID |
17
+ | `logs` | string[] | `null` | 直接传入日志行,优先级最高 |
18
+ | `input_file` | string | `null` | 单个本地日志文件 |
19
+ | `input_files` | string[] | `null` | 多个本地日志文件 |
20
+
21
+ 优先级:`logs` > `input_file/input_files` > 设备读取。
22
+
23
+ ### 过滤参数
24
+
25
+ | 参数 | 类型 | 默认值 | 说明 |
26
+ |---|---|---|---|
27
+ | `lines` | int | `100` | 返回最大行数 |
28
+ | `level` | string | `null` | `D/I/W/E/F` |
29
+ | `tag` | string | `null` | 解析后 tag 精确过滤 |
30
+ | `tag_search` | string | `null` | 原始行搜索 tag 关键字 |
31
+ | `keyword` | string | `null` | 原始行关键字 |
32
+ | `domain` | string | `null` | hilog domain |
33
+ | `pid` | int | `null` | 进程 ID |
34
+ | `package_name` | string | `null` | 包名(自动查 PID) |
35
+
36
+ ### 时间参数
37
+
38
+ | 参数 | 类型 | 说明 |
39
+ |---|---|---|
40
+ | `start_time` | string | `HH:MM:SS` 或 `YYYY-MM-DD HH:MM:SS` |
41
+ | `end_time` | string | 同上 |
42
+ | `seconds` | int | 最近 N 秒 |
43
+ | `time_expr` | string | 自然语言时间表达(例如“最近10分钟”) |
44
+
45
+ 说明:当查询窗口超过实时缓冲覆盖范围时,自动切换历史日志读取。
46
+
47
+ ### 分析与输出参数
48
+
49
+ | 参数 | 类型 | 默认值 | 说明 |
50
+ |---|---|---|---|
51
+ | `analysis_type` | string | `summary` | `summary/custom` |
52
+ | `custom_regex` | string | `null` | `analysis_type=custom` 时生效 |
53
+ | `save_path` | string | `null` | 结果落盘路径 |
54
+ | `include_diagnostics` | bool | `false` | 返回过滤统计信息 |
55
+ | `include_crash` | bool | `false` | 聚合 crash 信息 |
56
+
57
+ ## 返回结构
58
+
59
+ 外层统一 MCP,业务结果在 `structuredContent`。
60
+
61
+ 成功:
62
+
63
+ ```json
64
+ {
65
+ "tool": "logs_query",
66
+ "ok": true,
67
+ "result": {
68
+ "device_id": "3QC0124C11000711",
69
+ "source": "realtime_buffer",
70
+ "logs": ["03-05 15:41:03.543 ..."],
71
+ "total_lines": 1,
72
+ "truncated": false,
73
+ "filters_applied": {"level": "E"},
74
+ "analysis_type": "summary",
75
+ "analysis": {"level_stats": {"E": 1}},
76
+ "total_entries_analyzed": 1
77
+ },
78
+ "error": null
79
+ }
80
+ ```
81
+
82
+ 失败:
83
+
84
+ ```json
85
+ {
86
+ "tool": "logs_query",
87
+ "ok": false,
88
+ "result": {
89
+ "logs": [],
90
+ "total_lines": 0,
91
+ "truncated": false
92
+ },
93
+ "error": {
94
+ "code": "APP_NOT_RUNNING",
95
+ "detail": "app not running or pid not found: com.example.app"
96
+ }
97
+ }
98
+ ```
99
+
100
+ `error` 仅保留 `code/detail`。
101
+
102
+ ## 典型调用
103
+
104
+ ### 最近错误日志
105
+
106
+ ```json
107
+ {
108
+ "name": "logs_query",
109
+ "arguments": {
110
+ "level": "E",
111
+ "lines": 300
112
+ }
113
+ }
114
+ ```
115
+
116
+ ### 指定包最近 10 分钟
117
+
118
+ ```json
119
+ {
120
+ "name": "logs_query",
121
+ "arguments": {
122
+ "package_name": "com.example.myapplication",
123
+ "time_expr": "最近10分钟",
124
+ "include_diagnostics": true
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### 保存快照
130
+
131
+ ```json
132
+ {
133
+ "name": "logs_query",
134
+ "arguments": {
135
+ "package_name": "com.example.myapplication",
136
+ "lines": 500,
137
+ "save_path": "C:/Users/mu/Desktop/hilog_snapshot.txt"
138
+ }
139
+ }
140
+ ```
141
+
@@ -0,0 +1,139 @@
1
+ # query_package
2
+
3
+ 统一包查询工具,支持:
4
+ - 列包:`info_type=list`
5
+ - 查能力:`info_type=abilities`
6
+ - 查主入口:`info_type=main_ability`
7
+ - 查权限:`info_type=permissions`
8
+
9
+ ## 参数
10
+
11
+ | 参数 | 类型 | 默认值 | 说明 |
12
+ |---|---|---|---|
13
+ | `device_id` | string | `null` | 设备 ID,空时自动选第一台在线设备 |
14
+ | `bundle_name` | string | `null` | 应用包名 |
15
+ | `keyword` | string | `null` | 仅在 `list` 模式下生效,用于过滤包名 |
16
+ | `info_type` | string | `list` | `list/abilities/main_ability/permissions` |
17
+
18
+ 规则:
19
+ - 当 `info_type` 为 `abilities/main_ability/permissions` 时,必须传 `bundle_name`。
20
+ - 当传入 `bundle_name` 且 `info_type=list` 时,会自动切到 `abilities`。
21
+
22
+ ## 返回结构
23
+
24
+ 工具外层为 MCP 标准结构,业务数据在 `structuredContent`:
25
+
26
+ ```json
27
+ {
28
+ "tool": "query_package",
29
+ "ok": true,
30
+ "result": {},
31
+ "error": null,
32
+ "meta": {}
33
+ }
34
+ ```
35
+
36
+ 失败时:
37
+
38
+ ```json
39
+ {
40
+ "tool": "query_package",
41
+ "ok": false,
42
+ "result": {},
43
+ "error": {
44
+ "code": "MISSING_BUNDLE_NAME",
45
+ "detail": "info_type=\"main_ability\" requires bundle_name"
46
+ },
47
+ "meta": {}
48
+ }
49
+ ```
50
+
51
+ `error` 仅包含 `code/detail`,不再包含历史字段。
52
+
53
+ ## 结果示例
54
+
55
+ ### 1. `info_type=list`
56
+
57
+ ```json
58
+ {
59
+ "tool": "query_package",
60
+ "ok": true,
61
+ "result": {
62
+ "device_id": "3QC0124C11000711",
63
+ "info_type": "list",
64
+ "packages": ["com.example.myapplication"],
65
+ "count": 1,
66
+ "keyword": ""
67
+ },
68
+ "error": null
69
+ }
70
+ ```
71
+
72
+ ### 2. `info_type=abilities`
73
+
74
+ ```json
75
+ {
76
+ "tool": "query_package",
77
+ "ok": true,
78
+ "result": {
79
+ "device_id": "3QC0124C11000711",
80
+ "info_type": "abilities",
81
+ "bundle_name": "com.example.myapplication",
82
+ "abilities": [
83
+ {"name": "EntryAbility", "module": "entry", "type": "page"}
84
+ ],
85
+ "modules": ["entry"],
86
+ "main_ability": {"name": "EntryAbility", "module": "entry", "type": "page"},
87
+ "ability_count": 1
88
+ },
89
+ "error": null
90
+ }
91
+ ```
92
+
93
+ ### 3. `info_type=main_ability`
94
+
95
+ ```json
96
+ {
97
+ "tool": "query_package",
98
+ "ok": true,
99
+ "result": {
100
+ "device_id": "3QC0124C11000711",
101
+ "info_type": "main_ability",
102
+ "bundle_name": "com.example.myapplication",
103
+ "ability_name": "EntryAbility",
104
+ "module_name": "entry",
105
+ "candidates": [
106
+ {
107
+ "ability_name": "EntryAbility",
108
+ "module_name": "entry",
109
+ "is_entry_module": true,
110
+ "is_entry_main_ability": true,
111
+ "is_launcher": true,
112
+ "source": "entryModule.mainAbility, action.system.home",
113
+ "visible": true,
114
+ "type": "page"
115
+ }
116
+ ],
117
+ "recommended": 0
118
+ },
119
+ "error": null
120
+ }
121
+ ```
122
+
123
+ ### 4. `info_type=permissions`
124
+
125
+ ```json
126
+ {
127
+ "tool": "query_package",
128
+ "ok": true,
129
+ "result": {
130
+ "device_id": "3QC0124C11000711",
131
+ "info_type": "permissions",
132
+ "bundle_name": "com.example.myapplication",
133
+ "requested_permissions": ["ohos.permission.INTERNET"],
134
+ "permission_count": 1
135
+ },
136
+ "error": null
137
+ }
138
+ ```
139
+
@@ -0,0 +1,26 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "harmonyos-dev-mcp"
7
+ version = "0.7.0"
8
+ requires-python = ">=3.10"
9
+ dependencies = [
10
+ "harmonyos-mcp-common",
11
+ "fastmcp>=3.0.0",
12
+ "requests>=2.31.0",
13
+ "json5>=0.9.14",
14
+ "psutil>=5.9.0",
15
+ "loguru>=0.7.0",
16
+ "typing-extensions>=4.8.0",
17
+ ]
18
+
19
+ [project.scripts]
20
+ harmonyos-dev-mcp = "harmonyos_mcp:main"
21
+
22
+ [tool.uv.sources]
23
+ harmonyos-mcp-common = { workspace = true }
24
+
25
+ [tool.hatch.build.targets.wheel]
26
+ packages = ["src/harmonyos_mcp"]
@@ -0,0 +1,27 @@
1
+ """
2
+ HarmonyOS MCP Server
3
+
4
+ AI-assisted HarmonyOS development tools via Model Context Protocol.
5
+ """
6
+
7
+ __version__ = "0.7.0"
8
+ __author__ = "HarmonyOS MCP Team"
9
+
10
+ from .server import mcp, main
11
+ from .container import container, get_hdc, get_ui_operations, get_hilogtool, get_hvigor
12
+ from .config import Config, LogSecurityConfig
13
+ from common.exceptions import MCPError
14
+
15
+ __all__ = [
16
+ "mcp",
17
+ "main",
18
+ "__version__",
19
+ "container",
20
+ "get_hdc",
21
+ "get_ui_operations",
22
+ "get_hilogtool",
23
+ "get_hvigor",
24
+ "Config",
25
+ "LogSecurityConfig",
26
+ "MCPError",
27
+ ]
@@ -0,0 +1,9 @@
1
+ """
2
+ Entry point for running as a module: python -m harmonyos_mcp
3
+ """
4
+
5
+ from .server import main
6
+
7
+ if __name__ == "__main__":
8
+ main()
9
+