### Quick Start: Ingest Documents into Memgraph Source: https://github.com/memgraph/ai-toolkit/blob/main/unstructured2graph/README.md This example demonstrates how to set up Memgraph and LightRAG wrappers, create an index, and ingest documents from URLs or local files into a knowledge graph. Ensure LightRAG is initialized and finalized properly. ```python import asyncio from memgraph_toolbox.api.memgraph import Memgraph from lightrag_memgraph import MemgraphLightRAGWrapper from unstructured2graph import from_unstructured, create_index async def main(): memgraph = Memgraph(user_agent="unstructured2graph") create_index(memgraph, "Chunk", "hash") lightrag = MemgraphLightRAGWrapper() await lightrag.initialize(working_dir="./lightrag_storage") # Ingest documents from URLs or local files await from_unstructured( sources=["https://example.com/doc.pdf", "./local_file.md"], memgraph=memgraph, lightrag_wrapper=lightrag, link_chunks=True, # Create NEXT relationships between chunks ) await lightrag.afinalize() asyncio.run(main()) ``` -------------------------------- ### Bootstrap Agent Context Graph CLI Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-codex/README.md This script bootstraps the Agent Context Graph, installing necessary packages and verifying the setup. It requires uv and a running Memgraph instance. ```bash ./scripts/bootstrap.sh ``` -------------------------------- ### Install unstructured2graph from Source Source: https://github.com/memgraph/ai-toolkit/blob/main/unstructured2graph/README.md Clone the repository and install the library from source. For full document support including PDFs and DOCX, install with the 'all-docs' extra. ```bash git clone https://github.com/memgraph/ai-toolkit.git cd ai-toolkit/unstructured2graph pip install -e . ``` ```bash pip install -e ".[all-docs]" ``` -------------------------------- ### Install Hook Command and Graph Connector Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/docs/command-hooks.md Install the required packages into a virtual environment for the command hook and graph connector. This step is necessary for manual setup. ```bash python -m venv ~/.venvs/agent-context-graph-hooks ~/.venvs/agent-context-graph-hooks/bin/python -m pip install \ "agent-context-graph" \ "skills-graph[agent-context-graph]" ``` -------------------------------- ### Install agent-context-graph with OpenAI adapter Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Install the agent-context-graph package with the OpenAI adapter support. ```bash pip install agent-context-graph[openai] ``` -------------------------------- ### Run SQL2Graph Agent Source: https://github.com/memgraph/ai-toolkit/blob/main/agents/sql2graph/README.md Execute the main script to start the migration agent. The agent will guide you through the setup and migration process. ```bash uv run main ``` -------------------------------- ### Install agent-context-graph with Claude adapter Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Install the agent-context-graph package with the Claude adapter support. ```bash pip install agent-context-graph[claude] ``` -------------------------------- ### Install Memgraph Toolbox with Optional Dependencies Source: https://github.com/memgraph/ai-toolkit/blob/main/memgraph-toolbox/README.md Shows how to install the base memgraph-toolbox package and optional dependencies for specific functionalities like the MCP prompt client, evaluation metrics, or running tests. Use the bracket notation to specify which optional dependencies to install. ```bash pip install memgraph-toolbox ``` ```bash pip install 'memgraph-toolbox[client]' ``` ```bash pip install 'memgraph-toolbox[evaluations]' ``` ```bash pip install 'memgraph-toolbox[test]' ``` ```bash pip install 'memgraph-toolbox[client,evaluations,test]' ``` -------------------------------- ### Install skills-graph connector Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Install the skills-graph package with the agent-context-graph connector support. ```bash pip install skills-graph[agent-context-graph] ``` -------------------------------- ### Install memgraph-toolbox Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs the core utilities package for Memgraph. ```bash pip install memgraph-toolbox ``` -------------------------------- ### Minimal Async Example Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/lightrag-memgraph/README.md A basic asynchronous example demonstrating wrapper initialization, text insertion, and finalization. Ensure Memgraph is running and an LLM API key is set. ```python import asyncio from lightrag_memgraph import MemgraphLightRAGWrapper async def main(): wrapper = MemgraphLightRAGWrapper(disable_embeddings=True) await wrapper.initialize(working_dir="./lightrag_storage") await wrapper.ainsert(input="Your document text here.", file_paths=["doc1"]) # optional: rag = wrapper.get_lightrag(); print(await rag.get_graph_labels()) await wrapper.afinalize() asyncio.run(main()) ``` -------------------------------- ### ActionsGraph Setup and Management Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/actions-graph/README.md Initialize and manage the ActionsGraph instance. Use setup to create indexes, drop to remove them, and clear to remove all data. ```python graph = ActionsGraph() # Setup graph.setup() # Create indexes graph.drop() # Remove indexes graph.clear() # Clear all data ``` -------------------------------- ### Build and Install Package Locally Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Commands to build the project package using `uv build` and install it locally in editable mode using `uv pip install -e .`. ```bash # Build package uv build # Install locally in editable mode uv pip install -e . ``` -------------------------------- ### Install Context Graph Plugin Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-claude/README.md Installs the Agent Context Graph skill from the marketplace. This command makes the skill available for use. ```text /plugin install context-graph@context-graph-plugins ``` -------------------------------- ### Install Actions Graph Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/actions-graph/README.md Install the Actions Graph library using pip. For Agent Context Graph integration, install with the optional dependencies. ```bash pip install actions-graph ``` ```bash pip install "actions-graph[agent-context-graph]" ``` -------------------------------- ### Install lightrag-memgraph Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/lightrag-memgraph/README.md Install the library using pip. This is a prerequisite for using the integration. ```bash pip install lightrag-memgraph ``` -------------------------------- ### Install agent-context-graph for SDK usage Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Install the agent-context-graph package for use within an application's SDK. ```bash pip install agent-context-graph ``` -------------------------------- ### Install langchain-memgraph Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs the LangChain tools and chains integration for Memgraph. ```bash pip install langchain-memgraph ``` -------------------------------- ### SQL2Graph Agent Usage Examples Source: https://github.com/memgraph/ai-toolkit/blob/main/agents/sql2graph/README.md Examples demonstrating how to run the SQL2Graph agent using different LLM providers and models. The agent can auto-detect providers based on API keys or allow explicit selection. ```bash # Auto-detect provider based on API keys uv run main --strategy llm # Use specific provider uv run main --strategy llm --provider anthropic # Use specific model uv run main --strategy llm --provider openai --model gpt-4o # All options together uv run main --mode incremental --strategy llm --provider gemini --model gemini-1.5-flash ``` -------------------------------- ### Install Memgraph Toolkit Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/docs/toolkits.ipynb Install the `langchain-memgraph` package using pip. This command installs the toolkit and its dependencies. ```python %pip install -qU langchain-memgraph ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Install the necessary dependencies for running tests, including integration tests. ```bash poetry install --with test,test_integration ``` -------------------------------- ### Instantiate and Use Memgraph Toolbox Tools Source: https://github.com/memgraph/ai-toolkit/blob/main/memgraph-toolbox/README.md Demonstrates how to connect to a Memgraph instance, list available tools, and use a specific tool like ShowTriggersTool. Ensure you have a running Memgraph instance and the memgraph-toolbox package installed. ```python from memgraph_toolbox.tools.trigger import ShowTriggersTool from memgraph_toolbox.api.memgraph import Memgraph from memgraph_toolbox.memgraph_toolbox import MemgraphToolbox # Connect to Memgraph db = Memgraph(url="bolt://localhost:7687", username="", password="") # Show available tools toolbox = MemgraphToolbox(db) for tool in toolbox.get_all_tools(): print(f"Tool Name: {tool.name}, Description: {tool.description}") # Use the ShowTriggersTool tool = ShowTriggersTool(db) triggers = tool.call({}) print(triggers) ``` -------------------------------- ### Install mcp-memgraph Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs the MCP server package for LLMs with Memgraph. ```bash pip install mcp-memgraph ``` -------------------------------- ### Manual Setup Skill Graph Initialization Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/docs/command-hooks.md Initialize the skill graph using the `SkillGraph` class after setting the necessary Memgraph environment variables. ```python from skills_graph import SkillGraph skills = SkillGraph() skills.setup() ``` -------------------------------- ### Setup LangSmith Tracing Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/docs/toolkits.ipynb Optional setup for automated tracing from runs of individual tools using LangSmith. Requires LangSmith API key. ```python # os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ") # os.environ["LANGSMITH_TRACING"] = "true" ``` -------------------------------- ### Install agent-context-graph with skills-graph Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Install the agent-context-graph tool with skills-graph support for command-hook runtimes like Codex and Claude Code. ```bash uv tool install agent-context-graph --with "skills-graph[agent-context-graph]" ``` -------------------------------- ### Install Dependencies with uv Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/skills-graph/README.md Installs project dependencies using the uv package manager. ```Bash uv sync ``` -------------------------------- ### Implement New Runtime Adapter Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Example of implementing a new runtime adapter by inheriting from RuntimeAdapter and emitting ToolStartEvent. ```python from agent_context_graph import AgentLink, ToolStartEvent from agent_context_graph.protocols import RuntimeAdapter class MyRuntimeAdapter(RuntimeAdapter): def __init__(self, link: AgentLink, session_id: str): self._link = link self._session_id = session_id def get_runtime_hooks(self): # Return whatever your runtime expects. ... def _on_tool_call(self, name, args): self._link.emit( ToolStartEvent( session_id=self._session_id, tool_name=name, tool_input=args, ) ) ``` -------------------------------- ### Install unstructured2graph Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs the package for converting documents to graph format. ```bash pip install unstructured2graph ``` -------------------------------- ### Install Sessions Graph Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/sessions-graph/README.md Install the sessions-graph package. Use the agent-context-graph extra for integration with Agent Context Graph. ```bash pip install sessions-graph ``` ```bash pip install sessions-graph[agent-context-graph] ``` -------------------------------- ### Install LangChain Memgraph Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Install the LangChain Memgraph integration package using pip. ```bash pip install -U langchain-memgraph ``` -------------------------------- ### Install langchain-community Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/docs/tools.ipynb Install the langchain-community package to use the Memgraph integration. This is a prerequisite for using the tool. ```python %pip install --quiet -U langchain-community ``` -------------------------------- ### Install SQL2Graph Agent Source: https://github.com/memgraph/ai-toolkit/blob/main/agents/sql2graph/README.md Install the package using pip. Use the -e flag for development mode. ```bash uv pip install . # Or install in development mode uv pip install -e . ``` -------------------------------- ### ActionsGraph Setup and Management Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/actions-graph/README.md Methods for initializing, setting up, dropping, and clearing the ActionsGraph. ```APIDOC ## ActionsGraph Setup and Management ### Description Methods for initializing, setting up, dropping, and clearing the ActionsGraph. ### Methods - `setup()`: Creates necessary indexes in the graph. - `drop()`: Removes all indexes from the graph. - `clear()`: Deletes all data within the graph. ``` -------------------------------- ### Quick Start: Managing AI Skills with SkillGraph Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/skills-graph/README.md Demonstrates basic operations for adding, retrieving, searching, managing dependencies, listing, updating, and deleting AI skills using the SkillGraph library. ```Python from skills_graph import SkillGraph, Skill # Connect (uses MEMGRAPH_URL, MEMGRAPH_USER, MEMGRAPH_PASSWORD env vars by default) sg = SkillGraph() # Prepare the database schema (constraints + indexes) sg.setup() # Store a skill sg.add_skill(Skill( name="memgraph-cypher", description="Writing Cypher queries for Memgraph", content="# Cypher for Memgraph\n\nUse MATCH, CREATE, MERGE ...", )) # Retrieve by name skill = sg.get_skill("memgraph-cypher") # Search sg.search_by_name("memgraph") # Dependencies sg.add_dependency("advanced-cypher", "memgraph-cypher") deps = sg.get_dependencies("advanced-cypher") # List all all_skills = sg.list_skills() # Update sg.update_skill("memgraph-cypher", content="updated content") # Delete sg.delete_skill("memgraph-cypher") ``` -------------------------------- ### Running the Memgraph Server Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Install dependencies and run the Memgraph server using uv. The experimental server can be launched by setting the MCP_SERVER environment variable. ```bash # Install dependencies uv sync # Run default server uv run mcp-memgraph # Run experimental server MCP_SERVER=experimental uv run mcp-memgraph # Or install globally and run uv pip install -e . mcp-memgraph # Run specific server when installed MCP_SERVER=experimental mcp-memgraph # Run experimental Memgraph server MCP_SERVER=memgraph-experimental uv run mcp-memgraph ``` -------------------------------- ### Install Dependencies with uv Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Commands to manage project dependencies using `uv`. Use `uv sync` to install base dependencies and `uv sync --extra test` to include test dependencies. ```bash # Install dependencies uv sync # Install with test dependencies uv sync --extra test ``` -------------------------------- ### Start Memgraph Docker Container Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Start a Memgraph instance using Docker, exposing the default port and enabling schema information. ```bash docker run -p 7687:7687 \ --name memgraph \ memgraph/memgraph-mage:latest \ --schema-info-enabled=true ``` -------------------------------- ### Instantiate Memgraph Toolkit Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/docs/toolkits.ipynb Instantiate the `MemgraphToolkit` class. Replace `...` with relevant parameters for your setup. ```python from langchain_memgraph import MemgraphToolkit toolkit = MemgraphToolkit( # ... ) ``` -------------------------------- ### Install memgraph-toolbox with Zsh workaround Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs memgraph-toolbox with test dependencies, including a workaround for zsh shell on macOS. ```bash uv pip install -e memgraph-toolbox"[test]" ``` -------------------------------- ### Install OpenAI Dependency for QA Chain Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Install the `lanchain_openai` package, which is an extra dependency required for using the MemgraphQAChain. ```bash pip install lanchain_openai ``` -------------------------------- ### Install Code Formatting and Linting Dependencies Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Install dependencies required for code formatting and linting, including codespell. ```bash poetry install --with codespell,lint,typing ``` -------------------------------- ### Run Local Test Script Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-codex/README.md Execute the local test script from the plugin directory to verify the setup. ```bash ./scripts/doctor.sh ``` -------------------------------- ### Setup Local Codex Config (Default Memgraph) Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/docs/command-hooks.md Use this command to set up the local Codex configuration when Memgraph is running with default settings. The `--setup-schema` flag connects to Memgraph and runs `SkillGraph().setup()`. ```bash agent-context-graph setup codex --project-dir "$PWD" --setup-schema ``` -------------------------------- ### Bootstrap Codex Plugin Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Installs the runtime package, checks Memgraph, installs the graph connector, and runs doctor for the Codex runtime. ```bash agent-context-graph bootstrap --runtime codex --connector skills-graph ``` -------------------------------- ### Claude Desktop Future Server Examples Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Illustrative JSON configurations for future Memgraph server integrations in Claude Desktop, such as 'memgraph-experimental' and 'memgraph-hygm', specifying their commands and environment variables. ```json { "mcpServers": { "memgraph-experimental": { "command": "uv", "args": [ "run", "--with", "mcp-memgraph", "--python", "3.13", "mcp-memgraph" ], "env": { "MCP_SERVER": "memgraph-experimental" } }, "memgraph-hygm": { "command": "uv", "args": [ "run", "--with", "mcp-memgraph", "--python", "3.13", "mcp-memgraph" ], "env": { "MCP_SERVER": "hygm" } } } } ``` -------------------------------- ### Install Memgraph AI Toolkit Python Packages Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Install the core memgraph-toolbox, LangChain integration, MCP server, and unstructured2graph packages using pip. ```bash # Core toolbox pip install memgraph-toolbox # LangChain integration pip install langchain-memgraph # MCP server pip install mcp-memgraph # Unstructured to Graph pip install unstructured2graph ``` -------------------------------- ### Manual Setup Environment Variables Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/docs/command-hooks.md Set these environment variables to ensure your Python environment can reach Memgraph for manual setup. These are required before initializing the skill graph. ```bash export MEMGRAPH_URL="bolt://localhost:7687" export MEMGRAPH_USER="" export MEMGRAPH_PASSWORD="" ``` -------------------------------- ### Source Development Setup Codex Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/docs/command-hooks.md Command for source development within the workspace to set up Codex, specifying Memgraph connection details and schema setup. ```bash uv run --package skills-graph --extra agent-context-graph \ python -m agent_context_graph.cli setup codex \ --project-dir /path/to/your/repo \ --memgraph-url bolt://localhost:7687 \ --setup-schema ``` -------------------------------- ### Bootstrap Agent Context Graph Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-claude/README.md Installs and verifies the Agent Context Graph with specified connectors. This command ensures all components are set up correctly. ```bash agent-context-graph bootstrap --runtime claude-code --connector skills-graph --connector actions-graph --connector sessions-graph ``` -------------------------------- ### Agent Context Graph Connector Setup Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/actions-graph/README.md Integrate the ActionsGraph with the Agent Context Graph Connector to record lifecycle events and action nodes. ```python from actions_graph.connector import ActionsGraphConnector connector = ActionsGraphConnector(graph) link.add_connector(connector) ``` -------------------------------- ### Run LangChain Integration Tests Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs langchain-memgraph with test dependencies and runs integration tests. Requires an OPENAI_API_KEY in a .env file. ```bash uv pip install -e integrations/langchain-memgraph[test] pytest -s integrations/langchain-memgraph/tests ``` -------------------------------- ### Quick Start: Sessions Graph Usage Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/sessions-graph/README.md Initialize SessionsGraph, set up the database schema and text index, and perform basic operations like saving, retrieving, searching, updating, and deleting memories. ```python from sessions_graph import SessionsGraph graph = SessionsGraph() # connects via MEMGRAPH_HOST / MEMGRAPH_PORT env vars graph.setup() # creates constraints and the text index (run once) # Write a memory mem = graph.save_memory( user_id="alice", content="Prefers Python over TypeScript", session_id="s-abc123", # optional — links memory to a session for provenance ) # Retrieve all memories for a user memories = graph.get_memories("alice") # Search memories by content (full-text, powered by Tantivy) results = graph.search_memories("alice", "Python") # Update or delete graph.update_memory(mem.memory_id, "Prefers Python, especially for data tooling") graph.delete_memory(mem.memory_id) ``` -------------------------------- ### Setup Local Codex Config (Non-Default Memgraph) Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/docs/command-hooks.md Configure local Codex with non-default Memgraph connection details. The `--memgraph-*` options are used for `--setup-schema` but are not saved in `.codex/hooks.json`. ```bash agent-context-graph setup codex \ --project-dir /path/to/your/repo \ --memgraph-url bolt://localhost:7687 \ --memgraph-user "" \ --memgraph-password "" \ --memgraph-database memgraph \ --setup-schema ``` -------------------------------- ### Implement New Graph Connector Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Example of implementing a new graph connector by inheriting from GraphConnector and defining support and event handling logic. ```python from agent_context_graph import EventType from agent_context_graph.protocols import GraphConnector class MyGraphConnector(GraphConnector): def supports(self, event): return event.event_type in {EventType.TOOL_START, EventType.TOOL_END} def on_event(self, event): # Write to your graph component. ... ``` -------------------------------- ### Create a Tool Chain Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/docs/tools.ipynb Create a chain that takes user input, gets a response from the LLM (which may include a tool call), executes the tool, and then gets a final response from the LLM. This demonstrates how to use the Memgraph tool within a LangChain LCEL chain. ```python @chain def tool_chain(user_input: str, config: RunnableConfig): input_ = {"user_input": user_input} ai_msg = llm_chain.invoke(input_, config=config) tool_msgs = tool.batch(ai_msg.tool_calls, config=config) return llm_chain.invoke({**input_, "messages": [ai_msg, *tool_msgs]}, config=config) tool_chain.invoke("...") ``` -------------------------------- ### Run MCP Integration Tests Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs mcp-memgraph with test dependencies and runs integration tests. ```bash uv pip install -e integrations/mcp-memgraph[test] pytest -s integrations/mcp-memgraph/tests ``` -------------------------------- ### Run sql2graph Agent for Database Migration Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Start the sql2graph agent to assist in migrating data from MySQL/PostgreSQL to Memgraph using AI. ```bash cd agents/sql2graph uv run main.py ``` -------------------------------- ### Run Agent Integration Tests Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs the agents package with test dependencies and runs integration tests. ```bash uv pip install -e integrations/agents[test] pytest -s integrations/agents/tests ``` -------------------------------- ### Run Core Tests Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Installs memgraph-toolbox with test dependencies and runs core tests using pytest. ```bash uv pip install -e memgraph-toolbox[test] pytest -s memgraph-toolbox/src/memgraph_toolbox/tests ``` -------------------------------- ### Run Memgraph Docker Container Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-codex/README.md This command starts a Memgraph instance using Docker. Ensure Memgraph is running and reachable over Bolt before bootstrapping. ```bash docker run --rm -p 7687:7687 memgraph/memgraph ``` -------------------------------- ### Registering Configuration and Storage Tools Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Illustrates the registration of MCP tools for fetching Memgraph configuration settings and storage usage metrics. ```python @mcp.tool() def get_configuration(): """Fetch Memgraph configuration settings.""" return toolbox.get_configuration() @mcp.tool() def get_storage(): """Get storage usage metrics.""" return toolbox.get_storage() ``` -------------------------------- ### Build Docker Image Locally Source: https://github.com/memgraph/ai-toolkit/blob/main/agents/sql2graph/skills/build-and-or-publish-docker.md Use this command to build the release Docker image locally. It's useful for testing changes to the Docker setup before publishing. ```bash docker build -f Dockerfile.local -t memgraph/structured2graph: -t memgraph/structured2graph:latest . ``` -------------------------------- ### Registering MCP Tools with FastMCP Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Demonstrates how to register Memgraph operations as MCP tools using the @mcp.tool() decorator within the FastMCP framework. This example shows the 'run_query' tool. ```python from fastmcp import MCP from mcp_memgraph.config import MemgraphConfig from mcp_memgraph.tools import MemgraphToolbox mcp = MCP() config = MemgraphConfig() toolbox = MemgraphToolbox(config) @mcp.tool() def run_query(query: str): """Execute Cypher queries.""" return toolbox.run_query(query) ``` -------------------------------- ### Format and Type Check Code with uv Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Commands to format code using `black` and perform type checking with `mypy` via `uv`. Ensure these tools are installed and configured. ```bash # Format code (if configured) uv run black src/ tests/ # Type check (if mypy is added) uv run mypy src/ ``` -------------------------------- ### Run MCP Server and Tests with uv Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Commands to run the MCP server and execute tests using `uv`. The server is started with `uv run mcp-memgraph`, and tests are run with `uv run pytest tests/ -v`. ```bash # Run the MCP server uv run mcp-memgraph # Run tests uv run pytest tests/ -v ``` -------------------------------- ### Initialize MemgraphToolkit and Agent Executor Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Set up the MemgraphToolkit with a database connection and an LLM, then create a ReAct agent executor for querying Memgraph. ```python import os import pytest from dotenv import load_dotenv from langchain.chat_models import init_chat_model from langchain_memgraph import MemgraphToolkit from langchain_memgraph.graphs.memgraph import MemgraphLangChain from langgraph.prebuilt import create_react_agent os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "") url = os.getenv("MEMGRAPH_URL", "bolt://localhost:7687") username = os.getenv("MEMGRAPH_USER", "") password = os.getenv("MEMGRAPH_PASSWORD", "") llm = init_chat_model("gpt-4o-mini", model_provider="openai") db = MemgraphLangChain(url=url, username=username, password=password) toolkit = MemgraphToolkit(db=db, llm=llm) agent_executor = create_react_agent( llm, toolkit.get_tools(), prompt="You will get a cypher query, try to execute it on the Memgraph database." ) example_query = "MATCH (n) WHERE n.name = 'Jon Snow' RETURN n" events = agent_executor.stream( {"messages": [("user", example_query)]}, stream_mode="values", ) last_event = None for event in events: last_event = event event["messages"][-1].pretty_print() print(last_event) ``` -------------------------------- ### Initialize MCP and Logger for a New Server Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Imports necessary modules and initializes the logger and FastMCP instance for a new server implementation. Ensure the server name is correctly formatted. ```python from mcp_memgraph.config import get_memgraph_config, get_mcp_config from memgraph_toolbox.utils.logger import logger_init from fastmcp import FastMCP logger = logger_init("mcp-memgraph-") mcp = FastMCP("mcp-memgraph-") ``` -------------------------------- ### Basic Actions Graph Usage Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/actions-graph/README.md Initialize Actions Graph, set up indexes, create a session, record a tool call and its result, and retrieve a session summary. Ensure the graph is set up before performing operations. ```python from actions_graph import ActionsGraph, Session, ToolCall # Initialize the graph graph = ActionsGraph() graph.setup() # Create indexes and constraints # Create a session session = Session( session_id="session-123", model="claude-sonnet-4-20250514", working_directory="/path/to/project", ) graph.create_session(session) # Record a tool call tool_call = graph.record_tool_call( session_id="session-123", tool_name="Read", tool_input={"file_path": "/path/to/file.py"}, tool_use_id="tool-use-001", ) # Record the result tool_result = graph.record_tool_result( session_id="session-123", tool_use_id="tool-use-001", tool_name="Read", content="def hello():\n print('Hello, World!')", ) # Get session summary summary = graph.get_session_summary("session-123") print(f"Actions: {summary['action_count']}, Tools: {summary['tool_call_count']}") ``` -------------------------------- ### MCP Server Startup and Routing Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md The main entry point for the MCP Memgraph server. It handles server startup and routing, dynamically loading different server implementations based on the MCP_SERVER environment variable. ```python from mcp_memgraph.config import MCPServerConfig from mcp_memgraph.servers import get_server def main(): config = MCPServerConfig() server = get_server(config.server_name) server.run() if __name__ == "__main__": main() ``` -------------------------------- ### Bootstrap Claude Code Plugin Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Installs the runtime package, checks Memgraph, installs the graph connector, and runs doctor for the Claude Code runtime. ```bash agent-context-graph bootstrap --runtime claude-code --connector skills-graph ``` -------------------------------- ### Add Git Marketplace Repository (CLI) Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-claude/README.md CLI equivalent for adding the repository to the Claude Code marketplace. Use the --sparse flag for specific configurations. ```bash claude plugin marketplace add memgraph/ai-toolkit --sparse .claude-plugin ``` -------------------------------- ### Install Claude Code Hooks Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-claude/README.md Installs Claude Code lifecycle hooks to connect to graph connectors. Use this command to set up the plugin's integration points. ```bash agent-context-graph hook run claude-code --connector skills-graph --connector actions-graph --connector sessions-graph ``` -------------------------------- ### Start Docker Container in Background Source: https://github.com/memgraph/ai-toolkit/blob/main/agents/sql2graph/skills/running-under-docker-in-background.md Start the structured2graph container in detached mode. It is configured with network, name, environment variables, volume mounts, and an entrypoint to keep it running. ```bash docker run -d --rm --net memgql-net --name structured2graph-dev --env-file .env -v $(pwd)/output:/output --entrypoint sleep memgraph/structured2graph infinity ``` -------------------------------- ### Build Docker Image Source: https://github.com/memgraph/ai-toolkit/blob/main/agents/sql2graph/skills/running-under-docker-in-background.md Build the Docker image using the provided Dockerfile. Use Dockerfile.local for local source code. ```bash docker build -f Dockerfile.local -t memgraph/structured2graph . ``` -------------------------------- ### Check Claude Desktop Configuration Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Verify the syntax and content of `claude_desktop_config.json` if integration with Claude Desktop is failing. ```markdown Check `claude_desktop_config.json` syntax if Claude integration fails. ``` -------------------------------- ### Check Codex Runtime Doctor Output Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Verifies the successful installation and configuration of the Codex runtime and its connectors. ```text OK agent-context-graph executable: ... OK agent-context-graph: ... OK connector:skills-graph: installed=...; memgraph=reachable OK runtime:codex: strict hook smoke passed ``` -------------------------------- ### Register New Server Implementation Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Adds a new server implementation to the AVAILABLE_SERVERS dictionary in `servers/__init__.py`. This makes the server discoverable and loadable by the MCP. ```python "": { "module": "mcp_memgraph.servers.", "emoji": "🔬", "description": "Your server description", }, ``` -------------------------------- ### Check Claude Code Runtime Doctor Output Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Verifies the successful installation and configuration of the Claude Code runtime and its connectors. ```text OK runtime:claude-code: strict hook smoke passed ``` -------------------------------- ### Add Git Marketplace Repository Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-claude/README.md Registers the current repository as a Claude Code marketplace. This makes the plugin discoverable for installation. ```text /plugin marketplace add memgraph/ai-toolkit ``` -------------------------------- ### Generated Codex Files Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/docs/command-hooks.md These are the local files generated by the Codex setup command. They are ignored by default and do not contain Memgraph credentials. ```text .codex/config.toml .codex/hooks.json ``` -------------------------------- ### Run SQL2Graph Agent with Custom Configuration Source: https://github.com/memgraph/ai-toolkit/blob/main/agents/sql2graph/README.md Run the migration agent with specific configurations for mode, strategy, meta-graph policy, and log level. ```bash uv run main --mode incremental --strategy llm --meta-graph reset --log-level DEBUG ``` -------------------------------- ### Docker Build and Run Commands Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Build a Docker image for mcp-memgraph and run it as a container, specifying the Memgraph URL via an environment variable. ```bash docker build -t mcp-memgraph . docker run -e MEMGRAPH_URL=bolt://host.docker.internal:7687 mcp-memgraph ``` -------------------------------- ### Get Tool Calls in a Session Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/actions-graph/README.md Retrieve all actions of type TOOL_CALL within a specific session. Ensure the 'actions_graph' library is imported. ```python from actions_graph import ActionType tool_calls = graph.get_session_actions( session_id, action_type=ActionType.TOOL_CALL, ) ``` -------------------------------- ### Run Memgraph Experimental Server with uv Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/README.md Use this command to run the experimental Memgraph server with autonomous GraphRAG capabilities using the uv package manager. ```bash MCP_SERVER=memgraph-experimental uv run mcp-memgraph ``` -------------------------------- ### Instantiate Memgraph Tool Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/docs/tools.ipynb Instantiate the Memgraph tool. Replace '...' with the actual parameters required for your Memgraph connection. ```python from langchain_community.tools import Memgraph tool = Memgraph(...) ``` -------------------------------- ### Define Prompt and LLM with Tools Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/docs/tools.ipynb Define a chat prompt template and bind the initialized chat model with the Memgraph tool. Specifying `tool_choice` forces the model to call this specific tool. ```python from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnableConfig, chain prompt = ChatPromptTemplate( [ ("system", "You are a helpful assistant."), ("human", "{user_input}"), ("placeholder", "{messages}"), ] ) # specifying tool_choice will force the model to call this tool. llm_with_tools = llm.bind_tools([tool], tool_choice=tool.name) llm_chain = prompt | llm_with_tools ``` -------------------------------- ### Initialize MemgraphQAChain Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Initialize MemgraphQAChain for natural language interactions with Memgraph. Requires an LLM and MemgraphLangChain instance. Ensure OPENAI_API_KEY is set. ```python import os from langchain_memgraph.graphs.memgraph import MemgraphLangChain from langchain_memgraph.chains.graph_qa import MemgraphQAChain from langchain_openai import ChatOpenAI os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "") url = os.getenv("MEMGRAPH_URL", "bolt://localhost:7687") username = os.getenv("MEMGRAPH_USER", "") password = os.getenv("MEMGRAPH_PASSWORD", "") graph = MemgraphLangChain(url=url, username=username, password=password, refresh_schema=False) chain = MemgraphQAChain.from_llm( ChatOpenAI(temperature=0), graph=graph, model_name="gpt-4-turbo", allow_dangerous_requests=True, ) response = chain.invoke("Is there a any Person node in the dataset?") result = response["result"].lower() print(result) ``` -------------------------------- ### Running Memgraph Tests Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/PROMPT.md Install test dependencies and execute tests using pytest. Options include running all tests, specific files, or with code coverage. ```bash # Install test dependencies uv sync --extra test # Run all tests uv run pytest tests/ -v # Run specific test file uv run pytest tests/test_server.py -v # Run with coverage uv run pytest tests/ -v --cov=mcp_memgraph ``` -------------------------------- ### Bootstrap Agent Context Graph with Runtime and Connectors Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/plugins/agent-context-graph-codex/README.md This command performs the bootstrap process for Agent Context Graph, specifying the 'codex' runtime and the required connectors. ```bash agent-context-graph bootstrap --runtime codex --connector skills-graph --connector actions-graph --connector sessions-graph ``` -------------------------------- ### Integrate Graph Connectors with AgentLink Source: https://github.com/memgraph/ai-toolkit/blob/main/context-graph/agent-context-graph/README.md Demonstrates how to initialize an AgentLink and add multiple graph connectors, such as SkillGraphConnector and a custom MyGraphConnector. ```python from agent_context_graph import AgentLink from agent_context_graph.adapters.claude import ClaudeAdapter from skills_graph import SkillGraph from skills_graph.connector import SkillGraphConnector skills = SkillGraph() link = AgentLink() link.add_connector(SkillGraphConnector(skills)) link.add_connector(MyGraphConnector(...)) adapter = ClaudeAdapter(link, session_id="s-1") hooks = adapter.get_runtime_hooks() ``` -------------------------------- ### Ingest Documents into Memgraph with unstructured2graph Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Use unstructured2graph to transform documents from URLs or local files into a knowledge graph in Memgraph. Requires Memgraph and LightRAG setup. ```python import asyncio from memgraph_toolbox.api.memgraph import Memgraph from lightrag_memgraph import MemgraphLightRAGWrapper from unstructured2graph import from_unstructured, create_index async def main(): memgraph = Memgraph() create_index(memgraph, "Chunk", "hash") lightrag = MemgraphLightRAGWrapper() await lightrag.initialize(working_dir="./lightrag_storage") # Ingest documents from URLs or local files await from_unstructured( sources=["https://example.com/doc.pdf", "./local_file.md"], memgraph=memgraph, lightrag_wrapper=lightrag, link_chunks=True, ) await lightrag.afinalize() asyncio.run(main()) ``` -------------------------------- ### Initialize Wrapper with Anthropic Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/lightrag-memgraph/README.md Configure the MemgraphLightRAGWrapper to use Anthropic's LLM. Pass the anthropic_complete function and a specific model name to initialize. ```python from lightrag.llm.anthropic import anthropic_complete from lightrag_memgraph import MemgraphLightRAGWrapper wrapper = MemgraphLightRAGWrapper(disable_embeddings=True) # or set embedding_func await wrapper.initialize( working_dir="./lightrag_storage", llm_model_func=anthropic_complete, llm_model_name="claude-3-5-sonnet-20241022", # or claude-3-haiku-20240307, etc. ) ``` -------------------------------- ### Configure Memgraph MCP Server in Claude Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/README.md Add this JSON configuration to your Claude desktop app settings to enable the Memgraph MCP server. Ensure 'uv' is installed and accessible. ```json { "mcpServers": { "mpc-memgraph": { "command": "uv", "args": [ "run", "--with", "mcp-memgraph", "--python", "3.13", "mcp-memgraph" ] } } } ``` -------------------------------- ### Initialize MemgraphLangChain Client Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Initialize the MemgraphLangChain client with connection details. It supports environment variables for URL, username, and password. ```python import os from langchain_memgraph.graphs.memgraph import MemgraphLangChain url = os.getenv("MEMGRAPH_URL", "bolt://localhost:7687") username = os.getenv("MEMGRAPH_USER", "") password = os.getenv("MEMGRAPH_PASSWORD", "") graph = MemgraphLangChain(url=url, username=username, password=password) results = graph.query("MATCH (n) RETURN n LIMIT 1") print(results) ``` -------------------------------- ### Run Complete Agent Migration Workflow Source: https://github.com/memgraph/ai-toolkit/blob/main/README.md Navigates to the agents directory and executes the main script for a complete migration workflow. Requires MySQL and Memgraph connections, with environment variables set in .env. ```bash cd integrations/agents uv run main.py ``` -------------------------------- ### Run Unit Tests Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/README.md Execute the unit tests for the LangChain Memgraph integration. ```bash make tests ``` -------------------------------- ### Run Memgraph MAGE Docker Container Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/README.md Start a Memgraph MAGE Docker container. The `--schema-info-enabled=True` flag is crucial for allowing the LLM to execute schema information queries. ```bash docker run -p 7687:7687 memgraph/memgraph-mage --schema-info-enabled=True ``` -------------------------------- ### View Available Tools Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/langchain-memgraph/docs/toolkits.ipynb Retrieve a list of all available tools provided by the instantiated Memgraph toolkit. ```python toolkit.get_tools() ``` -------------------------------- ### Docker Usage for Local Development Source: https://github.com/memgraph/ai-toolkit/blob/main/agents/sql2graph/README.md Build and run the agent using Docker for local development. This includes building the image, running a container, and executing the agent within the container. ```bash docker build -f Dockerfile.local -t memgraph/structured2graph . docker run -d --rm --net memgql-net --name structured2graph-dev \ --env-file .env -v $(pwd)/output:/output \ --entrypoint sleep memgraph/structured2graph infinity docker exec -it structured2graph-dev uv run main.py --mapping /output/mapping.json ``` -------------------------------- ### Run Memgraph Experimental Server with Docker Source: https://github.com/memgraph/ai-toolkit/blob/main/integrations/mcp-memgraph/README.md Use this command to run the experimental Memgraph server with autonomous GraphRAG capabilities using Docker. ```bash docker run --rm -e MCP_SERVER=memgraph-experimental memgraph/mcp-memgraph:latest ```