@andrebuzeli/advanced-memory-markdown-mcp
Version:
Advanced Memory Bank MCP v3.1.5 - Sistema avançado de gerenciamento de memória com isolamento de projetos por IDE, sincronização sob demanda, backup a cada 30min, apenas arquivos .md principais sincronizados, pasta reasoning temporária com limpeza automát
478 lines • 20.6 kB
JavaScript
/**
* Advanced Memory Bank MCP Server v4.0.0
* Dyna process.stderr.write('\n🎯 Advanced Memory Bank MCP v4.0.9 - Project Detection Results:\n');ic project detection with streamlined architecture
*/
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { ListToolsRequestSchema, CallToolRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
import { exec } from 'child_process';
import { promisify } from 'util';
import { MemoryManager } from '../core/memory-manager.js';
import { SequentialThinking } from '../core/sequential-thinking.js';
import { WorkflowNavigator } from '../core/workflow-navigator.js';
import { CreativeAnalyzer } from '../core/creative-analyzer.js';
export class AdvancedMemoryBankServer {
server;
memoryManager;
sequentialThinking;
workflowNavigator;
creativeAnalyzer;
constructor() {
this.server = new Server({
name: 'advanced-memory-bank',
version: '4.0.9',
capabilities: {
tools: {},
}
}); // Initialize all managers
this.memoryManager = new MemoryManager();
this.sequentialThinking = new SequentialThinking();
this.workflowNavigator = new WorkflowNavigator(this.memoryManager);
this.creativeAnalyzer = new CreativeAnalyzer(this.memoryManager);
this.setupToolHandlers();
}
async initialize() {
// Get project detection info for display
const projectInfo = this.memoryManager.getProjectDetectionInfo();
// Display project detection results to stderr (visible in IDE but doesn't interfere with MCP protocol)
process.stderr.write('\n🎯 Advanced Memory Bank MCP v4.0.6 - Project Detection Results:\n');
process.stderr.write(`Project Name: "${projectInfo.projectName}"\n`);
process.stderr.write(`🔍 Detection Method: ${projectInfo.detectionMethod}\n`);
process.stderr.write(`📁 Project Path: ${projectInfo.projectPath}\n`);
process.stderr.write(`💾 Memory Directory: ${projectInfo.memoryDirectory}\n`);
process.stderr.write('Ready for memory operations!\n\n');
}
async connect(transport) {
await this.server.connect(transport);
// Connected via transport (silent for MCP protocol)
}
setupToolHandlers() {
// List available tools
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: this.getAvailableTools(),
};
});
// Handle tool calls
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
return await this.handleToolCall(request);
});
}
getAvailableTools() {
return [
// Memory Management Tools
{
name: 'store-memory',
description: 'Store new memory with automatic project detection',
inputSchema: {
type: 'object',
properties: {
content: { type: 'string', description: 'Memory content to store' },
tags: { type: 'array', items: { type: 'string' }, description: 'Tags for categorization' },
importance: { type: 'number', minimum: 1, maximum: 10, description: 'Importance level (1-10)' },
},
required: ['content'],
},
},
{
name: 'search-memories',
description: 'Search memories by content or tags',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string', description: 'Search query' },
tags: { type: 'array', items: { type: 'string' }, description: 'Filter by tags' },
limit: { type: 'number', minimum: 1, maximum: 100, description: 'Number of results' },
},
required: ['query'],
},
},
{
name: 'get-memory',
description: 'Get specific memory by ID',
inputSchema: {
type: 'object',
properties: {
id: { type: 'string', description: 'Memory ID' },
},
required: ['id'],
},
},
{
name: 'list-memories',
description: 'List all memories with optional filtering',
inputSchema: {
type: 'object',
properties: {
tags: { type: 'array', items: { type: 'string' }, description: 'Filter by tags' },
limit: { type: 'number', minimum: 1, maximum: 100, description: 'Number of results' },
sortBy: { type: 'string', enum: ['timestamp', 'importance'], description: 'Sort criteria' },
},
},
},
{
name: 'update-memory',
description: 'Update existing memory',
inputSchema: {
type: 'object',
properties: {
id: { type: 'string', description: 'Memory ID' },
content: { type: 'string', description: 'Updated content' },
tags: { type: 'array', items: { type: 'string' }, description: 'Updated tags' },
importance: { type: 'number', minimum: 1, maximum: 10, description: 'Updated importance' },
},
required: ['id'],
},
},
{
name: 'delete-memory',
description: 'Delete memory by ID',
inputSchema: {
type: 'object',
properties: {
id: { type: 'string', description: 'Memory ID to delete' },
},
required: ['id'],
},
},
{
name: 'get-project-info',
description: 'Get current project context and statistics',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'get-project-name',
description: 'Get current project name using PowerShell command Split-Path -Leaf $PWD',
inputSchema: {
type: 'object',
properties: {},
},
},
// Sequential Thinking Tools
{
name: 'sequential-thinking',
description: 'Process complex problems with step-by-step thinking',
inputSchema: {
type: 'object',
properties: {
thought: { type: 'string', description: 'Current thinking step' },
thoughtNumber: { type: 'number', minimum: 1, description: 'Current thought number' },
totalThoughts: { type: 'number', minimum: 1, description: 'Estimated total thoughts' },
nextThoughtNeeded: { type: 'boolean', description: 'Whether another thought is needed' },
isRevision: { type: 'boolean', description: 'Whether this revises previous thinking' },
revisesThought: { type: 'number', minimum: 1, description: 'Which thought is being revised' },
},
required: ['thought', 'thoughtNumber', 'totalThoughts', 'nextThoughtNeeded'],
},
},
// Workflow Navigation Tools
{
name: 'navigate-workflow',
description: 'Navigate and manage workflow steps',
inputSchema: {
type: 'object',
properties: {
action: { type: 'string', enum: ['create', 'next', 'previous', 'jump', 'complete', 'status'] },
workflowName: { type: 'string', description: 'Name of the workflow' },
stepNumber: { type: 'number', minimum: 1, description: 'Step number for jump action' },
stepContent: { type: 'string', description: 'Content for new steps' },
},
required: ['action'],
},
},
// Creative Analysis Tools
{
name: 'analyze-creative-content',
description: 'Analyze content for creative insights and patterns',
inputSchema: {
type: 'object',
properties: {
content: { type: 'string', description: 'Content to analyze' },
analysisType: {
type: 'string',
enum: ['structure', 'themes', 'style', 'patterns', 'comprehensive'],
description: 'Type of analysis to perform'
},
depth: { type: 'string', enum: ['basic', 'detailed', 'comprehensive'], description: 'Analysis depth' },
},
required: ['content'],
},
},
{
name: 'generate-creative-insights',
description: 'Generate creative insights based on stored memories',
inputSchema: {
type: 'object',
properties: {
theme: { type: 'string', description: 'Theme or topic for insights' },
creativityLevel: { type: 'string', enum: ['conservative', 'balanced', 'innovative'], description: 'Level of creativity' },
limit: { type: 'number', minimum: 1, maximum: 20, description: 'Number of insights' },
},
required: ['theme'],
},
},
];
}
async handleToolCall(request) {
const { name, arguments: args } = request.params;
try {
switch (name) {
// Memory Management
case 'store-memory':
return await this.handleStoreMemory(args);
case 'search-memories':
return await this.handleSearchMemories(args);
case 'get-memory':
return await this.handleGetMemory(args);
case 'list-memories':
return await this.handleListMemories(args);
case 'update-memory':
return await this.handleUpdateMemory(args);
case 'delete-memory':
return await this.handleDeleteMemory(args);
case 'get-project-info':
return await this.handleGetProjectInfo(args);
case 'get-project-name':
return await this.handleGetProjectName(args);
// Sequential Thinking
case 'sequential-thinking':
return await this.handleSequentialThinking(args);
// Workflow Navigation
case 'navigate-workflow':
return await this.handleNavigateWorkflow(args);
// Creative Analysis
case 'analyze-creative-content':
return await this.handleAnalyzeCreativeContent(args);
case 'generate-creative-insights':
return await this.handleGenerateCreativeInsights(args);
default:
throw new Error(`Unknown tool: ${name}`);
}
}
catch (error) {
return {
content: [
{
type: 'text',
text: `Error executing tool '${name}': ${error instanceof Error ? error.message : String(error)}`,
},
],
isError: true,
};
}
}
// Memory Management Handlers
async handleStoreMemory(args) {
const memory = await this.memoryManager.storeMemory(args.content, args.tags ?? [], args.importance ?? 5);
return {
content: [
{
type: 'text',
text: `Memory stored successfully with ID: ${memory.id}`,
},
],
isError: false,
};
}
async handleSearchMemories(args) {
const memories = await this.memoryManager.searchMemories(args.query, args.tags, args.limit ?? 10);
return {
content: [
{
type: 'text',
text: `Found ${memories.length} memories:\n\n${memories.map(m => `**ID:** ${m.id}\n**Content:** ${m.content}\n**Tags:** ${m.tags.join(', ')}\n**Importance:** ${m.importance}\n---`).join('\n')}`,
},
],
isError: false,
};
}
async handleGetMemory(args) {
const memory = await this.memoryManager.getMemory(args.id);
if (!memory) {
return {
content: [
{
type: 'text',
text: `Memory with ID '${args.id}' not found`,
},
],
isError: true,
};
}
return {
content: [
{
type: 'text',
text: `**Memory ID:** ${memory.id}\n**Content:** ${memory.content}\n**Tags:** ${memory.tags.join(', ')}\n**Importance:** ${memory.importance}\n**Created:** ${new Date(memory.timestamp).toISOString()}`,
},
],
isError: false,
};
}
async handleListMemories(args) {
const memories = await this.memoryManager.listMemories(args.tags, args.limit ?? 20, args.sortBy ?? 'timestamp');
return {
content: [
{
type: 'text',
text: `Found ${memories.length} memories:\n\n${memories.map(m => `**${m.id}** (${m.importance}/10) - ${m.content.substring(0, 100)}${m.content.length > 100 ? '...' : ''}`).join('\n')}`,
},
],
isError: false,
};
}
async handleUpdateMemory(args) {
const success = await this.memoryManager.updateMemory(args.id, args.content, args.tags, args.importance);
if (!success) {
return {
content: [
{
type: 'text',
text: `Memory with ID '${args.id}' not found`,
},
],
isError: true,
};
}
return {
content: [
{
type: 'text',
text: `Memory '${args.id}' updated successfully`,
},
],
isError: false,
};
}
async handleDeleteMemory(args) {
const success = await this.memoryManager.deleteMemory(args.id);
if (!success) {
return {
content: [
{
type: 'text',
text: `Memory with ID '${args.id}' not found`,
},
],
isError: true,
};
}
return {
content: [
{
type: 'text',
text: `Memory '${args.id}' deleted successfully`,
},
],
isError: false,
};
}
async handleGetProjectInfo(args) {
const info = await this.memoryManager.getProjectInfo();
const detectionInfo = this.memoryManager.getProjectDetectionInfo();
return {
content: [
{
type: 'text',
text: `**Project Auto-Detection Results**\n\n**Project Name:** ${info.projectName}\n**Detection Method:** ${detectionInfo.detectionMethod}\n**Detection Source:** ${detectionInfo.detectionSource}\n**Project Path:** ${info.projectPath}\n**Memory Directory:** ${info.memoryDirectory}\n**Total Memories:** ${info.totalMemories}\n**System Version:** ${info.version}\n\n*Project detected automatically - no configuration needed!*`,
},
],
isError: false,
};
}
async handleGetProjectName(args) {
const execAsync = promisify(exec);
try {
// Execute PowerShell command: Split-Path -Leaf $PWD
const { stdout, stderr } = await execAsync('powershell -Command "Split-Path -Leaf $PWD"', {
timeout: 5000 // 5 second timeout
});
if (stderr) {
return {
content: [
{
type: 'text',
text: `**Error executing PowerShell command:**\n${stderr.trim()}`,
},
],
isError: true,
};
}
const projectName = stdout.trim();
return {
content: [
{
type: 'text',
text: `**Current Project Name (via PowerShell):** ${projectName}`,
},
],
isError: false,
};
}
catch (error) {
return {
content: [
{
type: 'text',
text: `**Error executing PowerShell command:**\n${error instanceof Error ? error.message : String(error)}`,
},
],
isError: true,
};
}
}
// Sequential Thinking Handler
async handleSequentialThinking(args) {
const result = await this.sequentialThinking.processThought(args.thought, args.thoughtNumber, args.totalThoughts, args.nextThoughtNeeded, args.isRevision, args.revisesThought);
return {
content: [
{
type: 'text',
text: `**Thought ${result.thoughtNumber}/${result.totalThoughts}**\n\n${result.content}\n\n**Status:** ${result.status}\n**Next needed:** ${result.nextThoughtNeeded ? 'Yes' : 'No'}`,
},
],
isError: false,
};
}
// Workflow Navigation Handler
async handleNavigateWorkflow(args) {
const result = await this.workflowNavigator.navigate(args.action, args.workflowName, args.stepNumber, args.stepContent);
return {
content: [
{
type: 'text',
text: result.message,
},
],
isError: false,
};
}
// Creative Analysis Handlers
async handleAnalyzeCreativeContent(args) {
const analysis = await this.creativeAnalyzer.analyzeContent(args.content, args.analysisType ?? 'comprehensive', args.depth ?? 'detailed');
return {
content: [
{
type: 'text',
text: `**Creative Analysis**\n\n**Type:** ${analysis.analysisType}\n**Depth:** ${analysis.depth}\n**Word Count:** ${analysis.wordCount}\n**Sentences:** ${analysis.sentenceCount}\n\n**Key Insights:**\n${analysis.insights.join('\n')}\n\n**Suggestions:**\n${analysis.suggestions?.join('\n') || 'No suggestions available'}\n\n**Patterns:**\n${analysis.patterns?.join('\n') || 'No patterns detected'}\n\n**Themes:**\n${analysis.themes?.join(', ') || 'No themes identified'}`,
},
],
isError: false,
};
}
async handleGenerateCreativeInsights(args) {
const insights = await this.creativeAnalyzer.generateInsights(args.theme, args.creativityLevel ?? 'balanced', args.limit ?? 5);
return {
content: [
{
type: 'text',
text: `**Creative Insights for "${args.theme}"**\n\n${insights.map((insight, i) => `${i + 1}. ${insight}`).join('\n\n')}`,
},
],
isError: false,
};
}
}
//# sourceMappingURL=server.js.map