neuralbrain 0.0.0-stage → 0.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/.dockerignore +11 -0
- package/.env.example +245 -0
- package/Dockerfile +65 -0
- package/LICENSE +44 -0
- package/README.md +312 -2
- package/dist/ai/chat.d.ts +45 -0
- package/dist/ai/chat.d.ts.map +1 -0
- package/dist/ai/chat.js +153 -0
- package/dist/ai/chat.js.map +1 -0
- package/dist/ai/circuitBreaker.d.ts +35 -0
- package/dist/ai/circuitBreaker.d.ts.map +1 -0
- package/dist/ai/circuitBreaker.js +95 -0
- package/dist/ai/circuitBreaker.js.map +1 -0
- package/dist/ai/config.d.ts +88 -0
- package/dist/ai/config.d.ts.map +1 -0
- package/dist/ai/config.js +255 -0
- package/dist/ai/config.js.map +1 -0
- package/dist/ai/vendors.d.ts +58 -0
- package/dist/ai/vendors.d.ts.map +1 -0
- package/dist/ai/vendors.js +223 -0
- package/dist/ai/vendors.js.map +1 -0
- package/dist/app.d.ts +4 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +1013 -0
- package/dist/app.js.map +1 -0
- package/dist/cli.d.ts +133 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +912 -0
- package/dist/cli.js.map +1 -0
- package/dist/consolidation/candidates.d.ts +34 -0
- package/dist/consolidation/candidates.d.ts.map +1 -0
- package/dist/consolidation/candidates.js +150 -0
- package/dist/consolidation/candidates.js.map +1 -0
- package/dist/consolidation/fixtures.d.ts +25 -0
- package/dist/consolidation/fixtures.d.ts.map +1 -0
- package/dist/consolidation/fixtures.js +400 -0
- package/dist/consolidation/fixtures.js.map +1 -0
- package/dist/consolidation/gate.d.ts +39 -0
- package/dist/consolidation/gate.d.ts.map +1 -0
- package/dist/consolidation/gate.js +286 -0
- package/dist/consolidation/gate.js.map +1 -0
- package/dist/consolidation/runner.d.ts +63 -0
- package/dist/consolidation/runner.d.ts.map +1 -0
- package/dist/consolidation/runner.js +171 -0
- package/dist/consolidation/runner.js.map +1 -0
- package/dist/dashboard/clientScript.d.ts +2 -0
- package/dist/dashboard/clientScript.d.ts.map +1 -0
- package/dist/dashboard/clientScript.js +4212 -0
- package/dist/dashboard/clientScript.js.map +1 -0
- package/dist/dashboard/html.d.ts +2 -0
- package/dist/dashboard/html.d.ts.map +1 -0
- package/dist/dashboard/html.js +554 -0
- package/dist/dashboard/html.js.map +1 -0
- package/dist/dashboard/styles.d.ts +2 -0
- package/dist/dashboard/styles.d.ts.map +1 -0
- package/dist/dashboard/styles.js +1283 -0
- package/dist/dashboard/styles.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -0
- package/dist/learning/embedWorker.d.ts +58 -0
- package/dist/learning/embedWorker.d.ts.map +1 -0
- package/dist/learning/embedWorker.js +552 -0
- package/dist/learning/embedWorker.js.map +1 -0
- package/dist/learning/embedding.d.ts +52 -0
- package/dist/learning/embedding.d.ts.map +1 -0
- package/dist/learning/embedding.js +511 -0
- package/dist/learning/embedding.js.map +1 -0
- package/dist/learning/engine.d.ts +20 -0
- package/dist/learning/engine.d.ts.map +1 -0
- package/dist/learning/engine.js +69 -0
- package/dist/learning/engine.js.map +1 -0
- package/dist/learning/search.d.ts +4 -0
- package/dist/learning/search.d.ts.map +1 -0
- package/dist/learning/search.js +509 -0
- package/dist/learning/search.js.map +1 -0
- package/dist/learning/storeMeta.d.ts +11 -0
- package/dist/learning/storeMeta.d.ts.map +1 -0
- package/dist/learning/storeMeta.js +100 -0
- package/dist/learning/storeMeta.js.map +1 -0
- package/dist/learning/types.d.ts +101 -0
- package/dist/learning/types.d.ts.map +1 -0
- package/dist/learning/types.js +3 -0
- package/dist/learning/types.js.map +1 -0
- package/dist/lib/brainHome.d.ts +28 -0
- package/dist/lib/brainHome.d.ts.map +1 -0
- package/dist/lib/brainHome.js +104 -0
- package/dist/lib/brainHome.js.map +1 -0
- package/dist/lib/db.d.ts +10 -0
- package/dist/lib/db.d.ts.map +1 -0
- package/dist/lib/db.js +589 -0
- package/dist/lib/db.js.map +1 -0
- package/dist/lib/logger.d.ts +3 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +11 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/projectSlug.d.ts +61 -0
- package/dist/lib/projectSlug.d.ts.map +1 -0
- package/dist/lib/projectSlug.js +273 -0
- package/dist/lib/projectSlug.js.map +1 -0
- package/dist/lib/redactSecrets.d.ts +7 -0
- package/dist/lib/redactSecrets.d.ts.map +1 -0
- package/dist/lib/redactSecrets.js +90 -0
- package/dist/lib/redactSecrets.js.map +1 -0
- package/dist/lib/scope.d.ts +54 -0
- package/dist/lib/scope.d.ts.map +1 -0
- package/dist/lib/scope.js +103 -0
- package/dist/lib/scope.js.map +1 -0
- package/dist/lib/spool.d.ts +23 -0
- package/dist/lib/spool.d.ts.map +1 -0
- package/dist/lib/spool.js +317 -0
- package/dist/lib/spool.js.map +1 -0
- package/dist/lib/sqlite.d.ts +50 -0
- package/dist/lib/sqlite.d.ts.map +1 -0
- package/dist/lib/sqlite.js +130 -0
- package/dist/lib/sqlite.js.map +1 -0
- package/dist/lib/tls.d.ts +34 -0
- package/dist/lib/tls.d.ts.map +1 -0
- package/dist/lib/tls.js +212 -0
- package/dist/lib/tls.js.map +1 -0
- package/dist/mcp/server.d.ts +231 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +615 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/memory/actionStore.d.ts +75 -0
- package/dist/memory/actionStore.d.ts.map +1 -0
- package/dist/memory/actionStore.js +239 -0
- package/dist/memory/actionStore.js.map +1 -0
- package/dist/memory/deadLetterStore.d.ts +30 -0
- package/dist/memory/deadLetterStore.d.ts.map +1 -0
- package/dist/memory/deadLetterStore.js +91 -0
- package/dist/memory/deadLetterStore.js.map +1 -0
- package/dist/memory/embedQueueStore.d.ts +32 -0
- package/dist/memory/embedQueueStore.d.ts.map +1 -0
- package/dist/memory/embedQueueStore.js +143 -0
- package/dist/memory/embedQueueStore.js.map +1 -0
- package/dist/memory/failurePatternStore.d.ts +37 -0
- package/dist/memory/failurePatternStore.d.ts.map +1 -0
- package/dist/memory/failurePatternStore.js +179 -0
- package/dist/memory/failurePatternStore.js.map +1 -0
- package/dist/memory/graphStore.d.ts +38 -0
- package/dist/memory/graphStore.d.ts.map +1 -0
- package/dist/memory/graphStore.js +229 -0
- package/dist/memory/graphStore.js.map +1 -0
- package/dist/memory/noteStore.d.ts +58 -0
- package/dist/memory/noteStore.d.ts.map +1 -0
- package/dist/memory/noteStore.js +280 -0
- package/dist/memory/noteStore.js.map +1 -0
- package/dist/memory/observationStore.d.ts +40 -0
- package/dist/memory/observationStore.d.ts.map +1 -0
- package/dist/memory/observationStore.js +213 -0
- package/dist/memory/observationStore.js.map +1 -0
- package/dist/memory/projectRename.d.ts +14 -0
- package/dist/memory/projectRename.d.ts.map +1 -0
- package/dist/memory/projectRename.js +105 -0
- package/dist/memory/projectRename.js.map +1 -0
- package/dist/memory/rollupSweeper.d.ts +36 -0
- package/dist/memory/rollupSweeper.d.ts.map +1 -0
- package/dist/memory/rollupSweeper.js +235 -0
- package/dist/memory/rollupSweeper.js.map +1 -0
- package/dist/memory/sessionStore.d.ts +81 -0
- package/dist/memory/sessionStore.d.ts.map +1 -0
- package/dist/memory/sessionStore.js +285 -0
- package/dist/memory/sessionStore.js.map +1 -0
- package/dist/memory/trajectoryStore.d.ts +86 -0
- package/dist/memory/trajectoryStore.d.ts.map +1 -0
- package/dist/memory/trajectoryStore.js +528 -0
- package/dist/memory/trajectoryStore.js.map +1 -0
- package/dist/middleware/auth.d.ts +30 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +387 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/rateLimiter.d.ts +13 -0
- package/dist/middleware/rateLimiter.d.ts.map +1 -0
- package/dist/middleware/rateLimiter.js +153 -0
- package/dist/middleware/rateLimiter.js.map +1 -0
- package/dist/middleware/tracing.d.ts +15 -0
- package/dist/middleware/tracing.d.ts.map +1 -0
- package/dist/middleware/tracing.js +53 -0
- package/dist/middleware/tracing.js.map +1 -0
- package/dist/routes/dashboard.d.ts +2 -0
- package/dist/routes/dashboard.d.ts.map +1 -0
- package/dist/routes/dashboard.js +443 -0
- package/dist/routes/dashboard.js.map +1 -0
- package/dist/routes/learning.d.ts +2 -0
- package/dist/routes/learning.d.ts.map +1 -0
- package/dist/routes/learning.js +46 -0
- package/dist/routes/learning.js.map +1 -0
- package/dist/routes/mcp.d.ts +8 -0
- package/dist/routes/mcp.d.ts.map +1 -0
- package/dist/routes/mcp.js +316 -0
- package/dist/routes/mcp.js.map +1 -0
- package/dist/routes/memories.d.ts +2 -0
- package/dist/routes/memories.d.ts.map +1 -0
- package/dist/routes/memories.js +33 -0
- package/dist/routes/memories.js.map +1 -0
- package/dist/scripts/createApiKey.d.ts +2 -0
- package/dist/scripts/createApiKey.d.ts.map +1 -0
- package/dist/scripts/createApiKey.js +78 -0
- package/dist/scripts/createApiKey.js.map +1 -0
- package/dist/scripts/doctor.d.ts +24 -0
- package/dist/scripts/doctor.d.ts.map +1 -0
- package/dist/scripts/doctor.js +332 -0
- package/dist/scripts/doctor.js.map +1 -0
- package/dist/scripts/installAgent.d.ts +80 -0
- package/dist/scripts/installAgent.d.ts.map +1 -0
- package/dist/scripts/installAgent.js +1046 -0
- package/dist/scripts/installAgent.js.map +1 -0
- package/dist/scripts/migrateAgentMemory.d.ts +16 -0
- package/dist/scripts/migrateAgentMemory.d.ts.map +1 -0
- package/dist/scripts/migrateAgentMemory.js +209 -0
- package/dist/scripts/migrateAgentMemory.js.map +1 -0
- package/dist/scripts/smokeTest.d.ts +16 -0
- package/dist/scripts/smokeTest.d.ts.map +1 -0
- package/dist/scripts/smokeTest.js +150 -0
- package/dist/scripts/smokeTest.js.map +1 -0
- package/docker-compose.qdrant-port.yml +7 -0
- package/docker-compose.yml +107 -0
- package/npm-shrinkwrap.json +7635 -0
- package/package.json +107 -4
- package/plugin/hooks/postToolUse.js +513 -0
- package/plugin/hooks/sessionStart.js +416 -0
- package/plugin/hooks/sessionStop.js +346 -0
- package/plugin/hooks.json +30 -0
- package/plugin/mcp_config.json +13 -0
- package/plugin/plugin.json +15 -0
- package/plugin/rules/AGENTS.md +66 -0
- package/plugin/skills/brain-memory/REFERENCE.md +64 -0
- package/plugin/skills/brain-memory/SKILL.md +68 -0
- package/plugin/skills/brain-memory/TROUBLESHOOTING.md +24 -0
- package/plugin/skills/digest/SKILL.md +54 -0
- package/plugin/skills/digest/TROUBLESHOOTING.md +24 -0
- package/plugin/skills/handoff/SKILL.md +59 -0
- package/plugin/skills/handoff/TROUBLESHOOTING.md +24 -0
- package/plugin/skills/save/SKILL.md +76 -0
- package/plugin/skills/save/TROUBLESHOOTING.md +24 -0
- package/plugin/skills/search/SKILL.md +60 -0
- package/plugin/skills/search/TROUBLESHOOTING.md +24 -0
- package/src/ai/chat.ts +214 -0
- package/src/ai/circuitBreaker.ts +120 -0
- package/src/ai/config.ts +311 -0
- package/src/ai/vendors.ts +292 -0
- package/src/app.ts +1150 -0
- package/src/cli.ts +1080 -0
- package/src/consolidation/candidates.ts +219 -0
- package/src/consolidation/fixtures.ts +461 -0
- package/src/consolidation/gate.ts +408 -0
- package/src/consolidation/runner.ts +220 -0
- package/src/dashboard/clientScript.ts +4208 -0
- package/src/dashboard/html.ts +550 -0
- package/src/dashboard/styles.ts +1279 -0
- package/src/index.ts +139 -0
- package/src/learning/embedWorker.ts +651 -0
- package/src/learning/embedding.ts +522 -0
- package/src/learning/engine.ts +86 -0
- package/src/learning/search.ts +568 -0
- package/src/learning/storeMeta.ts +147 -0
- package/src/learning/types.ts +111 -0
- package/src/lib/brainHome.ts +101 -0
- package/src/lib/db.ts +627 -0
- package/src/lib/logger.ts +7 -0
- package/src/lib/projectSlug.ts +286 -0
- package/src/lib/redactSecrets.ts +87 -0
- package/src/lib/scope.ts +121 -0
- package/src/lib/spool.ts +372 -0
- package/src/lib/sqlite.ts +158 -0
- package/src/lib/tls.ts +252 -0
- package/src/mcp/server.ts +793 -0
- package/src/memory/actionStore.ts +378 -0
- package/src/memory/deadLetterStore.ts +141 -0
- package/src/memory/embedQueueStore.ts +176 -0
- package/src/memory/failurePatternStore.ts +221 -0
- package/src/memory/graphStore.ts +352 -0
- package/src/memory/noteStore.ts +403 -0
- package/src/memory/observationStore.ts +303 -0
- package/src/memory/projectRename.ts +147 -0
- package/src/memory/rollupSweeper.ts +309 -0
- package/src/memory/sessionStore.ts +410 -0
- package/src/memory/trajectoryStore.ts +775 -0
- package/src/middleware/auth.ts +450 -0
- package/src/middleware/rateLimiter.ts +186 -0
- package/src/middleware/tracing.ts +70 -0
- package/src/routes/dashboard.ts +496 -0
- package/src/routes/learning.ts +51 -0
- package/src/routes/mcp.ts +349 -0
- package/src/routes/memories.ts +33 -0
- package/src/scripts/createApiKey.ts +109 -0
- package/src/scripts/doctor.ts +359 -0
- package/src/scripts/installAgent.ts +1278 -0
- package/src/scripts/migrateAgentMemory.ts +263 -0
- package/src/scripts/smokeTest.ts +189 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP_INSTRUCTIONS = void 0;
|
|
4
|
+
exports.createBrainMcpHandlers = createBrainMcpHandlers;
|
|
5
|
+
exports.createBrainMcpServer = createBrainMcpServer;
|
|
6
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
7
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const brainHome_1 = require("../lib/brainHome");
|
|
10
|
+
const projectSlug_1 = require("../lib/projectSlug");
|
|
11
|
+
const tls_1 = require("../lib/tls");
|
|
12
|
+
exports.MCP_INSTRUCTIONS = [
|
|
13
|
+
'call brain_search before starting non-trivial work, not after failing',
|
|
14
|
+
'include record_types: ["summary"] (or ["note", "trajectory", "summary"]) in brain_search when resuming prior work on a file, debugging a recurring error, or when no curated notes exist yet',
|
|
15
|
+
'check ready next actions (via /inject or brain_action_list) at task start before picking up work',
|
|
16
|
+
'/inject content arrives unasked at task start; do not re-query for it',
|
|
17
|
+
'use brain_sessions to inspect prior agent sessions or replay a session timeline when resuming work',
|
|
18
|
+
'use brain_graph to explore relationships across notes, lessons, concepts, files, sessions, actions, and summaries',
|
|
19
|
+
'save a note when a correction or a non-obvious decision happens, not at session end when the detail is gone',
|
|
20
|
+
'save a note via brain_save immediately when you fix a non-trivial bug, hit an unexpected gotcha, make an architectural decision, or receive a user correction',
|
|
21
|
+
'before finishing any non-trivial task, verify whether any durable insight should be saved with brain_save',
|
|
22
|
+
'if /inject includes a CONSOLIDATION REMINDER, let the user know and suggest they start a new session with an example prompt (e.g., "Consolidate the brain observations for this project.")',
|
|
23
|
+
'when consolidating observations, redact any API keys, tokens, passwords, or other sensitive info before submitting via brain_submit_summary',
|
|
24
|
+
'surface unfinished work or blockers via brain_action_add so the next session can resume cleanly',
|
|
25
|
+
'call brain_session_end at session completion or pause to record a clean cross-agent handoff summary',
|
|
26
|
+
'pass scope: "unknown" rather than guessing',
|
|
27
|
+
'for project scope, project_id is the project root folder name (the folder holding .brainrc, else the git repo root — the main repo for a worktree — else the folder the session started in), lowercase, e.g. "neuralbrain"; never a subfolder you are working in and never a filesystem path, so all agents come up with the same id',
|
|
28
|
+
].join('\n');
|
|
29
|
+
function createBrainMcpHandlers(options = {}) {
|
|
30
|
+
const apiBaseUrl = (options.apiBaseUrl ||
|
|
31
|
+
process.env.BRAIN_API_URL ||
|
|
32
|
+
process.env.BRAIN_ENDPOINT ||
|
|
33
|
+
`http://127.0.0.1:${process.env.PORT || 3737}`).replace(/\/$/, '');
|
|
34
|
+
const apiKey = options.apiKey ?? process.env.BRAIN_API_KEY;
|
|
35
|
+
const fetchFn = options.fetchFn || (0, tls_1.createLocalTlsFetch)();
|
|
36
|
+
const defaultProjectId = options.defaultProjectId ??
|
|
37
|
+
(0, projectSlug_1.resolveCanonicalProjectId)({ fallbackToDirname: false }) ??
|
|
38
|
+
undefined;
|
|
39
|
+
const authHeaders = {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
};
|
|
42
|
+
if (apiKey) {
|
|
43
|
+
authHeaders['Authorization'] = `Bearer ${apiKey}`;
|
|
44
|
+
}
|
|
45
|
+
const brainSearch = async (args) => {
|
|
46
|
+
const targetProjectId = args.project_id || defaultProjectId;
|
|
47
|
+
const requestedTypes = args.record_types && args.record_types.length > 0 ? args.record_types : args.grains;
|
|
48
|
+
const body = {
|
|
49
|
+
q: args.q,
|
|
50
|
+
record_types: requestedTypes && requestedTypes.length > 0 ? requestedTypes : ['note', 'trajectory'],
|
|
51
|
+
include_global: args.include_global !== false,
|
|
52
|
+
limit: args.limit ?? 10,
|
|
53
|
+
};
|
|
54
|
+
if (targetProjectId) {
|
|
55
|
+
body.project_id = targetProjectId;
|
|
56
|
+
body.scope = 'project';
|
|
57
|
+
}
|
|
58
|
+
const filters = {};
|
|
59
|
+
if (args.type && args.type.length > 0) {
|
|
60
|
+
filters.type = args.type;
|
|
61
|
+
}
|
|
62
|
+
if (args.file_path) {
|
|
63
|
+
filters.file_path = args.file_path;
|
|
64
|
+
}
|
|
65
|
+
if (Object.keys(filters).length > 0) {
|
|
66
|
+
body.filters = filters;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const res = await fetchFn(`${apiBaseUrl}/search`, {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: authHeaders,
|
|
72
|
+
body: JSON.stringify(body),
|
|
73
|
+
signal: AbortSignal.timeout(10_000),
|
|
74
|
+
});
|
|
75
|
+
const data = await res.json().catch(() => ({}));
|
|
76
|
+
if (!res.ok) {
|
|
77
|
+
return {
|
|
78
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
79
|
+
isError: true,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
return {
|
|
88
|
+
content: [{ type: 'text', text: `MCP Transport Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
89
|
+
isError: true,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const brainSave = async (args) => {
|
|
94
|
+
if (!args.scope || (args.scope !== 'project' && args.scope !== 'global' && args.scope !== 'unknown')) {
|
|
95
|
+
const err = new Error("SCOPE_REQUIRED: Scope is required and must be 'project', 'global', or 'unknown'");
|
|
96
|
+
err.code = 'SCOPE_REQUIRED';
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
const effectiveProjectId = args.project_id || (args.scope === 'project' ? defaultProjectId : undefined);
|
|
100
|
+
if (args.scope === 'project' && !effectiveProjectId) {
|
|
101
|
+
const err = new Error("SCHEMA_INVALID: project_id is required when scope is 'project' (use the project root folder name, e.g. 'neuralbrain' — from .brainrc or the git repo root, not a subfolder or filesystem path)");
|
|
102
|
+
err.code = 'SCHEMA_INVALID';
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
const payload = {
|
|
106
|
+
type: args.type,
|
|
107
|
+
title: args.title,
|
|
108
|
+
content: args.content,
|
|
109
|
+
scope: args.scope,
|
|
110
|
+
project_id: effectiveProjectId || null,
|
|
111
|
+
projectId: effectiveProjectId || null,
|
|
112
|
+
concepts: args.concepts || [],
|
|
113
|
+
files: args.files || [],
|
|
114
|
+
supersedes: args.supersedes || null,
|
|
115
|
+
};
|
|
116
|
+
if (args.session_id !== undefined) {
|
|
117
|
+
payload.session_id = args.session_id;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const res = await fetchFn(`${apiBaseUrl}/notes`, {
|
|
121
|
+
method: 'POST',
|
|
122
|
+
headers: authHeaders,
|
|
123
|
+
body: JSON.stringify(payload),
|
|
124
|
+
signal: AbortSignal.timeout(10_000),
|
|
125
|
+
});
|
|
126
|
+
const data = await res.json().catch(() => ({}));
|
|
127
|
+
if (!res.ok) {
|
|
128
|
+
return {
|
|
129
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
130
|
+
isError: true,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
if (err?.code === 'SCOPE_REQUIRED' || err?.code === 'SCHEMA_INVALID') {
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
content: [{ type: 'text', text: `MCP Transport Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
143
|
+
isError: true,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const brainRecentFailures = async (args) => {
|
|
148
|
+
try {
|
|
149
|
+
const targetProjectId = args.project_id || defaultProjectId;
|
|
150
|
+
const query = new URLSearchParams();
|
|
151
|
+
if (targetProjectId)
|
|
152
|
+
query.set('project_id', targetProjectId);
|
|
153
|
+
if (args.task_type)
|
|
154
|
+
query.set('task_type', args.task_type);
|
|
155
|
+
if (args.limit)
|
|
156
|
+
query.set('limit', String(args.limit));
|
|
157
|
+
const url = `${apiBaseUrl}/failure-patterns${query.toString() ? `?${query.toString()}` : ''}`;
|
|
158
|
+
const res = await fetchFn(url, {
|
|
159
|
+
method: 'GET',
|
|
160
|
+
headers: authHeaders,
|
|
161
|
+
signal: AbortSignal.timeout(10_000),
|
|
162
|
+
});
|
|
163
|
+
const data = await res.json().catch(() => []);
|
|
164
|
+
if (!res.ok) {
|
|
165
|
+
return {
|
|
166
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
167
|
+
isError: true,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const items = Array.isArray(data) ? data : [];
|
|
171
|
+
const result = items.map((p) => ({
|
|
172
|
+
task_type: p.task_type,
|
|
173
|
+
error_text: p.error_text,
|
|
174
|
+
count: p.count,
|
|
175
|
+
last_seen_at: p.last_seen_at,
|
|
176
|
+
}));
|
|
177
|
+
return {
|
|
178
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
return {
|
|
183
|
+
content: [{ type: 'text', text: `MCP Transport Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
184
|
+
isError: true,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const brainConsolidateCandidates = async (args) => {
|
|
189
|
+
try {
|
|
190
|
+
const targetProjectId = args.project_id || defaultProjectId;
|
|
191
|
+
const query = new URLSearchParams();
|
|
192
|
+
if (targetProjectId)
|
|
193
|
+
query.set('project_id', targetProjectId);
|
|
194
|
+
if (args.limit)
|
|
195
|
+
query.set('limit', String(args.limit));
|
|
196
|
+
const url = `${apiBaseUrl}/consolidate/candidates${query.toString() ? `?${query.toString()}` : ''}`;
|
|
197
|
+
const res = await fetchFn(url, {
|
|
198
|
+
method: 'GET',
|
|
199
|
+
headers: authHeaders,
|
|
200
|
+
signal: AbortSignal.timeout(10_000),
|
|
201
|
+
});
|
|
202
|
+
const data = await res.json().catch(() => ({ candidates: [] }));
|
|
203
|
+
if (!res.ok) {
|
|
204
|
+
return {
|
|
205
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
206
|
+
isError: true,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
return {
|
|
215
|
+
content: [{ type: 'text', text: `MCP Transport Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
216
|
+
isError: true,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const brainSubmitSummary = async (args) => {
|
|
221
|
+
try {
|
|
222
|
+
const payload = {
|
|
223
|
+
lease_id: args.lease_id,
|
|
224
|
+
claims: args.claims,
|
|
225
|
+
files_touched: args.files_touched,
|
|
226
|
+
error_verbatim: args.error_verbatim,
|
|
227
|
+
producer_tier: 'agent',
|
|
228
|
+
producer_model: null,
|
|
229
|
+
prompt_version: 'extract-v1',
|
|
230
|
+
};
|
|
231
|
+
const res = await fetchFn(`${apiBaseUrl}/consolidate/summaries`, {
|
|
232
|
+
method: 'POST',
|
|
233
|
+
headers: authHeaders,
|
|
234
|
+
body: JSON.stringify(payload),
|
|
235
|
+
signal: AbortSignal.timeout(10_000),
|
|
236
|
+
});
|
|
237
|
+
const data = await res.json().catch(() => ({}));
|
|
238
|
+
if (!res.ok) {
|
|
239
|
+
return {
|
|
240
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
241
|
+
isError: true,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
catch (err) {
|
|
249
|
+
return {
|
|
250
|
+
content: [{ type: 'text', text: `MCP Transport Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
251
|
+
isError: true,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const requestJson = async (url, init) => {
|
|
256
|
+
try {
|
|
257
|
+
const res = await fetchFn(url, {
|
|
258
|
+
...init,
|
|
259
|
+
signal: AbortSignal.timeout(10_000),
|
|
260
|
+
});
|
|
261
|
+
const data = await res.json().catch(() => ({}));
|
|
262
|
+
if (!res.ok) {
|
|
263
|
+
return {
|
|
264
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
265
|
+
isError: true,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
return {
|
|
274
|
+
content: [{ type: 'text', text: `MCP Transport Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
275
|
+
isError: true,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const brainActionAdd = async (args) => {
|
|
280
|
+
if (!args.scope || (args.scope !== 'project' && args.scope !== 'global' && args.scope !== 'unknown')) {
|
|
281
|
+
const err = new Error("SCOPE_REQUIRED: Scope is required and must be 'project', 'global', or 'unknown'");
|
|
282
|
+
err.code = 'SCOPE_REQUIRED';
|
|
283
|
+
throw err;
|
|
284
|
+
}
|
|
285
|
+
const effectiveProjectId = args.project_id || (args.scope === 'project' ? defaultProjectId : undefined);
|
|
286
|
+
if (args.scope === 'project' && !effectiveProjectId) {
|
|
287
|
+
const err = new Error("SCHEMA_INVALID: project_id is required when scope is 'project' (use the project root folder name, e.g. 'neuralbrain' — from .brainrc or the git repo root, not a subfolder or filesystem path)");
|
|
288
|
+
err.code = 'SCHEMA_INVALID';
|
|
289
|
+
throw err;
|
|
290
|
+
}
|
|
291
|
+
const payload = {
|
|
292
|
+
title: args.title,
|
|
293
|
+
scope: args.scope,
|
|
294
|
+
};
|
|
295
|
+
if (args.description !== undefined)
|
|
296
|
+
payload.description = args.description;
|
|
297
|
+
if (effectiveProjectId)
|
|
298
|
+
payload.project_id = effectiveProjectId;
|
|
299
|
+
if (args.session_id !== undefined)
|
|
300
|
+
payload.session_id = args.session_id;
|
|
301
|
+
if (args.status !== undefined)
|
|
302
|
+
payload.status = args.status;
|
|
303
|
+
if (args.priority !== undefined)
|
|
304
|
+
payload.priority = args.priority;
|
|
305
|
+
if (args.blocked_reason !== undefined)
|
|
306
|
+
payload.blocked_reason = args.blocked_reason;
|
|
307
|
+
if (args.files !== undefined)
|
|
308
|
+
payload.files = args.files;
|
|
309
|
+
return requestJson(`${apiBaseUrl}/actions`, {
|
|
310
|
+
method: 'POST',
|
|
311
|
+
headers: authHeaders,
|
|
312
|
+
body: JSON.stringify(payload),
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
const brainActionList = async (args = {}) => {
|
|
316
|
+
const targetProjectId = args.project_id || defaultProjectId;
|
|
317
|
+
const query = new URLSearchParams();
|
|
318
|
+
if (targetProjectId)
|
|
319
|
+
query.set('project_id', targetProjectId);
|
|
320
|
+
if (args.include_global !== undefined)
|
|
321
|
+
query.set('include_global', String(args.include_global));
|
|
322
|
+
if (args.status)
|
|
323
|
+
query.set('status', args.status);
|
|
324
|
+
if (args.limit !== undefined)
|
|
325
|
+
query.set('limit', String(args.limit));
|
|
326
|
+
const url = `${apiBaseUrl}/actions${query.toString() ? `?${query.toString()}` : ''}`;
|
|
327
|
+
return requestJson(url, {
|
|
328
|
+
method: 'GET',
|
|
329
|
+
headers: authHeaders,
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
const brainActionUpdate = async (args) => {
|
|
333
|
+
const payload = {};
|
|
334
|
+
if (args.status !== undefined)
|
|
335
|
+
payload.status = args.status;
|
|
336
|
+
if (args.priority !== undefined)
|
|
337
|
+
payload.priority = args.priority;
|
|
338
|
+
if (args.title !== undefined)
|
|
339
|
+
payload.title = args.title;
|
|
340
|
+
if (args.description !== undefined)
|
|
341
|
+
payload.description = args.description;
|
|
342
|
+
if (args.blocked_reason !== undefined)
|
|
343
|
+
payload.blocked_reason = args.blocked_reason;
|
|
344
|
+
if (args.resolved_by_session_id !== undefined)
|
|
345
|
+
payload.resolved_by_session_id = args.resolved_by_session_id;
|
|
346
|
+
return requestJson(`${apiBaseUrl}/actions/${encodeURIComponent(args.id)}`, {
|
|
347
|
+
method: 'PATCH',
|
|
348
|
+
headers: authHeaders,
|
|
349
|
+
body: JSON.stringify(payload),
|
|
350
|
+
});
|
|
351
|
+
};
|
|
352
|
+
const brainSessions = async (args = {}) => {
|
|
353
|
+
const mode = args.mode || 'list';
|
|
354
|
+
if (mode === 'get' || mode === 'replay') {
|
|
355
|
+
if (!args.session_id) {
|
|
356
|
+
return {
|
|
357
|
+
content: [
|
|
358
|
+
{
|
|
359
|
+
type: 'text',
|
|
360
|
+
text: JSON.stringify({
|
|
361
|
+
error: {
|
|
362
|
+
code: 'SCHEMA_INVALID',
|
|
363
|
+
message: `session_id is required when mode is '${mode}'`,
|
|
364
|
+
},
|
|
365
|
+
}, null, 2),
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
isError: true,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const suffix = mode === 'replay' ? '/replay' : '';
|
|
372
|
+
return requestJson(`${apiBaseUrl}/sessions/${encodeURIComponent(args.session_id)}${suffix}`, {
|
|
373
|
+
method: 'GET',
|
|
374
|
+
headers: authHeaders,
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
const targetProjectId = args.project_id || defaultProjectId;
|
|
378
|
+
const query = new URLSearchParams();
|
|
379
|
+
if (targetProjectId)
|
|
380
|
+
query.set('project_id', targetProjectId);
|
|
381
|
+
if (args.status)
|
|
382
|
+
query.set('status', args.status);
|
|
383
|
+
if (args.agent_name)
|
|
384
|
+
query.set('agent_name', args.agent_name);
|
|
385
|
+
if (args.limit !== undefined)
|
|
386
|
+
query.set('limit', String(args.limit));
|
|
387
|
+
const url = `${apiBaseUrl}/sessions${query.toString() ? `?${query.toString()}` : ''}`;
|
|
388
|
+
return requestJson(url, {
|
|
389
|
+
method: 'GET',
|
|
390
|
+
headers: authHeaders,
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
const brainSessionEnd = async (args) => {
|
|
394
|
+
const payload = {};
|
|
395
|
+
if (args.status !== undefined)
|
|
396
|
+
payload.status = args.status;
|
|
397
|
+
if (args.summary !== undefined)
|
|
398
|
+
payload.summary = args.summary;
|
|
399
|
+
if (args.files_touched !== undefined)
|
|
400
|
+
payload.files_touched = args.files_touched;
|
|
401
|
+
if (args.handoff_summary_id !== undefined)
|
|
402
|
+
payload.handoff_summary_id = args.handoff_summary_id;
|
|
403
|
+
return requestJson(`${apiBaseUrl}/sessions/${encodeURIComponent(args.session_id)}/end`, {
|
|
404
|
+
method: 'POST',
|
|
405
|
+
headers: authHeaders,
|
|
406
|
+
body: JSON.stringify(payload),
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
const brainGraph = async (args = {}) => {
|
|
410
|
+
const targetProjectId = args.project_id || (args.scope === 'global' || args.scope === 'unknown' ? undefined : defaultProjectId);
|
|
411
|
+
const query = new URLSearchParams();
|
|
412
|
+
if (targetProjectId)
|
|
413
|
+
query.set('project_id', targetProjectId);
|
|
414
|
+
if (args.scope)
|
|
415
|
+
query.set('scope', args.scope);
|
|
416
|
+
if (args.limit !== undefined)
|
|
417
|
+
query.set('limit', String(args.limit));
|
|
418
|
+
const url = `${apiBaseUrl}/graph${query.toString() ? `?${query.toString()}` : ''}`;
|
|
419
|
+
return requestJson(url, {
|
|
420
|
+
method: 'GET',
|
|
421
|
+
headers: authHeaders,
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
return {
|
|
425
|
+
brainSearch,
|
|
426
|
+
brainSave,
|
|
427
|
+
brainRecentFailures,
|
|
428
|
+
brainConsolidateCandidates,
|
|
429
|
+
brainSubmitSummary,
|
|
430
|
+
brainActionAdd,
|
|
431
|
+
brainActionList,
|
|
432
|
+
brainActionUpdate,
|
|
433
|
+
brainSessions,
|
|
434
|
+
brainSessionEnd,
|
|
435
|
+
brainGraph,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
function createBrainMcpServer(options = {}) {
|
|
439
|
+
const server = new mcp_js_1.McpServer({
|
|
440
|
+
name: 'neuralbrain',
|
|
441
|
+
version: '0.0.2',
|
|
442
|
+
}, {
|
|
443
|
+
instructions: exports.MCP_INSTRUCTIONS,
|
|
444
|
+
});
|
|
445
|
+
const handlers = options.handlers ?? createBrainMcpHandlers(options);
|
|
446
|
+
// 1. brain_search
|
|
447
|
+
server.tool('brain_search', 'Search across memories, trajectories, observations, and summaries with hybrid dense + BM25 retrieval. Surfaces "degraded" verbatim when vector search is unavailable so the agent can tell BM25-only results from hybrid ones. Call before starting non-trivial work.', {
|
|
448
|
+
q: zod_1.z.string().describe('Search query text'),
|
|
449
|
+
record_types: zod_1.z
|
|
450
|
+
.array(zod_1.z.string())
|
|
451
|
+
.default(['note', 'trajectory'])
|
|
452
|
+
.describe("Memory record types to search (default: ['note', 'trajectory']). Options: 'note' (curated facts/decisions/bugs), 'trajectory' (session outcome rollups), 'summary' (consolidated session claims, touched files, and verbatim errors — pass ['summary'] or ['note', 'trajectory', 'summary'] when resuming work, checking file history, or debugging recurring errors), 'observation' (raw tool calls/prompts)."),
|
|
453
|
+
project_id: zod_1.z
|
|
454
|
+
.string()
|
|
455
|
+
.optional()
|
|
456
|
+
.describe('Project ID to filter by; omit for global-only. Use the project root folder name (from .brainrc, else the git repo root; the main repo for a worktree), e.g. "neuralbrain" — never a subfolder or filesystem path'),
|
|
457
|
+
include_global: zod_1.z.boolean().default(true).describe('Whether to include global records when project_id is specified'),
|
|
458
|
+
type: zod_1.z.array(zod_1.z.string()).optional().describe('Note type filter (fact, architecture, pattern, workflow, bug, preference, lesson)'),
|
|
459
|
+
file_path: zod_1.z.string().optional().describe('File path filter ("what do we know about this file?")'),
|
|
460
|
+
limit: zod_1.z.number().int().default(10).describe('Maximum number of results to return'),
|
|
461
|
+
}, async (args) => {
|
|
462
|
+
return handlers.brainSearch(args);
|
|
463
|
+
});
|
|
464
|
+
// 2. brain_save
|
|
465
|
+
server.tool('brain_save', "Write a note deliberately. Scope is REQUIRED and never inferred or defaulted ('project', 'global', or 'unknown'). If scope is omitted or invalid, rejects immediately with SCOPE_REQUIRED.", {
|
|
466
|
+
type: zod_1.z.enum(['fact', 'architecture', 'pattern', 'workflow', 'bug', 'preference', 'lesson']).describe('Note type'),
|
|
467
|
+
title: zod_1.z.string().describe('Title of the note'),
|
|
468
|
+
content: zod_1.z.string().describe('Content of the note'),
|
|
469
|
+
scope: zod_1.z.enum(['project', 'global', 'unknown']).describe("Scope: 'project', 'global', or 'unknown'. REQUIRED, never inferred!"),
|
|
470
|
+
project_id: zod_1.z
|
|
471
|
+
.string()
|
|
472
|
+
.optional()
|
|
473
|
+
.describe("Required iff scope is 'project'. Use the project root folder name (from .brainrc, else the git repo root; the main repo for a worktree), e.g. 'neuralbrain' — never a subfolder or filesystem path. If unsure, use scope 'unknown'"),
|
|
474
|
+
session_id: zod_1.z.string().optional().describe('Optional session ID that authored this note'),
|
|
475
|
+
concepts: zod_1.z.array(zod_1.z.string()).optional().describe('Concepts associated with this note'),
|
|
476
|
+
files: zod_1.z.array(zod_1.z.string()).optional().describe('File paths associated with this note'),
|
|
477
|
+
supersedes: zod_1.z.string().optional().describe('Previous note id being superseded'),
|
|
478
|
+
}, async (args) => {
|
|
479
|
+
return handlers.brainSave(args);
|
|
480
|
+
});
|
|
481
|
+
// 3. brain_recent_failures
|
|
482
|
+
server.tool('brain_recent_failures', 'Retrieve recent failure patterns and counts. Returns { task_type, error_text, count, last_seen_at }[] where count is from SQL.', {
|
|
483
|
+
project_id: zod_1.z
|
|
484
|
+
.string()
|
|
485
|
+
.optional()
|
|
486
|
+
.describe('Project ID to filter by (use the project root folder name, e.g. "neuralbrain"; never a subfolder or filesystem path); omit for global'),
|
|
487
|
+
task_type: zod_1.z.string().optional().describe('Task type filter'),
|
|
488
|
+
limit: zod_1.z.number().int().default(5).describe('Maximum number of failures to return'),
|
|
489
|
+
}, async (args) => {
|
|
490
|
+
return handlers.brainRecentFailures(args);
|
|
491
|
+
});
|
|
492
|
+
// 4. brain_consolidate_candidates
|
|
493
|
+
server.tool('brain_consolidate_candidates', 'Retrieve un-consolidated observation sessions with a lease. Returns lease_id, the source records (observations), and expires_at.', {
|
|
494
|
+
project_id: zod_1.z
|
|
495
|
+
.string()
|
|
496
|
+
.optional()
|
|
497
|
+
.describe('Filter candidates by project (use the project root folder name, e.g. "neuralbrain"; never a subfolder or filesystem path)'),
|
|
498
|
+
limit: zod_1.z.number().int().optional().describe('Maximum number of candidate leases to retrieve'),
|
|
499
|
+
}, async (args) => {
|
|
500
|
+
return handlers.brainConsolidateCandidates(args);
|
|
501
|
+
});
|
|
502
|
+
// 5. brain_submit_summary
|
|
503
|
+
server.tool('brain_submit_summary', 'Submit a consolidated summary for verification and storage. Always redact any API keys, tokens, passwords, or other sensitive info before submitting. If the HTTP API returns 422, returns the 422 failure reason and exact details to the agent so it can see which citation did not resolve or which string was not verbatim.', {
|
|
504
|
+
lease_id: zod_1.z.string().describe('Lease ID obtained from brain_consolidate_candidates'),
|
|
505
|
+
claims: zod_1.z
|
|
506
|
+
.array(zod_1.z.object({
|
|
507
|
+
text: zod_1.z.string().describe('Claim text'),
|
|
508
|
+
source_ids: zod_1.z.array(zod_1.z.string()).describe('IDs of source observations supporting this claim'),
|
|
509
|
+
}))
|
|
510
|
+
.describe('Array of claims with citations'),
|
|
511
|
+
files_touched: zod_1.z.array(zod_1.z.string()).optional().describe('Files touched during this session'),
|
|
512
|
+
error_verbatim: zod_1.z.string().nullable().optional().describe('Verbatim error text if outcome was failure'),
|
|
513
|
+
}, async (args) => {
|
|
514
|
+
return handlers.brainSubmitSummary(args);
|
|
515
|
+
});
|
|
516
|
+
// 6. brain_action_add
|
|
517
|
+
server.tool('brain_action_add', 'Create a Next Action to surface unfinished work, follow-ups, or blockers for future sessions. Scope is REQUIRED (project, global, or unknown).', {
|
|
518
|
+
title: zod_1.z.string().describe('Short, actionable title of the next action'),
|
|
519
|
+
description: zod_1.z.string().optional().describe('Detailed description or context for the next action'),
|
|
520
|
+
scope: zod_1.z.enum(['project', 'global', 'unknown']).describe("Scope: 'project', 'global', or 'unknown'. REQUIRED, never inferred!"),
|
|
521
|
+
project_id: zod_1.z
|
|
522
|
+
.string()
|
|
523
|
+
.optional()
|
|
524
|
+
.describe("Required iff scope is 'project'. Use the project root folder name (from .brainrc or the git repo root), e.g. 'neuralbrain' — never a subfolder or filesystem path"),
|
|
525
|
+
session_id: zod_1.z.string().optional().describe('Optional session ID that created this action'),
|
|
526
|
+
status: zod_1.z.enum(['ready', 'blocked', 'in_progress', 'done', 'dismissed']).optional().describe("Action status ('ready', 'blocked', 'in_progress', 'done', 'dismissed')"),
|
|
527
|
+
priority: zod_1.z.enum(['low', 'normal', 'high', 'urgent']).optional().describe("Priority level ('low', 'normal', 'high', 'urgent')"),
|
|
528
|
+
blocked_reason: zod_1.z.string().optional().describe('Reason the action is blocked, if status is blocked'),
|
|
529
|
+
files: zod_1.z.array(zod_1.z.string()).optional().describe('File paths associated with this action'),
|
|
530
|
+
}, async (args) => {
|
|
531
|
+
return handlers.brainActionAdd(args);
|
|
532
|
+
});
|
|
533
|
+
// 7. brain_action_list
|
|
534
|
+
server.tool('brain_action_list', 'List Next Actions for a project (and optionally global actions), filtered by status.', {
|
|
535
|
+
project_id: zod_1.z
|
|
536
|
+
.string()
|
|
537
|
+
.optional()
|
|
538
|
+
.describe('Project ID to filter by (use the project root folder name, e.g. "neuralbrain"; never a subfolder or filesystem path)'),
|
|
539
|
+
include_global: zod_1.z.boolean().optional().describe('Whether to include global actions when project_id is specified'),
|
|
540
|
+
status: zod_1.z.string().optional().describe("Filter by status (e.g. 'ready', 'in_progress', 'blocked', 'done')"),
|
|
541
|
+
limit: zod_1.z.number().int().optional().describe('Maximum number of actions to return'),
|
|
542
|
+
}, async (args) => {
|
|
543
|
+
return handlers.brainActionList(args);
|
|
544
|
+
});
|
|
545
|
+
// 8. brain_action_update
|
|
546
|
+
server.tool('brain_action_update', 'Update an existing Next Action (status, priority, title, description, blocked_reason, or resolved_by_session_id).', {
|
|
547
|
+
id: zod_1.z.string().describe('ID of the action to update'),
|
|
548
|
+
status: zod_1.z.enum(['ready', 'blocked', 'in_progress', 'done', 'dismissed']).optional().describe("Updated status ('ready', 'blocked', 'in_progress', 'done', 'dismissed')"),
|
|
549
|
+
priority: zod_1.z.enum(['low', 'normal', 'high', 'urgent']).optional().describe("Updated priority ('low', 'normal', 'high', 'urgent')"),
|
|
550
|
+
title: zod_1.z.string().optional().describe('Updated title'),
|
|
551
|
+
description: zod_1.z.string().optional().describe('Updated description'),
|
|
552
|
+
blocked_reason: zod_1.z.string().optional().describe('Updated blocked reason'),
|
|
553
|
+
resolved_by_session_id: zod_1.z.string().optional().describe('Session ID that resolved this action'),
|
|
554
|
+
}, async (args) => {
|
|
555
|
+
return handlers.brainActionUpdate(args);
|
|
556
|
+
});
|
|
557
|
+
// 9. brain_sessions
|
|
558
|
+
server.tool('brain_sessions', 'Inspect prior agent sessions: list sessions, fetch a single session with its details, or replay a session timeline chronologically.', {
|
|
559
|
+
mode: zod_1.z
|
|
560
|
+
.enum(['list', 'get', 'replay'])
|
|
561
|
+
.default('list')
|
|
562
|
+
.describe("Operation mode: 'list' (default), 'get', or 'replay'"),
|
|
563
|
+
session_id: zod_1.z
|
|
564
|
+
.string()
|
|
565
|
+
.optional()
|
|
566
|
+
.describe("Session ID (required when mode is 'get' or 'replay')"),
|
|
567
|
+
project_id: zod_1.z
|
|
568
|
+
.string()
|
|
569
|
+
.optional()
|
|
570
|
+
.describe('Project ID to filter by when listing sessions (use the project root folder name, e.g. "neuralbrain"; never a subfolder or filesystem path)'),
|
|
571
|
+
status: zod_1.z.string().optional().describe("Filter sessions by status when listing (e.g. 'active', 'completed', 'paused', 'abandoned')"),
|
|
572
|
+
agent_name: zod_1.z.string().optional().describe('Filter sessions by agent name when listing'),
|
|
573
|
+
limit: zod_1.z.number().int().optional().describe('Maximum number of sessions to return when listing'),
|
|
574
|
+
}, async (args) => {
|
|
575
|
+
return handlers.brainSessions(args);
|
|
576
|
+
});
|
|
577
|
+
// 10. brain_session_end
|
|
578
|
+
server.tool('brain_session_end', 'End or pause a session and record a clean cross-agent handoff summary, files touched, and optional handoff_summary_id.', {
|
|
579
|
+
session_id: zod_1.z.string().describe('ID of the session to end'),
|
|
580
|
+
status: zod_1.z
|
|
581
|
+
.enum(['completed', 'paused', 'abandoned'])
|
|
582
|
+
.optional()
|
|
583
|
+
.describe("Final session status ('completed', 'paused', or 'abandoned')"),
|
|
584
|
+
summary: zod_1.z.string().optional().describe('Handoff summary for the next agent or session'),
|
|
585
|
+
files_touched: zod_1.z.array(zod_1.z.string()).optional().describe('Files touched during this session'),
|
|
586
|
+
handoff_summary_id: zod_1.z.string().optional().describe('Optional derived summary ID linked as handoff'),
|
|
587
|
+
}, async (args) => {
|
|
588
|
+
return handlers.brainSessionEnd(args);
|
|
589
|
+
});
|
|
590
|
+
// 11. brain_graph
|
|
591
|
+
server.tool('brain_graph', 'Explore the relational knowledge graph across notes, lessons, concepts, files, sessions, actions, and summaries.', {
|
|
592
|
+
project_id: zod_1.z
|
|
593
|
+
.string()
|
|
594
|
+
.optional()
|
|
595
|
+
.describe('Project ID to filter by (use the project root folder name, e.g. "neuralbrain"; never a subfolder or filesystem path)'),
|
|
596
|
+
scope: zod_1.z
|
|
597
|
+
.enum(['project', 'global', 'unknown'])
|
|
598
|
+
.optional()
|
|
599
|
+
.describe("Optional scope filter ('project', 'global', or 'unknown')"),
|
|
600
|
+
limit: zod_1.z.number().int().optional().describe('Maximum number of graph nodes to return'),
|
|
601
|
+
}, async (args) => {
|
|
602
|
+
return handlers.brainGraph(args);
|
|
603
|
+
});
|
|
604
|
+
return server;
|
|
605
|
+
}
|
|
606
|
+
if (require.main === module) {
|
|
607
|
+
(0, brainHome_1.loadBrainEnv)();
|
|
608
|
+
const server = createBrainMcpServer();
|
|
609
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
610
|
+
server.connect(transport).catch((err) => {
|
|
611
|
+
console.error('Failed to start MCP server:', err);
|
|
612
|
+
process.exit(1);
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
//# sourceMappingURL=server.js.map
|