MCPcopy Index your code
hub / github.com/modelcontextprotocol/registry / addCursorCondition

Function addCursorCondition

internal/database/postgres.go:157–174  ·  view source on GitHub ↗

addCursorCondition adds pagination cursor condition to WHERE clause. The compound cursor uses a row-constructor comparison so PostgreSQL can seek directly into the (server_name, version) B-tree index. The OR-decomposed form `server_name > X OR (server_name = X AND version > Y)` is logically equival

(cursor string, argIndex int)

Source from the content-addressed store, hash-verified

155// prod). The row-constructor form `(server_name, version) > (X, Y)` is special-
156// cased and stays constant-time regardless of cursor depth.
157func addCursorCondition(cursor string, argIndex int) (string, []any, int) {
158 if cursor == "" {
159 return "", nil, argIndex
160 }
161
162 // Parse cursor format: "serverName:version"
163 parts := strings.SplitN(cursor, ":", 2)
164 if len(parts) == 2 {
165 cursorServerName := parts[0]
166 cursorVersion := parts[1]
167 condition := fmt.Sprintf("(server_name, version) > ($%d, $%d)", argIndex, argIndex+1)
168 return condition, []any{cursorServerName, cursorVersion}, argIndex + 2
169 }
170
171 // Fallback for malformed cursor - treat as server name only for backwards compatibility
172 condition := fmt.Sprintf("server_name > $%d", argIndex)
173 return condition, []any{cursor}, argIndex + 1
174}
175
176func (db *PostgreSQL) ListServers(
177 ctx context.Context,

Callers 1

ListServersMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…