memory_stream_next
Retrieve the next memory segment from the persistent memory system to enable continuous learning and knowledge retention across LLM sessions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/streaming/StreamingManager.js:42-82 (handler)Core handler logic that retrieves the next chunk of facts from an active memory stream, updates stream progress, determines if it's the last chunk, computes progress metrics, and formats facts for response.async getNextChunk(streamId) { const stream = this.activeStreams.get(streamId); if (!stream) { throw new Error(`Stream ${streamId} not found`); } if (stream.status !== 'active') { throw new Error(`Stream ${streamId} is not active`); } const startIndex = stream.currentIndex; const endIndex = Math.min(startIndex + stream.chunkSize, stream.totalFacts); const chunk = stream.facts.slice(startIndex, endIndex); stream.currentIndex = endIndex; const isLastChunk = endIndex >= stream.totalFacts; if (isLastChunk) { stream.status = 'completed'; stream.endTime = Date.now(); } const progress = { current: endIndex, total: stream.totalFacts, percentage: Math.round((endIndex / stream.totalFacts) * 100), remainingFacts: stream.totalFacts - endIndex, estimatedTimeRemaining: this.calculateEstimatedTime(stream, endIndex), }; const chunkData = { streamId, chunkIndex: Math.floor(startIndex / stream.chunkSize), isLastChunk, facts: chunk.map(fact => this.formatFactForStreaming(fact)), progress: stream.includeProgress ? progress : undefined, metadata: stream.metadata, }; return chunkData; }
- Tool-specific handler for 'memory_stream_next' that calls the StreamingManager's getNextChunk method and formats the response in MCP tool format with JSON content and error handling.async handleStreamNext(args) { try { const chunk = await this.streamingManager.getNextChunk(args.streamId); return { content: [ { type: 'text', text: JSON.stringify({ success: true, ...chunk, }), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: error.message, }), }, ], isError: true, }; } }
- src/tools/modules/MemoryStreamingTools.js:57-75 (registration)Registers the 'memory_stream_next' tool with the MCP server, defining its name, description, input schema (requiring streamId), and linking to the handleStreamNext handler.registerStreamNextTool(server) { server.registerTool( 'memory_stream_next', 'Get the next chunk from an active stream', { type: 'object', properties: { streamId: { type: 'string', description: 'The stream ID returned from memory_stream_query', }, }, required: ['streamId'], }, async (args) => { return await this.handleStreamNext(args); } ); }
- Helper function used by getNextChunk to format individual facts for the streaming response, selecting and transforming relevant fields including a content summary.formatFactForStreaming(fact) { return { id: fact.id, content: fact.content, type: fact.type, domain: fact.domain, qualityScore: fact.qualityScore, tags: fact.tags || [], timestamp: fact.timestamp, relevanceScore: fact.relevanceScore || 0, summary: fact.content.length > 150 ? fact.content.substring(0, 150) + '...' : fact.content, }; }
- src/tools/MemoryTools.js:23-28 (registration)Top-level registration in MemoryTools that calls registerTools on MemoryStreamingTools, which includes the memory_stream_next tool registration.async registerTools(server) { // Register tools from modular components this.operations.registerTools(server); this.queryHandler.registerTools(server); this.streamingTools.registerTools(server); this.management.registerTools(server);