@porast1/mcp-cognitive 1.0.0 → 1.1.0
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/AGENT_INSTRUCTIONS.md +81 -0
- package/README.md +346 -142
- package/config/.env.example +21 -0
- package/config/mcp.jsonc +33 -0
- package/config/profiles.json +42 -0
- package/dist/adapters/weaviate-v3.adapter.d.ts +136 -0
- package/dist/adapters/weaviate-v3.adapter.d.ts.map +1 -0
- package/dist/adapters/weaviate-v3.adapter.js +2214 -0
- package/dist/adapters/weaviate-v3.adapter.js.map +1 -0
- package/dist/cli/audit.js +4 -6
- package/dist/cli/audit.js.map +1 -1
- package/dist/cli/backup.d.ts +19 -0
- package/dist/cli/backup.d.ts.map +1 -0
- package/dist/cli/backup.js +141 -0
- package/dist/cli/backup.js.map +1 -0
- package/dist/cli/stale.js +4 -7
- package/dist/cli/stale.js.map +1 -1
- package/dist/cli/sync-ddd-docs.js +10 -10
- package/dist/cli/sync-ddd-docs.js.map +1 -1
- package/dist/cli/verify.js +8 -11
- package/dist/cli/verify.js.map +1 -1
- package/dist/hooks/pattern-registry.d.ts +73 -0
- package/dist/hooks/pattern-registry.d.ts.map +1 -0
- package/dist/hooks/pattern-registry.js +137 -0
- package/dist/hooks/pattern-registry.js.map +1 -0
- package/dist/hooks/post-commit.d.ts +5 -0
- package/dist/hooks/post-commit.d.ts.map +1 -1
- package/dist/hooks/post-commit.js +31 -122
- package/dist/hooks/post-commit.js.map +1 -1
- package/dist/ports/cognitive-store.port.d.ts +51 -3
- package/dist/ports/cognitive-store.port.d.ts.map +1 -1
- package/dist/profiles/agent-profiles.d.ts +26 -2
- package/dist/profiles/agent-profiles.d.ts.map +1 -1
- package/dist/profiles/agent-profiles.js +60 -60
- package/dist/profiles/agent-profiles.js.map +1 -1
- package/dist/server.js +32 -34
- package/dist/server.js.map +1 -1
- package/dist/tools/audit.tool.d.ts.map +1 -1
- package/dist/tools/audit.tool.js +7 -3
- package/dist/tools/audit.tool.js.map +1 -1
- package/dist/tools/compact.tool.d.ts +16 -0
- package/dist/tools/compact.tool.d.ts.map +1 -0
- package/dist/tools/compact.tool.js +85 -0
- package/dist/tools/compact.tool.js.map +1 -0
- package/dist/tools/correlate.tool.d.ts +25 -0
- package/dist/tools/correlate.tool.d.ts.map +1 -0
- package/dist/tools/correlate.tool.js +87 -0
- package/dist/tools/correlate.tool.js.map +1 -0
- package/dist/tools/forget.tool.d.ts +11 -0
- package/dist/tools/forget.tool.d.ts.map +1 -0
- package/dist/tools/forget.tool.js +27 -0
- package/dist/tools/forget.tool.js.map +1 -0
- package/dist/tools/health.tool.d.ts +8 -0
- package/dist/tools/health.tool.d.ts.map +1 -0
- package/dist/tools/health.tool.js +51 -0
- package/dist/tools/health.tool.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +134 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/reason.tool.d.ts +15 -0
- package/dist/tools/reason.tool.d.ts.map +1 -0
- package/dist/tools/reason.tool.js +157 -0
- package/dist/tools/reason.tool.js.map +1 -0
- package/dist/tools/recall.tool.d.ts +3 -10
- package/dist/tools/recall.tool.d.ts.map +1 -1
- package/dist/tools/recall.tool.js +92 -11
- package/dist/tools/recall.tool.js.map +1 -1
- package/dist/tools/search-code-artifacts.tool.d.ts +15 -0
- package/dist/tools/search-code-artifacts.tool.d.ts.map +1 -0
- package/dist/tools/search-code-artifacts.tool.js +55 -0
- package/dist/tools/search-code-artifacts.tool.js.map +1 -0
- package/dist/tools/search-documents.tool.d.ts +14 -0
- package/dist/tools/search-documents.tool.d.ts.map +1 -0
- package/dist/tools/search-documents.tool.js +48 -0
- package/dist/tools/search-documents.tool.js.map +1 -0
- package/dist/tools/search-test-artifacts.tool.d.ts +14 -0
- package/dist/tools/search-test-artifacts.tool.d.ts.map +1 -0
- package/dist/tools/search-test-artifacts.tool.js +50 -0
- package/dist/tools/search-test-artifacts.tool.js.map +1 -0
- package/dist/tools/stats.tool.d.ts +10 -0
- package/dist/tools/stats.tool.d.ts.map +1 -0
- package/dist/tools/stats.tool.js +110 -0
- package/dist/tools/stats.tool.js.map +1 -0
- package/dist/tools/store-code-artifact.tool.d.ts +18 -0
- package/dist/tools/store-code-artifact.tool.d.ts.map +1 -0
- package/dist/tools/store-code-artifact.tool.js +57 -0
- package/dist/tools/store-code-artifact.tool.js.map +1 -0
- package/dist/tools/store-document.tool.d.ts +16 -0
- package/dist/tools/store-document.tool.d.ts.map +1 -0
- package/dist/tools/store-document.tool.js +56 -0
- package/dist/tools/store-document.tool.js.map +1 -0
- package/dist/tools/store-test-artifact.tool.d.ts +17 -0
- package/dist/tools/store-test-artifact.tool.d.ts.map +1 -0
- package/dist/tools/store-test-artifact.tool.js +56 -0
- package/dist/tools/store-test-artifact.tool.js.map +1 -0
- package/dist/tools/store.tool.d.ts +2 -9
- package/dist/tools/store.tool.d.ts.map +1 -1
- package/dist/tools/store.tool.js +66 -11
- package/dist/tools/store.tool.js.map +1 -1
- package/dist/tools/timeline.tool.d.ts +29 -0
- package/dist/tools/timeline.tool.d.ts.map +1 -0
- package/dist/tools/timeline.tool.js +83 -0
- package/dist/tools/timeline.tool.js.map +1 -0
- package/dist/tools/tool-definition.d.ts +14 -0
- package/dist/tools/tool-definition.d.ts.map +1 -0
- package/dist/tools/tool-definition.js +2 -0
- package/dist/tools/tool-definition.js.map +1 -0
- package/dist/tools/update.tool.d.ts +27 -0
- package/dist/tools/update.tool.d.ts.map +1 -0
- package/dist/tools/update.tool.js +101 -0
- package/dist/tools/update.tool.js.map +1 -0
- package/dist/tools/verify.tool.d.ts.map +1 -1
- package/dist/tools/verify.tool.js +13 -9
- package/dist/tools/verify.tool.js.map +1 -1
- package/dist/types.d.ts +208 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/citation-checker.js +3 -3
- package/dist/utils/citation-checker.js.map +1 -1
- package/dist/utils/decay.d.ts.map +1 -1
- package/dist/utils/decay.js +4 -4
- package/dist/utils/decay.js.map +1 -1
- package/dist/utils/safety-guard.d.ts +57 -0
- package/dist/utils/safety-guard.d.ts.map +1 -0
- package/dist/utils/safety-guard.js +108 -0
- package/dist/utils/safety-guard.js.map +1 -0
- package/examples/README.md +146 -0
- package/examples/patterns/example-repo.patterns.ts +233 -0
- package/examples/profiles/example-repo.profiles.json +56 -0
- package/package.json +65 -57
- package/dist/adapters/sqlite.adapter.d.ts +0 -29
- package/dist/adapters/sqlite.adapter.d.ts.map +0 -1
- package/dist/adapters/sqlite.adapter.js +0 -450
- package/dist/adapters/sqlite.adapter.js.map +0 -1
- package/dist/adapters/weaviate.adapter.d.ts +0 -43
- package/dist/adapters/weaviate.adapter.d.ts.map +0 -1
- package/dist/adapters/weaviate.adapter.js +0 -678
- package/dist/adapters/weaviate.adapter.js.map +0 -1
- package/dist/cli/migrate-to-weaviate.d.ts +0 -2
- package/dist/cli/migrate-to-weaviate.d.ts.map +0 -1
- package/dist/cli/migrate-to-weaviate.js +0 -65
- package/dist/cli/migrate-to-weaviate.js.map +0 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# MCP Cognitive — Agent Instructions
|
|
2
|
+
|
|
3
|
+
> Copy this section into your project's `.github/copilot-instructions.md` or equivalent AI instructions file.
|
|
4
|
+
> It tells AI agents what tools are available, when to use them, and how.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Cognitive Memory (mcp-cognitive)
|
|
9
|
+
|
|
10
|
+
The project uses an MCP server (`mcp-cognitive`) backed by Weaviate hybrid search for persistent AI knowledge.
|
|
11
|
+
Facts survive between sessions — recall them before searching the codebase.
|
|
12
|
+
|
|
13
|
+
### Tool Inventory (18 tools)
|
|
14
|
+
|
|
15
|
+
#### CRUD — Core Knowledge
|
|
16
|
+
|
|
17
|
+
| Tool | When to use | Key params |
|
|
18
|
+
| ------------------ | --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| `cognitive_recall` | **At task start** — before codebase research. Search facts by semantic query, filter by module/tags/type. | `query?` (optional — omit for filter-only), `module?`, `modules?` (multi-module parallel), `tags?`, `types?`, `agent?`, `limit?` |
|
|
20
|
+
| `cognitive_store` | After discovering an insight worth remembering. Use `dryRun=true` first to check for duplicates. | `fact`, `type` (invariant/policy/convention/observation/ephemeral), `module`, `citations?`, `tags?`, `confidence?`, `dryRun?` |
|
|
21
|
+
| `cognitive_update` | To patch an existing fact in-place (confidence, tags, citations). Preserves ID and history. | `id` (UUID), `confidence?`, `type?`, `module?`, `tags?`, `addTags?`, `removeTags?`, `citations?` |
|
|
22
|
+
| `cognitive_forget` | To archive outdated/incorrect facts (soft-delete with reason). | `id` (UUID), `reason` |
|
|
23
|
+
|
|
24
|
+
#### Search & Discovery
|
|
25
|
+
|
|
26
|
+
| Tool | When to use | Key params |
|
|
27
|
+
| --------------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
|
28
|
+
| `cognitive_search_documents` | Find indexed docs (DDD, architecture, guides). | `query`, `docType?`, `module?`, `project?` |
|
|
29
|
+
| `cognitive_search_code_artifacts` | Find indexed code by semantic meaning or keyword. | `query`, `module?`, `layer?`, `artifactType?` |
|
|
30
|
+
| `cognitive_search_test_artifacts` | Find indexed tests by description or module. | `query`, `module?`, `testType?` |
|
|
31
|
+
| `cognitive_correlate` | Cross-collection traceability: docs ↔ code ↔ tests. Gap detection. | `sourceId` or `sourceQuery`, `sourceCollection`, `targetCollections?`, `module?` |
|
|
32
|
+
|
|
33
|
+
#### Indexing
|
|
34
|
+
|
|
35
|
+
| Tool | When to use | Key params |
|
|
36
|
+
| ------------------------------- | ----------------------------------------------------- | ------------------------------------------------------------ |
|
|
37
|
+
| `cognitive_store_document` | Index a markdown doc chunk (auto-dedup via checksum). | `content`, `filePath`, `docType`, `project`, `checksum` |
|
|
38
|
+
| `cognitive_store_code_artifact` | Index a TypeScript file with metadata. | `content`, `filePath`, `project`, `artifactType`, `checksum` |
|
|
39
|
+
| `cognitive_store_test_artifact` | Index a test file with describe/it blocks. | `content`, `filePath`, `project`, `testType`, `checksum` |
|
|
40
|
+
|
|
41
|
+
#### Analysis & Maintenance
|
|
42
|
+
|
|
43
|
+
| Tool | When to use | Key params |
|
|
44
|
+
| -------------------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------- |
|
|
45
|
+
| `cognitive_reason` | Need a synthesized answer, not raw facts. Groups by module/type, detects contradictions. | `question`, `modules?`, `depth?` (shallow/deep) |
|
|
46
|
+
| `cognitive_timeline` | Review what was learned during a period. Chronological, grouped by day. | `since?`, `until?`, `module?`, `status?`, `order?` |
|
|
47
|
+
| `cognitive_stats` | Quick overview before deciding what to do. Counts, top tags, activity. | `module?` |
|
|
48
|
+
| `cognitive_verify` | After refactors — check if citation file paths still exist. | `factId?` (omit = verify all) |
|
|
49
|
+
| `cognitive_audit` | Periodic quality check. Finds stale facts, broken citations, duplicates. Expensive. | _(no params)_ |
|
|
50
|
+
| `cognitive_compact` | Merge duplicate facts. Preview first, then execute. | `mode` (preview/execute), `factIdA?`, `factIdB?` |
|
|
51
|
+
| `cognitive_health` | Check Weaviate infrastructure is running. | _(no params)_ |
|
|
52
|
+
|
|
53
|
+
### Workflow Rules
|
|
54
|
+
|
|
55
|
+
1. **Recall BEFORE search** — always call `cognitive_recall` at task start to check for cached knowledge before grepping the codebase.
|
|
56
|
+
2. **Store with citations** — include `file:line` references so facts can be verified later.
|
|
57
|
+
3. **Use `dryRun`** — before storing, call `cognitive_store({ ..., dryRun: true })` to avoid duplicates.
|
|
58
|
+
4. **Fact types matter:**
|
|
59
|
+
- `invariant` (confidence: 1.0) — permanent architecture rules
|
|
60
|
+
- `policy` (0.9–0.95) — business decisions that may change
|
|
61
|
+
- `convention` (0.85–0.9) — team conventions, audit every 6 months
|
|
62
|
+
- `observation` (0.7–0.8) — debugging insights, re-verify in 30 days
|
|
63
|
+
- `ephemeral` (any) — temporary notes, auto-expire in 7 days
|
|
64
|
+
5. **Update > Supersede** — use `cognitive_update` to patch facts. Only use `store({ supersedes })` when the fact text itself changed fundamentally.
|
|
65
|
+
6. **Forget with reason** — when archiving, always explain why so the knowledge graph stays auditable.
|
|
66
|
+
|
|
67
|
+
### Example: Typical Agent Flow
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
1. cognitive_recall({ query: "form validation rules", module: "identity" })
|
|
71
|
+
2. ... analyze codebase ...
|
|
72
|
+
3. cognitive_store({
|
|
73
|
+
fact: "Registration form uses per-field Zod validation, not form-level",
|
|
74
|
+
type: "convention",
|
|
75
|
+
module: "identity",
|
|
76
|
+
citations: [{ file: "apps/web/lib/modules/identity/...", line: 42 }],
|
|
77
|
+
tags: ["forms", "validation", "zod"],
|
|
78
|
+
dryRun: true
|
|
79
|
+
})
|
|
80
|
+
4. // If no duplicates found: re-run without dryRun
|
|
81
|
+
```
|
package/README.md
CHANGED
|
@@ -1,142 +1,346 @@
|
|
|
1
|
-
# @
|
|
2
|
-
|
|
3
|
-
Universal MCP server
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
1
|
+
# @porast1/mcp-cognitive
|
|
2
|
+
|
|
3
|
+
Universal [MCP](https://modelcontextprotocol.io/) server that gives AI agents persistent, searchable memory backed by [Weaviate](https://weaviate.io/) hybrid search (BM25 keyword + vector embeddings + cross-encoder reranking).
|
|
4
|
+
|
|
5
|
+
Store facts, documents, code artifacts, and test artifacts. Query them with semantic search, filter by module/type/tags, reason across knowledge, detect contradictions, and keep the database healthy — all from 18 MCP tools.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
LLM agents lose context between sessions.
|
|
10
|
+
`mcp-cognitive` makes knowledge survive: conventions, architecture decisions, debugging insights, domain rules — anything worth remembering.
|
|
11
|
+
|
|
12
|
+
- **Hybrid search** — BM25 keyword matching + transformer vector embeddings + reranking. Not just text search.
|
|
13
|
+
- **Multi-tenancy** — one Weaviate instance, many projects. Data fully isolated via `WEAVIATE_TENANT`.
|
|
14
|
+
- **4 collections** — `CognitiveFact`, `DocumentChunk`, `CodeArtifact`, `TestArtifact`. Facts, docs, code, tests.
|
|
15
|
+
- **18 MCP tools** — CRUD, search, reasoning, audit, correlation, compaction, timeline, stats.
|
|
16
|
+
- **Agent profiles** — tune recall per agent role (architect vs. tester vs. debugger).
|
|
17
|
+
- **Pattern detection** — auto-detect conventions from git diffs via post-commit hooks.
|
|
18
|
+
- **Zero vendor lock-in** — port/adapter architecture. Weaviate is the sole adapter today.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### 1. Start Weaviate
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/porast1/weaviate-dev-stack
|
|
28
|
+
cd weaviate-dev-stack
|
|
29
|
+
docker-compose up -d
|
|
30
|
+
# ~1.5 GB RAM (Weaviate + text2vec-transformers + reranker-transformers)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Install the package
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @porast1/mcp-cognitive
|
|
37
|
+
# or
|
|
38
|
+
pnpm add @porast1/mcp-cognitive
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 3. Configure VS Code / Copilot
|
|
42
|
+
|
|
43
|
+
Copy the template config to your project:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Copy config templates (mcp.jsonc, profiles.json, .env.example)
|
|
47
|
+
cp -r ./node_modules/@porast1/mcp-cognitive/config/ ./.cognitive/
|
|
48
|
+
|
|
49
|
+
# Copy .env.example to project root
|
|
50
|
+
cp ./.cognitive/.env.example ./.env
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Then add to `.vscode/mcp.json` (or copy from `.cognitive/mcp.jsonc`):
|
|
54
|
+
|
|
55
|
+
```jsonc
|
|
56
|
+
{
|
|
57
|
+
"servers": {
|
|
58
|
+
"cognitive": {
|
|
59
|
+
"command": "node",
|
|
60
|
+
"args": ["./node_modules/@porast1/mcp-cognitive/dist/server.js"],
|
|
61
|
+
"env": {
|
|
62
|
+
"WEAVIATE_URL": "localhost:8200",
|
|
63
|
+
"WEAVIATE_TENANT": "myproject", // isolates your data
|
|
64
|
+
"WORKSPACE_ROOT": "${workspaceFolder}",
|
|
65
|
+
"COGNITIVE_PROFILES_FILE": "./.cognitive/profiles.json", // optional
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 4. Done
|
|
73
|
+
|
|
74
|
+
The MCP server registers 18 tools automatically. Your AI agent can now store and recall knowledge.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Environment Variables
|
|
79
|
+
|
|
80
|
+
Full reference in [`config/.env.example`](config/.env.example). Key variables:
|
|
81
|
+
|
|
82
|
+
| Variable | Default | Description |
|
|
83
|
+
| ------------------------- | ---------------- | ----------------------------------------------------- |
|
|
84
|
+
| `WEAVIATE_URL` | `localhost:8200` | Weaviate HTTP endpoint |
|
|
85
|
+
| `WEAVIATE_TENANT` | _(none)_ | Tenant name for data isolation (strongly recommended) |
|
|
86
|
+
| `WEAVIATE_GRPC_PORT` | _(auto)_ | gRPC port override |
|
|
87
|
+
| `WORKSPACE_ROOT` | `process.cwd()` | Project root for resolving citation file paths |
|
|
88
|
+
| `COGNITIVE_PROJECT` | `default` | Project identifier for multi-project tagging |
|
|
89
|
+
| `COGNITIVE_PROFILES_FILE` | _(none)_ | Path to agent profiles JSON |
|
|
90
|
+
| `COGNITIVE_PATTERNS_FILE` | _(none)_ | Path to pattern definitions for post-commit hook |
|
|
91
|
+
| `COGNITIVE_MAX_ARCHIVES` | `20` | Max archive operations per session (safety guard) |
|
|
92
|
+
| `COGNITIVE_MAX_COMPACTS` | `10` | Max compact operations per session (safety guard) |
|
|
93
|
+
| `COGNITIVE_ALLOW_RESET` | `false` | Enable `resetTenant()` — **test environments only** |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Tools Reference
|
|
98
|
+
|
|
99
|
+
### Core Knowledge (CRUD)
|
|
100
|
+
|
|
101
|
+
| Tool | Description |
|
|
102
|
+
| ------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| `cognitive_store` | Store a new fact. Supports `dryRun=true` to check for duplicates before writing. |
|
|
104
|
+
| `cognitive_recall` | Hybrid search facts. Query is optional (filter-only mode). Supports `modules[]` for multi-module parallel query. |
|
|
105
|
+
| `cognitive_update` | Patch a fact in-place (confidence, tags, citations, module, type). Supports incremental `addTags`/`removeTags`. |
|
|
106
|
+
| `cognitive_forget` | Archive (soft-delete) a fact with a reason. |
|
|
107
|
+
|
|
108
|
+
### Search & Discovery
|
|
109
|
+
|
|
110
|
+
| Tool | Description |
|
|
111
|
+
| --------------------------------- | ---------------------------------------------------------------------------------- |
|
|
112
|
+
| `cognitive_search_documents` | Hybrid search across indexed document chunks (DDD docs, architecture, guides). |
|
|
113
|
+
| `cognitive_search_code_artifacts` | Semantic search across indexed TypeScript code (entities, use cases, ports). |
|
|
114
|
+
| `cognitive_search_test_artifacts` | Semantic search across indexed tests (unit, integration, E2E). |
|
|
115
|
+
| `cognitive_correlate` | Cross-collection correlation: docs ↔ code ↔ tests. Gap detection & traceability. |
|
|
116
|
+
|
|
117
|
+
### Indexing
|
|
118
|
+
|
|
119
|
+
| Tool | Description |
|
|
120
|
+
| ------------------------------- | ------------------------------------------------------------ |
|
|
121
|
+
| `cognitive_store_document` | Index a document chunk with checksum-based change detection. |
|
|
122
|
+
| `cognitive_store_code_artifact` | Index a TypeScript code artifact with AST metadata. |
|
|
123
|
+
| `cognitive_store_test_artifact` | Index a test file with describe/it block metadata. |
|
|
124
|
+
|
|
125
|
+
### Analysis & Maintenance
|
|
126
|
+
|
|
127
|
+
| Tool | Description |
|
|
128
|
+
| -------------------- | ------------------------------------------------------------------------------------------ |
|
|
129
|
+
| `cognitive_reason` | Synthesize a structured answer from facts — groups by module/type, detects contradictions. |
|
|
130
|
+
| `cognitive_timeline` | Chronological view with date range filtering and daily grouping. |
|
|
131
|
+
| `cognitive_stats` | Quick dashboard: counts by type/module/status, top tags, recent activity. |
|
|
132
|
+
| `cognitive_verify` | Check if file:line citations still exist on disk. |
|
|
133
|
+
| `cognitive_audit` | Full quality audit: stale facts, broken citations, duplicate candidates. |
|
|
134
|
+
| `cognitive_compact` | Find and merge duplicate facts (preview or execute mode). |
|
|
135
|
+
| `cognitive_health` | Weaviate infrastructure health: version, nodes, collections, tenants. |
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Fact Types & Lifecycle
|
|
140
|
+
|
|
141
|
+
| Type | TTL | Use for |
|
|
142
|
+
| ------------- | ------------- | --------------------------------------------- |
|
|
143
|
+
| `invariant` | ∞ | Permanent architecture rules. Confidence: 1.0 |
|
|
144
|
+
| `policy` | Until changed | Business decisions that may evolve |
|
|
145
|
+
| `convention` | 6 months | Team conventions, re-audit periodically |
|
|
146
|
+
| `observation` | 30 days | Debugging insights, re-verify when recalled |
|
|
147
|
+
| `ephemeral` | 7 days | Temporary notes, auto-expire |
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Agent Profiles
|
|
152
|
+
|
|
153
|
+
Profiles tune recall behavior per agent role. See [config/profiles.json](config/profiles.json) for a full example.
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"architect-agent": {
|
|
158
|
+
"name": "architect-agent",
|
|
159
|
+
"priorityTypes": ["invariant", "policy", "convention"],
|
|
160
|
+
"boostTags": ["architecture", "design"],
|
|
161
|
+
"suppressTags": ["test-only"],
|
|
162
|
+
"maxRecall": 10,
|
|
163
|
+
"alpha": 0.7
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**`alpha`** controls hybrid search balance: `0.0` = keyword-heavy (BM25), `1.0` = semantic-heavy (vector).
|
|
169
|
+
|
|
170
|
+
Use `agent` parameter in `cognitive_recall` to activate a profile:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
cognitive_recall({ query: "cross-BC rules", agent: "architect-agent" })
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Pattern Detection (Git Hooks)
|
|
179
|
+
|
|
180
|
+
Auto-detect conventions from git diffs. See [examples/patterns/](examples/patterns/) for pattern templates.
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
# Set up
|
|
184
|
+
export COGNITIVE_PATTERNS_FILE=./.cognitive/patterns.ts
|
|
185
|
+
|
|
186
|
+
# After each commit
|
|
187
|
+
npx tsx ./node_modules/@porast1/mcp-cognitive/dist/hooks/post-commit.js
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## CLI Tools
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
npx mcp-cognitive-sync # Sync markdown docs → knowledge base
|
|
196
|
+
npx mcp-cognitive-audit # Audit stale facts and broken citations
|
|
197
|
+
npx mcp-cognitive-verify # Verify citation file references
|
|
198
|
+
npx mcp-cognitive-stale # List stale facts that need re-verification
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Development
|
|
204
|
+
|
|
205
|
+
**Code Quality Tools:**
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# ESLint — TypeScript linting (181 warnings tracked, 0 errors)
|
|
209
|
+
pnpm lint # Check for issues
|
|
210
|
+
pnpm lint:fix # Auto-fix where possible
|
|
211
|
+
|
|
212
|
+
# Prettier — Code formatting
|
|
213
|
+
pnpm format # Format all files
|
|
214
|
+
pnpm format:check # Check formatting status
|
|
215
|
+
|
|
216
|
+
# Tests
|
|
217
|
+
pnpm test # Run all 162 tests
|
|
218
|
+
pnpm test:watch # Watch mode for development
|
|
219
|
+
|
|
220
|
+
# Build
|
|
221
|
+
pnpm build # Compile TypeScript → dist/
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Linting Rules:**
|
|
225
|
+
|
|
226
|
+
- ✅ Basic: unused vars, explicit any, non-null assertions
|
|
227
|
+
- ✅ Code style: prefer const, no var, template literals
|
|
228
|
+
- ✅ Safety: no debugger, eqeqeq
|
|
229
|
+
- ⚠️ Tests: relaxed rules (any allowed, console.log allowed)
|
|
230
|
+
|
|
231
|
+
**Configuration:**
|
|
232
|
+
|
|
233
|
+
- `eslint.config.mjs` — flat config with TypeScript parser
|
|
234
|
+
- `.prettierrc` — single quotes, 100 print width, trailing commas
|
|
235
|
+
- `.prettierignore` — excludes dist/, node_modules/, backups
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Testing
|
|
240
|
+
|
|
241
|
+
**Test Tenant Isolation:** All integration tests use dedicated test tenants to prevent production data loss.
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# First-time setup: Create test tenants in Weaviate
|
|
245
|
+
cd weaviate-dev-stack
|
|
246
|
+
./scripts/create-tenant.sh mcp-cognitive-test
|
|
247
|
+
./scripts/create-tenant.sh test-isolation-a
|
|
248
|
+
./scripts/create-tenant.sh test-isolation-b
|
|
249
|
+
|
|
250
|
+
# Run tests (uses TEST_TENANT constants, never touches production data)
|
|
251
|
+
pnpm test # 162 tests covering all 18 tools + Phase 8 features
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**Test Coverage:**
|
|
255
|
+
|
|
256
|
+
- ✅ CRUD operations: store, recall, update, archive (forget), verify
|
|
257
|
+
- ✅ Search: hybrid (BM25 + vector), filters (type, module, tags, confidence)
|
|
258
|
+
- ✅ Indexing: document sync, code artifacts, test artifacts
|
|
259
|
+
- ✅ Analysis: stats, timeline, audit, health, correlate
|
|
260
|
+
- ✅ Safety: archive/compact guards, decay tracking, citation validation
|
|
261
|
+
- ✅ Phase 8: multi-module recall, optional query, dryRun mode
|
|
262
|
+
- ✅ **Multi-tenant isolation: resetTenant, store UUID5, recall, archive** (4 tests)
|
|
263
|
+
|
|
264
|
+
**Tenant Isolation Guarantees:**
|
|
265
|
+
|
|
266
|
+
1. `resetTenant()` operates only on `this.tenantId` — other tenants remain untouched
|
|
267
|
+
2. `COGNITIVE_ALLOW_RESET` global flag protects ALL tenants unless explicitly set
|
|
268
|
+
3. Verified: reset tenant A → tenant B data survives (see [tenant-isolation.test.ts](tests/tenant-isolation.test.ts))
|
|
269
|
+
4. Verified: UUID5 deterministic IDs work correctly across isolated tenants
|
|
270
|
+
5. Verified: `recall()` queries never cross tenant boundaries
|
|
271
|
+
6. Verified: `archive()` in one tenant does not affect facts in other tenants
|
|
272
|
+
|
|
273
|
+
**Production Safety:** Test utilities in [tests/weaviate-test-utils.ts](tests/weaviate-test-utils.ts) enforce isolation via `TEST_TENANT` constant. Production tenant (e.g., `WEAVIATE_TENANT=diamondpage`) is never accessed during tests.
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Architecture
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
┌──────────────────────────────────────────────┐
|
|
281
|
+
│ MCP Protocol (stdio) │
|
|
282
|
+
├──────────────────────────────────────────────┤
|
|
283
|
+
│ server.ts — auto-registers 18 tools │
|
|
284
|
+
├──────────────────────────────────────────────┤
|
|
285
|
+
│ tools/*.tool.ts — Zod schema + execute fn │
|
|
286
|
+
├──────────────────────────────────────────────┤
|
|
287
|
+
│ ports/cognitive-store.port.ts — interface │
|
|
288
|
+
├──────────────────────────────────────────────┤
|
|
289
|
+
│ adapters/weaviate-v3.adapter.ts — impl │
|
|
290
|
+
│ (BM25 + vector + gRPC + multi-tenancy) │
|
|
291
|
+
└──────────────────────────────────────────────┘
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**Collections:**
|
|
295
|
+
|
|
296
|
+
- `CognitiveFact` — structured knowledge with confidence, citations, tags
|
|
297
|
+
- `DocumentChunk` — markdown docs split by section
|
|
298
|
+
- `CodeArtifact` — TypeScript files with AST metadata
|
|
299
|
+
- `TestArtifact` — test files with describe/it block text
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Weaviate Infrastructure
|
|
304
|
+
|
|
305
|
+
This package requires a running Weaviate instance with `text2vec-transformers` and `reranker-transformers` modules.
|
|
306
|
+
|
|
307
|
+
**Recommended:** Use [weaviate-dev-stack](https://github.com/porast1/weaviate-dev-stack) — a pre-configured Docker Compose stack:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
git clone https://github.com/porast1/weaviate-dev-stack
|
|
311
|
+
cd weaviate-dev-stack
|
|
312
|
+
docker-compose up -d
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
| Port | Service |
|
|
316
|
+
| ------- | ----------------- |
|
|
317
|
+
| `8200` | Weaviate HTTP API |
|
|
318
|
+
| `50052` | Weaviate gRPC |
|
|
319
|
+
|
|
320
|
+
Multi-tenancy is handled automatically. Each project gets its own tenant via `WEAVIATE_TENANT`.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## Project Setup Template
|
|
325
|
+
|
|
326
|
+
Recommended structure in your project:
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
your-project/
|
|
330
|
+
├── .cognitive/
|
|
331
|
+
│ ├── profiles.json # Agent profiles (from config/profiles.json)
|
|
332
|
+
│ ├── patterns.ts # Pattern definitions (optional, see examples/)
|
|
333
|
+
│ └── pending-facts.json # Auto-detected facts by post-commit hook (git-ignored)
|
|
334
|
+
├── .vscode/
|
|
335
|
+
│ └── mcp.json # MCP server config (from config/mcp.jsonc)
|
|
336
|
+
├── .env # Environment variables (from config/.env.example)
|
|
337
|
+
└── .gitignore # Add: .cognitive/pending-facts.json, .cognitive/facts.sqlite
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
See [`examples/`](examples/) for pattern & profile templates with detailed documentation.
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## License
|
|
345
|
+
|
|
346
|
+
MIT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# ─── MCP Cognitive Environment Variables ─────────────────────────────────────
|
|
2
|
+
# Copy this file to your project root as .env and adjust values.
|
|
3
|
+
# All variables are optional — defaults shown in comments.
|
|
4
|
+
|
|
5
|
+
# ─── Weaviate Connection ─────────────────────────────────────────────────────
|
|
6
|
+
WEAVIATE_URL=localhost:8200 # Weaviate HTTP endpoint
|
|
7
|
+
WEAVIATE_TENANT=myproject # Tenant name for data isolation (strongly recommended)
|
|
8
|
+
# WEAVIATE_GRPC_PORT=50052 # gRPC port override (default: auto-detected from WEAVIATE_URL)
|
|
9
|
+
|
|
10
|
+
# ─── Workspace ───────────────────────────────────────────────────────────────
|
|
11
|
+
# WORKSPACE_ROOT=/path/to/your/project # Project root for resolving citation paths (default: cwd)
|
|
12
|
+
# COGNITIVE_PROJECT=MyProject # Project identifier for multi-project tagging (default: "default")
|
|
13
|
+
|
|
14
|
+
# ─── Agent Configuration ─────────────────────────────────────────────────────
|
|
15
|
+
# COGNITIVE_PROFILES_FILE=./.cognitive/profiles.json # Agent profiles JSON for recall tuning
|
|
16
|
+
# COGNITIVE_PATTERNS_FILE=./.cognitive/patterns.ts # Pattern definitions for post-commit hook
|
|
17
|
+
|
|
18
|
+
# ─── Safety Guards ───────────────────────────────────────────────────────────
|
|
19
|
+
# COGNITIVE_MAX_ARCHIVES=20 # Max archive operations per session (default: 20)
|
|
20
|
+
# COGNITIVE_MAX_COMPACTS=10 # Max compact operations per session (default: 10)
|
|
21
|
+
# COGNITIVE_ALLOW_RESET=false # Enable resetTenant() — TEST ENVIRONMENTS ONLY (default: false)
|
package/config/mcp.jsonc
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
// MCP Cognitive Server — VS Code / Copilot configuration
|
|
3
|
+
//
|
|
4
|
+
// Copy this file to your project's .vscode/mcp.json (merge with existing if needed).
|
|
5
|
+
//
|
|
6
|
+
// Prerequisite: Weaviate must be running.
|
|
7
|
+
// git clone https://github.com/porast1/weaviate-dev-stack && cd weaviate-dev-stack && docker-compose up -d
|
|
8
|
+
//
|
|
9
|
+
// Full docs: https://github.com/porast1/mcp-cognitive#readme
|
|
10
|
+
// All env vars: see config/.env.example
|
|
11
|
+
|
|
12
|
+
"servers": {
|
|
13
|
+
"cognitive": {
|
|
14
|
+
"type": "stdio",
|
|
15
|
+
"command": "node",
|
|
16
|
+
"args": ["./node_modules/@porast1/mcp-cognitive/dist/server.js"],
|
|
17
|
+
"env": {
|
|
18
|
+
// ─── Required ──────────────────────────────────────────────
|
|
19
|
+
"WEAVIATE_URL": "localhost:8200",
|
|
20
|
+
"WEAVIATE_TENANT": "myproject",
|
|
21
|
+
|
|
22
|
+
// ─── Recommended ───────────────────────────────────────────
|
|
23
|
+
"WORKSPACE_ROOT": "${workspaceFolder}",
|
|
24
|
+
"COGNITIVE_PROFILES_FILE": "./.cognitive/profiles.json"
|
|
25
|
+
|
|
26
|
+
// ─── Optional (uncomment as needed) ────────────────────────
|
|
27
|
+
// "COGNITIVE_PROJECT": "MyProject",
|
|
28
|
+
// "WEAVIATE_GRPC_PORT": "50052",
|
|
29
|
+
// "COGNITIVE_PATTERNS_FILE": "./.cognitive/patterns.ts"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|