kontexta-mcp 2.0.2

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.
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Safiyu
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # kontexta-mcp
2
+
3
+ [![npm](https://img.shields.io/npm/v/kontexta-mcp.svg)](https://www.npmjs.com/package/kontexta-mcp)
4
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
5
+
6
+ MCP server for [Kontexta](https://github.com/safiyu/kontexta) — 46 tools that let agents search, read, edit (section-level), tag, version, and clip web content into a local SQLite-backed knowledge base. Designed for context-window economy: every file-returning response is annotated with `est_tokens` and `size_bytes`.
7
+
8
+ ## Install
9
+
10
+ The server is launched on demand by your AI client; no global install needed.
11
+
12
+ ```json
13
+ {
14
+ "mcpServers": {
15
+ "kontexta": {
16
+ "command": "npx",
17
+ "args": ["-y", "kontexta-mcp"],
18
+ "env": {
19
+ "KONTEXTA_DATA_DIR": "/absolute/path/to/your/data"
20
+ }
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ `KONTEXTA_DATA_DIR` **must** be an absolute path. The directory is created on first run and holds your SQLite DB plus the markdown files the agent indexes.
27
+
28
+ ## Client config locations
29
+
30
+ | Client | Path |
31
+ |---|---|
32
+ | Claude Desktop (macOS) | `~/Library/Application Support/Claude/claude_desktop_config.json` |
33
+ | Claude Desktop (Windows) | `%APPDATA%\Claude\claude_desktop_config.json` |
34
+ | Cursor | Settings → Features → MCP |
35
+ | Continue | `~/.continue/config.json` |
36
+ | Codex | `.codex/mcp_servers.json` |
37
+ | Gemini / Antigravity | `~/.gemini/antigravity/mcp_servers.json` |
38
+
39
+ ## Web UI (optional)
40
+
41
+ The MCP server runs headless. If you want the matching three-pane web UI, run the Docker image alongside it (it reads the same `KONTEXTA_DATA_DIR`):
42
+
43
+ ```bash
44
+ docker run -d -p 3000:3000 -v /absolute/path/to/your/data:/app/data safiyu/kontexta:latest
45
+ ```
46
+
47
+ Open `http://localhost:3000`.
48
+
49
+ ## Requirements
50
+
51
+ - Node ≥ 20 (the package is published as ESM, target node20).
52
+ - `better-sqlite3` ships prebuilt binaries for linux/macos/windows on x64 and arm64. If your platform isn't covered (Alpine/musl, RISC-V, older Node), `npm install` falls back to a from-source build that needs `python3` and a C++ toolchain.
53
+
54
+ ## Documentation
55
+
56
+ Full docs, the reference for 46 core + unlimited custom hand tools, and the web UI live in the [main repository](https://github.com/safiyu/kontexta). See [`CHANGELOG.md`](https://github.com/safiyu/kontexta/blob/main/CHANGELOG.md) for what's new.
57
+
58
+ ## License
59
+
60
+ Apache-2.0
@@ -0,0 +1,164 @@
1
+ <!--
2
+ Source of truth for the kontexta agent rules block.
3
+
4
+ Authoring rules:
5
+ 1. One clause per cell. <= 80 chars. Verbs, no fluff.
6
+ 2. "When NOT" is the documented failure mode, not a hypothetical edge case.
7
+ 3. "Use instead" is the BETTER sibling tool. Empty if no sibling.
8
+ 4. Every row stands alone — no cross-references.
9
+ 5. Every new server.tool() in apps/mcp/src/index.ts MUST add a row in the
10
+ relevant bucket below AND bump rulesVersion in packages/core/package.json.
11
+ Tests enforce this.
12
+
13
+ The placeholder {{VERSION}} is substituted at module init with RULE_BLOCK_VERSION.
14
+ -->
15
+ <!-- BEGIN kontexta:rules v{{VERSION}} -->
16
+ ## Working with kontexta
17
+
18
+ This project is registered with kontexta. Honor these rules to keep the index, history, and journal coherent — and to avoid burning tokens on workflows kontexta already solves. Tools live under the `kxta` MCP server.
19
+
20
+ ### Core rules
21
+
22
+ **Search before reading.** Use `search`, `bundle_search`, or `regex_search` to find context first. Skipping straight to `read_file` on a guessed path wastes tokens and often misses the right file.
23
+
24
+ **All KB writes go through kontexta.** Use `create_file` / `update_file` / `update_file_section` / `journal_note`. **Never** edit a KB file with raw filesystem tools (Edit/Write/cat) — the watcher and FTS index will diverge until `refresh_index` runs, and subsequent searches will return stale results.
25
+
26
+ **Batch reads. Don't loop `read_file`.** Need ≥2 files? Call `read_files` (one round-trip, up to 200 IDs) or `bundle_search` (token-budgeted blob). Looping `read_file` wastes round-trips and inflates response overhead.
27
+
28
+ **Address `journal.suggested_action` before the next tool call.** Many tool responses include a `journal` envelope. If `journal.suggested_action` is set (e.g., `"distill_journal"`), call that tool before issuing your next tool. To dismiss for the rest of the session, pass `journal_acknowledge: true` on your next tool call.
29
+
30
+ **Use `journal_note(text, tags)` for decisions and abandonments.** When you make a non-obvious call, try something that doesn't work, or capture a workaround, log it. Hands runs are auto-captured now.
31
+
32
+ **Use `journal_intent(summary)` when the user pivots.** One short sentence so the distillation step knows the topic shifted.
33
+
34
+ **Strict mode awareness.** If a project sets `journal.mode = "strict"` in its `kontexta.json`, the MCP server returns a `JOURNAL_BACKLOG` error on read tools (search/read_*/list_*) when undistilled events exist. The error includes `next_action: "distill_journal"`. Either run `distill_journal` first, OR pass `journal_bypass: true` on the read call to override (logged for audit).
35
+
36
+ **Confirm Hands tokens within 60 seconds.** When a Hands tool returns an approval token, do NOT chain a long question or another tool call before `confirm_hand`. Tokens expire; the user will have to re-issue the whole flow.
37
+
38
+ **Save specs to a canonical location.** When generating a spec, plan, or design doc, write it to the KB at `specs/<project-name>/<spec-name>.md` (use `create_file` with `destination: "knowledge"`, `folder: "specs/<project-name>"`). One folder per project keeps specs queryable.
39
+
40
+ **Tag new KB files at creation time.** Pass `tags` on `create_file`, or call `add_tags` immediately after. Untagged files are recoverable but invisible to `find_related`.
41
+
42
+ **`whats_new` early. `commit_backup` late.** Run `whats_new` at session start if you've been away — it returns files added/changed since a cutoff. End the session with `commit_backup` if you mutated KB files and the project has a remote.
43
+
44
+ **Use `.mmd` for diagrams, not fenced code in `.md`.** When creating an architecture / flow / sequence diagram, call `create_file` with `format: "mmd"` and put the raw mermaid source as the body (no ```` ```mermaid ```` fence). The web UI renders `.mmd` files as live diagrams with SVG/PNG export; mermaid embedded in markdown is just text. Default folder: `mermaid/` (or `<project>/mermaid/` for project-scoped diagrams).
45
+
46
+
47
+ ### Knowledge Items (KI)
48
+
49
+ KIs are curated, distilled KB files — the highest-signal context in the vault.
50
+ They save tokens and prevent redundant research when used correctly.
51
+
52
+ **Check KIs before independent research.** At the start of any task, run
53
+ `search` or `bundle_search` over the KB for the task topic. If a matching KI
54
+ exists, read it before writing code, designing architecture, or forming a plan.
55
+ Skipping this step is the single most common source of duplicated work.
56
+
57
+ **KIs are starting points, not ground truth.** KIs are snapshots. Always
58
+ cross-reference a KI's API patterns, file paths, and config values against the
59
+ *current* source on disk before acting on them. KIs can lag behind code.
60
+
61
+ **Close the loop: update the KI after significant changes.** When you ship a
62
+ meaningful change (new API, config schema change, architecture shift), update
63
+ the relevant KI via `update_file` or `update_file_section`. If no KI exists
64
+ yet, create one with `create_file` under `knowledge/` with appropriate tags.
65
+ A KI that isn't maintained becomes noise — which is worse than no KI.
66
+
67
+ **Use `whats_new` at session start after a gap.** If you haven't touched the
68
+ project in a while, run `whats_new(since: "7d")` to surface recently changed
69
+ files — including KIs updated by other agents or the user.
70
+
71
+ ### Tool reference
72
+
73
+ The matrix below is grouped by intent. For each tool: when to reach for it, the most common wrong context, and the better sibling tool when wrong.
74
+
75
+ #### Find
76
+
77
+ | Tool | When | Not when | Use instead |
78
+ |---|---|---|---|
79
+ | `search` | Natural-language keyword across KB (FTS) | Substrings, URLs, code idents | `regex_search` |
80
+ | `regex_search` | Substrings, URLs, code identifiers | Natural-language queries | `search` |
81
+ | `grep_in_file` | Substring/regex within ONE known file | Searching across files | `regex_search` |
82
+ | `bundle_search` | Need search hits + bodies in a token budget | Only need IDs | `search` |
83
+ | `find_related` | Discover siblings via tag overlap | Text content matching | `search` |
84
+ | `suggest_tags` | Propose tags for an existing file | Finding files by tag | `find_related` |
85
+
86
+ #### Read
87
+
88
+ | Tool | When | Not when | Use instead |
89
+ |---|---|---|---|
90
+ | `read_file` | One file ID, full body | ≥2 file IDs | `read_files` |
91
+ | `read_files` | 2–200 file IDs in one call | Only need a section of one file | `read_section` |
92
+ | `read_file_by_path` | Known absolute path, no ID handy | You already have the ID | `read_file` |
93
+ | `read_file_lines` | Known line range | Guessing line numbers | `read_section` |
94
+ | `read_section` | Known heading | Need the whole file | `read_file` |
95
+ | `read_file_outline` | Triaging an unfamiliar file's structure | Structure already known | `describe_file` |
96
+ | `describe_file` | Metadata only (size, tags, mtime) | Need content | `read_file` |
97
+
98
+ #### Write
99
+
100
+ | Tool | When | Not when | Use instead |
101
+ |---|---|---|---|
102
+ | `create_file` | One new file (md or mmd via `format`) | Bulk-creating ≥2 files | `create_files` |
103
+ | `create_files` | 2+ new files in one call | Single file | `create_file` |
104
+ | `update_file` | Replacing the whole body | Editing one section | `update_file_section` |
105
+ | `update_file_section` | Surgical edit at a known heading | Replacing the whole file | `update_file` |
106
+ | `delete_file` | One file | Bulk delete | `delete_files` |
107
+ | `delete_files` | 2+ files in one call | Single file | `delete_file` |
108
+ | `move_file` | Rename or relocate a file | File content needs changing | `update_file` |
109
+
110
+ #### Organize
111
+
112
+ | Tool | When | Not when | Use instead |
113
+ |---|---|---|---|
114
+ | `add_tags` | Tag an existing file | Tagging at creation time | `create_file` (with `tags` param) |
115
+ | `remove_tags` | Untag a file | Want to delete the file | `delete_file` |
116
+ | `list_tags` | Enumerate all tags in the vault | Want files for a given tag | `find_related` |
117
+ | `set_favorite` | Pin / unpin a file | Semantic categorization | `add_tags` |
118
+ | `tag_search_results` | Bulk-tag every hit from a search | Tagging a single file | `add_tags` |
119
+ | `journal_note` | Log a decision, workaround, or abandonment | Editing regular content | `update_file` |
120
+ | `journal_intent` | Record a user-initiated topic pivot | Auto-captured tool calls | `journal_note` |
121
+ | `journal_append` | Append timestamped text to today's daily KB journal file | Structured notes | `journal_note` |
122
+ | `distill_journal` | Summarize accumulated journal events | Individual events | `journal_note` |
123
+ | `clip_url` | Capture a web URL into the KB | Saving a local file | `create_file` |
124
+ | `list_folders` | Enumerate folders in the project | Finding files | `list_files` |
125
+ | `create_folder` | Create a new (possibly nested) folder | Files don't need explicit folders | |
126
+ | `delete_folder` | Remove an empty folder | Folder still has files | `delete_files` first |
127
+
128
+ #### History & recovery
129
+
130
+ | Tool | When | Not when | Use instead |
131
+ |---|---|---|---|
132
+ | `get_history` | List a file's revisions | Want a diff between two revisions | `get_diff` |
133
+ | `get_diff` | Compare two specific revisions | Want full content of one | `restore_file` |
134
+ | `restore_file` | Roll back a KB file to an earlier revision | Want to use raw `git` | |
135
+ | `diff_against_disk` | Find drift after raw filesystem edits | Normal search staleness | `refresh_index` |
136
+ | `refresh_index` | Rescan after out-of-band changes | Normal in-app edits | |
137
+ | `commit_backup` | Push KB changes to remote git | Local-only work | |
138
+
139
+ #### Discover
140
+
141
+ | Tool | When | Not when | Use instead |
142
+ |---|---|---|---|
143
+ | `list_projects` | Enumerate registered projects | Files within one project | `list_files` |
144
+ | `list_files` | Files in a project (filterable) | Full-text content matters | `search` |
145
+ | `project_map` | Folder/file tree for a project | Flat file list | `list_files` |
146
+ | `stats` | Counts and health for a project | Per-file detail | `describe_file` |
147
+ | `whats_new` | Files added/changed since a cutoff | Full-text search | `search` |
148
+
149
+ #### Hands (project tools)
150
+
151
+ | Tool | When | Not when | Use instead |
152
+ |---|---|---|---|
153
+ | `list_hands` | Enumerate Hands tools available in this project | Want the YAML schema | `describe_hands_schema` |
154
+ | `describe_hands_schema` | Explain the `hands.yaml` format | Listing tools | `list_hands` |
155
+ | `confirm_hand` | Approve a Hands token within 60s of issue | Normal MCP tool calls | |
156
+ | `reload_hands` | Re-read `hands.yaml` after editing it | First-time use (auto-loads) | |
157
+
158
+ #### Onboarding
159
+
160
+ | Tool | When | Not when | Use instead |
161
+ |---|---|---|---|
162
+ | `register_project` | Register a new project root with kontexta | Already registered | `list_projects` |
163
+ | `onboard_agent` | Write/update the rules block in CLAUDE.md / AGENTS.md / etc. | Editing regular project content | `update_file` |
164
+ <!-- END kontexta:rules v{{VERSION}} -->