Skip to main content
Glama
connectimtiazh

Bi-Temporal Knowledge Graph MCP Server

Pasted-bjective-Refactor-my-current-MCP-server-into-a-high-per_1766144953868.txt2.52 kB
bjective: Refactor my current MCP server into a high-performance, decoupled 3-file system (memory.py, tools.py, main.py). The goal is to separate the "Knowledge Brain" (Bi-Temporal Graph) from the "Automation Hands" (Generated Webhooks). Architecture Requirements: 1. memory.py (The Brain): Implement a Bi-Temporal Knowledge Graph using FalkorDB. Fact Model: Every relation must track created_at, valid_at, and invalid_at. Smart Conflict Resolution: Create a logic wrapper for add_fact. If a fact involves a "Location" (lives in, based in) or "Employment" (works at, job is), the code must first search for any existing valid facts of that type for the entity and set their invalid_at timestamp to now() before adding the new fact. Session Awareness: Maintain a memory-bounded SessionStore with a 30-minute idle TTL. AI Extraction: Use OpenAI to extract entities and relationships from raw chat messages. 2. tools.py (The Hands): This file acts as a container for dynamically generated tools. Include a base helper function async def execute_webhook(url, payload) using httpx. Developer Note: This file will be appended to by an external Automation Engine. Every webhook—even those from the same template—must be generated as an independent, unique @mcp.tool function. Ensure the file starts with the necessary imports: asyncio, httpx, fastmcp, and typing. 3. main.py (The Orchestrator): Initialize the FastMCP instance. Database-Blind Discovery: Instead of hardcoding tools, use importlib and inspect to scan tools.py on startup. Every function found in tools.py (that isn't a private helper) should be automatically registered to the MCP server. Register all core memory functions from memory.py. Implement a background cleanup task for expired sessions. 4. Documentation & Setup: Provide a README.md explaining the "Brain & Hands" architecture and how the Bi-Temporal model handles truth over time. Provide a requirements.txt including fastmcp, falkordb, openai, httpx, and psycopg2-binary. Deterministic Tool Generation Rule: When generating tools for tools.py, the function names must be sanitized (lowercase, underscores only) and the docstrings must be automatically derived from the database description so the AI knows exactly when and how to use the tool. Deliverable: Please provide the full, production-ready code for all five files (main.py, memory.py, tools.py, README.md, requirements.txt) ensuring they are fully integrated and optimized for a Replit autoscale environment.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/connectimtiazh/Graphiti-Knowledge-MCP-Server-Starter'

If you have feedback or need assistance with the MCP directory API, please join our Discord server