@magic-ingredients/tiny-brain-local 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/core/console-logger.d.ts +30 -0
- package/dist/core/console-logger.d.ts.map +1 -0
- package/dist/core/console-logger.js +101 -0
- package/dist/core/console-logger.js.map +1 -0
- package/dist/core/file-logger.d.ts +40 -0
- package/dist/core/file-logger.d.ts.map +1 -0
- package/dist/core/file-logger.js +223 -0
- package/dist/core/file-logger.js.map +1 -0
- package/dist/core/mcp-server.d.ts +54 -0
- package/dist/core/mcp-server.d.ts.map +1 -0
- package/dist/core/mcp-server.js +295 -0
- package/dist/core/mcp-server.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts/index.d.ts +39 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +5 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/memory/memory.prompt.d.ts +32 -0
- package/dist/prompts/memory/memory.prompt.d.ts.map +1 -0
- package/dist/prompts/memory/memory.prompt.js +204 -0
- package/dist/prompts/memory/memory.prompt.js.map +1 -0
- package/dist/prompts/persona/persona.prompt.d.ts +27 -0
- package/dist/prompts/persona/persona.prompt.d.ts.map +1 -0
- package/dist/prompts/persona/persona.prompt.js +592 -0
- package/dist/prompts/persona/persona.prompt.js.map +1 -0
- package/dist/prompts/planning/planning.prompt.d.ts +56 -0
- package/dist/prompts/planning/planning.prompt.d.ts.map +1 -0
- package/dist/prompts/planning/planning.prompt.js +1016 -0
- package/dist/prompts/planning/planning.prompt.js.map +1 -0
- package/dist/prompts/prompt-registry.d.ts +25 -0
- package/dist/prompts/prompt-registry.d.ts.map +1 -0
- package/dist/prompts/prompt-registry.js +68 -0
- package/dist/prompts/prompt-registry.js.map +1 -0
- package/dist/prompts/thinking/thinking.prompt.d.ts +29 -0
- package/dist/prompts/thinking/thinking.prompt.d.ts.map +1 -0
- package/dist/prompts/thinking/thinking.prompt.js +171 -0
- package/dist/prompts/thinking/thinking.prompt.js.map +1 -0
- package/dist/services/UpdateService.d.ts +29 -0
- package/dist/services/UpdateService.d.ts.map +1 -0
- package/dist/services/UpdateService.js +132 -0
- package/dist/services/UpdateService.js.map +1 -0
- package/dist/services/plan-watcher.service.d.ts +143 -0
- package/dist/services/plan-watcher.service.d.ts.map +1 -0
- package/dist/services/plan-watcher.service.js +914 -0
- package/dist/services/plan-watcher.service.js.map +1 -0
- package/dist/storage/local-filesystem-adapter.d.ts +39 -0
- package/dist/storage/local-filesystem-adapter.d.ts.map +1 -0
- package/dist/storage/local-filesystem-adapter.js +208 -0
- package/dist/storage/local-filesystem-adapter.js.map +1 -0
- package/dist/storage/storage-path-builder.d.ts +14 -0
- package/dist/storage/storage-path-builder.d.ts.map +1 -0
- package/dist/storage/storage-path-builder.js +43 -0
- package/dist/storage/storage-path-builder.js.map +1 -0
- package/dist/test-setup.d.ts +2 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/test-setup.js +12 -0
- package/dist/test-setup.js.map +1 -0
- package/dist/tools/analyse-request/analyse-request.tool.d.ts +8 -0
- package/dist/tools/analyse-request/analyse-request.tool.d.ts.map +1 -0
- package/dist/tools/analyse-request/analyse-request.tool.js +120 -0
- package/dist/tools/analyse-request/analyse-request.tool.js.map +1 -0
- package/dist/tools/index.d.ts +69 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +24 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/memory/memory.tool.d.ts +15 -0
- package/dist/tools/memory/memory.tool.d.ts.map +1 -0
- package/dist/tools/memory/memory.tool.js +110 -0
- package/dist/tools/memory/memory.tool.js.map +1 -0
- package/dist/tools/persona/as.tool.d.ts +25 -0
- package/dist/tools/persona/as.tool.d.ts.map +1 -0
- package/dist/tools/persona/as.tool.js +294 -0
- package/dist/tools/persona/as.tool.js.map +1 -0
- package/dist/tools/persona/persona.tool.d.ts +8 -0
- package/dist/tools/persona/persona.tool.d.ts.map +1 -0
- package/dist/tools/persona/persona.tool.js +193 -0
- package/dist/tools/persona/persona.tool.js.map +1 -0
- package/dist/tools/plan/plan.tool.d.ts +18 -0
- package/dist/tools/plan/plan.tool.d.ts.map +1 -0
- package/dist/tools/plan/plan.tool.js +643 -0
- package/dist/tools/plan/plan.tool.js.map +1 -0
- package/dist/tools/strategy/strategy.tool.d.ts +13 -0
- package/dist/tools/strategy/strategy.tool.d.ts.map +1 -0
- package/dist/tools/strategy/strategy.tool.js +199 -0
- package/dist/tools/strategy/strategy.tool.js.map +1 -0
- package/dist/tools/thinking/thinking.tool.d.ts +13 -0
- package/dist/tools/thinking/thinking.tool.d.ts.map +1 -0
- package/dist/tools/thinking/thinking.tool.js +226 -0
- package/dist/tools/thinking/thinking.tool.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +20 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +61 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/tools/update/update.tool.d.ts +15 -0
- package/dist/tools/update/update.tool.d.ts.map +1 -0
- package/dist/tools/update/update.tool.js +86 -0
- package/dist/tools/update/update.tool.js.map +1 -0
- package/dist/tools/validate-response/validate-response.tool.d.ts +13 -0
- package/dist/tools/validate-response/validate-response.tool.d.ts.map +1 -0
- package/dist/tools/validate-response/validate-response.tool.js +142 -0
- package/dist/tools/validate-response/validate-response.tool.js.map +1 -0
- package/dist/types/request-context.d.ts +7 -0
- package/dist/types/request-context.d.ts.map +1 -0
- package/dist/types/request-context.js +7 -0
- package/dist/types/request-context.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Simplified MCP server for local execution without deployment complexity
|
|
5
|
+
*/
|
|
6
|
+
import { Server as McpServer } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
+
import { ListToolsRequestSchema, CallToolRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, SetLevelRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
import { LocalFilesystemStorageAdapter } from '../storage/local-filesystem-adapter.js';
|
|
9
|
+
import { FileLogger } from './file-logger.js';
|
|
10
|
+
import { ToolRegistry } from '../tools/tool-registry.js';
|
|
11
|
+
import { PromptRegistry } from '../prompts/prompt-registry.js';
|
|
12
|
+
/**
|
|
13
|
+
* MCP Server for local execution
|
|
14
|
+
*/
|
|
15
|
+
export class MCPServer {
|
|
16
|
+
server;
|
|
17
|
+
storage;
|
|
18
|
+
logger;
|
|
19
|
+
config;
|
|
20
|
+
sessionId;
|
|
21
|
+
activePersona = 'default';
|
|
22
|
+
userId = 'local-user';
|
|
23
|
+
personaChangeListeners = [];
|
|
24
|
+
instanceId = `mcp-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
25
|
+
constructor(config = {}) {
|
|
26
|
+
this.config = {
|
|
27
|
+
name: 'tiny-brain-local',
|
|
28
|
+
version: '0.3.7',
|
|
29
|
+
dataDir: process.env.TINY_BRAIN_DATA_DIR || '~/.tiny-brain',
|
|
30
|
+
logLevel: process.env.LOG_LEVEL || 'info',
|
|
31
|
+
watchAutoOpen: true,
|
|
32
|
+
...config,
|
|
33
|
+
};
|
|
34
|
+
// Create logger - file logger for local (stdio transport requires no console output)
|
|
35
|
+
this.logger = new FileLogger({
|
|
36
|
+
logLevel: this.config.logLevel,
|
|
37
|
+
enabled: true,
|
|
38
|
+
});
|
|
39
|
+
// Create storage - always local filesystem for local package
|
|
40
|
+
this.storage = new LocalFilesystemStorageAdapter({
|
|
41
|
+
baseDir: this.config.dataDir,
|
|
42
|
+
});
|
|
43
|
+
// Generate session ID
|
|
44
|
+
this.sessionId = `local-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
45
|
+
// Create MCP server instance
|
|
46
|
+
this.server = new McpServer({
|
|
47
|
+
name: this.config.name,
|
|
48
|
+
version: this.config.version,
|
|
49
|
+
}, {
|
|
50
|
+
capabilities: {
|
|
51
|
+
tools: {},
|
|
52
|
+
prompts: {},
|
|
53
|
+
logging: {},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
// Set up handlers
|
|
57
|
+
this.setupHandlers();
|
|
58
|
+
}
|
|
59
|
+
setupHandlers() {
|
|
60
|
+
// Tool handlers
|
|
61
|
+
this.server.setRequestHandler(ListToolsRequestSchema, this.handleListTools.bind(this));
|
|
62
|
+
this.server.setRequestHandler(CallToolRequestSchema, this.handleCallTool.bind(this));
|
|
63
|
+
// Prompt handlers
|
|
64
|
+
this.server.setRequestHandler(ListPromptsRequestSchema, this.handleListPrompts.bind(this));
|
|
65
|
+
this.server.setRequestHandler(GetPromptRequestSchema, this.handleGetPrompt.bind(this));
|
|
66
|
+
// Logging handler
|
|
67
|
+
this.server.setRequestHandler(SetLevelRequestSchema, this.handleSetLogLevel.bind(this));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get server configuration
|
|
71
|
+
*/
|
|
72
|
+
getConfig() {
|
|
73
|
+
return this.config;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Initialize the server
|
|
77
|
+
*/
|
|
78
|
+
async initialize() {
|
|
79
|
+
this.logger.info('Initializing Local MCP Server', {
|
|
80
|
+
dataDir: this.config.dataDir,
|
|
81
|
+
logLevel: this.config.logLevel,
|
|
82
|
+
});
|
|
83
|
+
try {
|
|
84
|
+
// Initialize user storage first
|
|
85
|
+
await this.storage.initializeUserStorage(this.userId);
|
|
86
|
+
// Load default persona if available
|
|
87
|
+
try {
|
|
88
|
+
const personas = await this.storage.listPersonas();
|
|
89
|
+
if (personas.length > 0) {
|
|
90
|
+
this.activePersona = personas[0];
|
|
91
|
+
this.logger.info(`Loaded default persona: ${this.activePersona}`);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Create default persona
|
|
95
|
+
await this.storage.storePersonaFile('default', 'profile.json', JSON.stringify({
|
|
96
|
+
id: 'default',
|
|
97
|
+
name: 'Default',
|
|
98
|
+
description: 'Default persona',
|
|
99
|
+
created: new Date().toISOString(),
|
|
100
|
+
}, null, 2), this.userId);
|
|
101
|
+
this.activePersona = 'default';
|
|
102
|
+
this.logger.info('Created default persona');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
this.logger.warn('Could not load personas, using default', error);
|
|
107
|
+
this.activePersona = 'default';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
this.logger.error('Failed to initialize storage', error);
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Connect to transport
|
|
117
|
+
*/
|
|
118
|
+
async connect(transport) {
|
|
119
|
+
await this.server.connect(transport);
|
|
120
|
+
this.logger.info('Connected to transport');
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Shutdown the server
|
|
124
|
+
*/
|
|
125
|
+
async shutdown() {
|
|
126
|
+
this.logger.info('Shutting down Local MCP Server');
|
|
127
|
+
await this.server.close();
|
|
128
|
+
}
|
|
129
|
+
// Tool handlers
|
|
130
|
+
async handleListTools(_request) {
|
|
131
|
+
const tools = ToolRegistry.getTools();
|
|
132
|
+
this.logger.debug(`Listing ${tools.length} tools`);
|
|
133
|
+
return { tools };
|
|
134
|
+
}
|
|
135
|
+
async handleCallTool(request) {
|
|
136
|
+
const { name, arguments: args } = request.params;
|
|
137
|
+
this.logger.info(`Calling tool: ${name}`, { args });
|
|
138
|
+
// Create request context - simplified for local
|
|
139
|
+
const activePersona = this.activePersona ? {
|
|
140
|
+
id: this.activePersona,
|
|
141
|
+
userContent: {
|
|
142
|
+
profile: undefined,
|
|
143
|
+
background: undefined,
|
|
144
|
+
expertise: undefined,
|
|
145
|
+
preferences: undefined
|
|
146
|
+
}
|
|
147
|
+
} : undefined;
|
|
148
|
+
const context = {
|
|
149
|
+
sessionId: this.sessionId,
|
|
150
|
+
userId: (typeof args?.userId === 'string' ? args.userId : undefined) || this.userId,
|
|
151
|
+
storage: this.storage,
|
|
152
|
+
logger: this.logger.child(name),
|
|
153
|
+
input: args || {},
|
|
154
|
+
conversationId: `conv-${this.sessionId}`,
|
|
155
|
+
enhancementActive: false,
|
|
156
|
+
requestId: `req-${Date.now()}`,
|
|
157
|
+
timestamp: new Date(),
|
|
158
|
+
deploymentMode: 'local',
|
|
159
|
+
activePersona,
|
|
160
|
+
updateActivePersona: (persona) => {
|
|
161
|
+
const newPersonaId = persona?.id || 'default';
|
|
162
|
+
this.activePersona = newPersonaId;
|
|
163
|
+
this.logger.info(`[${this.instanceId}] Active persona updated to: ${newPersonaId}, notifying ${this.personaChangeListeners.length} listeners`);
|
|
164
|
+
// Notify all registered listeners
|
|
165
|
+
for (const listener of this.personaChangeListeners) {
|
|
166
|
+
try {
|
|
167
|
+
const result = listener(newPersonaId);
|
|
168
|
+
if (result instanceof Promise) {
|
|
169
|
+
result.catch(err => this.logger.error('Persona change listener error:', err));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
this.logger.error('Persona change listener error:', err);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
getCurrentActivePersona: () => this.activePersona,
|
|
178
|
+
personaChangeListeners: this.personaChangeListeners,
|
|
179
|
+
};
|
|
180
|
+
// Get the tool
|
|
181
|
+
const ToolClass = ToolRegistry.getToolByName(name);
|
|
182
|
+
if (!ToolClass) {
|
|
183
|
+
const error = `Unknown tool: ${name}`;
|
|
184
|
+
this.logger.error(error);
|
|
185
|
+
return {
|
|
186
|
+
content: [{ type: 'text', text: error }],
|
|
187
|
+
isError: true,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
// Execute the tool
|
|
192
|
+
const result = await ToolClass.execute(args || {}, context);
|
|
193
|
+
// Result already has content and isError properties
|
|
194
|
+
if (!result.isError) {
|
|
195
|
+
this.logger.debug(`Tool ${name} executed successfully`, {
|
|
196
|
+
contentLength: result.content?.length,
|
|
197
|
+
hasContent: !!result.content
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.logger.warn(`Tool ${name} returned error`, { result });
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
this.logger.error(`Tool execution failed: ${name}`, error);
|
|
207
|
+
return {
|
|
208
|
+
content: [
|
|
209
|
+
{
|
|
210
|
+
type: 'text',
|
|
211
|
+
text: `Tool execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
isError: true,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Prompt handlers
|
|
219
|
+
async handleListPrompts(_request) {
|
|
220
|
+
const prompts = PromptRegistry.getPrompts();
|
|
221
|
+
this.logger.debug(`Listing ${prompts.length} prompts`);
|
|
222
|
+
return { prompts };
|
|
223
|
+
}
|
|
224
|
+
async handleGetPrompt(request) {
|
|
225
|
+
const { name, arguments: args } = request.params;
|
|
226
|
+
this.logger.info(`Getting prompt: ${name}`);
|
|
227
|
+
// Create request context
|
|
228
|
+
const activePersona = this.activePersona ? {
|
|
229
|
+
id: this.activePersona,
|
|
230
|
+
userContent: {
|
|
231
|
+
profile: undefined,
|
|
232
|
+
background: undefined,
|
|
233
|
+
expertise: undefined,
|
|
234
|
+
preferences: undefined
|
|
235
|
+
}
|
|
236
|
+
} : undefined;
|
|
237
|
+
const context = {
|
|
238
|
+
sessionId: this.sessionId,
|
|
239
|
+
userId: this.userId,
|
|
240
|
+
storage: this.storage,
|
|
241
|
+
logger: this.logger.child(`prompt:${name}`),
|
|
242
|
+
input: args || {},
|
|
243
|
+
conversationId: `conv-${this.sessionId}`,
|
|
244
|
+
enhancementActive: false,
|
|
245
|
+
requestId: `req-${Date.now()}`,
|
|
246
|
+
timestamp: new Date(),
|
|
247
|
+
deploymentMode: 'local',
|
|
248
|
+
activePersona,
|
|
249
|
+
updateActivePersona: (persona) => {
|
|
250
|
+
const newPersonaId = persona?.id || 'default';
|
|
251
|
+
this.activePersona = newPersonaId;
|
|
252
|
+
this.logger.info(`[${this.instanceId}] Active persona updated to: ${newPersonaId}, notifying ${this.personaChangeListeners.length} listeners`);
|
|
253
|
+
// Notify all registered listeners
|
|
254
|
+
for (const listener of this.personaChangeListeners) {
|
|
255
|
+
try {
|
|
256
|
+
const result = listener(newPersonaId);
|
|
257
|
+
if (result instanceof Promise) {
|
|
258
|
+
result.catch(err => this.logger.error('Persona change listener error:', err));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
this.logger.error('Persona change listener error:', err);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
getCurrentActivePersona: () => this.activePersona,
|
|
267
|
+
personaChangeListeners: this.personaChangeListeners,
|
|
268
|
+
};
|
|
269
|
+
// Get the prompt class
|
|
270
|
+
const PromptClass = PromptRegistry.getPromptByName(name);
|
|
271
|
+
if (!PromptClass) {
|
|
272
|
+
const error = `Unknown prompt: ${name}`;
|
|
273
|
+
this.logger.error(error);
|
|
274
|
+
throw new Error(error);
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
// Execute the prompt handler
|
|
278
|
+
const result = await PromptClass.handle(name, args || {}, context);
|
|
279
|
+
this.logger.debug(`Prompt ${name} generated`);
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
this.logger.error(`Error executing prompt ${name}:`, error);
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// Logging handler
|
|
288
|
+
async handleSetLogLevel(request) {
|
|
289
|
+
const { level } = request.params;
|
|
290
|
+
this.logger.setLogLevel(level);
|
|
291
|
+
this.logger.info(`Log level set to: ${level}`);
|
|
292
|
+
return {};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../src/core/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAc5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAa/D;;GAEG;AACH,MAAM,OAAO,SAAS;IACZ,MAAM,CAAY;IAClB,OAAO,CAA2B;IAClC,MAAM,CAAa;IACnB,MAAM,CAAY;IAClB,SAAS,CAAS;IAClB,aAAa,GAAW,SAAS,CAAC;IAClC,MAAM,GAAW,YAAY,CAAC;IAC9B,sBAAsB,GAAuD,EAAE,CAAC;IAChF,UAAU,GAAW,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAE/F,YAAY,SAAoB,EAAE;QAChC,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,kBAAkB;YACxB,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,eAAe;YAC3D,QAAQ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C;QAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC;QAE/C,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny Brain Local MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Local implementation of the Tiny Brain AI assistant
|
|
5
|
+
* using the Model Context Protocol (MCP)
|
|
6
|
+
*/
|
|
7
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
+
import { MCPServer } from './core/mcp-server.js';
|
|
9
|
+
async function main() {
|
|
10
|
+
// Create MCP server with config from environment
|
|
11
|
+
const server = new MCPServer({
|
|
12
|
+
name: 'tiny-brain-local',
|
|
13
|
+
version: '0.3.7',
|
|
14
|
+
dataDir: process.env.TINY_BRAIN_DATA_DIR,
|
|
15
|
+
logLevel: process.env.LOG_LEVEL,
|
|
16
|
+
});
|
|
17
|
+
// Initialize server
|
|
18
|
+
await server.initialize();
|
|
19
|
+
// Create and connect transport
|
|
20
|
+
const transport = new StdioServerTransport();
|
|
21
|
+
await server.connect(transport);
|
|
22
|
+
// Handle shutdown
|
|
23
|
+
process.on('SIGINT', async () => {
|
|
24
|
+
await server.shutdown();
|
|
25
|
+
process.exit(0);
|
|
26
|
+
});
|
|
27
|
+
process.on('SIGTERM', async () => {
|
|
28
|
+
await server.shutdown();
|
|
29
|
+
process.exit(0);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Run the server
|
|
33
|
+
main().catch((error) => {
|
|
34
|
+
console.error('Failed to start server:', error);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingUR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CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt System Types and Interfaces
|
|
3
|
+
*/
|
|
4
|
+
import type { RequestContext } from '../types/request-context.js';
|
|
5
|
+
import type { Prompt } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Response format for all prompts
|
|
8
|
+
*/
|
|
9
|
+
export interface PromptResponse {
|
|
10
|
+
description?: string;
|
|
11
|
+
messages: Array<{
|
|
12
|
+
role: 'user' | 'assistant';
|
|
13
|
+
content: {
|
|
14
|
+
type: 'text';
|
|
15
|
+
text: string;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Interface that all prompt classes must implement
|
|
21
|
+
*/
|
|
22
|
+
export interface TinyBrainPrompt {
|
|
23
|
+
/**
|
|
24
|
+
* Get the prompt definitions for this prompt class
|
|
25
|
+
*/
|
|
26
|
+
getPromptDefinitions(): Prompt[];
|
|
27
|
+
/**
|
|
28
|
+
* Handle a prompt execution
|
|
29
|
+
*/
|
|
30
|
+
handle(name: string, args: Record<string, unknown>, context: RequestContext): Promise<PromptResponse>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Type for prompt class constructors
|
|
34
|
+
*/
|
|
35
|
+
export type PromptClass = {
|
|
36
|
+
getPromptDefinitions(): Prompt[];
|
|
37
|
+
handle(name: string, args: Record<string, unknown>, context: RequestContext): Promise<PromptResponse>;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAC3B,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;KACH,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,oBAAoB,IAAI,MAAM,EAAE,CAAC;IAEjC;;OAEG;IACH,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,oBAAoB,IAAI,MAAM,EAAE,CAAC;IACjC,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Prompt Handler
|
|
3
|
+
*
|
|
4
|
+
* Thin dispatcher for memory-related prompt executions
|
|
5
|
+
* Validates args with Zod, dispatches to MemoryService, formats responses
|
|
6
|
+
*/
|
|
7
|
+
import type { RequestContext } from '../../types/request-context.js';
|
|
8
|
+
import type { Prompt } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
import type { PromptResponse } from '../index.js';
|
|
10
|
+
export declare class MemoryPrompt {
|
|
11
|
+
/**
|
|
12
|
+
* Get all memory-related prompt definitions
|
|
13
|
+
*/
|
|
14
|
+
static getPromptDefinitions(): Prompt[];
|
|
15
|
+
/**
|
|
16
|
+
* Main handler that routes to specific prompt handlers
|
|
17
|
+
*/
|
|
18
|
+
static handle(name: string, args: Record<string, unknown>, context: RequestContext): Promise<PromptResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Handle remember prompt - stores information in appropriate memory tier
|
|
21
|
+
*/
|
|
22
|
+
static handleRemember(args: Record<string, unknown>, context: RequestContext): Promise<PromptResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Handle recall prompt - searches memory across tiers
|
|
25
|
+
*/
|
|
26
|
+
static handleRecall(args: Record<string, unknown>, context: RequestContext): Promise<PromptResponse>;
|
|
27
|
+
/**
|
|
28
|
+
* Handle forget prompt - removes information from memory
|
|
29
|
+
*/
|
|
30
|
+
static handleForget(args: Record<string, unknown>, context: RequestContext): Promise<PromptResponse>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=memory.prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.prompt.d.ts","sourceRoot":"","sources":["../../../src/prompts/memory/memory.prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAiBlD,qBAAa,YAAY;IACvB;;OAEG;IACH,MAAM,CAAC,oBAAoB,IAAI,MAAM,EAAE;IA4CvC;;OAEG;WACU,MAAM,CACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,cAAc,CAAC;IAa1B;;OAEG;WACU,cAAc,CACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,cAAc,CAAC;IA4C1B;;OAEG;WACU,YAAY,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,cAAc,CAAC;IA4C1B;;OAEG;WACU,YAAY,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,cAAc,CAAC;CAwC3B"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Prompt Handler
|
|
3
|
+
*
|
|
4
|
+
* Thin dispatcher for memory-related prompt executions
|
|
5
|
+
* Validates args with Zod, dispatches to MemoryService, formats responses
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { MemoryService } from '@magic-ingredients/tiny-brain-core';
|
|
9
|
+
// Zod schemas for each prompt handler
|
|
10
|
+
const RememberArgsSchema = z.object({
|
|
11
|
+
fact: z.string(),
|
|
12
|
+
category: z.string().optional(),
|
|
13
|
+
});
|
|
14
|
+
const RecallArgsSchema = z.object({
|
|
15
|
+
query: z.string(),
|
|
16
|
+
});
|
|
17
|
+
const ForgetArgsSchema = z.object({
|
|
18
|
+
query: z.string(),
|
|
19
|
+
});
|
|
20
|
+
export class MemoryPrompt {
|
|
21
|
+
/**
|
|
22
|
+
* Get all memory-related prompt definitions
|
|
23
|
+
*/
|
|
24
|
+
static getPromptDefinitions() {
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
name: 'remember',
|
|
28
|
+
description: '💾 Store information in personal or conversation memory with smart classification',
|
|
29
|
+
arguments: [
|
|
30
|
+
{
|
|
31
|
+
name: 'fact',
|
|
32
|
+
description: 'The information you want to remember',
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'category',
|
|
37
|
+
description: 'Category to store this in (e.g., preferences, project_details)',
|
|
38
|
+
required: false,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'recall',
|
|
44
|
+
description: '🔍 Search through personal and conversation memory',
|
|
45
|
+
arguments: [
|
|
46
|
+
{
|
|
47
|
+
name: 'query',
|
|
48
|
+
description: 'What you want to search for',
|
|
49
|
+
required: true,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'forget',
|
|
55
|
+
description: '🗑️ Remove information from memory',
|
|
56
|
+
arguments: [
|
|
57
|
+
{
|
|
58
|
+
name: 'query',
|
|
59
|
+
description: 'What information to forget',
|
|
60
|
+
required: true,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Main handler that routes to specific prompt handlers
|
|
68
|
+
*/
|
|
69
|
+
static async handle(name, args, context) {
|
|
70
|
+
switch (name) {
|
|
71
|
+
case 'remember':
|
|
72
|
+
return await MemoryPrompt.handleRemember(args, context);
|
|
73
|
+
case 'recall':
|
|
74
|
+
return await MemoryPrompt.handleRecall(args, context);
|
|
75
|
+
case 'forget':
|
|
76
|
+
return await MemoryPrompt.handleForget(args, context);
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(`Unknown memory prompt: ${name}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Handle remember prompt - stores information in appropriate memory tier
|
|
83
|
+
*/
|
|
84
|
+
static async handleRemember(args, context) {
|
|
85
|
+
try {
|
|
86
|
+
// Validate args with Zod
|
|
87
|
+
const validatedArgs = RememberArgsSchema.parse(args);
|
|
88
|
+
// Create memory service with context
|
|
89
|
+
const memoryService = new MemoryService(context);
|
|
90
|
+
// Call service method with validated args
|
|
91
|
+
const result = await memoryService.rememberFact(validatedArgs.fact, validatedArgs.category);
|
|
92
|
+
// Format response
|
|
93
|
+
const resultText = `${result.message}\n\nExtracted:\n- Entities: ${result.entities.map((e) => `${e.name} (${e.entityType})`).join(', ')}\n- Relations: ${result.relations.map((r) => `${r.from} ${r.relationType} ${r.to}`).join(', ')}\n- Context: ${result.context || 'general'}`;
|
|
94
|
+
return {
|
|
95
|
+
description: 'Remember information with smart classification',
|
|
96
|
+
messages: [
|
|
97
|
+
{
|
|
98
|
+
role: 'user',
|
|
99
|
+
content: {
|
|
100
|
+
type: 'text',
|
|
101
|
+
text: `Remember: ${validatedArgs.fact}${validatedArgs.category ? ` (category: ${validatedArgs.category})` : ''}`,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
role: 'assistant',
|
|
106
|
+
content: {
|
|
107
|
+
type: 'text',
|
|
108
|
+
text: resultText,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error instanceof z.ZodError) {
|
|
116
|
+
throw new Error(`Invalid arguments: ${error.errors.map(e => e.message).join(', ')}`);
|
|
117
|
+
}
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Handle recall prompt - searches memory across tiers
|
|
123
|
+
*/
|
|
124
|
+
static async handleRecall(args, context) {
|
|
125
|
+
try {
|
|
126
|
+
// Validate args with Zod
|
|
127
|
+
const validatedArgs = RecallArgsSchema.parse(args);
|
|
128
|
+
// Create memory service with context
|
|
129
|
+
const memoryService = new MemoryService(context);
|
|
130
|
+
// Call service method with validated args
|
|
131
|
+
const result = await memoryService.recallMemories(validatedArgs.query);
|
|
132
|
+
// Format response
|
|
133
|
+
const resultText = result.results.length > 0
|
|
134
|
+
? `Found ${result.totalMatches} relevant memories:\n\n${JSON.stringify(result.results, null, 2)}`
|
|
135
|
+
: `No memories found for query: ${validatedArgs.query}`;
|
|
136
|
+
return {
|
|
137
|
+
description: 'Search both personal and conversation memory',
|
|
138
|
+
messages: [
|
|
139
|
+
{
|
|
140
|
+
role: 'user',
|
|
141
|
+
content: {
|
|
142
|
+
type: 'text',
|
|
143
|
+
text: `What do you know about: ${validatedArgs.query}`,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
role: 'assistant',
|
|
148
|
+
content: {
|
|
149
|
+
type: 'text',
|
|
150
|
+
text: resultText,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (error instanceof z.ZodError) {
|
|
158
|
+
throw new Error(`Invalid arguments: ${error.errors.map(e => e.message).join(', ')}`);
|
|
159
|
+
}
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Handle forget prompt - removes information from memory
|
|
165
|
+
*/
|
|
166
|
+
static async handleForget(args, context) {
|
|
167
|
+
try {
|
|
168
|
+
// Validate args with Zod
|
|
169
|
+
const validatedArgs = ForgetArgsSchema.parse(args);
|
|
170
|
+
// Create memory service with context
|
|
171
|
+
const memoryService = new MemoryService(context);
|
|
172
|
+
// Call service method with validated args
|
|
173
|
+
const result = await memoryService.forgetMemories(validatedArgs.query);
|
|
174
|
+
// Format response
|
|
175
|
+
const resultText = result.message;
|
|
176
|
+
return {
|
|
177
|
+
description: 'Remove information from memory',
|
|
178
|
+
messages: [
|
|
179
|
+
{
|
|
180
|
+
role: 'user',
|
|
181
|
+
content: {
|
|
182
|
+
type: 'text',
|
|
183
|
+
text: `Forget: ${validatedArgs.query}`,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
role: 'assistant',
|
|
188
|
+
content: {
|
|
189
|
+
type: 'text',
|
|
190
|
+
text: resultText,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (error instanceof z.ZodError) {
|
|
198
|
+
throw new Error(`Invalid arguments: ${error.errors.map(e => e.message).join(', ')}`);
|
|
199
|
+
}
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=memory.prompt.js.map
|