neuralbrain 0.0.1 → 0.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/.env.example +2 -2
- package/README.md +19 -4
- package/dist/ai/chat.d.ts +1 -2
- package/dist/ai/chat.d.ts.map +1 -1
- package/dist/ai/chat.js +1 -2
- package/dist/ai/chat.js.map +1 -1
- package/dist/ai/config.d.ts +1 -1
- package/dist/ai/config.js +2 -2
- package/dist/ai/config.js.map +1 -1
- package/dist/app.d.ts +1 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +417 -50
- package/dist/app.js.map +1 -1
- package/dist/cli.d.ts +53 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +437 -37
- package/dist/cli.js.map +1 -1
- package/dist/consolidation/candidates.d.ts.map +1 -1
- package/dist/consolidation/candidates.js +19 -4
- package/dist/consolidation/candidates.js.map +1 -1
- package/dist/consolidation/fixtures.js +1 -1
- package/dist/consolidation/fixtures.js.map +1 -1
- package/dist/consolidation/gate.d.ts.map +1 -1
- package/dist/consolidation/gate.js +145 -109
- package/dist/consolidation/gate.js.map +1 -1
- package/dist/consolidation/runner.d.ts +6 -0
- package/dist/consolidation/runner.d.ts.map +1 -1
- package/dist/consolidation/runner.js +22 -2
- package/dist/consolidation/runner.js.map +1 -1
- package/dist/dashboard/clientScript.d.ts +1 -1
- package/dist/dashboard/clientScript.d.ts.map +1 -1
- package/dist/dashboard/clientScript.js +3774 -905
- package/dist/dashboard/clientScript.js.map +1 -1
- package/dist/dashboard/html.d.ts.map +1 -1
- package/dist/dashboard/html.js +605 -101
- package/dist/dashboard/html.js.map +1 -1
- package/dist/dashboard/styles.d.ts +1 -1
- package/dist/dashboard/styles.d.ts.map +1 -1
- package/dist/dashboard/styles.js +1591 -359
- package/dist/dashboard/styles.js.map +1 -1
- package/dist/learning/embedWorker.d.ts +13 -0
- package/dist/learning/embedWorker.d.ts.map +1 -1
- package/dist/learning/embedWorker.js +329 -59
- package/dist/learning/embedWorker.js.map +1 -1
- package/dist/learning/embedding.d.ts +1 -0
- package/dist/learning/embedding.d.ts.map +1 -1
- package/dist/learning/embedding.js +101 -26
- package/dist/learning/embedding.js.map +1 -1
- package/dist/learning/engine.js +1 -1
- package/dist/learning/engine.js.map +1 -1
- package/dist/learning/search.d.ts +17 -1
- package/dist/learning/search.d.ts.map +1 -1
- package/dist/learning/search.js +2094 -354
- package/dist/learning/search.js.map +1 -1
- package/dist/learning/storeMeta.d.ts +9 -0
- package/dist/learning/storeMeta.d.ts.map +1 -1
- package/dist/learning/storeMeta.js +30 -24
- package/dist/learning/storeMeta.js.map +1 -1
- package/dist/learning/types.d.ts +57 -8
- package/dist/learning/types.d.ts.map +1 -1
- package/dist/lib/condenser.d.ts +112 -0
- package/dist/lib/condenser.d.ts.map +1 -0
- package/dist/lib/condenser.js +1337 -0
- package/dist/lib/condenser.js.map +1 -0
- package/dist/lib/db.d.ts +10 -0
- package/dist/lib/db.d.ts.map +1 -1
- package/dist/lib/db.js +654 -167
- package/dist/lib/db.js.map +1 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +3 -2
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/projectSlug.d.ts +12 -5
- package/dist/lib/projectSlug.d.ts.map +1 -1
- package/dist/lib/projectSlug.js +62 -23
- package/dist/lib/projectSlug.js.map +1 -1
- package/dist/lib/recurrence.d.ts +16 -0
- package/dist/lib/recurrence.d.ts.map +1 -0
- package/dist/lib/recurrence.js +293 -0
- package/dist/lib/recurrence.js.map +1 -0
- package/dist/lib/scope.d.ts +36 -1
- package/dist/lib/scope.d.ts.map +1 -1
- package/dist/lib/scope.js +183 -19
- package/dist/lib/scope.js.map +1 -1
- package/dist/lib/signalTags.d.ts +39 -0
- package/dist/lib/signalTags.d.ts.map +1 -0
- package/dist/lib/signalTags.js +203 -0
- package/dist/lib/signalTags.js.map +1 -0
- package/dist/lib/spool.d.ts +2 -0
- package/dist/lib/spool.d.ts.map +1 -1
- package/dist/lib/spool.js +176 -65
- package/dist/lib/spool.js.map +1 -1
- package/dist/lib/storeDiagnostics.d.ts +41 -0
- package/dist/lib/storeDiagnostics.d.ts.map +1 -0
- package/dist/lib/storeDiagnostics.js +148 -0
- package/dist/lib/storeDiagnostics.js.map +1 -0
- package/dist/lib/temporal.d.ts +44 -0
- package/dist/lib/temporal.d.ts.map +1 -0
- package/dist/lib/temporal.js +1063 -0
- package/dist/lib/temporal.js.map +1 -0
- package/dist/mcp/server.d.ts +93 -3
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +499 -68
- package/dist/mcp/server.js.map +1 -1
- package/dist/memory/actionStore.d.ts +94 -3
- package/dist/memory/actionStore.d.ts.map +1 -1
- package/dist/memory/actionStore.js +412 -124
- package/dist/memory/actionStore.js.map +1 -1
- package/dist/memory/deadLetterStore.d.ts.map +1 -1
- package/dist/memory/deadLetterStore.js +4 -2
- package/dist/memory/deadLetterStore.js.map +1 -1
- package/dist/memory/embedQueueStore.d.ts +19 -8
- package/dist/memory/embedQueueStore.d.ts.map +1 -1
- package/dist/memory/embedQueueStore.js +55 -25
- package/dist/memory/embedQueueStore.js.map +1 -1
- package/dist/memory/failurePatternStore.d.ts +17 -1
- package/dist/memory/failurePatternStore.d.ts.map +1 -1
- package/dist/memory/failurePatternStore.js +54 -31
- package/dist/memory/failurePatternStore.js.map +1 -1
- package/dist/memory/graphStore.d.ts +133 -3
- package/dist/memory/graphStore.d.ts.map +1 -1
- package/dist/memory/graphStore.js +980 -155
- package/dist/memory/graphStore.js.map +1 -1
- package/dist/memory/noteStore.d.ts +27 -2
- package/dist/memory/noteStore.d.ts.map +1 -1
- package/dist/memory/noteStore.js +89 -26
- package/dist/memory/noteStore.js.map +1 -1
- package/dist/memory/observationStore.d.ts +11 -1
- package/dist/memory/observationStore.d.ts.map +1 -1
- package/dist/memory/observationStore.js +90 -15
- package/dist/memory/observationStore.js.map +1 -1
- package/dist/memory/projectRename.d.ts.map +1 -1
- package/dist/memory/projectRename.js +5 -1
- package/dist/memory/projectRename.js.map +1 -1
- package/dist/memory/rollupSweeper.d.ts.map +1 -1
- package/dist/memory/rollupSweeper.js +43 -23
- package/dist/memory/rollupSweeper.js.map +1 -1
- package/dist/memory/sessionStore.d.ts +25 -7
- package/dist/memory/sessionStore.d.ts.map +1 -1
- package/dist/memory/sessionStore.js +145 -33
- package/dist/memory/sessionStore.js.map +1 -1
- package/dist/memory/trajectoryStore.d.ts +8 -0
- package/dist/memory/trajectoryStore.d.ts.map +1 -1
- package/dist/memory/trajectoryStore.js +196 -130
- package/dist/memory/trajectoryStore.js.map +1 -1
- package/dist/middleware/rateLimiter.d.ts.map +1 -1
- package/dist/middleware/rateLimiter.js +24 -1
- package/dist/middleware/rateLimiter.js.map +1 -1
- package/dist/routes/dashboard.d.ts.map +1 -1
- package/dist/routes/dashboard.js +181 -8
- package/dist/routes/dashboard.js.map +1 -1
- package/dist/routes/mcp.d.ts.map +1 -1
- package/dist/routes/mcp.js +173 -21
- package/dist/routes/mcp.js.map +1 -1
- package/dist/routes/memories.js +9 -1
- package/dist/routes/memories.js.map +1 -1
- package/dist/scripts/doctor.d.ts +26 -2
- package/dist/scripts/doctor.d.ts.map +1 -1
- package/dist/scripts/doctor.js +371 -259
- package/dist/scripts/doctor.js.map +1 -1
- package/dist/scripts/installAgent.d.ts.map +1 -1
- package/dist/scripts/installAgent.js +101 -19
- package/dist/scripts/installAgent.js.map +1 -1
- package/dist/scripts/migrateAgentMemory.js +2 -2
- package/dist/scripts/smokeTest.js +1 -1
- package/dist/scripts/smokeTest.js.map +1 -1
- package/docker-compose.yml +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +3 -2
- package/plugin/hooks/postToolUse.js +155 -50
- package/plugin/hooks/sessionStart.js +179 -27
- package/plugin/hooks/sessionStop.js +152 -37
- package/plugin/plugin.json +1 -1
- package/plugin/rules/AGENTS.md +10 -8
- package/plugin/skills/brain-memory/REFERENCE.md +15 -14
- package/plugin/skills/brain-memory/SKILL.md +2 -2
- package/plugin/skills/digest/SKILL.md +1 -1
- package/plugin/skills/handoff/SKILL.md +1 -1
- package/plugin/skills/save/SKILL.md +2 -2
- package/plugin/skills/search/SKILL.md +2 -2
- package/src/ai/chat.ts +1 -2
- package/src/ai/config.ts +2 -2
- package/src/app.ts +475 -54
- package/src/cli.ts +500 -38
- package/src/consolidation/candidates.ts +22 -4
- package/src/consolidation/fixtures.ts +1 -1
- package/src/consolidation/gate.ts +177 -140
- package/src/consolidation/runner.ts +26 -2
- package/src/dashboard/clientScript.ts +3774 -905
- package/src/dashboard/html.ts +605 -101
- package/src/dashboard/styles.ts +1591 -359
- package/src/learning/embedWorker.ts +350 -70
- package/src/learning/embedding.ts +141 -28
- package/src/learning/engine.ts +1 -1
- package/src/learning/search.ts +2533 -397
- package/src/learning/storeMeta.ts +36 -29
- package/src/learning/types.ts +66 -8
- package/src/lib/condenser.ts +1515 -0
- package/src/lib/db.ts +690 -171
- package/src/lib/logger.ts +4 -2
- package/src/lib/projectSlug.ts +77 -23
- package/src/lib/recurrence.ts +382 -0
- package/src/lib/scope.ts +220 -22
- package/src/lib/signalTags.ts +257 -0
- package/src/lib/spool.ts +181 -71
- package/src/lib/storeDiagnostics.ts +181 -0
- package/src/lib/temporal.ts +1250 -0
- package/src/mcp/server.ts +559 -88
- package/src/memory/actionStore.ts +642 -171
- package/src/memory/deadLetterStore.ts +4 -2
- package/src/memory/embedQueueStore.ts +63 -27
- package/src/memory/failurePatternStore.ts +84 -31
- package/src/memory/graphStore.ts +1396 -215
- package/src/memory/noteStore.ts +151 -30
- package/src/memory/observationStore.ts +117 -17
- package/src/memory/projectRename.ts +6 -2
- package/src/memory/rollupSweeper.ts +46 -23
- package/src/memory/sessionStore.ts +197 -38
- package/src/memory/trajectoryStore.ts +260 -140
- package/src/middleware/rateLimiter.ts +24 -1
- package/src/routes/dashboard.ts +194 -9
- package/src/routes/mcp.ts +185 -26
- package/src/routes/memories.ts +8 -1
- package/src/scripts/doctor.ts +461 -262
- package/src/scripts/installAgent.ts +106 -19
- package/src/scripts/migrateAgentMemory.ts +2 -2
- package/src/scripts/smokeTest.ts +1 -1
package/src/mcp/server.ts
CHANGED
|
@@ -16,21 +16,49 @@ export interface BrainMcpServerOptions {
|
|
|
16
16
|
export const MCP_INSTRUCTIONS = [
|
|
17
17
|
'call brain_search before starting non-trivial work, not after failing',
|
|
18
18
|
'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',
|
|
19
|
-
'check ready next actions (via /inject or brain_action_list) at task start before picking up work',
|
|
19
|
+
'check ready and due next actions (via /inject, brain_action_due, or brain_action_list) at task start before picking up work',
|
|
20
20
|
'/inject content arrives unasked at task start; do not re-query for it',
|
|
21
21
|
'use brain_sessions to inspect prior agent sessions or replay a session timeline when resuming work',
|
|
22
|
-
'use brain_graph to explore relationships across notes, lessons, concepts, files, sessions, actions, and summaries',
|
|
22
|
+
'use brain_graph to explore multi-hop relationships or upsert/link persistent entities (upsert_entity, link, unlink) across notes, lessons, concepts, files, sessions, actions, entities, and summaries',
|
|
23
23
|
'save a note when a correction or a non-obvious decision happens, not at session end when the detail is gone',
|
|
24
24
|
'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',
|
|
25
25
|
'before finishing any non-trivial task, verify whether any durable insight should be saved with brain_save',
|
|
26
26
|
'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.")',
|
|
27
27
|
'when consolidating observations, redact any API keys, tokens, passwords, or other sensitive info before submitting via brain_submit_summary',
|
|
28
|
-
'surface unfinished work or
|
|
28
|
+
'surface unfinished work, blockers, or scheduled follow-ups (due_at, remind_at, recurrence, snooze_until) via brain_action_add / brain_action_update and check overdue items with brain_action_due',
|
|
29
29
|
'call brain_session_end at session completion or pause to record a clean cross-agent handoff summary',
|
|
30
30
|
'pass scope: "unknown" rather than guessing',
|
|
31
|
-
'for project scope, project_id is the
|
|
31
|
+
'for project scope, project_id is the project_id configured in .brainrc / .brain.json if present (that value wins over the folder name and may be a flat slug like "neuralbrain" or a hierarchical slash-path slug like "acme/socials/calendar"), otherwise the lowercase name of the git repo root (the main repo for a worktree), otherwise the folder the session started in — never a subfolder or filesystem path, so all agents come up with the same id; child subprojects automatically inherit parent project context while isolating sibling subprojects',
|
|
32
32
|
].join('\n');
|
|
33
33
|
|
|
34
|
+
function validateScopeAndProject(
|
|
35
|
+
scope: string | undefined,
|
|
36
|
+
projectId: string | undefined,
|
|
37
|
+
defaultProjectId: string | undefined
|
|
38
|
+
): { effectiveProjectId?: string; error?: { code: string; message: string } } {
|
|
39
|
+
if (!scope || (scope !== 'project' && scope !== 'global' && scope !== 'unknown')) {
|
|
40
|
+
return {
|
|
41
|
+
error: {
|
|
42
|
+
code: 'SCOPE_REQUIRED',
|
|
43
|
+
message: "SCOPE_REQUIRED: Scope is required and must be 'project', 'global', or 'unknown'",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const effectiveProjectId = projectId || (scope === 'project' ? defaultProjectId : undefined);
|
|
49
|
+
if (scope === 'project' && !effectiveProjectId) {
|
|
50
|
+
return {
|
|
51
|
+
error: {
|
|
52
|
+
code: 'SCHEMA_INVALID',
|
|
53
|
+
message:
|
|
54
|
+
"SCHEMA_INVALID: project_id is required when scope is 'project' (use the project_id in .brainrc if present, else the git repo root folder name, e.g. 'neuralbrain' or 'acme/socials/calendar', not a subfolder or filesystem path)",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { effectiveProjectId };
|
|
60
|
+
}
|
|
61
|
+
|
|
34
62
|
export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
35
63
|
const apiBaseUrl = (
|
|
36
64
|
options.apiBaseUrl ||
|
|
@@ -57,9 +85,28 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
57
85
|
record_types?: string[];
|
|
58
86
|
grains?: string[];
|
|
59
87
|
project_id?: string;
|
|
88
|
+
include_ancestors?: boolean;
|
|
89
|
+
include_children?: boolean;
|
|
60
90
|
include_global?: boolean;
|
|
91
|
+
include_history?: boolean;
|
|
92
|
+
user_id?: string;
|
|
93
|
+
after?: string;
|
|
94
|
+
before?: string;
|
|
95
|
+
as_of?: string;
|
|
96
|
+
reference_date?: string;
|
|
97
|
+
temporal_bias?: 'none' | 'recent' | 'upcoming';
|
|
98
|
+
snippet_mode?: 'query_focused' | 'condensed' | 'raw';
|
|
99
|
+
max_record_chars?: number;
|
|
100
|
+
kind_weights?: Partial<Record<'prompt' | 'response' | 'tool_call', number>>;
|
|
101
|
+
max_kind_share?: Partial<Record<'prompt' | 'response' | 'tool_call', number>>;
|
|
102
|
+
entity_type?: string;
|
|
103
|
+
memory_layer?: 'semantic' | 'procedural';
|
|
104
|
+
signal_tag?: 'preference' | 'state_update' | 'completed_action' | 'planned_action';
|
|
61
105
|
type?: string[];
|
|
62
106
|
file_path?: string;
|
|
107
|
+
include_sources?: boolean;
|
|
108
|
+
sources_limit?: number;
|
|
109
|
+
sources_offset?: number;
|
|
63
110
|
limit?: number;
|
|
64
111
|
}) => {
|
|
65
112
|
const targetProjectId = args.project_id || defaultProjectId;
|
|
@@ -69,7 +116,23 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
69
116
|
q: args.q,
|
|
70
117
|
record_types:
|
|
71
118
|
requestedTypes && requestedTypes.length > 0 ? requestedTypes : ['note', 'trajectory'],
|
|
119
|
+
include_ancestors: args.include_ancestors !== false,
|
|
120
|
+
include_children: Boolean(args.include_children),
|
|
72
121
|
include_global: args.include_global !== false,
|
|
122
|
+
include_history: Boolean(args.include_history),
|
|
123
|
+
include_sources: Boolean(args.include_sources),
|
|
124
|
+
...(args.user_id !== undefined ? { user_id: args.user_id } : {}),
|
|
125
|
+
...(args.after !== undefined ? { after: args.after } : {}),
|
|
126
|
+
...(args.before !== undefined ? { before: args.before } : {}),
|
|
127
|
+
...(args.as_of !== undefined ? { as_of: args.as_of } : {}),
|
|
128
|
+
...(args.reference_date !== undefined ? { reference_date: args.reference_date } : {}),
|
|
129
|
+
...(args.temporal_bias !== undefined ? { temporal_bias: args.temporal_bias } : {}),
|
|
130
|
+
...(args.snippet_mode !== undefined ? { snippet_mode: args.snippet_mode } : {}),
|
|
131
|
+
...(args.max_record_chars !== undefined ? { max_record_chars: args.max_record_chars } : {}),
|
|
132
|
+
...(args.kind_weights !== undefined ? { kind_weights: args.kind_weights } : {}),
|
|
133
|
+
...(args.max_kind_share !== undefined ? { max_kind_share: args.max_kind_share } : {}),
|
|
134
|
+
...(args.sources_limit !== undefined ? { sources_limit: args.sources_limit } : {}),
|
|
135
|
+
...(args.sources_offset !== undefined ? { sources_offset: args.sources_offset } : {}),
|
|
73
136
|
limit: args.limit ?? 10,
|
|
74
137
|
};
|
|
75
138
|
if (targetProjectId) {
|
|
@@ -83,6 +146,18 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
83
146
|
if (args.file_path) {
|
|
84
147
|
filters.file_path = args.file_path;
|
|
85
148
|
}
|
|
149
|
+
if (args.entity_type) {
|
|
150
|
+
filters.entity_type = args.entity_type;
|
|
151
|
+
}
|
|
152
|
+
if (args.memory_layer) {
|
|
153
|
+
filters.memory_layer = args.memory_layer;
|
|
154
|
+
}
|
|
155
|
+
if (args.signal_tag) {
|
|
156
|
+
filters.signal_tag = args.signal_tag;
|
|
157
|
+
}
|
|
158
|
+
if (args.user_id) {
|
|
159
|
+
filters.user_id = args.user_id;
|
|
160
|
+
}
|
|
86
161
|
if (Object.keys(filters).length > 0) {
|
|
87
162
|
body.filters = filters;
|
|
88
163
|
}
|
|
@@ -98,13 +173,13 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
98
173
|
const data = await res.json().catch(() => ({}));
|
|
99
174
|
if (!res.ok) {
|
|
100
175
|
return {
|
|
101
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
176
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
102
177
|
isError: true,
|
|
103
178
|
};
|
|
104
179
|
}
|
|
105
180
|
|
|
106
181
|
return {
|
|
107
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
182
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
108
183
|
};
|
|
109
184
|
} catch (err) {
|
|
110
185
|
return {
|
|
@@ -120,27 +195,24 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
120
195
|
content: string;
|
|
121
196
|
scope?: 'project' | 'global' | 'unknown' | string;
|
|
122
197
|
project_id?: string;
|
|
198
|
+
user_id?: string;
|
|
199
|
+
agent_id?: string;
|
|
123
200
|
session_id?: string;
|
|
124
201
|
concepts?: string[];
|
|
125
202
|
files?: string[];
|
|
126
203
|
supersedes?: string;
|
|
204
|
+
event_at?: string;
|
|
205
|
+
valid_from?: string;
|
|
206
|
+
valid_until?: string;
|
|
127
207
|
}) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const effectiveProjectId =
|
|
135
|
-
args.project_id || (args.scope === 'project' ? defaultProjectId : undefined);
|
|
136
|
-
|
|
137
|
-
if (args.scope === 'project' && !effectiveProjectId) {
|
|
138
|
-
const err = new Error(
|
|
139
|
-
"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)"
|
|
140
|
-
);
|
|
141
|
-
(err as any).code = 'SCHEMA_INVALID';
|
|
142
|
-
throw err;
|
|
208
|
+
const check = validateScopeAndProject(args.scope, args.project_id, defaultProjectId);
|
|
209
|
+
if (check.error) {
|
|
210
|
+
return {
|
|
211
|
+
content: [{ type: 'text' as const, text: JSON.stringify({ error: check.error }) }],
|
|
212
|
+
isError: true,
|
|
213
|
+
};
|
|
143
214
|
}
|
|
215
|
+
const effectiveProjectId = check.effectiveProjectId;
|
|
144
216
|
|
|
145
217
|
const payload: Record<string, any> = {
|
|
146
218
|
type: args.type,
|
|
@@ -153,9 +225,12 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
153
225
|
files: args.files || [],
|
|
154
226
|
supersedes: args.supersedes || null,
|
|
155
227
|
};
|
|
156
|
-
if (args.session_id !== undefined)
|
|
157
|
-
|
|
158
|
-
|
|
228
|
+
if (args.session_id !== undefined) payload.session_id = args.session_id;
|
|
229
|
+
if (args.user_id !== undefined) payload.user_id = args.user_id;
|
|
230
|
+
if (args.agent_id !== undefined) payload.agent_id = args.agent_id;
|
|
231
|
+
if (args.event_at !== undefined) payload.event_at = args.event_at;
|
|
232
|
+
if (args.valid_from !== undefined) payload.valid_from = args.valid_from;
|
|
233
|
+
if (args.valid_until !== undefined) payload.valid_until = args.valid_until;
|
|
159
234
|
|
|
160
235
|
try {
|
|
161
236
|
const res = await fetchFn(`${apiBaseUrl}/notes`, {
|
|
@@ -168,18 +243,15 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
168
243
|
const data = await res.json().catch(() => ({}));
|
|
169
244
|
if (!res.ok) {
|
|
170
245
|
return {
|
|
171
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
246
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
172
247
|
isError: true,
|
|
173
248
|
};
|
|
174
249
|
}
|
|
175
250
|
|
|
176
251
|
return {
|
|
177
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
252
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
178
253
|
};
|
|
179
254
|
} catch (err) {
|
|
180
|
-
if ((err as any)?.code === 'SCOPE_REQUIRED' || (err as any)?.code === 'SCHEMA_INVALID') {
|
|
181
|
-
throw err;
|
|
182
|
-
}
|
|
183
255
|
return {
|
|
184
256
|
content: [{ type: 'text' as const, text: `MCP Transport Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
185
257
|
isError: true,
|
|
@@ -190,6 +262,10 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
190
262
|
const brainRecentFailures = async (args: {
|
|
191
263
|
project_id?: string;
|
|
192
264
|
task_type?: string;
|
|
265
|
+
include_ancestors?: boolean;
|
|
266
|
+
include_children?: boolean;
|
|
267
|
+
include_global?: boolean;
|
|
268
|
+
user_id?: string;
|
|
193
269
|
limit?: number;
|
|
194
270
|
}) => {
|
|
195
271
|
try {
|
|
@@ -197,6 +273,16 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
197
273
|
const query = new URLSearchParams();
|
|
198
274
|
if (targetProjectId) query.set('project_id', targetProjectId);
|
|
199
275
|
if (args.task_type) query.set('task_type', args.task_type);
|
|
276
|
+
if (args.include_ancestors !== undefined) {
|
|
277
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
278
|
+
}
|
|
279
|
+
if (args.include_children !== undefined) {
|
|
280
|
+
query.set('include_children', String(args.include_children));
|
|
281
|
+
}
|
|
282
|
+
if (args.include_global !== undefined) {
|
|
283
|
+
query.set('include_global', String(args.include_global));
|
|
284
|
+
}
|
|
285
|
+
if (args.user_id) query.set('user_id', args.user_id);
|
|
200
286
|
if (args.limit) query.set('limit', String(args.limit));
|
|
201
287
|
|
|
202
288
|
const url = `${apiBaseUrl}/failure-patterns${query.toString() ? `?${query.toString()}` : ''}`;
|
|
@@ -209,7 +295,7 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
209
295
|
const data = await res.json().catch(() => []);
|
|
210
296
|
if (!res.ok) {
|
|
211
297
|
return {
|
|
212
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
298
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
213
299
|
isError: true,
|
|
214
300
|
};
|
|
215
301
|
}
|
|
@@ -220,10 +306,12 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
220
306
|
error_text: p.error_text,
|
|
221
307
|
count: p.count,
|
|
222
308
|
last_seen_at: p.last_seen_at,
|
|
309
|
+
project_id: p.project_id ?? null,
|
|
310
|
+
match_tier: p.match_tier ?? null,
|
|
223
311
|
}));
|
|
224
312
|
|
|
225
313
|
return {
|
|
226
|
-
content: [{ type: 'text' as const, text: JSON.stringify(result
|
|
314
|
+
content: [{ type: 'text' as const, text: JSON.stringify(result) }],
|
|
227
315
|
};
|
|
228
316
|
} catch (err) {
|
|
229
317
|
return {
|
|
@@ -253,13 +341,13 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
253
341
|
const data = await res.json().catch(() => ({ candidates: [] }));
|
|
254
342
|
if (!res.ok) {
|
|
255
343
|
return {
|
|
256
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
344
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
257
345
|
isError: true,
|
|
258
346
|
};
|
|
259
347
|
}
|
|
260
348
|
|
|
261
349
|
return {
|
|
262
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
350
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
263
351
|
};
|
|
264
352
|
} catch (err) {
|
|
265
353
|
return {
|
|
@@ -296,13 +384,13 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
296
384
|
const data = await res.json().catch(() => ({}));
|
|
297
385
|
if (!res.ok) {
|
|
298
386
|
return {
|
|
299
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
387
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
300
388
|
isError: true,
|
|
301
389
|
};
|
|
302
390
|
}
|
|
303
391
|
|
|
304
392
|
return {
|
|
305
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
393
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
306
394
|
};
|
|
307
395
|
} catch (err) {
|
|
308
396
|
return {
|
|
@@ -322,13 +410,13 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
322
410
|
const data = await res.json().catch(() => ({}));
|
|
323
411
|
if (!res.ok) {
|
|
324
412
|
return {
|
|
325
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
413
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
326
414
|
isError: true,
|
|
327
415
|
};
|
|
328
416
|
}
|
|
329
417
|
|
|
330
418
|
return {
|
|
331
|
-
content: [{ type: 'text' as const, text: JSON.stringify(data
|
|
419
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data) }],
|
|
332
420
|
};
|
|
333
421
|
} catch (err) {
|
|
334
422
|
return {
|
|
@@ -343,28 +431,26 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
343
431
|
description?: string;
|
|
344
432
|
scope?: 'project' | 'global' | 'unknown' | string;
|
|
345
433
|
project_id?: string;
|
|
434
|
+
user_id?: string;
|
|
435
|
+
agent_id?: string;
|
|
346
436
|
session_id?: string;
|
|
347
437
|
status?: 'ready' | 'blocked' | 'in_progress' | 'done' | 'dismissed';
|
|
348
438
|
priority?: 'low' | 'normal' | 'high' | 'urgent';
|
|
349
439
|
blocked_reason?: string;
|
|
350
440
|
files?: string[];
|
|
441
|
+
due_at?: string;
|
|
442
|
+
remind_at?: string;
|
|
443
|
+
recurrence?: string;
|
|
444
|
+
snooze_until?: string;
|
|
351
445
|
}) => {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const effectiveProjectId =
|
|
359
|
-
args.project_id || (args.scope === 'project' ? defaultProjectId : undefined);
|
|
360
|
-
|
|
361
|
-
if (args.scope === 'project' && !effectiveProjectId) {
|
|
362
|
-
const err = new Error(
|
|
363
|
-
"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)"
|
|
364
|
-
);
|
|
365
|
-
(err as any).code = 'SCHEMA_INVALID';
|
|
366
|
-
throw err;
|
|
446
|
+
const check = validateScopeAndProject(args.scope, args.project_id, defaultProjectId);
|
|
447
|
+
if (check.error) {
|
|
448
|
+
return {
|
|
449
|
+
content: [{ type: 'text' as const, text: JSON.stringify({ error: check.error }) }],
|
|
450
|
+
isError: true,
|
|
451
|
+
};
|
|
367
452
|
}
|
|
453
|
+
const effectiveProjectId = check.effectiveProjectId;
|
|
368
454
|
|
|
369
455
|
const payload: Record<string, any> = {
|
|
370
456
|
title: args.title,
|
|
@@ -372,11 +458,17 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
372
458
|
};
|
|
373
459
|
if (args.description !== undefined) payload.description = args.description;
|
|
374
460
|
if (effectiveProjectId) payload.project_id = effectiveProjectId;
|
|
461
|
+
if (args.user_id !== undefined) payload.user_id = args.user_id;
|
|
462
|
+
if (args.agent_id !== undefined) payload.agent_id = args.agent_id;
|
|
375
463
|
if (args.session_id !== undefined) payload.session_id = args.session_id;
|
|
376
464
|
if (args.status !== undefined) payload.status = args.status;
|
|
377
465
|
if (args.priority !== undefined) payload.priority = args.priority;
|
|
378
466
|
if (args.blocked_reason !== undefined) payload.blocked_reason = args.blocked_reason;
|
|
379
467
|
if (args.files !== undefined) payload.files = args.files;
|
|
468
|
+
if (args.due_at !== undefined) payload.due_at = args.due_at;
|
|
469
|
+
if (args.remind_at !== undefined) payload.remind_at = args.remind_at;
|
|
470
|
+
if (args.recurrence !== undefined) payload.recurrence = args.recurrence;
|
|
471
|
+
if (args.snooze_until !== undefined) payload.snooze_until = args.snooze_until;
|
|
380
472
|
|
|
381
473
|
return requestJson(`${apiBaseUrl}/actions`, {
|
|
382
474
|
method: 'POST',
|
|
@@ -387,14 +479,28 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
387
479
|
|
|
388
480
|
const brainActionList = async (args: {
|
|
389
481
|
project_id?: string;
|
|
482
|
+
include_ancestors?: boolean;
|
|
483
|
+
include_children?: boolean;
|
|
390
484
|
include_global?: boolean;
|
|
485
|
+
due_only?: boolean;
|
|
486
|
+
before?: string;
|
|
487
|
+
user_id?: string;
|
|
391
488
|
status?: string;
|
|
392
489
|
limit?: number;
|
|
393
490
|
} = {}) => {
|
|
394
491
|
const targetProjectId = args.project_id || defaultProjectId;
|
|
395
492
|
const query = new URLSearchParams();
|
|
396
493
|
if (targetProjectId) query.set('project_id', targetProjectId);
|
|
494
|
+
if (args.include_ancestors !== undefined) {
|
|
495
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
496
|
+
}
|
|
497
|
+
if (args.include_children !== undefined) {
|
|
498
|
+
query.set('include_children', String(args.include_children));
|
|
499
|
+
}
|
|
397
500
|
if (args.include_global !== undefined) query.set('include_global', String(args.include_global));
|
|
501
|
+
if (args.due_only !== undefined) query.set('due_only', String(args.due_only));
|
|
502
|
+
if (args.before) query.set('before', args.before);
|
|
503
|
+
if (args.user_id) query.set('user_id', args.user_id);
|
|
398
504
|
if (args.status) query.set('status', args.status);
|
|
399
505
|
if (args.limit !== undefined) query.set('limit', String(args.limit));
|
|
400
506
|
|
|
@@ -413,6 +519,12 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
413
519
|
description?: string;
|
|
414
520
|
blocked_reason?: string;
|
|
415
521
|
resolved_by_session_id?: string;
|
|
522
|
+
due_at?: string | null;
|
|
523
|
+
remind_at?: string | null;
|
|
524
|
+
recurrence?: string | null;
|
|
525
|
+
snooze_until?: string | null;
|
|
526
|
+
user_id?: string | null;
|
|
527
|
+
agent_id?: string | null;
|
|
416
528
|
}) => {
|
|
417
529
|
const payload: Record<string, any> = {};
|
|
418
530
|
if (args.status !== undefined) payload.status = args.status;
|
|
@@ -421,6 +533,12 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
421
533
|
if (args.description !== undefined) payload.description = args.description;
|
|
422
534
|
if (args.blocked_reason !== undefined) payload.blocked_reason = args.blocked_reason;
|
|
423
535
|
if (args.resolved_by_session_id !== undefined) payload.resolved_by_session_id = args.resolved_by_session_id;
|
|
536
|
+
if (args.due_at !== undefined) payload.due_at = args.due_at;
|
|
537
|
+
if (args.remind_at !== undefined) payload.remind_at = args.remind_at;
|
|
538
|
+
if (args.recurrence !== undefined) payload.recurrence = args.recurrence;
|
|
539
|
+
if (args.snooze_until !== undefined) payload.snooze_until = args.snooze_until;
|
|
540
|
+
if (args.user_id !== undefined) payload.user_id = args.user_id;
|
|
541
|
+
if (args.agent_id !== undefined) payload.agent_id = args.agent_id;
|
|
424
542
|
|
|
425
543
|
return requestJson(`${apiBaseUrl}/actions/${encodeURIComponent(args.id)}`, {
|
|
426
544
|
method: 'PATCH',
|
|
@@ -429,10 +547,44 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
429
547
|
});
|
|
430
548
|
};
|
|
431
549
|
|
|
550
|
+
const brainActionDue = async (args: {
|
|
551
|
+
project_id?: string;
|
|
552
|
+
include_ancestors?: boolean;
|
|
553
|
+
include_children?: boolean;
|
|
554
|
+
include_global?: boolean;
|
|
555
|
+
before?: string;
|
|
556
|
+
user_id?: string;
|
|
557
|
+
limit?: number;
|
|
558
|
+
} = {}) => {
|
|
559
|
+
const targetProjectId = args.project_id || defaultProjectId;
|
|
560
|
+
const query = new URLSearchParams();
|
|
561
|
+
if (targetProjectId) query.set('project_id', targetProjectId);
|
|
562
|
+
if (args.include_ancestors !== undefined) {
|
|
563
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
564
|
+
}
|
|
565
|
+
if (args.include_children !== undefined) {
|
|
566
|
+
query.set('include_children', String(args.include_children));
|
|
567
|
+
}
|
|
568
|
+
if (args.include_global !== undefined) query.set('include_global', String(args.include_global));
|
|
569
|
+
if (args.before) query.set('before', args.before);
|
|
570
|
+
if (args.user_id) query.set('user_id', args.user_id);
|
|
571
|
+
if (args.limit !== undefined) query.set('limit', String(args.limit));
|
|
572
|
+
|
|
573
|
+
const url = `${apiBaseUrl}/actions/due${query.toString() ? `?${query.toString()}` : ''}`;
|
|
574
|
+
return requestJson(url, {
|
|
575
|
+
method: 'GET',
|
|
576
|
+
headers: authHeaders,
|
|
577
|
+
});
|
|
578
|
+
};
|
|
579
|
+
|
|
432
580
|
const brainSessions = async (args: {
|
|
433
581
|
mode?: 'list' | 'get' | 'replay';
|
|
434
582
|
session_id?: string;
|
|
435
583
|
project_id?: string;
|
|
584
|
+
include_ancestors?: boolean;
|
|
585
|
+
include_children?: boolean;
|
|
586
|
+
include_global?: boolean;
|
|
587
|
+
user_id?: string;
|
|
436
588
|
status?: string;
|
|
437
589
|
agent_name?: string;
|
|
438
590
|
limit?: number;
|
|
@@ -444,16 +596,12 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
444
596
|
content: [
|
|
445
597
|
{
|
|
446
598
|
type: 'text' as const,
|
|
447
|
-
text: JSON.stringify(
|
|
448
|
-
{
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
message: `session_id is required when mode is '${mode}'`,
|
|
452
|
-
},
|
|
599
|
+
text: JSON.stringify({
|
|
600
|
+
error: {
|
|
601
|
+
code: 'SCHEMA_INVALID',
|
|
602
|
+
message: `session_id is required when mode is '${mode}'`,
|
|
453
603
|
},
|
|
454
|
-
|
|
455
|
-
2
|
|
456
|
-
),
|
|
604
|
+
}),
|
|
457
605
|
},
|
|
458
606
|
],
|
|
459
607
|
isError: true,
|
|
@@ -469,6 +617,16 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
469
617
|
const targetProjectId = args.project_id || defaultProjectId;
|
|
470
618
|
const query = new URLSearchParams();
|
|
471
619
|
if (targetProjectId) query.set('project_id', targetProjectId);
|
|
620
|
+
if (args.include_ancestors !== undefined) {
|
|
621
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
622
|
+
}
|
|
623
|
+
if (args.include_children !== undefined) {
|
|
624
|
+
query.set('include_children', String(args.include_children));
|
|
625
|
+
}
|
|
626
|
+
if (args.include_global !== undefined) {
|
|
627
|
+
query.set('include_global', String(args.include_global));
|
|
628
|
+
}
|
|
629
|
+
if (args.user_id) query.set('user_id', args.user_id);
|
|
472
630
|
if (args.status) query.set('status', args.status);
|
|
473
631
|
if (args.agent_name) query.set('agent_name', args.agent_name);
|
|
474
632
|
if (args.limit !== undefined) query.set('limit', String(args.limit));
|
|
@@ -501,15 +659,110 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
501
659
|
};
|
|
502
660
|
|
|
503
661
|
const brainGraph = async (args: {
|
|
662
|
+
mode?: 'query' | 'upsert_entity' | 'link' | 'unlink';
|
|
504
663
|
project_id?: string;
|
|
505
|
-
scope?: 'project' | 'global' | 'unknown';
|
|
664
|
+
scope?: 'project' | 'global' | 'unknown' | string;
|
|
665
|
+
include_ancestors?: boolean;
|
|
666
|
+
include_children?: boolean;
|
|
667
|
+
include_global?: boolean;
|
|
668
|
+
depth?: number;
|
|
669
|
+
node_id?: string;
|
|
670
|
+
entity_type?: string;
|
|
671
|
+
relation?: string;
|
|
672
|
+
user_id?: string;
|
|
673
|
+
agent_id?: string;
|
|
674
|
+
id?: string;
|
|
675
|
+
entity_id?: string;
|
|
676
|
+
name?: string;
|
|
677
|
+
description?: string;
|
|
678
|
+
external_ref?: string;
|
|
679
|
+
metadata?: Record<string, unknown> | string;
|
|
680
|
+
source_type?: string;
|
|
681
|
+
source_id?: string;
|
|
682
|
+
target_type?: string;
|
|
683
|
+
target_id?: string;
|
|
506
684
|
limit?: number;
|
|
507
685
|
} = {}) => {
|
|
686
|
+
const mode = args.mode || 'query';
|
|
687
|
+
|
|
688
|
+
if (mode === 'upsert_entity') {
|
|
689
|
+
const check = validateScopeAndProject(args.scope, args.project_id, defaultProjectId);
|
|
690
|
+
if (check.error) {
|
|
691
|
+
return {
|
|
692
|
+
content: [{ type: 'text' as const, text: JSON.stringify({ error: check.error }) }],
|
|
693
|
+
isError: true,
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
const payload: Record<string, any> = {
|
|
697
|
+
scope: args.scope,
|
|
698
|
+
};
|
|
699
|
+
if (check.effectiveProjectId) payload.project_id = check.effectiveProjectId;
|
|
700
|
+
const entityId = args.entity_id ?? args.id;
|
|
701
|
+
if (entityId !== undefined) payload.id = entityId;
|
|
702
|
+
if (args.entity_type !== undefined) payload.entity_type = args.entity_type;
|
|
703
|
+
if (args.name !== undefined) payload.name = args.name;
|
|
704
|
+
if (args.description !== undefined) payload.description = args.description;
|
|
705
|
+
if (args.external_ref !== undefined) payload.external_ref = args.external_ref;
|
|
706
|
+
if (args.metadata !== undefined) payload.metadata = args.metadata;
|
|
707
|
+
if (args.user_id !== undefined) payload.user_id = args.user_id;
|
|
708
|
+
if (args.agent_id !== undefined) payload.agent_id = args.agent_id;
|
|
709
|
+
|
|
710
|
+
return requestJson(`${apiBaseUrl}/graph/entities`, {
|
|
711
|
+
method: 'POST',
|
|
712
|
+
headers: authHeaders,
|
|
713
|
+
body: JSON.stringify(payload),
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (mode === 'link') {
|
|
718
|
+
const payload: Record<string, any> = {};
|
|
719
|
+
if (args.source_type !== undefined) payload.source_type = args.source_type;
|
|
720
|
+
if (args.source_id !== undefined) payload.source_id = args.source_id;
|
|
721
|
+
if (args.target_type !== undefined) payload.target_type = args.target_type;
|
|
722
|
+
if (args.target_id !== undefined) payload.target_id = args.target_id;
|
|
723
|
+
if (args.relation !== undefined) payload.relation = args.relation;
|
|
724
|
+
if (args.metadata !== undefined) payload.metadata = args.metadata;
|
|
725
|
+
|
|
726
|
+
return requestJson(`${apiBaseUrl}/graph/edges`, {
|
|
727
|
+
method: 'POST',
|
|
728
|
+
headers: authHeaders,
|
|
729
|
+
body: JSON.stringify(payload),
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (mode === 'unlink') {
|
|
734
|
+
const payload: Record<string, any> = {};
|
|
735
|
+
if (args.id !== undefined) payload.id = args.id;
|
|
736
|
+
if (args.source_id !== undefined) payload.source_id = args.source_id;
|
|
737
|
+
if (args.target_id !== undefined) payload.target_id = args.target_id;
|
|
738
|
+
if (args.relation !== undefined) payload.relation = args.relation;
|
|
739
|
+
|
|
740
|
+
return requestJson(`${apiBaseUrl}/graph/edges`, {
|
|
741
|
+
method: 'DELETE',
|
|
742
|
+
headers: authHeaders,
|
|
743
|
+
body: JSON.stringify(payload),
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
|
|
508
747
|
const targetProjectId =
|
|
509
748
|
args.project_id || (args.scope === 'global' || args.scope === 'unknown' ? undefined : defaultProjectId);
|
|
510
749
|
const query = new URLSearchParams();
|
|
511
750
|
if (targetProjectId) query.set('project_id', targetProjectId);
|
|
512
751
|
if (args.scope) query.set('scope', args.scope);
|
|
752
|
+
if (args.include_ancestors !== undefined) {
|
|
753
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
754
|
+
}
|
|
755
|
+
if (args.include_children !== undefined) {
|
|
756
|
+
query.set('include_children', String(args.include_children));
|
|
757
|
+
}
|
|
758
|
+
if (args.include_global !== undefined) {
|
|
759
|
+
query.set('include_global', String(args.include_global));
|
|
760
|
+
}
|
|
761
|
+
if (args.depth !== undefined) query.set('depth', String(args.depth));
|
|
762
|
+
if (args.node_id) query.set('node_id', args.node_id);
|
|
763
|
+
if (args.entity_type) query.set('entity_type', args.entity_type);
|
|
764
|
+
if (args.relation) query.set('relation', args.relation);
|
|
765
|
+
if (args.user_id) query.set('user_id', args.user_id);
|
|
513
766
|
if (args.limit !== undefined) query.set('limit', String(args.limit));
|
|
514
767
|
|
|
515
768
|
const url = `${apiBaseUrl}/graph${query.toString() ? `?${query.toString()}` : ''}`;
|
|
@@ -528,6 +781,7 @@ export function createBrainMcpHandlers(options: BrainMcpServerOptions = {}) {
|
|
|
528
781
|
brainActionAdd,
|
|
529
782
|
brainActionList,
|
|
530
783
|
brainActionUpdate,
|
|
784
|
+
brainActionDue,
|
|
531
785
|
brainSessions,
|
|
532
786
|
brainSessionEnd,
|
|
533
787
|
brainGraph,
|
|
@@ -540,7 +794,7 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
540
794
|
const server = new McpServer(
|
|
541
795
|
{
|
|
542
796
|
name: 'neuralbrain',
|
|
543
|
-
version: '0.0
|
|
797
|
+
version: '0.1.0',
|
|
544
798
|
},
|
|
545
799
|
{
|
|
546
800
|
instructions: MCP_INSTRUCTIONS,
|
|
@@ -552,23 +806,109 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
552
806
|
// 1. brain_search
|
|
553
807
|
server.tool(
|
|
554
808
|
'brain_search',
|
|
555
|
-
'Search across memories, trajectories, observations, and
|
|
809
|
+
'Search across memories, trajectories, observations, summaries, entities, and actions with 3-signal hybrid dense + FTS5 BM25 + Entity-Graph RRF 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.',
|
|
556
810
|
{
|
|
557
811
|
q: z.string().describe('Search query text'),
|
|
558
812
|
record_types: z
|
|
559
813
|
.array(z.string())
|
|
560
814
|
.default(['note', 'trajectory'])
|
|
561
815
|
.describe(
|
|
562
|
-
"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
|
|
816
|
+
"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), 'observation' (raw tool calls/prompts), 'entity' (persistent entity nodes), 'action' (Next Actions and reminders)."
|
|
563
817
|
),
|
|
564
818
|
project_id: z
|
|
565
819
|
.string()
|
|
566
820
|
.optional()
|
|
567
|
-
.describe('Project ID
|
|
821
|
+
.describe('Project ID or hierarchical slug (e.g. "neuralbrain" or "acme/socials/calendar"); omit for global-only. Never pass a filesystem path.'),
|
|
822
|
+
include_ancestors: z
|
|
823
|
+
.boolean()
|
|
824
|
+
.default(true)
|
|
825
|
+
.describe('Whether to include ancestor projects when project_id is hierarchical (default true)'),
|
|
826
|
+
include_children: z
|
|
827
|
+
.boolean()
|
|
828
|
+
.default(false)
|
|
829
|
+
.describe('Whether to include child subprojects below project_id (default false)'),
|
|
568
830
|
include_global: z.boolean().default(true).describe('Whether to include global records when project_id is specified'),
|
|
831
|
+
include_history: z
|
|
832
|
+
.boolean()
|
|
833
|
+
.default(false)
|
|
834
|
+
.describe('Whether to include superseded historical versions of notes and summaries (default false)'),
|
|
835
|
+
user_id: z.string().optional().describe('Optional user_id filter'),
|
|
836
|
+
after: z.string().optional().describe('ISO-8601 lower bound timestamp filter'),
|
|
837
|
+
before: z.string().optional().describe('ISO-8601 upper bound timestamp filter'),
|
|
838
|
+
as_of: z.string().optional().describe('ISO-8601 point-in-time validity filter for notes (valid_from <= as_of <= valid_until)'),
|
|
839
|
+
reference_date: z
|
|
840
|
+
.string()
|
|
841
|
+
.optional()
|
|
842
|
+
.describe(
|
|
843
|
+
'Optional ISO-8601 reference timestamp used to anchor relative temporal expressions in q (e.g. "four weeks ago", "last month", "in March"); defaults to current time'
|
|
844
|
+
),
|
|
845
|
+
temporal_bias: z
|
|
846
|
+
.enum(['none', 'recent', 'upcoming'])
|
|
847
|
+
.optional()
|
|
848
|
+
.describe("Optional temporal ranking bias ('none', 'recent', or 'upcoming')"),
|
|
849
|
+
snippet_mode: z
|
|
850
|
+
.enum(['query_focused', 'condensed', 'raw'])
|
|
851
|
+
.optional()
|
|
852
|
+
.describe(
|
|
853
|
+
"Observation snippet mode: 'query_focused' (default — extracts query-matching passages from full observation text), 'condensed' (uses precomputed extractive condensed_text), or 'raw' (full raw input/output)"
|
|
854
|
+
),
|
|
855
|
+
max_record_chars: z
|
|
856
|
+
.number()
|
|
857
|
+
.int()
|
|
858
|
+
.min(32)
|
|
859
|
+
.max(100000)
|
|
860
|
+
.optional()
|
|
861
|
+
.describe('Optional character budget cap for returned observation fields and snippet'),
|
|
862
|
+
kind_weights: z
|
|
863
|
+
.object({
|
|
864
|
+
prompt: z.number().min(0.1).max(5).optional(),
|
|
865
|
+
response: z.number().min(0.1).max(5).optional(),
|
|
866
|
+
tool_call: z.number().min(0.1).max(5).optional(),
|
|
867
|
+
})
|
|
868
|
+
.optional()
|
|
869
|
+
.describe('Optional per-kind score multipliers overriding intent-aware defaults for observations'),
|
|
870
|
+
max_kind_share: z
|
|
871
|
+
.object({
|
|
872
|
+
prompt: z.number().gt(0).max(1).optional(),
|
|
873
|
+
response: z.number().gt(0).max(1).optional(),
|
|
874
|
+
tool_call: z.number().gt(0).max(1).optional(),
|
|
875
|
+
})
|
|
876
|
+
.optional()
|
|
877
|
+
.describe('Optional maximum result-set share (0..1] per observation kind with score-ordered backfill'),
|
|
878
|
+
entity_type: z
|
|
879
|
+
.string()
|
|
880
|
+
.optional()
|
|
881
|
+
.describe("Optional entity_type filter (e.g. 'brand', 'person', 'asset', 'metric', 'document', 'tool')"),
|
|
882
|
+
memory_layer: z
|
|
883
|
+
.enum(['semantic', 'procedural'])
|
|
884
|
+
.optional()
|
|
885
|
+
.describe("Optional note layer filter: 'semantic' (fact/architecture/preference) or 'procedural' (workflow/pattern/lesson/bug)"),
|
|
886
|
+
signal_tag: z
|
|
887
|
+
.enum(['preference', 'state_update', 'completed_action', 'planned_action'])
|
|
888
|
+
.optional()
|
|
889
|
+
.describe(
|
|
890
|
+
"Optional observation linguistic signal tag filter ('preference', 'state_update', 'completed_action', or 'planned_action')"
|
|
891
|
+
),
|
|
569
892
|
type: z.array(z.string()).optional().describe('Note type filter (fact, architecture, pattern, workflow, bug, preference, lesson)'),
|
|
570
893
|
file_path: z.string().optional().describe('File path filter ("what do we know about this file?")'),
|
|
571
|
-
|
|
894
|
+
include_sources: z
|
|
895
|
+
.boolean()
|
|
896
|
+
.default(false)
|
|
897
|
+
.describe('Include paginated source provenance entries (with observation titles) on summary results (default false)'),
|
|
898
|
+
sources_limit: z
|
|
899
|
+
.number()
|
|
900
|
+
.int()
|
|
901
|
+
.min(1)
|
|
902
|
+
.max(100)
|
|
903
|
+
.default(20)
|
|
904
|
+
.describe('Maximum number of source entries per summary when include_sources is true (default 20)'),
|
|
905
|
+
sources_offset: z
|
|
906
|
+
.number()
|
|
907
|
+
.int()
|
|
908
|
+
.min(0)
|
|
909
|
+
.default(0)
|
|
910
|
+
.describe('Offset into summary sources for pagination when include_sources is true (default 0)'),
|
|
911
|
+
limit: z.number().int().min(1).max(100).default(10).describe('Maximum number of results to return'),
|
|
572
912
|
},
|
|
573
913
|
async (args) => {
|
|
574
914
|
return handlers.brainSearch(args);
|
|
@@ -588,12 +928,17 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
588
928
|
.string()
|
|
589
929
|
.optional()
|
|
590
930
|
.describe(
|
|
591
|
-
"Required iff scope is 'project'. Use the project root folder name
|
|
931
|
+
"Required iff scope is 'project'. Use the project root folder name or hierarchical slug (e.g. 'neuralbrain' or 'acme/socials/calendar') — never a filesystem path. If unsure, use scope 'unknown'"
|
|
592
932
|
),
|
|
933
|
+
user_id: z.string().optional().describe('Optional user_id attribution'),
|
|
934
|
+
agent_id: z.string().optional().describe('Optional agent_id provenance (stored, never filtered)'),
|
|
593
935
|
session_id: z.string().optional().describe('Optional session ID that authored this note'),
|
|
594
936
|
concepts: z.array(z.string()).optional().describe('Concepts associated with this note'),
|
|
595
937
|
files: z.array(z.string()).optional().describe('File paths associated with this note'),
|
|
596
938
|
supersedes: z.string().optional().describe('Previous note id being superseded'),
|
|
939
|
+
event_at: z.string().optional().describe('Optional ISO-8601 timestamp when the event occurred'),
|
|
940
|
+
valid_from: z.string().optional().describe('Optional ISO-8601 start of fact validity window'),
|
|
941
|
+
valid_until: z.string().optional().describe('Optional ISO-8601 end of fact validity window'),
|
|
597
942
|
},
|
|
598
943
|
async (args) => {
|
|
599
944
|
return handlers.brainSave(args);
|
|
@@ -603,14 +948,27 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
603
948
|
// 3. brain_recent_failures
|
|
604
949
|
server.tool(
|
|
605
950
|
'brain_recent_failures',
|
|
606
|
-
'Retrieve recent failure patterns and counts. Returns { task_type, error_text, count, last_seen_at }[] where count is from SQL.',
|
|
951
|
+
'Retrieve recent failure patterns and counts. Returns { task_type, error_text, count, last_seen_at, project_id, match_tier }[] where count is from SQL.',
|
|
607
952
|
{
|
|
608
953
|
project_id: z
|
|
609
954
|
.string()
|
|
610
955
|
.optional()
|
|
611
|
-
.describe('Project ID to filter by (
|
|
956
|
+
.describe('Project ID or hierarchical slug to filter by (never a filesystem path); omit for global'),
|
|
612
957
|
task_type: z.string().optional().describe('Task type filter'),
|
|
613
|
-
|
|
958
|
+
include_ancestors: z
|
|
959
|
+
.boolean()
|
|
960
|
+
.default(true)
|
|
961
|
+
.describe('Whether to include ancestor projects when project_id is hierarchical (default true)'),
|
|
962
|
+
include_children: z
|
|
963
|
+
.boolean()
|
|
964
|
+
.default(false)
|
|
965
|
+
.describe('Whether to include child subprojects below project_id (default false)'),
|
|
966
|
+
include_global: z
|
|
967
|
+
.boolean()
|
|
968
|
+
.default(true)
|
|
969
|
+
.describe('Whether to include global failure patterns when project_id is specified (default true)'),
|
|
970
|
+
user_id: z.string().optional().describe('Optional user_id filter'),
|
|
971
|
+
limit: z.number().int().min(1).max(200).default(5).describe('Maximum number of failures to return'),
|
|
614
972
|
},
|
|
615
973
|
async (args) => {
|
|
616
974
|
return handlers.brainRecentFailures(args);
|
|
@@ -626,7 +984,7 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
626
984
|
.string()
|
|
627
985
|
.optional()
|
|
628
986
|
.describe('Filter candidates by project (use the project root folder name, e.g. "neuralbrain"; never a subfolder or filesystem path)'),
|
|
629
|
-
limit: z.number().int().optional().describe('Maximum number of candidate leases to retrieve'),
|
|
987
|
+
limit: z.number().int().min(1).max(200).optional().describe('Maximum number of candidate leases to retrieve'),
|
|
630
988
|
},
|
|
631
989
|
async (args) => {
|
|
632
990
|
return handlers.brainConsolidateCandidates(args);
|
|
@@ -658,7 +1016,7 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
658
1016
|
// 6. brain_action_add
|
|
659
1017
|
server.tool(
|
|
660
1018
|
'brain_action_add',
|
|
661
|
-
'Create a Next Action to surface unfinished work, follow-ups, or blockers for future sessions. Scope is REQUIRED (project, global, or unknown).',
|
|
1019
|
+
'Create a Next Action (or scheduled/recurring reminder) to surface unfinished work, follow-ups, or blockers for future sessions. Scope is REQUIRED (project, global, or unknown).',
|
|
662
1020
|
{
|
|
663
1021
|
title: z.string().describe('Short, actionable title of the next action'),
|
|
664
1022
|
description: z.string().optional().describe('Detailed description or context for the next action'),
|
|
@@ -666,12 +1024,18 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
666
1024
|
project_id: z
|
|
667
1025
|
.string()
|
|
668
1026
|
.optional()
|
|
669
|
-
.describe("Required iff scope is 'project'. Use the project root folder name
|
|
1027
|
+
.describe("Required iff scope is 'project'. Use the project root folder name or hierarchical slug (e.g. 'neuralbrain' or 'acme/socials/calendar') — never a filesystem path"),
|
|
1028
|
+
user_id: z.string().optional().describe('Optional user_id attribution'),
|
|
1029
|
+
agent_id: z.string().optional().describe('Optional agent_id provenance (stored, never filtered)'),
|
|
670
1030
|
session_id: z.string().optional().describe('Optional session ID that created this action'),
|
|
671
1031
|
status: z.enum(['ready', 'blocked', 'in_progress', 'done', 'dismissed']).optional().describe("Action status ('ready', 'blocked', 'in_progress', 'done', 'dismissed')"),
|
|
672
1032
|
priority: z.enum(['low', 'normal', 'high', 'urgent']).optional().describe("Priority level ('low', 'normal', 'high', 'urgent')"),
|
|
673
1033
|
blocked_reason: z.string().optional().describe('Reason the action is blocked, if status is blocked'),
|
|
674
1034
|
files: z.array(z.string()).optional().describe('File paths associated with this action'),
|
|
1035
|
+
due_at: z.string().optional().describe('Optional ISO-8601 due date/time (normalized to UTC)'),
|
|
1036
|
+
remind_at: z.string().optional().describe('Optional ISO-8601 reminder trigger date/time (normalized to UTC)'),
|
|
1037
|
+
recurrence: z.string().optional().describe("Optional recurrence expression: 5-field UTC cron, macro (@daily, @weekly), or ISO-8601 duration (P1D, P1W, PT2H)"),
|
|
1038
|
+
snooze_until: z.string().optional().describe('Optional ISO-8601 timestamp until which reminders are snoozed'),
|
|
675
1039
|
},
|
|
676
1040
|
async (args) => {
|
|
677
1041
|
return handlers.brainActionAdd(args);
|
|
@@ -681,15 +1045,26 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
681
1045
|
// 7. brain_action_list
|
|
682
1046
|
server.tool(
|
|
683
1047
|
'brain_action_list',
|
|
684
|
-
'List Next Actions for a project (and optionally global actions), filtered by status.',
|
|
1048
|
+
'List Next Actions for a project (and optionally ancestors, children, and global actions), filtered by status, due_only, before, or user_id.',
|
|
685
1049
|
{
|
|
686
1050
|
project_id: z
|
|
687
1051
|
.string()
|
|
688
1052
|
.optional()
|
|
689
|
-
.describe('Project ID to filter by (
|
|
690
|
-
|
|
1053
|
+
.describe('Project ID or hierarchical slug to filter by (never a filesystem path)'),
|
|
1054
|
+
include_ancestors: z
|
|
1055
|
+
.boolean()
|
|
1056
|
+
.default(true)
|
|
1057
|
+
.describe('Whether to include ancestor projects when project_id is hierarchical (default true)'),
|
|
1058
|
+
include_children: z
|
|
1059
|
+
.boolean()
|
|
1060
|
+
.default(false)
|
|
1061
|
+
.describe('Whether to include child subprojects below project_id (default false)'),
|
|
1062
|
+
include_global: z.boolean().optional().describe('Whether to include global actions when project_id is specified (default true)'),
|
|
1063
|
+
due_only: z.boolean().optional().describe('When true, return only open actions that are currently due/reminded and not snoozed'),
|
|
1064
|
+
before: z.string().optional().describe('ISO-8601 upper bound cutoff for due_at / remind_at'),
|
|
1065
|
+
user_id: z.string().optional().describe('Optional user_id filter'),
|
|
691
1066
|
status: z.string().optional().describe("Filter by status (e.g. 'ready', 'in_progress', 'blocked', 'done')"),
|
|
692
|
-
limit: z.number().int().optional().describe('Maximum number of actions to return'),
|
|
1067
|
+
limit: z.number().int().min(1).max(200).optional().describe('Maximum number of actions to return'),
|
|
693
1068
|
},
|
|
694
1069
|
async (args) => {
|
|
695
1070
|
return handlers.brainActionList(args);
|
|
@@ -699,7 +1074,7 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
699
1074
|
// 8. brain_action_update
|
|
700
1075
|
server.tool(
|
|
701
1076
|
'brain_action_update',
|
|
702
|
-
'Update an existing Next Action (status, priority, title, description, blocked_reason, or resolved_by_session_id).',
|
|
1077
|
+
'Update an existing Next Action (status, priority, title, description, blocked_reason, due_at, remind_at, recurrence, snooze_until, user_id, agent_id, or resolved_by_session_id). Completing a recurring action spawns its next occurrence.',
|
|
703
1078
|
{
|
|
704
1079
|
id: z.string().describe('ID of the action to update'),
|
|
705
1080
|
status: z.enum(['ready', 'blocked', 'in_progress', 'done', 'dismissed']).optional().describe("Updated status ('ready', 'blocked', 'in_progress', 'done', 'dismissed')"),
|
|
@@ -708,13 +1083,49 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
708
1083
|
description: z.string().optional().describe('Updated description'),
|
|
709
1084
|
blocked_reason: z.string().optional().describe('Updated blocked reason'),
|
|
710
1085
|
resolved_by_session_id: z.string().optional().describe('Session ID that resolved this action'),
|
|
1086
|
+
due_at: z.string().nullable().optional().describe('Updated ISO-8601 due date/time (or null to clear)'),
|
|
1087
|
+
remind_at: z.string().nullable().optional().describe('Updated ISO-8601 reminder trigger date/time (or null to clear)'),
|
|
1088
|
+
recurrence: z.string().nullable().optional().describe('Updated cron/macro/ISO-8601 recurrence expression (or null to clear)'),
|
|
1089
|
+
snooze_until: z.string().nullable().optional().describe('Updated ISO-8601 snooze cutoff timestamp (or null to clear)'),
|
|
1090
|
+
user_id: z.string().nullable().optional().describe('Updated user_id attribution (or null to clear)'),
|
|
1091
|
+
agent_id: z.string().nullable().optional().describe('Updated agent_id provenance (or null to clear)'),
|
|
711
1092
|
},
|
|
712
1093
|
async (args) => {
|
|
713
1094
|
return handlers.brainActionUpdate(args);
|
|
714
1095
|
}
|
|
715
1096
|
);
|
|
716
1097
|
|
|
717
|
-
// 9.
|
|
1098
|
+
// 9. brain_action_due
|
|
1099
|
+
server.tool(
|
|
1100
|
+
'brain_action_due',
|
|
1101
|
+
'List due, reminded, or overdue Next Actions that are open and not snoozed.',
|
|
1102
|
+
{
|
|
1103
|
+
project_id: z
|
|
1104
|
+
.string()
|
|
1105
|
+
.optional()
|
|
1106
|
+
.describe('Project ID or hierarchical slug to filter by (never a filesystem path)'),
|
|
1107
|
+
include_ancestors: z
|
|
1108
|
+
.boolean()
|
|
1109
|
+
.default(true)
|
|
1110
|
+
.describe('Whether to include ancestor projects when project_id is hierarchical (default true)'),
|
|
1111
|
+
include_children: z
|
|
1112
|
+
.boolean()
|
|
1113
|
+
.default(false)
|
|
1114
|
+
.describe('Whether to include child subprojects below project_id (default false)'),
|
|
1115
|
+
include_global: z
|
|
1116
|
+
.boolean()
|
|
1117
|
+
.default(true)
|
|
1118
|
+
.describe('Whether to include global actions when project_id is specified (default true)'),
|
|
1119
|
+
before: z.string().optional().describe('ISO-8601 upper bound cutoff timestamp (defaults to now)'),
|
|
1120
|
+
user_id: z.string().optional().describe('Optional user_id filter'),
|
|
1121
|
+
limit: z.number().int().min(1).max(200).optional().describe('Maximum number of due actions to return'),
|
|
1122
|
+
},
|
|
1123
|
+
async (args) => {
|
|
1124
|
+
return handlers.brainActionDue(args);
|
|
1125
|
+
}
|
|
1126
|
+
);
|
|
1127
|
+
|
|
1128
|
+
// 10. brain_sessions
|
|
718
1129
|
server.tool(
|
|
719
1130
|
'brain_sessions',
|
|
720
1131
|
'Inspect prior agent sessions: list sessions, fetch a single session with its details, or replay a session timeline chronologically.',
|
|
@@ -730,17 +1141,30 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
730
1141
|
project_id: z
|
|
731
1142
|
.string()
|
|
732
1143
|
.optional()
|
|
733
|
-
.describe('Project ID to filter by when listing sessions (
|
|
1144
|
+
.describe('Project ID or hierarchical slug to filter by when listing sessions (never a filesystem path)'),
|
|
1145
|
+
include_ancestors: z
|
|
1146
|
+
.boolean()
|
|
1147
|
+
.default(true)
|
|
1148
|
+
.describe('Whether to include ancestor projects when listing sessions (default true)'),
|
|
1149
|
+
include_children: z
|
|
1150
|
+
.boolean()
|
|
1151
|
+
.default(false)
|
|
1152
|
+
.describe('Whether to include child subprojects when listing sessions (default false)'),
|
|
1153
|
+
include_global: z
|
|
1154
|
+
.boolean()
|
|
1155
|
+
.default(false)
|
|
1156
|
+
.describe('Whether to include global sessions when project_id is specified (default false)'),
|
|
1157
|
+
user_id: z.string().optional().describe('Optional user_id filter when listing sessions'),
|
|
734
1158
|
status: z.string().optional().describe("Filter sessions by status when listing (e.g. 'active', 'completed', 'paused', 'abandoned')"),
|
|
735
1159
|
agent_name: z.string().optional().describe('Filter sessions by agent name when listing'),
|
|
736
|
-
limit: z.number().int().optional().describe('Maximum number of sessions to return when listing'),
|
|
1160
|
+
limit: z.number().int().min(1).max(200).optional().describe('Maximum number of sessions to return when listing'),
|
|
737
1161
|
},
|
|
738
1162
|
async (args) => {
|
|
739
1163
|
return handlers.brainSessions(args);
|
|
740
1164
|
}
|
|
741
1165
|
);
|
|
742
1166
|
|
|
743
|
-
//
|
|
1167
|
+
// 11. brain_session_end
|
|
744
1168
|
server.tool(
|
|
745
1169
|
'brain_session_end',
|
|
746
1170
|
'End or pause a session and record a clean cross-agent handoff summary, files touched, and optional handoff_summary_id.',
|
|
@@ -759,20 +1183,67 @@ export function createBrainMcpServer(options: BrainMcpServerOptions = {}): McpSe
|
|
|
759
1183
|
}
|
|
760
1184
|
);
|
|
761
1185
|
|
|
762
|
-
//
|
|
1186
|
+
// 12. brain_graph
|
|
763
1187
|
server.tool(
|
|
764
1188
|
'brain_graph',
|
|
765
|
-
'Explore the relational knowledge graph across notes, lessons, concepts, files, sessions, actions, and summaries.',
|
|
1189
|
+
'Explore or mutate the relational knowledge graph across notes, lessons, concepts, files, sessions, actions, entities, and summaries. Supports mode: query (1..3 hop BFS), upsert_entity (requires explicit scope), link, and unlink.',
|
|
766
1190
|
{
|
|
1191
|
+
mode: z
|
|
1192
|
+
.enum(['query', 'upsert_entity', 'link', 'unlink'])
|
|
1193
|
+
.default('query')
|
|
1194
|
+
.describe("Operation mode: 'query' (default), 'upsert_entity', 'link', or 'unlink'"),
|
|
767
1195
|
project_id: z
|
|
768
1196
|
.string()
|
|
769
1197
|
.optional()
|
|
770
|
-
.describe('Project ID
|
|
1198
|
+
.describe('Project ID or hierarchical slug (required iff mode is upsert_entity and scope is project; never a filesystem path)'),
|
|
771
1199
|
scope: z
|
|
772
1200
|
.enum(['project', 'global', 'unknown'])
|
|
773
1201
|
.optional()
|
|
774
|
-
.describe("
|
|
775
|
-
|
|
1202
|
+
.describe("Scope ('project', 'global', or 'unknown'). REQUIRED when mode is 'upsert_entity'"),
|
|
1203
|
+
include_ancestors: z
|
|
1204
|
+
.boolean()
|
|
1205
|
+
.default(true)
|
|
1206
|
+
.describe('Whether to include ancestor projects in query mode (default true)'),
|
|
1207
|
+
include_children: z
|
|
1208
|
+
.boolean()
|
|
1209
|
+
.default(false)
|
|
1210
|
+
.describe('Whether to include child subprojects in query mode (default false)'),
|
|
1211
|
+
include_global: z
|
|
1212
|
+
.boolean()
|
|
1213
|
+
.default(false)
|
|
1214
|
+
.describe('Whether to include global nodes in query mode (default false)'),
|
|
1215
|
+
depth: z
|
|
1216
|
+
.number()
|
|
1217
|
+
.int()
|
|
1218
|
+
.min(1)
|
|
1219
|
+
.max(3)
|
|
1220
|
+
.optional()
|
|
1221
|
+
.describe('Multi-hop BFS depth across entity_edges in query mode (1..3, default 1)'),
|
|
1222
|
+
node_id: z.string().optional().describe('Optional focal node ID to expand from in query mode'),
|
|
1223
|
+
entity_type: z
|
|
1224
|
+
.string()
|
|
1225
|
+
.optional()
|
|
1226
|
+
.describe("Entity type (required when mode is 'upsert_entity', optional filter in 'query' mode; e.g. 'brand', 'person', 'asset', 'metric', 'document', 'tool')"),
|
|
1227
|
+
relation: z
|
|
1228
|
+
.string()
|
|
1229
|
+
.optional()
|
|
1230
|
+
.describe("Edge relation (required for 'link', optional filter for 'query'/'unlink'; e.g. 'part_of', 'depends_on', 'references', 'owns', 'produced_by', 'blocks', 'related_to')"),
|
|
1231
|
+
user_id: z.string().optional().describe('Optional user_id attribution/filter'),
|
|
1232
|
+
agent_id: z.string().optional().describe('Optional agent_id provenance (stored, never filtered)'),
|
|
1233
|
+
id: z.string().optional().describe("Entity ID (for upsert_entity) or Edge ID (for unlink)"),
|
|
1234
|
+
entity_id: z.string().optional().describe("Optional explicit entity ID alias for mode='upsert_entity'"),
|
|
1235
|
+
name: z.string().optional().describe("Entity display name (required when mode is 'upsert_entity')"),
|
|
1236
|
+
description: z.string().optional().describe("Entity description (for mode='upsert_entity')"),
|
|
1237
|
+
external_ref: z.string().optional().describe("External URI/ID pointer (for mode='upsert_entity', e.g. 's3://...', 'https://...')"),
|
|
1238
|
+
metadata: z
|
|
1239
|
+
.union([z.record(z.string(), z.unknown()), z.string()])
|
|
1240
|
+
.optional()
|
|
1241
|
+
.describe('Optional JSON object or JSON string metadata for entity or edge'),
|
|
1242
|
+
source_type: z.string().optional().describe("Source node type for mode='link' (auto-resolved if omitted)"),
|
|
1243
|
+
source_id: z.string().optional().describe("Source node ID (required for 'link', optional for 'unlink')"),
|
|
1244
|
+
target_type: z.string().optional().describe("Target node type for mode='link' (auto-resolved if omitted)"),
|
|
1245
|
+
target_id: z.string().optional().describe("Target node ID (required for 'link', optional for 'unlink')"),
|
|
1246
|
+
limit: z.number().int().min(1).max(200).optional().describe('Maximum number of seed graph nodes to return in query mode'),
|
|
776
1247
|
},
|
|
777
1248
|
async (args) => {
|
|
778
1249
|
return handlers.brainGraph(args);
|