UNPKG

@muhtalipdede/hierarchical-belief-memory-system

Version:

A simple hierarchical belief memory system using Model Context Protocol

90 lines (89 loc) 3.4 kB
#!/usr/bin/env node import { Server } from "@modelcontextprotocol/sdk/server/index.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js"; import { buildPrompt } from "./prompt-builder.js"; const PROMPT_BUILDER_WITH_HIERARCHICAL_BELIEF_MEMORY_SYSTEM = { name: "prompt_builder_with_hierarchical_belief_memory_system", description: "Builds a prompt using a hierarchical belief memory system for all prompting.", inputSchema: { type: "object", properties: { instant_query: { type: "string", description: "The instant query to be used in the prompt.", }, short_term_memory: { type: "string", description: "Short-term memory context.", }, mid_term_memory: { type: "string", description: "Mid-term memory context.", }, long_term_memory: { type: "string", description: "Long-term memory context.", }, character_memory: { type: "string", description: "Character memory context.", }, core_values_memory: { type: "string", description: "Core values memory context.", }, }, required: ["instant_query", "short_term_memory", "mid_term_memory", "long_term_memory", "character_memory", "core_values_memory"], }, }; const server = new Server({ name: "hierarchical_belief_memory_system_server", version: "0.0.1" }, { capabilities: { tools: { [PROMPT_BUILDER_WITH_HIERARCHICAL_BELIEF_MEMORY_SYSTEM.name]: PROMPT_BUILDER_WITH_HIERARCHICAL_BELIEF_MEMORY_SYSTEM, }, }, }); server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [PROMPT_BUILDER_WITH_HIERARCHICAL_BELIEF_MEMORY_SYSTEM], }; }); server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const { name, arguments: args } = request.params; if (!args) { throw new Error(`No arguments provided for tool: ${name}`); } switch (name) { case PROMPT_BUILDER_WITH_HIERARCHICAL_BELIEF_MEMORY_SYSTEM.name: { const { instant_query, short_term_memory, mid_term_memory, long_term_memory, character_memory, core_values_memory } = args; const result = buildPrompt(instant_query, short_term_memory, mid_term_memory, long_term_memory, character_memory, core_values_memory); return { content: [{ type: "text", text: `${result}` }], isError: false, }; } default: throw new Error(`Tool ${name} not recognized.`); } } catch (error) { return { content: [{ type: "text", text: "Error" }], isError: true, }; } }); async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error("Server started. Waiting for client connection..."); } main().catch((error) => { console.error("Fatal error in main():", error); process.exit(1); });