ME
OfficialAI & ML

Memgraph MCP Server for LLM Integration

Connect Memgraph with LLMs and clients using the lightweight MCP server for seamless Model Context Protocol integration and fast, secure data exchange.

Quick Install
npx -y @integrations/mcp-memgraph

Overview

Memgraph MCP Server is a lightweight implementation of the Model Context Protocol (MCP) that exposes Memgraph database capabilities to LLMs and other MCP-aware clients. It bridges LLM-based agents and external applications with Memgraph by wrapping common graph operations, analytics, and vector searches as callable MCP tools. The server is intentionally minimal and configurable so it can be deployed inside Docker or run directly during development.

Using this server lets you safely run read-only exploration queries by default, discover available procedures (including MAGE algorithms), compute graph analytics (PageRank, betweenness), and perform node vector similarity searches — all through the same MCP endpoint. This makes it easier to integrate Memgraph-backed context retrieval or reasoning into LLM-driven pipelines and client applications.

Features

  • MCP-compliant server exposing Memgraph operations as tools
  • Read-only default mode to prevent accidental writes
  • Vector similarity search over node vectors (cosine similarity)
  • Graph analytics tools: PageRank, Betweenness Centrality
  • Schema, index, constraint, storage and trigger discovery tools
  • Procedure discovery (list MAGE and custom procedures with write flags)
  • Supports two transports: streamable-http (default) and stdio
  • Docker-first distribution for easy deployment

Installation / Configuration

Build the Docker image (from ai-toolkit root) to include local memgraph-toolbox code:

cd /path/to/ai-toolkit
docker build -f integrations/mcp-memgraph/Dockerfile -t mcp-memgraph:latest .

Run the image (streamable HTTP mode — recommended):

docker run --rm -p 8000:8000 mcp-memgraph:latest
# MCP server will be reachable at http://localhost:8000/mcp/

Run in stdio mode (for integrating with MCP stdio clients):

docker run --rm -i -e MCP_TRANSPORT=stdio mcp-memgraph:latest

Connect to an external Memgraph instance (no host networking):

docker run --rm -p 8000:8000 \
  -e MEMGRAPH_URL=bolt://memgraph:7687 \
  -e MEMGRAPH_USER=myuser \
  -e MEMGRAPH_PASSWORD=password \
  mcp-memgraph:latest

Environment variables (defaults shown):

VariablePurposeDefault
MEMGRAPH_URLBolt URL for Memgraph connectionbolt://host.docker.internal:7687
MEMGRAPH_USERMemgraph usernamememgraph
MEMGRAPH_PASSWORDMemgraph password(empty)
MEMGRAPH_DATABASEDatabase namememgraph
MCP_SERVERServer implementation: server or memgraph-experimentalserver
MCP_TRANSPORTTransport: streamable-http or stdiostreamable-http
MCP_READ_ONLYBlock write queries when truetrue

Notes:

  • The memgraph-experimental server provides experimental features (adaptive query/index management) and may require write permissions; it ignores MCP_READ_ONLY.
  • MCP_READ_ONLY blocks write Cypher statements (CREATE, MERGE, DELETE, SET, DROP, REMOVE) when enabled.

Available Tools

Each tool runs a memgraph-toolbox operation and returns a list of records (dictionaries).

  • run_query(query: str)
    • Execute arbitrary Cypher.
    • Read-only mode blocks write queries by default.
  • get_configuration()
    • Returns SHOW CONFIGURATION output.
  • get_index()
    • Returns SHOW INDEX INFO.
  • get_constraint()
    • Returns SHOW CONSTRAINT INFO.
  • get_schema()
    • Returns SHOW SCHEMA INFO (labels, relationships, keys).
  • get_storage()
    • Returns SHOW STORAGE INFO (node/rel/property usage).
  • get_triggers()
    • Returns SHOW TRIGGERS.
  • get_procedures()
    • Lists procedures (name, signature, write flag). Equivalent to CALL mg.procedures().
  • get_betweenness_centrality()
    • Computes betweenness centrality for the graph.
  • get_page_rank()
    • Computes PageRank scores for nodes.
  • get_node_neighborhood(node_id: str, max_distance: int = 1, limit: int = 100)
    • Returns nodes within specified hops.
  • search_node_vectors(index_name: str, query_vector: [float], limit: int = 10)
    • Vector similarity (cosine) search over node vectors.

Example: Calling run_query via HTTP

Send an MCP-compliant request to the server (POST to /mcp/). Example JSON payload pattern:

curl -X POST http://localhost:8000/mcp/ \
  -H "Content-Type: application/json" \
  -d '{
    "type": "tool_request",
    "tool": "run_query",
    "input": {"query": "MATCH (n) RETURN n LIMIT 5"}
  }'

Typical response: a JSON array of record dictionaries (tool-specific). Example:

{
  "type": "tool_response",
  "tool": "run_query",
  "output": [
    {"n": {"id": 0, "labels": ["Person"], "properties": {"name":"Alice"}}},
    {"n": {"id": 1, "labels": ["Person"], "properties": {"name":"Bob"}}}
  ]
}

(Protocol envelope keys may vary slightly by MCP implementation; this example shows the typical request/response idea.)

Use Cases

  • LLM-assisted knowledge retrieval: Use search_node_vectors to find semantically relevant nodes and pass results to an LLM for augmented responses.
  • Graph analytics in agent workflows: Invoke get_page_rank or get_betweenness_centrality to surface important nodes for downstream reasoning.
  • Schema and capability discovery: Before running complex operations, call get_procedures, get_index, and get_schema to understand available algorithms and indexes.
  • Controlled data exploration: Developers can leave MCP_READ_ONLY=true to let LLMs run read-only queries safely, reducing risk of accidental mutations.
  • Neighborhood expansion for context windows: Use get_node_neighborhood to extract surrounding subgraphs to include as context for LLM prompts.

Tips for Developers

  • Start with MCP_READ_ONLY=true while experimenting to avoid accidental data changes.
  • Use get_procedures to discover available MAGE algorithms that you can call via run_query.
  • When deploying behind proxies or service meshes, ensure the chosen transport (HTTP or stdio) is compatible with your orchestration setup.
  • For production systems that need autonomous indexing or optimization, evaluate the experimental server but be aware it may require write access.

For full source and Dockerfile, see the repository: https://github.com/memgraph/ai-toolkit/tree/main/integrations/mcp-memgraph

Tags:ai-ml