mcp-memgraph

Memgraph MCP Server: Connect Memgraph to LLMs securely via MCP. Run Cypher queries and access schema info.

mcp-memgraph
mcp-memgraph Capabilities Showcase

mcp-memgraph Solution Overview

Memgraph MCP Server is a lightweight MCP server designed to seamlessly connect Memgraph databases with Large Language Models (LLMs). This server empowers LLMs to securely access and leverage data stored within Memgraph through the MCP protocol. It offers tools like run_query() for executing Cypher queries against Memgraph and resources such as get_schema() to retrieve Memgraph schema information, provided schema info is enabled.

By integrating Memgraph MCP Server, developers can build graph-driven AI applications and intelligent agents with ease. The server facilitates a secure and efficient interaction between LLMs and Memgraph, enabling advanced data analysis and knowledge discovery. The server is implemented in Python and can be easily integrated into existing workflows using uv. This solution simplifies the process of incorporating graph database capabilities into modern AI workflows.

mcp-memgraph Key Capabilities

Cypher Query Execution

The core functionality of mcp-memgraph is to enable Large Language Models (LLMs) to execute Cypher queries against a Memgraph database. This is achieved through the run_query() tool, which receives a Cypher query from the LLM, executes it against the connected Memgraph instance, and returns the results to the LLM. This allows the LLM to leverage the graph database for knowledge retrieval, reasoning, and data manipulation. The executed queries can be complex, involving multiple relationships and filtering criteria, allowing the LLM to perform sophisticated data analysis.

For example, an LLM could use run_query() to find all customers who bought a specific product and then identify other products those customers also purchased. This enables personalized recommendations and targeted marketing campaigns. The technical implementation involves establishing a connection to the Memgraph database using a suitable driver (e.g., Bolt protocol) and then using the driver to execute the Cypher query.

Memgraph Schema Retrieval

mcp-memgraph provides the get_schema() resource, allowing LLMs to dynamically retrieve the schema information of the connected Memgraph database. This is crucial for LLMs to understand the structure of the graph, including node labels, relationship types, and properties. By understanding the schema, the LLM can generate more accurate and relevant Cypher queries, avoiding syntax errors and ensuring that the queries target the correct data elements. The schema information is retrieved by executing the SHOW SCHEMA INFO query in Memgraph, which must be enabled via the --schema-info-enabled=True configuration.

For instance, if an LLM needs to find all movies directed by a specific director, it can first use get_schema() to determine the correct node label for movies (e.g., "Movie") and the relationship type connecting directors to movies (e.g., "DIRECTED"). This ensures that the generated Cypher query is syntactically correct and targets the appropriate data. The technical implementation involves executing the SHOW SCHEMA INFO query and parsing the results into a structured format that can be easily understood by the LLM.

LLM-Memgraph Integration via MCP

mcp-memgraph acts as a bridge, enabling seamless integration between LLMs and the Memgraph graph database through the Model Context Protocol (MCP). This integration allows LLMs to leverage the unique capabilities of graph databases, such as relationship analysis and pattern recognition, while also benefiting from the natural language understanding and generation capabilities of LLMs. By adhering to the MCP standard, mcp-memgraph ensures interoperability with various LLM clients and servers, fostering a flexible and extensible ecosystem.

Consider a scenario where an LLM is used to build a knowledge graph from unstructured text data. The LLM can use mcp-memgraph to store the extracted entities and relationships in Memgraph, creating a structured representation of the knowledge. This knowledge graph can then be queried by the LLM to answer questions, generate summaries, or perform other knowledge-intensive tasks. The MCP integration simplifies the process of connecting the LLM to Memgraph, abstracting away the complexities of database connectivity and query execution.