### JSON: Example AI Platform Server Configuration Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md A JSON example demonstrating the configuration for an AI platform, specifically for the 'mcpServers.memory' component, specifying the command and arguments to run the memory server with custom contexts directory and a default context. ```json { "mcpServers": { "memory": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-memory", "--contexts-directory", "/Users/username/.ai-memory/contexts", "--default-context", "personal" ] } } } ``` -------------------------------- ### Create Project Directory Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/placeholder.md Initializes the project by creating a new directory named `mcp-knowledge-base` and navigating into it, preparing the environment for package setup. ```bash mkdir mcp-knowledge-base cd mcp-knowledge-base ``` -------------------------------- ### JSON: Example Application Context Configuration Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md A JSON example showing how different memory contexts are defined, including 'default', 'work', and 'project-specific' contexts, with details like path, project-based flag, and detection rules for project-specific contexts. ```json { "activeContext": "work", "contexts": [ { "name": "default", "path": "/Users/username/.ai-memory/default.jsonl", "isProjectBased": false, "description": "Default memory context" }, { "name": "work", "path": "/Users/username/.ai-memory/work.jsonl", "isProjectBased": false, "description": "Work-related memories" }, { "name": "project-specific", "path": "{projectDir}/.ai-memory.jsonl", "isProjectBased": true, "description": "Project-specific memories", "projectDetectionRules": { "markers": [".git", "package.json", "pyproject.toml"], "maxDepth": 3 } } ] } ``` -------------------------------- ### Example System Prompt for AI Model Memory Utilization Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/README.md This text snippet provides a detailed system prompt designed to guide an AI model in utilizing its knowledge graph ('memory') for chat personalization. It outlines steps for user identification, memory retrieval, gathering new information (identity, behaviors, preferences, goals, relationships), and updating the memory with new entities, relations, and observations. ```txt Follow these steps for each interaction: 1. User Identification: - You should assume that you are interacting with default_user - If you have not identified default_user, proactively try to do so. 2. Memory Retrieval: - Always begin your chat by saying only "Remembering..." and retrieve all relevant information from your knowledge graph - Always refer to your knowledge graph as your "memory" 3. Memory Gathering: - While conversing with the user, be attentive to any new information that falls into these categories: a) Basic Identity (age, gender, location, job title, education level, etc.) b) Behaviors (interests, habits, etc.) c) Preferences (communication style, preferred language, etc.) d) Goals (goals, targets, aspirations, etc.) e) Relationships (personal and professional relationships up to 3 degrees of separation) 4. Memory Update: - If any new information was gathered during the interaction, update your memory as follows: a) Create entities for recurring organizations, people, and significant events b) Connect them to the current entities using relations c) Store facts about them as observations ``` -------------------------------- ### Configure Placeholder package.json Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/placeholder.md Provides the JSON structure for `package.json`, configuring the package name, initial version (0.0.1), a placeholder description, main entry point, and keywords. This setup is crucial for reserving the name and indicating future development. ```json { "name": "mcp-knowledge-base", "version": "0.0.1", "description": "MCP server for knowledge base functionality - Coming Soon", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ "mcp", "knowledge-base", "ai", "memory" ], "author": "Your Name", "license": "MIT" } ``` -------------------------------- ### Install TypeScript Globally with Volta Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/workflow.md Command to install TypeScript globally using Volta, ensuring consistent version management across the development environment. ```Bash volta install typescript ``` -------------------------------- ### Dockerfile Commands for MCP Server Build and Run Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/entity-versioning-update-operations.md This snippet provides the Dockerfile instructions to build and run the MCP server. It includes steps for copying package files, installing dependencies, copying application code, building the project, and finally running the Node.js application. ```Dockerfile COPY package*.json ./ RUN npm install --ignore-scripts COPY . . RUN npm run build CMD [ "node", "dist/index.js" ] ``` -------------------------------- ### Build Monorepo Project for Testing Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/pr-instructions.md These bash commands are used to install all necessary npm dependencies and then build the entire monorepo project. This step is crucial for verifying that the integrated local changes compile correctly and do not introduce any build errors within the monorepo environment. ```bash npm install npm run build ``` -------------------------------- ### Add Type Definitions for Minimist Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/workflow.md Command to install development-only type definitions for the 'minimist' package, improving type safety for JavaScript libraries without native TypeScript support. ```Bash volta run npm install --save-dev @types/minimist ``` -------------------------------- ### Specify Custom Memory Path for MCP Knowledge Graph Server Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/README.md This configuration example demonstrates how to set a custom file path for the memory.jsonl file used by the mcp-knowledge-graph server. It's identical to the Claude Desktop setup but emphasizes the '--memory-path' argument for flexible storage. ```json { "mcpServers": { "memory": { "command": "npx", "args": [ "-y", "mcp-knowledge-graph", "--memory-path", "/Users/shaneholloman/Dropbox/shane/db/memory.jsonl" ], "autoapprove": [ "create_entities", "create_relations", "add_observations", "delete_entities", "delete_observations", "delete_relations", "read_graph", "search_nodes", "open_nodes" ] } } } ``` -------------------------------- ### Implement Project Directory Detection in TypeScript Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md This asynchronous TypeScript function detects the root directory of a project by searching for common project marker files (e.g., `package.json`, `.git`, `pyproject.toml`) starting from the current working directory and moving up to a specified maximum depth. It returns information about the detected project, including its directory, name, and the marker file found, or defaults to the current directory if no project is detected. ```typescript async function detectProjectInfo(): Promise { // Start at current directory let currentDir = process.cwd(); const maxDepth = 5; // Default max depth for (let i = 0; i < maxDepth; i++) { // Check for project markers for (const marker of ['package.json', '.git', 'pyproject.toml']) { if (await fileExists(path.join(currentDir, marker))) { // Found a project marker return { directory: currentDir, name: path.basename(currentDir), marker: marker }; } } // Move up one directory const parentDir = path.dirname(currentDir); if (parentDir === currentDir) { // Reached root directory break; } currentDir = parentDir; } // No project detected, use current directory return { directory: process.cwd(), name: path.basename(process.cwd()), marker: null }; } ``` -------------------------------- ### JSON Schema: Update Tool Input for Context Specification Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md An example JSON schema snippet demonstrating how to add an optional 'context' property to tool inputs, allowing tools to operate within a specified memory context, defaulting to the active context if not provided. ```json { "name": "create_entities", "description": "Create multiple new entities in the knowledge graph", "inputSchema": { "type": "object", "properties": { "entities": { // existing schema }, "context": { "type": "string", "description": "Memory context to use (optional, defaults to active context)" } }, "required": ["entities"] } } ``` -------------------------------- ### Initialize npm Package Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/placeholder.md Runs `npm init -y` to quickly create a default `package.json` file, setting up the basic metadata for the npm package without interactive prompts. ```bash npm init -y ``` -------------------------------- ### Create Minimal index.js Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/placeholder.md Creates a simple `index.js` file, serving as the package's main entry point. It contains a basic `console.log` statement to indicate the package's placeholder status. ```javascript console.log('MCP Knowledge Base - Coming Soon'); ``` -------------------------------- ### Generate Placeholder README.md Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/placeholder.md Outlines the content for `README.md`, which informs users that the package is currently under development and serves as a placeholder. It also hints at future features and the package's relationship with `mcp-knowledge-graph`. ```markdown # MCP Knowledge Base > [!NOTE] > This package is currently in development. Future versions will provide knowledge base functionality for AI models that support the Model Context Protocol (MCP). ## Coming Soon This package will build upon mcp-knowledge-graph to provide: - Enhanced knowledge base capabilities - Improved memory management - Advanced querying features ## Status This is a placeholder release. Production version coming soon. ``` -------------------------------- ### Publish Placeholder Package Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/placeholder.md Instructs on how to publish the minimal package to the npm registry. It includes commands for logging in and then publishing the package, effectively reserving the name. ```bash npm login # if not already logged in npm publish ``` -------------------------------- ### Local MCP Memory Server Configuration Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/pr-instructions.md This JSON configuration snippet illustrates how to set up the MCP Memory Server to run locally, specifying the `volta` command, arguments, and paths for the server's `index.js` and its `memory.jsonl` data file. It's crucial for maintaining a functional local development environment before merging changes. ```json { "mcpServers": { "memory": { "command": "volta", "args": [ "run", "node", "C:\\Users\\shane\\Desktop\\memory\\dist\\index.js", "--memory-path", "C:\\Users\\shane\\Desktop\\memory\\memory.jsonl" ] } } } ``` -------------------------------- ### Provide Dockerfile for Containerized Deployment Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/entity-versioning-update-operations.md A basic Dockerfile snippet illustrating the initial steps for containerizing the application. It uses the `node:lts-alpine` image as a base and sets the working directory inside the container to `/app`, preparing for application files. ```dockerfile FROM node:lts-alpine # Create app directory WORKDIR /app ``` -------------------------------- ### Configure MCP Knowledge Graph Server for Claude Desktop Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/README.md This JSON configuration snippet shows how to integrate the mcp-knowledge-graph server with Claude Desktop. It defines a 'memory' server, specifies the command to run it using 'npx', sets a custom memory file path, and lists the MCP actions that are automatically approved. ```json { "mcpServers": { "memory": { "command": "npx", "args": [ "-y", "mcp-knowledge-graph", "--memory-path", "/Users/shaneholloman/Dropbox/shane/db/memory.jsonl" ], "autoapprove": [ "create_entities", "create_relations", "add_observations", "delete_entities", "delete_observations", "delete_relations", "read_graph", "search_nodes", "open_nodes" ] } } } ``` -------------------------------- ### Execute Project Build with Volta Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/workflow.md Command to run the defined build script using Volta, ensuring the correct Node.js and npm versions are used for the build process. ```Bash volta run npm run build ``` -------------------------------- ### TypeScript: Load and Save Context Configurations Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md Functions to manage application contexts, including loading from a file, handling missing or invalid files by creating a default configuration, and saving updated configurations to a specified path. ```typescript async function loadContexts(contextsFilePath: string): Promise { try { const data = await fs.readFile(contextsFilePath, "utf-8"); return JSON.parse(data); } catch (error) { // If file doesn't exist or is invalid, create default const defaultConfig: ContextsConfig = { activeContext: "default", contexts: [{ name: "default", path: MEMORY_FILE_PATH, isProjectBased: false, description: "Default memory context" }] }; // Ensure directory exists await fs.mkdir(path.dirname(contextsFilePath), { recursive: true }); // Write default config await fs.writeFile(contextsFilePath, JSON.stringify(defaultConfig, null, 2)); return defaultConfig; } } async function saveContexts(contextsFilePath: string, config: ContextsConfig): Promise { await fs.writeFile(contextsFilePath, JSON.stringify(config, null, 2)); } ``` -------------------------------- ### Clone Original Servers Repository Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/pr-instructions.md These bash commands are used to clone the `servers` monorepo from GitHub and then navigate into its root directory. This is the initial step to obtain the official codebase before applying local modifications for a pull request. ```bash git clone https://github.com/modelcontextprotocol/servers.git cd servers ``` -------------------------------- ### Implement Environment Variable Support for Configuration Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/entity-versioning-update-operations.md Demonstrates a common pattern for configuration flexibility, allowing the `memoryPath` to be determined either from command line arguments (`argv['memory-path']`) or an environment variable (`process.env.MEMORY_FILE_PATH`). This ensures the application can be configured easily in different deployment environments. ```typescript // Check for memory path in command line args or environment variable let memoryPath = argv['memory-path'] || process.env.MEMORY_FILE_PATH; ``` -------------------------------- ### MCP Memory Server Package Dependencies Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/pr-instructions.md This JSON snippet outlines the `dependencies` and `devDependencies` required for the MCP Memory Server package. It specifically includes `minimist` for argument parsing and its corresponding TypeScript type definitions, ensuring proper functionality within the monorepo's `package.json`. ```json { "dependencies": { "minimist": "^1.2.8" }, "devDependencies": { "@types/minimist": "^1.2.5" } } ``` -------------------------------- ### Verify Package Reservation Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/placeholder.md Provides the command to verify that the package name `mcp-knowledge-base` has been successfully reserved on npm by displaying its public information. ```bash npm view mcp-knowledge-base ``` -------------------------------- ### MCP Knowledge Graph Memory Context Management Tools Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md These are the new command-line tools provided for managing memory contexts within the MCP Knowledge Graph server. They allow users to list, activate, add, and remove different memory contexts, providing flexibility for project-specific memory management. ```APIDOC list_contexts: description: List all available memory contexts. get_active_context: description: Show which memory context is currently active. set_active_context: description: Change the active memory context. parameters: context_name: type: string description: The name of the context to activate. add_context: description: Add a new memory context. parameters: name: type: string description: Human-readable name for the new context. path: type: string | PathTemplate description: File path for the context (static or dynamic template). description: type: string (optional) description: Optional description for the context. isProjectBased: type: boolean description: Whether the context uses project detection. projectDetectionRules: type: object (optional) description: Rules for detecting project directories. properties: markers: type: string[] description: Files that indicate a project root. maxDepth: type: number description: How far up to look for project markers. remove_context: description: Remove a memory context. parameters: context_name: type: string description: The name of the context to remove. (Note: Does not delete the actual memory file). ``` -------------------------------- ### Run Inspector for Testing Memory Path Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/workflow.md Command to execute the '@modelcontextprotocol/inspector' tool, passing the compiled JavaScript file and a memory path argument for testing purposes. ```Shell volta run npx @modelcontextprotocol/inspector dist/index.js --memory-path=C:/Users/shane/Desktop/memory/memory.jsonl ``` -------------------------------- ### Define Build and Watch Scripts in package.json Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/workflow.md Defines standard npm scripts for building the project using 'tsc', preparing the package, and watching for file changes. It also includes a 'chmod' command for executable JavaScript files. ```JSON "scripts": { "build": "tsc && shx chmod +x dist/*.js", "prepare": "npm run build", "watch": "tsc --watch" } ``` -------------------------------- ### Monorepo tsconfig.json for Memory Server Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/pr-instructions.md This JSON snippet shows the correct `tsconfig.json` structure for the `server-memory` package when integrated into the monorepo. It extends the main monorepo `tsconfig.json` and defines specific compiler options for the package's build output and source root. ```json { "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "./dist", "rootDir": "." }, "include": [ "./**/*.ts" ] } ``` -------------------------------- ### TypeScript: Update KnowledgeGraphManager for Dynamic File Paths Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md Illustrates how the KnowledgeGraphManager class methods, specifically 'loadGraph', are updated to accept a 'filePath' parameter, enabling dynamic loading of knowledge graphs based on the active context. ```typescript class KnowledgeGraphManager { private async loadGraph(filePath: string): Promise { try { const data = await fs.readFile(filePath, "utf-8"); // Rest of the method remains the same } catch (error) { // Error handling } } // Other methods would be updated similarly to accept a filePath parameter } ``` -------------------------------- ### Configure Project TypeScript for Monorepo Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/workflow.md Extends the base TypeScript configuration, specifying the output directory for compiled files and the root directory for source files. This configuration is tailored for monorepo compatibility. ```JSON { "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "./dist", "rootDir": "." }, "include": [ "./**/*.ts" ] } ``` -------------------------------- ### Knowledge Graph API Tools Reference Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/README.md This section provides a detailed reference for the API tools available to interact with the `mcp-knowledge-graph` server. It covers methods for managing entities, relations, and observations, including their inputs, outputs, and behaviors. ```APIDOC Tools: - create_entities - Description: Create multiple new entities in the knowledge graph. Ignores entities with existing names. - Input: `entities` (array of objects) - Each object contains: - `name` (string): Entity identifier - `entityType` (string): Type classification - `observations` (string[]): Associated observations - create_relations - Description: Create multiple new relations between entities. Skips duplicate relations. - Input: `relations` (array of objects) - Each object contains: - `from` (string): Source entity name - `to` (string): Target entity name - `relationType` (string): Relationship type in active voice - add_observations - Description: Add new observations to existing entities. Returns added observations per entity. Fails if entity doesn't exist. - Input: `observations` (array of objects) - Each object contains: - `entityName` (string): Target entity - `contents` (string[]): New observations to add - delete_entities - Description: Remove entities and their relations. Cascading deletion of associated relations. Silent operation if entity doesn't exist. - Input: `entityNames` (string[]) - delete_observations - Description: Remove specific observations from entities. Silent operation if observation doesn't exist. - Input: `deletions` (array of objects) - Each object contains: - `entityName` (string): Target entity - `observations` (string[]): Observations to remove - delete_relations - Description: Remove specific relations from the graph. Silent operation if relation doesn't exist. - Input: `relations` (array of objects) - Each object contains: - `from` (string): Source entity name - `to` (string): Target entity name - `relationType` (string): Relationship type - read_graph - Description: Read the entire knowledge graph. - Input: No input required - Returns: Complete graph structure with all entities and relations - search_nodes - Description: Search for nodes based on query. Searches across entity names, entity types, and observation content. - Input: `query` (string) - Returns: Matching entities and their relations - open_nodes - Description: Retrieve specific nodes by name. Silently skips non-existent nodes. - Input: `names` (string[]) - Returns: Requested entities and relations between requested entities ``` -------------------------------- ### Define Memory Context Interfaces for MCP Knowledge Graph Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md This TypeScript interface defines the structure for a single memory context, including its name, path (which can be static or a dynamic template), an optional description, a flag for project-based detection, last access date, and rules for project detection. The `ContextsConfig` interface holds the active context name and an array of all defined memory contexts. ```typescript interface MemoryContext { name: string; // Human-readable name path: string | PathTemplate; // File path (static or dynamic) description?: string; // Optional description isProjectBased: boolean; // Whether to use project detection lastAccessed?: Date; // When it was last used projectDetectionRules?: { // Rules for detecting project directories markers: string[]; // Files that indicate a project root maxDepth: number; // How far up to look for project markers }; } type PathTemplate = string; // e.g., "{projectDir}/.ai-memory.jsonl" interface ContextsConfig { activeContext: string; contexts: MemoryContext[]; } ``` -------------------------------- ### Copy Modified Files to Monorepo Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/pr-instructions.md This bash command copies the locally modified `index.ts` file from a specified path into the `packages/server-memory/` directory within the cloned monorepo. This step integrates the local changes into the monorepo structure before building and committing. ```bash cp /path/to/your/index.ts packages/server-memory/ ``` -------------------------------- ### Identify MCP Knowledge Graph Server Name Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/README.md This snippet shows the designated server name for the `mcp-knowledge-graph` service, which is used for identification within the Model Context Protocol ecosystem. ```txt mcp-knowledge-graph ``` -------------------------------- ### Configure Base TypeScript for ES Modules Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/workflow.md Defines the base TypeScript compiler options for the project, enabling ES module support, strict type checking, and source map generation. This configuration is designed for a modern Node.js environment. ```JSON { "compilerOptions": { "target": "ES2020", "module": "NodeNext", "moduleResolution": "NodeNext", "esModuleInterop": true, "strict": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "declaration": true, "sourceMap": true, "allowJs": true, "checkJs": true } } ``` -------------------------------- ### Commit Changes for Pull Request Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/pr-instructions.md These bash commands stage all current changes in the working directory and then commit them to the active Git branch with a descriptive message. This prepares the changes for pushing to the remote repository and subsequent pull request creation. ```bash git add . git commit -m "Add custom memory path support with cross-platform handling" ``` -------------------------------- ### Create Git Feature Branch for PR Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/development/pr-instructions.md This bash command creates a new Git branch named `feature/custom-memory-path` and switches to it. This is a standard practice for isolating new features or bug fixes, ensuring the main branch remains stable during development for a pull request. ```bash git checkout -b feature/custom-memory-path ``` -------------------------------- ### Implement Memory Path Resolution Logic in TypeScript Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/multiple-memory-contexts.md This asynchronous TypeScript function resolves the correct memory file path based on a given context name or the currently active context. It loads the contexts configuration, finds the relevant context, and if it's project-based, it dynamically resolves the path using detected project information. It falls back to a default path if no context is found. ```typescript async function resolveMemoryPath(contextName?: string): Promise { // Load contexts configuration const config = await loadContexts(CONTEXTS_FILE_PATH); // Get requested context or active context const contextToUse = contextName || config.activeContext || "default"; const context = config.contexts.find(c => c.name === contextToUse); if (!context) { // Fall back to default if context not found return MEMORY_FILE_PATH; } // If it's a static path, return it directly if (!context.isProjectBased) { return context.path; } // For project-based paths, resolve the template const projectInfo = await detectProjectInfo(); return resolvePathTemplate(context.path, projectInfo); } ``` -------------------------------- ### Define TypeScript Interfaces for Versioned Entities and Relations Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/entity-versioning-update-operations.md Defines the TypeScript interfaces for `Entity` and `Relation` objects, incorporating `createdAt` timestamps and `version` numbers. These fields are crucial for tracking the history and evolution of knowledge entities and relations within the MCP Knowledge Graph, enabling versioning and update capabilities. ```typescript interface Entity { name: string; entityType: string; observations: string[]; createdAt: string; // ISO timestamp of creation/update version: number; // Incremented with each update } interface Relation { from: string; to: string; relationType: string; createdAt: string; // ISO timestamp of creation/update version: number; // Incremented with each update } ``` -------------------------------- ### Define Knowledge Graph Relation Structure Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/README.md This JSON snippet demonstrates the structure of a relation in the knowledge graph. Relations define directed connections between entities, specifying the 'from' entity, 'to' entity, and the 'relationType' in active voice. ```json { "from": "John_Smith", "to": "ExampleCorp", "relationType": "works_at" } ``` -------------------------------- ### API Documentation for update_entities Tool Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/entity-versioning-update-operations.md Documents the `update_entities` tool, which is exposed through the MCP server interface. This API allows updating multiple existing entities in the knowledge graph. The input schema defines an array of `entities`, where each entity object requires a `name` and can optionally include `entityType` and `observations`. ```APIDOC { name: "update_entities", description: "Update multiple existing entities in the knowledge graph", inputSchema: { type: "object", properties: { entities: { type: "array", items: { type: "object", properties: { name: { type: "string", description: "The name of the entity to update" }, entityType: { type: "string", description: "The updated type of the entity" }, observations: { type: "array", items: { type: "string" }, description: "The updated array of observation contents" } }, required: ["name"] } } }, required: ["entities"] } } ``` -------------------------------- ### Define Knowledge Graph Observation Structure Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/README.md This JSON snippet outlines the structure for observations, which are discrete, atomic pieces of information attached to specific entities. Observations are stored as strings and can be independently added or removed. ```json { "entityName": "John_Smith", "observations": [ "Speaks fluent Spanish", "Graduated in 2019", "Prefers morning meetings" ] } ``` -------------------------------- ### Define Knowledge Graph Entity Structure Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/README.md This JSON snippet illustrates the structure of an entity within the knowledge graph. Each entity has a unique name, a type, and a list of associated observations, forming the primary nodes of the graph. ```json { "name": "John_Smith", "entityType": "person", "observations": ["Speaks fluent Spanish"] } ``` -------------------------------- ### Implement Asynchronous Update Operations for Knowledge Graph Entities and Relations Source: https://github.com/shaneholloman/mcp-knowledge-graph/blob/main/docs/briefs/entity-versioning-update-operations.md Provides TypeScript asynchronous functions, `updateEntities` and `updateRelations`, designed to modify existing knowledge graph elements. These methods load the graph, locate the target items, increment their version, update their `createdAt` timestamp, and persist the changes. The implementation includes robust error handling for cases where entities or relations are not found. ```typescript async updateEntities(entities: Entity[]): Promise { const graph = await this.loadGraph(); const updatedEntities = entities.map(updateEntity => { const existingEntity = graph.entities.find(e => e.name === updateEntity.name); if (!existingEntity) { throw new Error(`Entity with name ${updateEntity.name} not found`); } return { ...existingEntity, ...updateEntity, version: existingEntity.version + 1, createdAt: new Date().toISOString() }; }); // Update entities in the graph updatedEntities.forEach(updatedEntity => { const index = graph.entities.findIndex(e => e.name === updatedEntity.name); if (index !== -1) { graph.entities[index] = updatedEntity; } }); await this.saveGraph(graph); return updatedEntities; } async updateRelations(relations: Relation[]): Promise { const graph = await this.loadGraph(); const updatedRelations = relations.map(updateRelation => { const existingRelation = graph.relations.find(r => r.from === updateRelation.from && r.to === updateRelation.to && r.relationType === updateRelation.relationType ); if (!existingRelation) { throw new Error(`Relation not found`); } return { ...existingRelation, ...updateRelation, version: existingRelation.version + 1, createdAt: new Date().toISOString() }; }); // Update relations in the graph updatedRelations.forEach(updatedRelation => { const index = graph.relations.findIndex(r => r.from === updatedRelation.from && r.to === updatedRelation.to && r.relationType === updatedRelation.relationType ); if (index !== -1) { graph.relations[index] = updatedRelation; } }); await this.saveGraph(graph); return updatedRelations; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.