Skip to content

API Surface

GraphQL Schema

The gateway (services/gateway) exposes a GraphQL API over HTTP and WebSocket (graphql-ws). The schema is code-first via Pothos with Zod-derived types.

The committed SDL lives at services/gateway/schema.graphql — it is auto-generated and CI-verified:

Terminal window
pnpm --filter @mnemose/gateway schema:export # regenerate
pnpm --filter @mnemose/gateway schema:check # verify committed SDL matches

This page summarizes the surface. The SDL is the authoritative contract — the counts below drift as the schema evolves; treat the SDL as truth.

Queries (representative)

The schema currently exposes ~49 queries. Representative groups:

GroupQueries
Tenancy / identitymyTenants, org, projects, groups, user, workspace, tenantKey
Cloud projectscloudProjects, deployments(cloudProjectId), resources, adoptedResource(s)
IAMiamEscalation(id), iamEscalations, iamRoleBindings(principalId, principalType), evaluateToolPermission(riskScore, toolName)
Kernelskernel(id), kernels(status), kernelSessions, kernelInvocations
Provisioning / remediationprovisionJobs, provisionStatus, remediationJobs
Apps / toolsapp(id), appHealth(id), installedApps, availableApps, availableCloudProviders, listTools, searchTools
Models / telemetryavailableLlmProviderKinds, modelCall(id), modelCalls(limit, offset)
Sandboxessandbox, sandboxes, execSandbox, execSandboxes
Reportsreports
Bootstrap / environmentsbootstrapStates(targetType), environment(s)
EvaluationsevaluationRun(id)
Platform coreplatformCore — health of the kernels declared in CoreManifest

Mutations (representative)

The schema currently exposes ~70 mutations. Representative groups:

GroupMutations
OnboardingregisterSelf, bootstrapOrganization, bootstrapCloudProject, delegateCloudProject, inviteUser, createOrg, createProject, createWorkspace
IAM escalationrequestIamEscalation(input), approveIamEscalation, denyIamEscalation, grantRoleBinding, revokeRoleBinding, setToolPermission, deleteToolPermission
InfrastructureprovisionResource, refreshInfrastructure, previewInfrastructure, deployInfrastructure, remediateFinding, syncResourceInventory, discoverResources, adoptResource, orphanResource
KernelsenrollKernel(input), revokeKernel, requestKernelSession, approveKernelSession, denyKernelSession, invokeKernelTool
ReportsbuildReport
Apps / storeinstallApp(input), uninstallApp(input), enableApp, disableApp, updateAppConfig, registerTool
LLM providerssetLlmProviderConfig, setLlmProviderSecret, syncLlmProviderModels, addLlmProviderModel, updateLlmProviderModel, removeLlmProviderModel, createLlmRoute, updateLlmRoute, deleteLlmRoute, testLlmProviderModel, setLlmPersonaOverride
SandboxescreateSandbox, destroySandbox, execInSandbox, createExecSandbox, destroyExecSandbox, grantSandboxFacet, revokeSandboxFacet, bindSandboxService, unbindSandboxService, updateSandboxNetworkPolicy, updateSandboxDataSources, updateSandboxDeceptionPolicy
Retention / telemetryupsertRetentionPolicy, deleteRetentionPolicy
Platform coreprovisionPlatformCore — idempotently upserts every CoreManifest.kernels[] row in agent_kernels (direct resolver write; no Queue round-trip)

Subscriptions

SubscriptionDescription
deploymentStatus(...)Live infrastructure deployment progress
environmentCreated(...)New environment events
onKernelInvocation(kernelId)Per-kernel tool-invocation results
onKernelMetrics(...)Live kernel metrics
onKernelStatusChanged(...)Live kernel connection state

platformCore query

Returns the health of the platform core as derived from CoreManifest:

type CoreKernelStatus {
id: String!
label: String!
role: String! # e.g. "diagnostics" | "operations"
platform: String! # e.g. "alpine" | "ubuntu"
permissionTier: String! # "read-only" | "workspace-write" | "danger-full-access"
status: String! # "online" | "offline" | "pending" | "missing"
}
type PlatformCoreHealth {
healthy: Boolean!
kernels: [CoreKernelStatus!]!
}

The resolver lives in services/gateway/src/schema/platform.ts. It:

  1. Calls coreManifestForEnv(NODE_ENV) from @mnemose/bootstrap to get the target manifest.
  2. Selects agent_kernels rows for the current tenant scope, filtered to the manifest’s kernel IDs.
  3. Calls assessCoreHealth(manifest, rows) — pure function shared with CLI + tests.
  4. Returns the typed health structure.

The provisionPlatformCore mutation iterates the manifest’s kernels and inserts each row with .onConflictDoNothing(). It is safe to call repeatedly.

Command Schema

All commands are defined in @mnemose/domain/commands as Zod schemas. The canonical type is AnyCommand = z.infer<typeof AnyCommandSchema>. The committed catalog is packages/domain/contracts/index.json (68 command types at last export); regenerate with pnpm --filter @mnemose/domain contracts:export.

Representative command types:

  • RegisterSubscription — tenant creation
  • BootstrapOrganization / BootstrapCloudProject — control-plane onboarding
  • DelegateCloudProject — provider, projectId, region, serviceAccountEmail / roleArn, wifPoolId
  • RequestIamEscalation / ApproveIamEscalation / DenyIamEscalation — escalationId, agentReasoning
  • SyncResourceInventory — cloudProjectId, resourceTypes (optional filter)
  • ProvisionResource — cloudProjectId, spec (discriminated union: compute.Instance | storage.Bucket | iam.ServiceAccount)
  • RemediateFinding — cloudProjectId, findingId, action, agentReasoning, requiresHumanConfirmation
  • BuildReport — reportType, format, periodStart, periodEnd, recipientEmails
  • EnrollKernel / RevokeKernel / InvokeKernelTool — remote kernel lifecycle and dispatch
  • RequestKernelSession / ApproveKernelSession / DenyKernelSession — kernel session tier approvals
  • CreateAgentHarness / UpdateAgentHarness / DeleteAgentHarness — harness aggregate lifecycle
  • InstallApp / UninstallApp / EnableApp / DisableApp / UpdateAppConfig — installable app lifecycle

Domain Event Schema

All domain events are defined in @mnemose/domain/events as Zod schemas and stored append-only in the domain_events table in D1. The committed catalog is packages/domain/contracts/index.json (67 event types at last export).

Representative event types:

  • PlatformSelfRegistered / SubscriptionRegistered / OrganizationBootstrapped
  • CloudProjectDelegated — project registered and credentials validated
  • IamEscalationRequested / IamEscalationApproved / IamEscalationDenied / IamEscalationRevoked
  • ResourceInventorySynced — resource counts by type, sync duration
  • ResourceProvisioningStarted / ResourceProvisioned / ResourceProvisioningFailed
  • FindingRemediated / FindingRemediationFailed
  • ReportGenerated — signed download URL, format, size, recipient list
  • KernelEnrolled / KernelRevoked / KernelOnline / KernelOffline / KernelCertRotated
  • KernelSessionRequested / KernelSessionDecided / KernelSessionExpired
  • KernelInvocationDispatched / KernelInvocationCompleted / KernelInvocationFailed / KernelMetricsCollected — every remote tool call
  • AppInstalled / AppConfigUpdated — installable app lifecycle

MCP Servers

Mnemose ships first-party MCP servers exposing platform surfaces to agents. Each server exposes its tools over stdio (for in-process agent-loop) and HTTP/SSE (for remote agents). Tool schemas are derived from the same Zod types used in the domain layer.

PackageTools
@mnemose/mcp-mnemose-kernelskernel.list, kernel.invoke
@mnemose/mcp-mnemose-servicesservices.list, services.invoke

kernel.invoke dispatches InvokeKernelTool onto the command spine; mutating kernel tools require an approved kernel session (read-only tools do not).

Database Schema

The read model lives in Cloudflare D1 (SQLite) via Drizzle ORM. The authoritative schema is packages/db/src/schema/ and the migrations in packages/db/src/migrations/. Key tables:

TablePurpose
tenantsMulti-tenant SaaS subscriptions
cloud_projectsDelegated customer cloud accounts
iam_escalationsEscalation lifecycle (requested → approved/denied → revoked)
iam_role_bindingsPersistent role bindings per principal
resource_snapshotsCached inventory per resource type / project
provision_jobsProvisioning lifecycle (pending → running → completed/failed)
remediation_jobsRemediation lifecycle (pending → running → completed/failed/awaiting-human)
reportsReport jobs with signed download URLs
agent_kernelsEnrolled remote kernels (CoreManifest rows upsert here)
kernel_sessions / kernel_invocationsSession tiers and per-tool-call audit
agent_harnesses / agent_harness_toolsHarness aggregate (migration 0010)
marketplace_artifactsInstallable apps and harness artifacts
domain_eventsImmutable append-only audit log