diff --git a/integrations/mcp-memgraph/README.md b/integrations/mcp-memgraph/README.md index a9a4b05..dcf5a33 100644 --- a/integrations/mcp-memgraph/README.md +++ b/integrations/mcp-memgraph/README.md @@ -154,6 +154,15 @@ docker run --rm \ mcp-memgraph:latest ``` +### Docker environment variables + +- `MEMGRAPH_URL`: The Bolt URL of the Memgraph instance to connect to. Default: `bolt://host.docker.internal:7687` + - The default value allows you to connect to a Memgraph instance running on your host machine from within the Docker container. +- `MEMGRAPH_USER`: The username for authentication. Default: `memgraph` +- `MEMGRAPH_PASSWORD`: The password for authentication. Default: empty +- `MEMGRAPH_DATABASE`: The database name to connect to. Default: `memgraph` +- `MCP_TRANSPORT`: The transport protocol to use. Options: `http` (default), `stdio` + ### Connecting from VS Code (HTTP server) If you are using VS Code MCP extension or similar, your configuration for an HTTP server would look like: diff --git a/integrations/mcp-memgraph/src/mcp_memgraph/server.py b/integrations/mcp-memgraph/src/mcp_memgraph/server.py index 4dcf5ab..0a1ff8b 100644 --- a/integrations/mcp-memgraph/src/mcp_memgraph/server.py +++ b/integrations/mcp-memgraph/src/mcp_memgraph/server.py @@ -25,14 +25,16 @@ MEMGRAPH_URL = os.environ.get("MEMGRAPH_URL", "bolt://localhost:7687") MEMGRAPH_USER = os.environ.get("MEMGRAPH_USER", "") MEMGRAPH_PASSWORD = os.environ.get("MEMGRAPH_PASSWORD", "") +MEMGRAPH_DATABASE = os.environ.get("MEMGRAPH_DATABASE", "memgraph") -logger.info(f"Connecting to Memgraph at {MEMGRAPH_URL} with user '{MEMGRAPH_USER}'") +logger.info(f"Connecting to Memgraph db '{MEMGRAPH_DATABASE}' at {MEMGRAPH_URL} with user '{MEMGRAPH_USER}'") # Initialize Memgraph client db = Memgraph( url=MEMGRAPH_URL, username=MEMGRAPH_USER, password=MEMGRAPH_PASSWORD, + database=MEMGRAPH_DATABASE, ) diff --git a/memgraph-toolbox/src/memgraph_toolbox/api/memgraph.py b/memgraph-toolbox/src/memgraph_toolbox/api/memgraph.py index f486237..9aaf95d 100644 --- a/memgraph-toolbox/src/memgraph_toolbox/api/memgraph.py +++ b/memgraph-toolbox/src/memgraph_toolbox/api/memgraph.py @@ -13,6 +13,7 @@ def __init__( url: str = None, username: str = None, password: str = None, + database: str = None, driver_config: Optional[Dict] = None, ): """ @@ -22,11 +23,13 @@ def __init__( - MEMGRAPH_URL (default: "bolt://localhost:7687") - MEMGRAPH_USER (default: "") - MEMGRAPH_PASSWORD (default: "") + - MEMGRAPH_DATABASE (default: "memgraph") Args: url: The Memgraph connection URL username: Username for authentication password: Password for authentication + database: The database name to connect to (default: "memgraph") driver_config: Additional Neo4j driver configuration """ @@ -38,6 +41,9 @@ def __init__( self.driver = GraphDatabase.driver( url, auth=(username, password), **(driver_config or {}) ) + + self.database = database or os.environ.get("MEMGRAPH_DATABASE", "memgraph") + try: import neo4j except ImportError: @@ -74,6 +80,7 @@ def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]: data, _, _ = self.driver.execute_query( query, parameters_=params, + database_=self.database, ) json_data = [r.data() for r in data] return json_data @@ -106,7 +113,7 @@ def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]: raise # fallback to allow implicit transactions - with self.driver.session() as session: + with self.driver.session(database=self.database) as session: data = session.run(query, params) json_data = [r.data() for r in data] return json_data