# Endpoint Execution Scopes

When writing Custom Endpoints, your code executes within a specific scope that determines what operations are allowed.

# Endpoints Scope

This is the standard scope for endpoints running on a Primary node or when the system allows write access.

Class: CodeEndpointExecutionScope

Property/Method Type Description
Graph / G Mosaik.GraphDB.Safe.Graph Thread-safe graph for reading and writing.
Query() / Q() IQuery Creates a new query.
Logger ILogger Logger for the scope.
Body string The HTTP request body.
Headers IReadOnlyDictionary Request headers.
CurrentUser UID128 The UID of the authenticated user.
CancellationToken CancellationToken Request cancellation token.
ChatAI ChatAI Chat AI helper.
Tracker QueryTracker Performance tracker.
RelayStatusAsync(msg) Task Send status update to caller.
RunEndpointAsync<T> Task<T> Execute another endpoint locally.
RunEndpointOnPrimaryAsync<T> Task<T> Execute endpoint on Primary (for replicas).
RunToolAsync Task<ToolCallResult> Execute an AI tool.
GetDownloadTokenForFile string Generate a download token for a file.

# Read-Only Endpoints Scope

This scope is used when an endpoint is executed on a Read-Only Replica. You cannot modify the graph directly in this scope. However, you can use RunEndpointOnPrimaryAsync to forward write operations to the primary node.

Class: ReadOnlyCodeEndpointExecutionScope

Property/Method Type Description
Graph / G ReadOnlyGraph Read-only graph access.
Query() / Q() IQuery Creates a new query.
Logger ILogger Logger.
Body string HTTP request body.
CurrentUser UID128 Authenticated user.
RunEndpointOnPrimaryAsync<T> Task<T> Forward execution to the Primary node for writing.

For more on Replicas, see Read-Only Replicas.