# harmonymcp **Repository Path**: cy3007/harmonymcp ## Basic Information - **Project Name**: harmonymcp - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-19 - **Last Updated**: 2026-06-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # harmonymcp `harmonymcp` is a stdio MCP server for common HarmonyOS / DevEco command-line workflows. It exposes tools for: - listing `hdc` targets - running bounded `hdc shell` commands - cleaning and building HarmonyOS projects through `hvigorw` / `hvigor` - listing project Hvigor tasks - finding built `.hap`, `.app`, `.har`, and `.hsp` artifacts - installing an app artifact with `hdc install -r` - starting/stopping abilities with `aa` - capturing bounded HiLog output - running a practical install/start/screenshot/log debug pipeline - taking device screenshots - recording Huawei developer documentation learning sessions with an audit trail ## Requirements - Node.js 20+ - DevEco Studio command-line tools available on `PATH`, especially `hdc`, or a standard DevEco SDK install path. On Windows, the server also checks common SDK locations such as `H:\DevEcoStudio\sdk\default\openharmony\toolchains\hdc.exe` and supports `HDC_PATH` / `HDC_HOME`. - A HarmonyOS project with `hvigorw`/`hvigorw.bat`, or `hvigor` available on `PATH` ## Install ```powershell npm.cmd install npm.cmd run build ``` ## MCP client config After building, add a stdio server entry that points to the built file: ```json { "mcpServers": { "harmonymcp": { "command": "node", "args": ["H:\\harmonymcp\\dist\\index.js"] } } } ``` For development, you can run the TypeScript source directly: ```json { "mcpServers": { "harmonymcp": { "command": "npx", "args": ["tsx", "H:\\harmonymcp\\src\\index.ts"] } } } ``` ## Tools ## Learning rule When an agent studies Huawei developer documentation for this project, it must call one of these tools: - `learn_huawei_doc_official_api` first when reading a concrete URL under `https://developer.huawei.com/consumer/cn/doc/`; it uses Huawei's official `documentPortal/getDocumentById` endpoint and records the readable document body when available - `search_huawei_doc_catalog` when a URL slug may not be the real document `objectId`; it uses Huawei's official `documentPortal/getCatalogTree` endpoint to find matching catalog nodes - `learn_huawei_doc` only as a direct-fetch fallback; many Huawei pages return an app shell and must not be treated as verified content - `learn_huawei_doc_browser` when the official API and direct fetch cannot provide the document body and browser rendering is available - `record_learning` when the learning happened outside direct fetch, for example from browser notes, multi-agent summaries, or copied excerpts - `batch_learn_huawei_docs` when checking several official URLs in one learning pass - `learning_gap_report` after multi-agent learning to see what still needs verification - `learning_integrity_report` when checking that `index.jsonl` and Markdown records have not drifted - `repair_learning_integrity` after an integrity report finds duplicate ids or paths; run with `dryRun: true` first Every learning-related call writes to `learning/audit.jsonl`. Successful or failed learning attempts also write to `learning/index.jsonl` and a readable Markdown file under `learning/records/`. This makes the learning process replayable instead of relying on hidden chat context. Learning records separate evidence quality: - `contentStatus`: `fetched`, `dynamic_unavailable`, `insufficient_content`, `manual`, or `failed` - `verifiedClaims`: facts checked against readable official content - `unverifiedClaims`: useful but not fully verified claims - `reviewNeeded`: concrete follow-up checks before relying on a claim - `sourceUrls`: all official URLs used for the record - `docVersion`: optional version marker such as `V5` or `V13` ### `list_targets` Lists connected devices or emulators: ```json {} ``` ### `device_shell` Runs one device shell command: ```json { "command": "param get const.product.model", "device": "SERIAL" } ``` ### `hvigor_clean` Runs `clean` in a HarmonyOS project: ```json { "projectDir": "H:\\path\\to\\HarmonyProject" } ``` ### `hvigor_tasks` Lists available Hvigor tasks and returns structured command evidence: ```json { "projectDir": "H:\\path\\to\\HarmonyProject", "module": "entry", "all": true } ``` The response includes parsed `tasks[]` when the Hvigor output matches a known task-list format, while retaining raw `stdout` and `stderr` for review. Structured command tools use `status: "ok" | "failed" | "timeout" | "start_error"` and include `ok`, `timedOut`, and `error` fields, so command failures can still be inspected as evidence. ### `hvigor_assemble` Builds a target: ```json { "projectDir": "H:\\path\\to\\HarmonyProject", "task": "assembleHap", "module": "entry", "buildMode": "debug" } ``` ### `hvigor_assemble_evidence` Builds a target and returns structured command evidence: ```json { "projectDir": "H:\\path\\to\\HarmonyProject", "task": "assembleHap", "module": "entry", "buildMode": "debug", "findExtension": "hap" } ``` This sibling tool does not change `hvigor_assemble`. It returns `status`, `ok`, `timedOut`, command args, stdout/stderr, duration, and optional `outputs[]` when `findExtension` is supplied and the build succeeds. ### `find_build_output` Finds artifacts under the project: ```json { "projectDir": "H:\\path\\to\\HarmonyProject", "extension": "hap", "module": "entry" } ``` ### `install_app` Installs a `.hap` or `.app`: ```json { "artifactPath": "H:\\path\\to\\entry-default.hap", "device": "SERIAL", "installCommand": "install", "autoStart": true, "bundleName": "com.example.demo", "abilityName": "EntryAbility" } ``` ### `screenshot` Captures a screenshot into a local directory: ```json { "outputDir": "H:\\path\\to\\HarmonyProject\\screenshots", "filename": "home.jpeg" } ``` `snapshot_display` requires a `.jpeg` suffix, so the tool rejects other screenshot filename suffixes before running `hdc`. ### `install_app_evidence` Installs a `.hap` or `.app` and returns per-step command evidence: ```json { "artifactPath": "H:\\path\\to\\entry-default.hap", "device": "SERIAL", "installCommand": "auto", "forceStop": true, "bundleName": "com.example.demo", "autoStart": true, "abilityName": "EntryAbility" } ``` The response includes the resolved `artifactPath`, `artifactFileUrl`, `steps[]`, and an optional `failure` object. This tool preserves stdout/stderr and status for force-stop, install, and auto-start steps. `installCommand` can be `"install"`, `"app install"`, or `"auto"`. The text tool defaults to `"install"` for compatibility. The evidence tool defaults to `"auto"`, probes `hdc -h verbose`, and records `requestedInstallCommand`, `selectedInstallCommand`, `installCommandSource`, `installCommandProbe`, `probeSummary`, and `warnings`. Auto mode is conservative: it falls back to `hdc install` unless the help output clearly points only to `hdc app install`. If help probing fails or mentions both variants, the result uses `installCommandSource: "fallback"` or `"ambiguous_help"` and keeps the probe output as evidence; it does not try a real install with another variant automatically. ### `aa_start` Starts an ability through `hdc shell aa start`: ```json { "device": "SERIAL", "bundleName": "com.example.demo", "abilityName": "EntryAbility", "moduleName": "entry", "wait": true, "parameters": { "string": { "mode": "debug" }, "bool": { "enabled": true }, "int": { "count": 1 } } } ``` The tool returns JSON with command args, stdout, stderr, start time, duration, and exit code. ### `aa_force_stop` Force-stops a bundle through `hdc shell aa force-stop`: ```json { "device": "SERIAL", "bundleName": "com.example.demo" } ``` If `pid` is supplied, `reason` must also be supplied. ### `hilog_capture` Captures a bounded non-blocking HiLog snapshot: ```json { "device": "SERIAL", "type": "app", "level": "E", "tag": "EntryAbility", "regex": "com.example.demo|error", "tail": 300, "format": ["time"], "outputDir": "H:\\path\\to\\logs", "filename": "hilog.txt" } ``` When `tail` is omitted, it defaults to `-z 300` unless `head` is provided. `head` and `tail` are mutually exclusive because real `hilog` rejects `-a` and `-z` together. If `outputDir` is set, the full stdout is saved to disk while `maxChars` limits the inline response. ### `device_debug_pipeline` Runs a practical device debug flow: ```json { "device": "SERIAL", "artifactPath": "H:\\path\\to\\entry-default.hap", "bundleName": "com.example.demo", "abilityName": "EntryAbility", "moduleName": "entry", "forceStopBeforeInstall": true, "screenshot": { "outputDir": "H:\\path\\to\\screenshots", "filename": "after-start.jpeg" }, "hilog": { "type": "app", "tail": 300, "regex": "com.example.demo|EntryAbility", "outputDir": "H:\\path\\to\\logs" } } ``` The pipeline records each step separately: `list_targets`, optional `install`, `aa_start`, optional `screenshot`, and optional `hilog_capture`. ### `learn_huawei_doc` Direct-fetches a Huawei developer documentation URL and stores a learning record: ```json { "url": "https://developer.huawei.com/consumer/cn/doc/", "agent": "researcher", "tags": ["arkts", "ui"], "note": "Focus on API usage that affects the current implementation.", "verifiedClaims": [ "Only include claims that were checked against readable official content." ], "reviewNeeded": [ "Open dynamic pages in a browser before relying on detailed API syntax." ] } ``` Prefer `learn_huawei_doc_official_api` for current Huawei documentation pages. Use this direct-fetch tool to prove whether a page exposes readable HTML without the document portal API. If it only returns a dynamic shell, keep detailed claims out of `verifiedClaims`. ### `learn_huawei_doc_official_api` Fetches a Huawei developer documentation page through the official document portal API and records readable body text without browser rendering: ```json { "url": "https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/hdc", "agent": "researcher", "tags": ["hdc", "official-api"], "note": "Use the official documentPortal API as the primary source for body text.", "maxChars": 20000 } ``` By default, the tool derives `objectId` from the last URL path segment, for example `hdc` from `/harmonyos-guides/hdc`, and derives `language` and `catalogName` from the URL. When `objectId` is not supplied, it first searches `getCatalogTree` for a matching `relateDocument`; pass `objectId` explicitly to skip catalog lookup. Successful records include the official API endpoint in `sourceUrls`, set `contentStatus` to `fetched` when enough body text is returned, and store the returned document version when available. When catalog lookup resolves the id, records also include `getCatalogTree` in `sourceUrls` and `fetchInfo.catalogResolvedBy`. ### `search_huawei_doc_catalog` Searches Huawei's official document catalog for document ids: ```json { "catalogName": "harmonyos-guides", "language": "cn", "query": "Navigation", "limit": 10 } ``` The returned `matches[].relateDocument` value is the candidate `objectId` for `learn_huawei_doc_official_api`. ### `learn_huawei_doc_browser` Renders a Huawei documentation page with Playwright through `npx` and records visible text: ```json { "url": "https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/hdc", "agent": "researcher", "tags": ["browser-check"], "note": "Use browser rendering because direct fetch returned only the document center shell.", "waitMs": 1500, "timeoutMs": 60000 } ``` This tool does not add Playwright to `package.json`. It uses `npx -y -p playwright ...` at runtime. If Playwright or browser binaries are unavailable, the failed attempt is still recorded. ### `record_learning` Stores a manual learning record when direct fetch is not the source of truth: ```json { "title": "ArkUI component lifecycle notes", "sourceUrl": "https://developer.huawei.com/consumer/cn/doc/", "agent": "executor", "summary": "Lifecycle behavior that matters for the current HarmonyOS page.", "contentStatus": "manual", "keyPoints": [ "Record the exact API behavior before changing code.", "Link learned behavior to the file or feature that uses it." ], "verifiedClaims": [ "Manual notes were copied from the official page while visible in a browser." ], "unverifiedClaims": [ "Any claim that came from memory or a secondary agent goes here until rechecked." ], "reviewNeeded": [ "Re-open the official page and confirm API names before implementation." ], "tags": ["arkui", "lifecycle"], "confidence": "medium" } ``` ### `search_learning` Searches previous learning records and writes an audit event: ```json { "query": "lifecycle", "limit": 5 } ``` ### `batch_learn_huawei_docs` Fetches several Huawei documentation URLs and records each result with its own `contentStatus`: ```json { "urls": [ "https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/hdc", "https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-hvigor-build-profile" ], "agent": "researcher", "tags": ["batch-check"], "note": "Check whether these official pages expose readable body text to direct fetch." } ``` ### `learning_gap_report` Summarizes records that are not yet strong enough to rely on: ```json { "tag": "huawei-doc", "limit": 20 } ``` The report includes dynamic or insufficient content, unverified claims, review items, open questions, and recommended next actions. ### `learning_integrity_report` Checks index and Markdown file consistency: ```json {} ``` The report detects duplicate ids, duplicate Markdown paths, missing Markdown files, and orphan Markdown files. ### `repair_learning_integrity` Repairs duplicate ids and duplicate Markdown paths without deleting learning content. It backs up `index.jsonl`, rewrites the index, and regenerates Markdown files for each indexed record. Preview first: ```json { "dryRun": true } ``` Apply: ```json { "dryRun": false } ``` ### `get_learning_record` Reads a recorded Markdown learning entry by id: ```json { "id": "20260608233000-arkui-component-lifecycle-notes" } ``` ### `learning_stats` Returns record counts, failed attempts, tag counts, and audit path: ```json {} ``` ## Notes - Commands are executed without a shell to avoid accidental command-line interpolation. - Build commands prefer a project-local `hvigorw` wrapper and fall back to `hvigor` on `PATH`. - `device_shell` is intentionally generic because HarmonyOS device diagnostics vary by OS version and target hardware. Use precise, bounded commands. - Huawei documentation pages can be dynamic. If direct fetch does not capture useful text, use `record_learning` with the observed notes and put uncertain details in `unverifiedClaims` / `reviewNeeded`.