# Cypher Functions Supported by Codebase-Memory-MCP: Complete Reference

> Explore the complete reference of Cypher functions supported by Codebase-Memory-MCP. Discover supported string, aggregate, and logical operators for read-only querying.

- Repository: [Martin Vogel/codebase-memory-mcp](https://github.com/DeusData/codebase-memory-mcp)
- Tags: api-reference
- Published: 2026-07-04

---

**Codebase-Memory-MCP supports a read-only subset of OpenCypher including string conversion functions, aggregates, string matching operators, and logical operators, while explicitly blocking all write operations.**

Codebase-Memory-MCP implements a specialized query engine that translates OpenCypher syntax into SQLite SQL for graph analysis of codebases. Understanding which Cypher functions are supported is essential for crafting effective read-only queries against your repository graph. This guide examines the exact function set defined in the lexer keyword table and planner implementation at [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c).

## Built-in String Conversion Functions

The engine provides case-conversion and type-casting utilities for normalizing node and relationship properties. These functions accept case-insensitive identifiers.

- **`toLower()` / `tolower()`** – Converts strings to lowercase
- **`toUpper()` / `toupper()`** – Converts strings to uppercase  
- **`toString()` / `tostring()`** – Casts values to string representation

These are hard-coded in the keyword lexer at [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c) (lines 70-80).

## Aggregate Functions for Graph Analytics

Codebase-Memory-MCP supports standard OpenCypher aggregates for computing summary statistics across matched paths. These functions operate on collections of values and are defined at lines 63-71 in [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c).

- **`COUNT`** – Returns the number of matching elements
- **`SUM`** – Calculates the total of numeric values
- **`AVG`** – Computes the arithmetic mean
- **`MIN`** – Finds the minimum value
- **`MAX`** – Finds the maximum value
- **`COLLECT`** – Aggregates values into a list

```cypher
-- Count all function calls in the codebase
MATCH (caller)-[r:CALLS]->(callee) 
RETURN COUNT(r) AS totalCalls

```

## String Matching and Comparison Operators

The engine implements pattern matching predicates as tokenized operators rather than function calls. These are recognized at lines 48-55 in [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c).

- **`CONTAINS`** – Substring inclusion test
- **`STARTS WITH`** – Prefix match (tokenized as `STARTS`)
- **`ENDS WITH`** – Suffix match (tokenized as `ENDS`)

```cypher
-- Find all files in the source directory
MATCH (f:File) 
WHERE f.path STARTS WITH "/src/" 
RETURN f.name

```

## Logical Operators and Set Predicates

Boolean logic and membership testing are supported through the following operators, defined at lines 41-45 and 56-62 in [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c).

- **`AND`**, **`OR`**, **`NOT`** – Standard Boolean logic
- **`IN`** – Membership test for lists
- **`IS NULL`** – Null value checking
- **`XOR`** – Exclusive disjunction

## Control Flow with CASE Expressions

While not a function, the conditional **`CASE … WHEN … THEN … ELSE … END`** expression is fully supported for creating computed fields in RETURN clauses. This control-flow structure is implemented at lines 73-80 in [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c).

```cypher
-- Categorize nodes by status
MATCH (n) 
RETURN CASE 
  WHEN n.active = true THEN "online" 
  ELSE "offline" 
END AS status

```

## Query Constraints and Engine Limits

The Cypher engine enforces strict resource boundaries defined as constants in the source code. Queries exceeding these limits are rejected early in the planning phase.

- **`CYP_MAX_VARS`** – Maximum of 16 query variables per statement
- **`CYP_MAX_DEPTH`** – Maximum traversal depth of 10 relationships

Additionally, the engine is strictly read-only. All write-oriented keywords are identified during lexing and rejected with an "unsupported Cypher feature" error before execution.

## Blocked Write Operations

The following OpenCypher keywords are explicitly recognized but blocked at parse time (lines 84-103 in [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c)). Any query containing these will fail immediately.

- Data manipulation: `CREATE`, `DELETE`, `DETACH`, `SET`, `REMOVE`, `MERGE`
- Schema operations: `DROP`, `CONSTRAINT`
- Procedural clauses: `YIELD`, `CALL`, `FOREACH`

This security model ensures the codebase graph remains immutable through the query interface.

## Practical Query Examples

The following queries demonstrate valid syntax against the Codebase-Memory-MCP engine:

```cypher
-- Case-insensitive name lookup
MATCH (n) 
WHERE toLower(n.name) = "alice" 
RETURN n

-- Aggregate analysis of call relationships
MATCH (a)-[e:CALLS]->(b) 
RETURN COUNT(e) AS callCount

-- Path containment search
MATCH (f) 
WHERE f.path CONTAINS "/tests/" 
RETURN f

-- Conditional aggregation with CASE
MATCH (p:Project) 
RETURN CASE 
  WHEN p.stars > 100 THEN "popular" 
  ELSE "standard" 
END AS projectTier

```

## Implementation Details and Source File Locations

The Cypher function support is distributed across four core files in the repository:

| File | Role |
|------|-------|
| [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c) | Contains the keyword lexer (lines 41-103), parser, query planner, and executor implementation |
| [`src/cypher/cypher.h`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.h) | Public API exposing `cbm_cypher_query` for external callers |
| [`src/cli/cli.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cli/cli.c) | Command-line wrapper that forwards `query_graph` Cypher strings to the engine |
| [`src/store/store.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/store/store.c) | SQLite storage layer where translated SQL statements are executed |

According to the DeusData/codebase-memory-mcp source code, the hard-coded keyword tables in [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c) serve as the single source of truth for supported functionality.

## Summary

- Codebase-Memory-MCP supports **scalar functions** (`toLower`, `toUpper`, `toString`), **aggregates** (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`, `COLLECT`), and **operators** (`CONTAINS`, `STARTS WITH`, `ENDS WITH`, `AND`, `OR`, `NOT`, `IN`, `IS NULL`, `XOR`).
- The engine implements **CASE expressions** for conditional logic but rejects all **write operations** (`CREATE`, `DELETE`, `SET`, `MERGE`, etc.) at parse time.
- Query complexity is constrained by `CYP_MAX_VARS` (16 variables) and `CYP_MAX_DEPTH` (10 levels).
- All function definitions reside in [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c), with the public API exposed through [`src/cypher/cypher.h`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.h).

## Frequently Asked Questions

### Does Codebase-Memory-MCP support user-defined functions?

No. The engine only recognizes the built-in functions hard-coded in [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c). There is no extension mechanism for registering custom Cypher functions or procedures in the current implementation.

### Why are write operations like CREATE and DELETE blocked?

The engine is designed as a read-only analysis tool for codebases. Write keywords are explicitly identified in the lexer (lines 84-103 of [`src/cypher/cypher.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cypher/cypher.c)) and rejected with an "unsupported Cypher feature" error to prevent accidental modification of the graph data.

### Are Cypher functions case-sensitive?

Function names are case-insensitive for the supported string conversion utilities. Both `toLower()` and `tolower()` execute identically, as the lexer normalizes these tokens before the planner processes the abstract syntax tree.

### What happens if a query exceeds the 16-variable limit?

Queries referencing more than 16 distinct variables (the `CYP_MAX_VARS` constant) fail during the planning phase with an error indicating the query is too complex. This limit prevents excessive memory consumption during SQL translation and execution.