@danielblomma/cortex-mcp 0.4.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.
Files changed (41) hide show
  1. package/README.md +203 -0
  2. package/bin/cortex.mjs +621 -0
  3. package/docs/MCP_MARKETPLACE.md +160 -0
  4. package/package.json +42 -0
  5. package/scaffold/.context/config.yaml +21 -0
  6. package/scaffold/.context/ontology.cypher +63 -0
  7. package/scaffold/.context/rules.yaml +25 -0
  8. package/scaffold/.githooks/_cortex-update-runner.sh +58 -0
  9. package/scaffold/.githooks/post-checkout +22 -0
  10. package/scaffold/.githooks/post-merge +14 -0
  11. package/scaffold/docs/architecture.md +22 -0
  12. package/scaffold/mcp/package-lock.json +2623 -0
  13. package/scaffold/mcp/package.json +29 -0
  14. package/scaffold/mcp/src/embed.ts +416 -0
  15. package/scaffold/mcp/src/embeddings.ts +192 -0
  16. package/scaffold/mcp/src/graph.ts +666 -0
  17. package/scaffold/mcp/src/loadGraph.ts +597 -0
  18. package/scaffold/mcp/src/paths.ts +33 -0
  19. package/scaffold/mcp/src/search.ts +412 -0
  20. package/scaffold/mcp/src/server.ts +98 -0
  21. package/scaffold/mcp/src/types.ts +109 -0
  22. package/scaffold/mcp/tests/server.test.mjs +60 -0
  23. package/scaffold/mcp/tsconfig.json +13 -0
  24. package/scaffold/scripts/bootstrap.sh +57 -0
  25. package/scaffold/scripts/capture-note.sh +55 -0
  26. package/scaffold/scripts/context.sh +109 -0
  27. package/scaffold/scripts/embed.sh +15 -0
  28. package/scaffold/scripts/ingest.mjs +1118 -0
  29. package/scaffold/scripts/ingest.sh +20 -0
  30. package/scaffold/scripts/install-git-hooks.sh +21 -0
  31. package/scaffold/scripts/load-kuzu.sh +6 -0
  32. package/scaffold/scripts/load-ryu.sh +18 -0
  33. package/scaffold/scripts/parsers/javascript.mjs +390 -0
  34. package/scaffold/scripts/parsers/package-lock.json +51 -0
  35. package/scaffold/scripts/parsers/package.json +17 -0
  36. package/scaffold/scripts/plan-state-engine.cjs +310 -0
  37. package/scaffold/scripts/plan-state.sh +71 -0
  38. package/scaffold/scripts/refresh.sh +9 -0
  39. package/scaffold/scripts/status.sh +282 -0
  40. package/scaffold/scripts/update-context.sh +18 -0
  41. package/scaffold/scripts/watch.sh +374 -0
@@ -0,0 +1,160 @@
1
+ # MCP Marketplace Submission
2
+
3
+ ## Package Information
4
+
5
+ **Name:** `@danielblomma/cortex-mcp`
6
+ **Description:** Local, repo-scoped context platform for coding assistants. Semantic search, graph relationships, and architectural rule context.
7
+ **Author:** Daniel Blomma
8
+ **License:** MIT
9
+ **Repository:** https://github.com/DanielBlomma/cortex
10
+
11
+ ## MCP Server Details
12
+
13
+ ### Tools Provided
14
+
15
+ 1. **context.search**
16
+ - Semantic search across indexed entities (files, rules, ADRs)
17
+ - Hybrid ranking (semantic + graph + trust + recency)
18
+ - Optional content return for high-signal snippets
19
+
20
+ 2. **context.get_related**
21
+ - Graph-based entity relationships
22
+ - Finds connected rules/files/ADRs with optional edge details
23
+
24
+ 3. **context.get_rules**
25
+ - Active rules and architectural decisions
26
+ - Scope-based filtering
27
+
28
+ 4. **context.reload**
29
+ - Hot-reload graph after code changes
30
+
31
+ ### Advanced Features (Experimental)
32
+
33
+ Cortex can extract function-level chunks and build call graphs in experimental builds:
34
+
35
+ - `context.find_callers` - What calls this function?
36
+ - `context.trace_calls` - What does this function call?
37
+ - `context.impact_analysis` - What is impacted if this function changes?
38
+ - Requires JavaScript/TypeScript codebase and semantic chunking/call graph indexing enabled.
39
+
40
+ Note: these APIs are experimental and are not part of the stable tool contract in this submission.
41
+
42
+ ### Installation
43
+
44
+ #### For MCP Marketplace Users
45
+
46
+ ```bash
47
+ # Install CLI globally
48
+ npm i -g @danielblomma/cortex-mcp
49
+
50
+ # Navigate to your project
51
+ cd ~/my-project
52
+
53
+ # Initialize Cortex in your project
54
+ cortex init --bootstrap
55
+ ```
56
+
57
+ This will:
58
+ - Create `.context/` directory with graph schema
59
+ - Set up MCP server for Claude Desktop/Code
60
+ - Start background sync for automatic updates
61
+ - Build a local context graph for indexed files/rules/ADRs
62
+
63
+ #### Manual MCP Configuration
64
+
65
+ If `cortex init` doesn't auto-register, add to Claude's MCP config:
66
+
67
+ **Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
68
+ ```json
69
+ {
70
+ "mcpServers": {
71
+ "cortex": {
72
+ "command": "cortex",
73
+ "args": ["mcp"],
74
+ "env": {
75
+ "CORTEX_PROJECT_ROOT": "/absolute/path/to/your-project"
76
+ }
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ **Codex** (`~/.config/codex/mcp-config.json`):
83
+ ```json
84
+ {
85
+ "mcpServers": {
86
+ "cortex-myproject": {
87
+ "command": "cortex",
88
+ "args": ["mcp"],
89
+ "cwd": "/absolute/path/to/your-project"
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ ### Usage
96
+
97
+ Once installed and initialized, Cortex tools are available in Claude:
98
+
99
+ ```
100
+ "Find files that handle authentication"
101
+ "Show related files for this ADR"
102
+ "What are the active architectural rules for this API?"
103
+ ```
104
+
105
+ ### Key Features
106
+
107
+ - **Semantic search**: ranked retrieval across source files, rules and ADRs
108
+ - **Graph relationships**: quickly discover related entities and constraints
109
+ - **Experimental call graph APIs**: function caller/callee and impact traversal in semantic chunking builds
110
+ - **Local & private**: All data stays on your machine
111
+ - **Incremental updates**: Background sync keeps context fresh
112
+ - **Flexible ingestion**: configurable source paths and ranking signals
113
+
114
+ ### Requirements
115
+
116
+ - Node.js 18+
117
+ - Git repository (for change tracking)
118
+ - ~50MB disk space per project
119
+
120
+ ### Unique Value Proposition
121
+
122
+ Unlike other MCP servers that provide external data (GitHub, web search), Cortex provides **deep, structured knowledge of YOUR codebase**:
123
+
124
+ - Search with semantic ranking across files, rules, and ADRs
125
+ - Understand rule and ADR dependencies in your repo
126
+ - Enforce architectural rules and ADRs
127
+ - Context that evolves with your code
128
+
129
+ Perfect for:
130
+ - Large codebases where plain keyword search is not enough
131
+ - Refactoring guided by rule and ADR context
132
+ - Onboarding (architectural rules, design decisions)
133
+ - Code review (what constraints and related entities apply?)
134
+
135
+ ### Limitations
136
+
137
+ - **Setup required**: Not instant plug-and-play (needs `cortex init`)
138
+ - **Per-project**: Each repo needs its own Cortex instance
139
+ - **Local only**: No cloud sync (by design - your code stays private)
140
+
141
+ ### Support
142
+
143
+ - Issues: https://github.com/DanielBlomma/cortex/issues
144
+ - Docs: https://github.com/DanielBlomma/cortex/blob/main/README.md
145
+
146
+ ## Submission Checklist
147
+
148
+ - [x] MCP SDK integration (JSON-RPC over stdio)
149
+ - [x] Tools documented with schemas
150
+ - [ ] npm package published (@danielblomma/cortex-mcp)
151
+ - [x] Marketplace-ready README
152
+ - [ ] Example usage screenshots/GIFs
153
+ - [ ] Submit PR to modelcontextprotocol/servers
154
+
155
+ ## Next Steps
156
+
157
+ 1. Publish to npm as `@danielblomma/cortex-mcp`
158
+ 2. Test installation from marketplace perspective
159
+ 3. Submit to https://github.com/modelcontextprotocol/servers
160
+ 4. Add to Anthropic's community registry
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@danielblomma/cortex-mcp",
3
+ "version": "0.4.0",
4
+ "description": "Local, repo-scoped context platform for coding assistants. Semantic search, graph relationships, and architectural rule context.",
5
+ "type": "module",
6
+ "author": "Daniel Blomma",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/DanielBlomma/cortex.git"
11
+ },
12
+ "homepage": "https://github.com/DanielBlomma/cortex",
13
+ "bugs": {
14
+ "url": "https://github.com/DanielBlomma/cortex/issues"
15
+ },
16
+ "keywords": [
17
+ "mcp",
18
+ "model-context-protocol",
19
+ "context",
20
+ "code-search",
21
+ "semantic-search",
22
+ "refactoring",
23
+ "claude",
24
+ "codex"
25
+ ],
26
+ "bin": {
27
+ "cortex": "bin/cortex.mjs"
28
+ },
29
+ "files": [
30
+ "bin",
31
+ "scaffold",
32
+ "README.md",
33
+ "docs/MCP_MARKETPLACE.md"
34
+ ],
35
+ "scripts": {
36
+ "test": "node tests/plan-state.test.mjs",
37
+ "prepublishOnly": "echo 'Ready to publish to npm'"
38
+ },
39
+ "engines": {
40
+ "node": ">=18"
41
+ }
42
+ }
@@ -0,0 +1,21 @@
1
+ repo_id: cortex
2
+ source_paths:
3
+ - src
4
+ - docs
5
+ - design
6
+ - .context/notes
7
+ - .context/decisions
8
+ - README.md
9
+ truth_order:
10
+ - ADR
11
+ - RULE
12
+ - CODE
13
+ - WIKI
14
+ ranking:
15
+ semantic: 0.40
16
+ graph: 0.25
17
+ trust: 0.20
18
+ recency: 0.15
19
+ runtime:
20
+ top_k: 5
21
+ include_uncertainties: true
@@ -0,0 +1,63 @@
1
+ // Core node labels for v1
2
+ CREATE NODE TABLE IF NOT EXISTS File(
3
+ id STRING,
4
+ path STRING,
5
+ kind STRING,
6
+ excerpt STRING,
7
+ checksum STRING,
8
+ updated_at STRING,
9
+ source_of_truth BOOL,
10
+ trust_level INT64,
11
+ status STRING,
12
+ PRIMARY KEY(id)
13
+ );
14
+
15
+ CREATE NODE TABLE IF NOT EXISTS Rule(
16
+ id STRING,
17
+ title STRING,
18
+ body STRING,
19
+ scope STRING,
20
+ priority INT64,
21
+ updated_at STRING,
22
+ source_of_truth BOOL,
23
+ trust_level INT64,
24
+ status STRING,
25
+ PRIMARY KEY(id)
26
+ );
27
+
28
+ CREATE NODE TABLE IF NOT EXISTS ADR(
29
+ id STRING,
30
+ path STRING,
31
+ title STRING,
32
+ body STRING,
33
+ decision_date STRING,
34
+ supersedes_id STRING,
35
+ source_of_truth BOOL,
36
+ trust_level INT64,
37
+ status STRING,
38
+ PRIMARY KEY(id)
39
+ );
40
+
41
+ CREATE NODE TABLE IF NOT EXISTS Chunk(
42
+ id STRING,
43
+ file_id STRING,
44
+ name STRING,
45
+ kind STRING,
46
+ signature STRING,
47
+ body STRING,
48
+ start_line INT64,
49
+ end_line INT64,
50
+ language STRING,
51
+ checksum STRING,
52
+ updated_at STRING,
53
+ trust_level INT64,
54
+ PRIMARY KEY(id)
55
+ );
56
+
57
+ // Core relation tables for v1
58
+ CREATE REL TABLE IF NOT EXISTS IMPLEMENTS(FROM File TO Rule, note STRING);
59
+ CREATE REL TABLE IF NOT EXISTS CONSTRAINS(FROM Rule TO File, note STRING);
60
+ CREATE REL TABLE IF NOT EXISTS SUPERSEDES(FROM ADR TO ADR, reason STRING);
61
+ CREATE REL TABLE IF NOT EXISTS DEFINES(FROM File TO Chunk);
62
+ CREATE REL TABLE IF NOT EXISTS CALLS(FROM Chunk TO Chunk, call_type STRING);
63
+ CREATE REL TABLE IF NOT EXISTS IMPORTS(FROM Chunk TO File, import_name STRING);
@@ -0,0 +1,25 @@
1
+ rules:
2
+ - id: rule.source_of_truth
3
+ description: "Source-of-truth entities must be prioritized in retrieval and final context."
4
+ priority: 100
5
+ enforce: true
6
+
7
+ - id: rule.deprecated_filter
8
+ description: "Deprecated entities must be excluded unless explicitly requested."
9
+ priority: 95
10
+ enforce: true
11
+
12
+ - id: rule.adr_recency
13
+ description: "Newer ADR supersedes older ADR when both address the same decision."
14
+ priority: 90
15
+ enforce: true
16
+
17
+ - id: rule.conflict_flag
18
+ description: "If two active sources conflict, return both and flag a conflict instead of guessing."
19
+ priority: 90
20
+ enforce: true
21
+
22
+ - id: rule.context_budget
23
+ description: "Limit runtime context to highest-signal evidence blocks (top_k)."
24
+ priority: 80
25
+ enforce: true
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
5
+ if [[ -z "$REPO_ROOT" ]]; then
6
+ exit 0
7
+ fi
8
+
9
+ CONTEXT_SCRIPT="$REPO_ROOT/scripts/context.sh"
10
+ if [[ ! -x "$CONTEXT_SCRIPT" ]]; then
11
+ exit 0
12
+ fi
13
+
14
+ PARSER_MODULES_DIR="$REPO_ROOT/scripts/parsers/node_modules"
15
+
16
+ HOOK_DIR="$REPO_ROOT/.context/hooks"
17
+ LOCK_DIR="$HOOK_DIR/update.lock"
18
+ LAST_RUN_FILE="$HOOK_DIR/last-update.epoch"
19
+ LOG_FILE="$HOOK_DIR/update.log"
20
+ MIN_INTERVAL_SEC="${CORTEX_HOOK_MIN_INTERVAL:-8}"
21
+
22
+ mkdir -p "$HOOK_DIR"
23
+
24
+ if [[ ! -d "$PARSER_MODULES_DIR" ]]; then
25
+ printf "[hook] %s skip update (missing %s, run cortex bootstrap)\n" \
26
+ "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
27
+ "$PARSER_MODULES_DIR" >> "$LOG_FILE" 2>&1
28
+ exit 0
29
+ fi
30
+
31
+ if ! mkdir "$LOCK_DIR" 2>/dev/null; then
32
+ # Another hook-triggered update is already running.
33
+ exit 0
34
+ fi
35
+
36
+ cleanup() {
37
+ rmdir "$LOCK_DIR" >/dev/null 2>&1 || true
38
+ }
39
+ trap cleanup EXIT
40
+
41
+ now_epoch="$(date +%s)"
42
+ if [[ -f "$LAST_RUN_FILE" ]]; then
43
+ last_epoch="$(cat "$LAST_RUN_FILE" 2>/dev/null || echo 0)"
44
+ if [[ "$last_epoch" =~ ^[0-9]+$ ]] && (( now_epoch - last_epoch < MIN_INTERVAL_SEC )); then
45
+ exit 0
46
+ fi
47
+ fi
48
+
49
+ echo "$now_epoch" > "$LAST_RUN_FILE"
50
+
51
+ {
52
+ printf "[hook] %s start context update\n" "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
53
+ if bash "$CONTEXT_SCRIPT" update; then
54
+ printf "[hook] %s update ok\n" "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
55
+ else
56
+ printf "[hook] %s update failed\n" "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
57
+ fi
58
+ } >> "$LOG_FILE" 2>&1
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Args:
5
+ # 1: previous HEAD
6
+ # 2: new HEAD
7
+ # 3: 1 if branch checkout, 0 if file checkout
8
+ if [[ "${3:-0}" != "1" ]]; then
9
+ exit 0
10
+ fi
11
+
12
+ REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
13
+ if [[ -z "$REPO_ROOT" ]]; then
14
+ exit 0
15
+ fi
16
+
17
+ RUNNER="$REPO_ROOT/.githooks/_cortex-update-runner.sh"
18
+ if [[ ! -x "$RUNNER" ]]; then
19
+ exit 0
20
+ fi
21
+
22
+ nohup bash "$RUNNER" >/dev/null 2>&1 &
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
5
+ if [[ -z "$REPO_ROOT" ]]; then
6
+ exit 0
7
+ fi
8
+
9
+ RUNNER="$REPO_ROOT/.githooks/_cortex-update-runner.sh"
10
+ if [[ ! -x "$RUNNER" ]]; then
11
+ exit 0
12
+ fi
13
+
14
+ nohup bash "$RUNNER" >/dev/null 2>&1 &
@@ -0,0 +1,22 @@
1
+ # Cortex v1 Architecture
2
+
3
+ ## Goal
4
+ Provide high-signal, repo-local context to coding agents without bloating instruction files.
5
+
6
+ ## Pipeline
7
+ 1. Ingestion: source files -> entities + relations
8
+ 2. Storage: graph (RyuGraph) + optional vector index
9
+ 3. Retrieval: semantic + graph
10
+ 4. Policy: rules filter conflicts/deprecated/source-of-truth
11
+ 5. Assembly: runtime context package for MCP tool responses
12
+
13
+ ## Runtime Context Order
14
+ 1. Task
15
+ 2. Hard rules
16
+ 3. Evidence blocks (top_k)
17
+ 4. Uncertainties
18
+
19
+ ## Guardrails
20
+ - Source-of-truth must be preferred
21
+ - Deprecated content excluded by default
22
+ - Conflicts are flagged, not guessed