# KineX Developer & MCP Agent Specification (llms.txt) > Target Host: KineX 0.1.0-beta.8+ | Plugin API: "1.2" | Local MCP: http://127.0.0.1:45129/mcp (Streamable HTTP JSON-RPC 2.0) This file gives AI coding agents everything required to scaffold a valid `.kxplugin` extension or integrate with KineX over MCP without guessing field names or security boundaries. ================================================================================ PART 1: PLUGIN API v1.2 (manifest.json + Transports + Schemas) ================================================================================ ## 1. Archive & Manifest Rules - Distribution format: `.kxplugin` (standard ZIP containing `manifest.json` at root). - `manifest.json` limits: <= 256 KiB; archive <= 128 files / 32 MiB extracted; NO symlinks, NO `..` path segments. - Required top-level fields: - `manifestVersion`: `1` (literal number) - `apiVersion`: `"1.2"` (compatible with `"1.0"` and `"1.1"`) - `id`: regex `/^[a-z0-9][a-z0-9.-]{2,78}[a-z0-9]$/` (e.g. `"com.example.my-plugin"`) - `name`: string (1..80 chars) - `version`: string (1..32 chars, semver e.g. `"1.0.0"`) - `platforms`: non-empty subset of `["windows", "macos", "android", "ios"]` - NOTE: If using `reader.webview.partition` or `reader.webview.bridge`, `ios` MUST NOT be in `platforms`. - `runtime`: - `{ "kind": "declarative" }` - `{ "kind": "local-http", "endpointUrl": "http://127.0.0.1:PORT/path", "timeoutMs": 1000..25000 }` - `{ "kind": "stdio", "command": "node", "args": ["${pluginDir}/adapter.mjs"], "timeoutMs": 1000..25000 }` - BLOCKED SHELLS (hard error): `cmd`, `cmd.exe`, `powershell`, `powershell.exe`, `pwsh`, `pwsh.exe`, `sh`, `bash`, `zsh`, `fish`, `wscript`, `cscript`. Never wrap commands in a shell. - `permissions`: array of valid `PluginPermission` strings (see Section 2). - `allowedHosts`: optional array of hostnames or single-level `*.domain.com` (NEVER `"*"` or `"*.*"`). - `configSchema`: optional JSON-Schema-like object: `{ "type": "object", "properties": { "": { "type": "string|number|boolean", "title": "...", "description": "...", "default": ..., "placeholder": "...", "format": "secret|url|text", "enum": [...], "enumLabels": {...}, "section": "...", "advanced": true|false } } }`. - Fields with `"format": "secret"` are stored in OS Keychain (`kinex.secret.plugin..*`) and injected into `req.secrets.` at runtime. ## 2. Wire Framing & Execution Boundary (CRITICAL FOR WINDOWS & RUNTIME) - Out-of-process execution: `.kxplugin` `stdio` scripts run as standalone child processes with NO `kinex.storage` or `kinex.inbox` JS globals inside `adapter.mjs`. Read config from `req.config` and keychain secrets from `req.secrets`. For workspace content reads/writes, connect to the Local MCP Server (`http://127.0.0.1:45129/mcp`). - `stdio` framing: KineX writes one JSON request onto `stdin`, closes `stdin` (EOF), and parses `stdout` (accepts single-line or pretty-printed JSON; write debug logs ONLY to `stderr`). - `local-http` framing: KineX sends `POST` with `Content-Type: application/json` and `X-KineX-Plugin-Api: 1.2`. - Response byte caps: - `readAloudProviders`: `12 MiB` - `contentImporters` & `contentExporters`: `8 MiB` - `mediaSubtitles`: `4 MiB` - All other domains (`searchProviders`, `lookupProviders`, `mediaSources`): `512 KiB` - WINDOWS PIPE BUG WARNING: NEVER use `fs.readFileSync(0, 'utf8')` in Node.js (throws `EAGAIN` on Windows child pipes). ALWAYS read `stdin` asynchronously: ```js function readStdin() { return new Promise((resolve) => { let raw = ''; process.stdin.setEncoding('utf8'); process.stdin.on('data', (c) => { raw += c; }); process.stdin.on('end', () => resolve(raw.trim())); }); } ``` ## 3. All 25 Valid PluginPermission Values - AI & Study: `ai.provider.register`, `ai.quota.register`, `ai.usage.read`, `ai.pricing.register`, `ai.relay.register`, `ai.study.preset`, `ai.search.register` - Media, Read-Aloud & Reader: `media.source.register`, `media.subtitles.register`, `readaloud.provider.register`, `reader.lookup.register`, `reader.webview.partition`, `reader.webview.bridge` - Content & Workspace: `content.import`, `content.export`, `workspace.read`, `workspace.propose` - System, Security & UI: `auth.oauth`, `network.loopback`, `network.internet`, `process.external`, `secrets.own`, `storage.own`, `ui.slots`, `ui.theme` Note on Active vs Reserved Contribution Domains: - **8 Active Host UI Domains**: `themes` (ThemeQuickMenu), `readAloudProviders` (Read-Aloud Engine), `contentExporters` (Reader Notes Panel + Flashcard Management Tree), `contentImporters` (Material Sidebar `+` Import menu), `lookupProviders` (Reader selection Look Up popup), `searchProviders` (AI Chat search), `mediaSources` (Course video/audio import & player), `mediaSubtitles` (Player subtitle tracks). All 8 plus `oauth` (`kinex://plugin-auth/`) also support one-click **Self-Test** inside Settings → Plugins & Extensions. - **Reserved Manifest Fields** (validated & stored in registry, NO host UI wired yet): `pricingSources`, `relayEndpoints`, `studyPresets`. ## 4. Exact Protocol Contracts for All 8 Active Contributes ### A. Declarative Dual-Mode Themes (`contributes.themes`, perm: `ui.theme`) CSS vars MUST start with `--[a-z0-9-]+` and MUST NOT contain `[;{}`<>]`, `url(`, `expression(`, or `@import`. Host compiles `lightCssVars` / `darkCssVars` onto `html body.light-theme, html body .light-theme, html[data-kinex-light] body.light-theme, html[data-kinex-light] .kinex-app-engine.light-theme` (and matching `.dark-theme` selectors) and uses `--kinex-paper-bg` for reader background pages. ```json { "id": "warm-study-paper", "title": "Warm Study Paper", "appearance": "both", "previewSwatches": ["#efe5cf", "#9a5b25", "#241e18", "#e0a458"], "cssVars": { "--color-accent": "#9a5b25" }, "lightCssVars": { "--bg-main": "#efe5cf", "--bg-panel": "#f7f0df", "--text-main": "#33271a", "--kinex-paper-bg": "#f5edd9" }, "darkCssVars": { "--bg-main": "#241e18", "--bg-panel": "#2d251e", "--text-main": "#f3e8d8", "--kinex-paper-bg": "#2a221b" } } ``` ### B. Read-Aloud / TTS Provider (`contributes.readAloudProviders`, perm: `readaloud.provider.register`) Contribution item: `{ "id": "local-tts", "title": "Local TTS", "protocol": "stdio-json" | "local-http-json" | "openai-speech-http", "endpointUrl"?: "...", "isLocalLan"?: true, "secretConfigKey"?: "apiKey", "rateRange"?: [0.5, 2.0], "supportsPitch"?: true, "defaultVoice"?: "..." }` - Request: `{ "schemaVersion": "kinex.read-aloud-request.v1", "requestId": "...", "providerId": "...", "action": "listVoices" | "synthesize", "text"?: "...", "voice"?: "...", "rate"?: 1.0, "pitch"?: 1.0, "format": "wav", "privacyLockEnabled": false, "config": {}, "secrets": {} }` - Response (<= 12 MiB): `{ "schemaVersion": "kinex.read-aloud-response.v1", "ok": true, "voices"?: [{ "id": "v1", "name": "Voice 1", "locale": "zh-CN", "offline": true }], "audioBase64"?: "", "mimeType"?: "audio/wav", "durationMs"?: 800 }` ### C. Content Exporter (`contributes.contentExporters`, perm: `content.export`) Contribution item: `{ "id": "obsidian-callout", "title": "Obsidian Notes (.md)", "formatId": "obsidian-callout", "fileExtension": "md", "mimeType": "text/markdown; charset=utf-8", "scopes": ["highlights", "notes", "flashcards", "whiteboard", "material"] }` - Request: `{ "schemaVersion": "kinex.content-exporter-request.v1", "requestId": "...", "exporterId": "...", "scope": "...", "themeTitle"?: "...", "materialTitle"?: "...", "items": [{ "id"?, "title"?, "text": "...", "backText"?, "note"?, "anchorLabel"?, "tags"?: [] }], "config": {} }` - Response (<= 8 MiB): `{ "schemaVersion": "kinex.content-exporter-response.v1", "ok": true, "fileName": "export.md", "mimeType": "text/markdown; charset=utf-8", "contentText"?: "...", "contentBase64"?: "...", "itemCount"?: 1 }` ### D. Content Importer (`contributes.contentImporters`, perm: `content.import`) Contribution item: `{ "id": "podcast-shownotes", "title": "Podcast Show Notes", "description"?: "...", "urlPatterns"?: ["https://feeds.transistor.fm/*"] }` - Request: `{ "schemaVersion": "kinex.content-importer-request.v1", "requestId": "...", "importerId": "...", "inputKind": "url|file|text", "source": "...", "titleHint"?: "...", "privacyLockEnabled": false, "config": {}, "secrets": {} }` - Response (<= 8 MiB, max 50 items): `{ "schemaVersion": "kinex.content-importer-response.v1", "ok": true, "items": [{ "title": "...", "format": "markdown|txt|html", "content": "...", "canonicalUrl"?: "https://...", "author"?, "publishedAt"?, "folderPath"?: ["Dir"] }] }` ### E. Selection Lookup Provider (`contributes.lookupProviders`, perm: `reader.lookup.register`) Contribution item: `{ "id": "term-glossary", "title": "Term Glossary", "languages"?: ["en", "zh"], "isLocalLan"?: true }` - Request: `{ "schemaVersion": "kinex.lookup-request.v1", "requestId": "...", "providerId": "...", "term": "...", "contextSentence"?: "...", "language"?: "...", "privacyLockEnabled": false, "config": {}, "secrets": {} }` - Response (<= 512 KiB): `{ "schemaVersion": "kinex.lookup-response.v1", "ok": true, "headword": "...", "phonetic"?: "...", "entries": [{ "partOfSpeech"?, "definition": "...", "examples"?: ["..."], "sourceUrl"?: "https://..." }] }` ### F. Search Provider (`contributes.searchProviders`, perm: `ai.search.register`) Contribution item: `{ "id": "searxng", "title": "Local SearXNG", "isLocalLan"?: true }` - Request: `{ "schemaVersion": "kinex.search-request.v1", "requestId": "...", "providerId": "...", "query": "...", "maxResults": 6, "language"?: "...", "privacyLockEnabled": false, "config": {}, "secrets": {} }` - Response (<= 512 KiB): `{ "schemaVersion": "kinex.search-response.v1", "ok": true, "results": [{ "title": "...", "url": "https://...", "siteName"?: "...", "publishedAt"?: "...", "snippet": "...", "quotes"?: [{ "exact": "..." }] }] }` ### G. Media Source (`contributes.mediaSources`, perm: `media.source.register`) Contribution item: `{ "id": "jellyfin-lan", "title": "Jellyfin", "urlPatterns": ["http://127.0.0.1:8096/*"], "renderModes": ["stream"], "supportsChapters"?: true }` (NO wildcard `"*"` allowed) - Request: `{ "schemaVersion": "kinex.media-source-request.v1", "requestId": "...", "action": "resolveMetadata" | "resolvePlayback", "sourceId": "...", "url": "...", "privacyLockEnabled": false, "config": {}, "secrets": {} }` - Response (<= 512 KiB): `{ "schemaVersion": "kinex.media-source.v1", "ok": true, "title"?: "...", "mediaType"?: "video|audio", "durationSec"?: 120, "coverUrl"?: "http://...", "canonicalUrl"?: "...", "playback"?: { "kind": "stream", "streamUrl": "http://...", "mimeType": "video/mp4", "headers"?: {} } }` ### H. Subtitle Provider (`contributes.mediaSubtitles`, perm: `media.subtitles.register`) Contribution item: `{ "id": "local-whisper-http", "title": "Local Whisper", "modes": ["local-transcribe", "file-import"], "supportedLanguages": ["zh", "en", "auto"] }` - Request: `{ "schemaVersion": "kinex.media-subtitles-request.v1", "requestId": "...", "providerId": "...", "mode": "local-transcribe|url-lookup|file-import", "mediaPathOrUrl": "...", "language"?: "...", "config": {}, "secrets": {} }` - Response (<= 4 MiB): `{ "schemaVersion": "kinex.media-subtitles.v1", "ok": true, "language"?: "zh", "cues": [{ "startMs": 0, "endMs": 2200, "text": "..." }] }` ================================================================================ PART 2: LOCAL MCP SERVER (Streamable HTTP, Exact 23 Tools) ================================================================================ - Endpoint: `http://127.0.0.1:45129/mcp` - Auth Header: `Authorization: Bearer ` - Client config snippet (TRAE / Cherry Studio / Zed / Cline / Roo Code): `{ "mcpServers": { "kinex": { "type": "streamable-http", "url": "http://127.0.0.1:45129/mcp", "headers": { "Authorization": "Bearer " } } } }` - Permission Tiers: `"read-only"` | `"read-propose"` (default) | `"trusted-direct"` - Security Rules: - `.kxa` answer vaults, OS keychains, and usage ledgers are NEVER exposed. - All read passages are wrapped in `untrustedSourceText` to prevent prompt injection. - Exact 23 Tools Exposed by `tools/list`: 1. `kinex_get_active_dispatch` — Fast 2-step entry: returns active Push-to-MCP text + exact `submitTemplate` 2. `kinex_get_current_context` — Current open theme, material, chapter, and position 3. `kinex_list_themes` — List themes in library 4. `kinex_list_materials` — List materials (`{ themeId? }`) 5. `kinex_get_outline` — Document TOC or media chapters (`{ materialId }`) 6. `kinex_read_units` — Paginated passage units (`{ materialId, chapterId?, cursor?, maxTokens?, clientContextCeilingTokens? }`) 7. `kinex_search` — Full-text excerpt search (`{ query, materialIds?, limit? }`) 8. `kinex_get_whiteboard_cards` — Whiteboard nodes & edges (`{ themeId? }`) 9. `kinex_get_highlights` — Reader highlights & comments (`{ materialId? }`) 10. `kinex_list_flashcards` — FSRS flashcards (`{ themeId? }`) 11. `kinex_get_chat_context` — Incremental AI Chat history (`{ sessionId, lastN?, maxChars? }`) 12. `kinex_export_theme_digest` *(v1.2)* — Export full theme synthesis digest in `"markdown"` or `"json"` (`{ themeId, format?, includeMaterials?, includeHighlights?, includeWhiteboard?, includeFlashcards? }`; excludes `.kxa` answer vaults) 13. `kinex_navigate_to_anchor` — Seek/scroll UI to `{ materialId, unitId?, pageNumber?, timeSec? }` 14. `kinex_propose_board_cards` — Propose grounded whiteboard tree into AI Inbox 15. `kinex_propose_flashcards` — Propose FSRS flashcards into AI Inbox 16. `kinex_propose_chapters` — Propose non-invasive external TOC chapters 17. `kinex_propose_study_pack` *(v1.2)* — Propose up to 30 curated study-pack items (`title`, `format: "markdown"|"md"|"txt"|"html"`, `content`, `folderPath?`, `sourceUrl?`, `author?`, `tags?`, `bindRoadmapNodeId?`) into AI Inbox -> Apply imports real files into the Reading Theme. Blocks `..`, unsafe URI schemes, dotfiles/secrets (`.env`, `.pem`, `.key`, `.ssh`), executables, and items > 1.5M chars (`-32003`). 18. `kinex_submit_dispatch_result` — Submit `submitTemplate` result into AI Inbox 19. `kinex_append_chat_reply` — Append assistant analysis back to AI Chat (`{ sessionId, content }`) 20. `kinex_roadmap_get` — Read learning roadmap DAG (`{ roadmapId?, themeId? }`) 21. `kinex_roadmap_next` — Next unlocked roadmap nodes (`{ roadmapId?, themeId?, limit? }`) 22. `kinex_roadmap_update_status` — Update node progress/mastery (`{ nodeId, status }`) 23. `kinex_roadmap_add_resource` — Attach validated resource link/material to roadmap node (`{ nodeId, title, url?, materialId? }`)